bakery  2.6
App_WithDoc.h
Go to the documentation of this file.
1 /*
2  * Copyright 2000 Murray Cumming
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18 
19 #ifndef BAKERY_APP_WITHDOC_H
20 #define BAKERY_APP_WITHDOC_H
21 
22 #include <bakery/App/App.h>
24 
25 namespace Bakery
26 {
27 
55 class App_WithDoc : virtual public App //virtual because App_WithDoc_Gtk will inherit it via App_With_Doc and via App_Gtk.
56 {
57 public:
59  App_WithDoc(const Glib::ustring& appname = ""); //TODO: appname when using get_derived_widget()
60 
61  virtual ~App_WithDoc();
62 
63  virtual void init(); //overridden to create document.
64 
66  {
70  };
71 
72  static bool file_exists(const Glib::ustring& uri);
73 
74 protected:
75  virtual void init_create_document(); //override this to new() the specific document type.
76 
81  static void add_mime_type(const Glib::ustring& mime_type);
82 
84  virtual Document* get_document();
85 
87  virtual const Document* get_document() const ;
88 
89  virtual void set_document_modified(bool bModified = true);
90 
95  virtual bool open_document(const Glib::ustring& file_uri);
96 
97  //This cannot be virtual, because that would break our ABI.
98  //Hopefully that is not necessary.
105  bool open_document_from_data(const guchar* data, std::size_t length);
106 
107  virtual void document_history_add(const Glib::ustring& file_uri);
108  virtual void document_history_remove(const Glib::ustring& file_uri);
109 
110 public:
111  // We can not take function pointers of these methods in
112  // a derived class if they are protected - for instance, with sigc::mem_fun()
113  //Signal handlers:
114 
115  //Menu items:
116  virtual void on_menu_file_open();
117  virtual void on_menu_file_saveas(); //signal handler.
118  virtual void offer_saveas(); //For direct use.
119  virtual void on_menu_file_save(); //signal handler.
120  virtual void on_menu_file_close();
121 
122  virtual void on_menu_edit_copy();
123  virtual void on_menu_edit_paste();
124  virtual void on_menu_edit_clear();
125 
126 protected:
127  //Document:
128 
130  virtual void on_document_modified(bool modified);
131 
133  virtual bool on_document_load();
134 
135  virtual void offer_to_save_changes();
136 
138  virtual void cancel_close_or_exit();
139 
141  virtual void close_mark_or_destroy();
142 
143  virtual void update_window_title();
144 
145  virtual void after_successful_save(); //e.g. disable File|Save.
146 
147  virtual void ui_warning(const Glib::ustring& text, const Glib::ustring& secondary_text) = 0;
148  virtual Glib::ustring ui_file_select_open(const Glib::ustring& ui_file_select_open = Glib::ustring()) = 0;
149 
154  virtual Glib::ustring ui_file_select_save(const Glib::ustring& old_file_uri) = 0;
155 
156  virtual void ui_show_modification_status() = 0;
157 
159 
160  static Glib::ustring get_conf_fullkey(const Glib::ustring& key);
161 
162  //Document:
163  Document* m_pDocument; //An instance of a derived type.
165 
166  //Mime types which this application can load and save:
167  typedef std::list<Glib::ustring> type_list_strings;
168  static type_list_strings m_mime_types;
169 };
170 
171 } //namespace
172 
173 #endif //BAKERY_APP_WITHDOC_H
Main Window which supports documents.
Definition: App_WithDoc.h:55
virtual Glib::ustring ui_file_select_save(const Glib::ustring &old_file_uri)=0
Present a user interface that allows the user to select a location to save the file.
Definition: App_WithDoc.h:67
virtual ~App_WithDoc()
App_WithDoc(const Glib::ustring &appname="")
Don't forget to call init() too.
virtual void init()
static void add_mime_type(const Glib::ustring &mime_type)
Add a MIME-type that this application can support.
enumSaveChanges
Definition: App_WithDoc.h:65
virtual void on_menu_file_saveas()
virtual void offer_saveas()
virtual void update_window_title()
virtual void on_menu_file_save()
virtual void on_menu_file_close()
virtual void init_create_document()
virtual void document_history_add(const Glib::ustring &file_uri)
static Glib::ustring get_conf_fullkey(const Glib::ustring &key)
Definition: App_WithDoc.h:69
virtual void set_document_modified(bool bModified=true)
Document * m_pDocument
Definition: App_WithDoc.h:163
virtual void ui_show_modification_status()=0
static type_list_strings m_mime_types
Definition: App_WithDoc.h:168
virtual void offer_to_save_changes()
static bool file_exists(const Glib::ustring &uri)
virtual void on_document_modified(bool modified)
Update visual status.
The Document is like the 'Model' in the Model-View-Controller framework.
Definition: Document.h:34
Definition: App_WithDoc.h:68
Definition: App.h:29
virtual void on_menu_edit_clear()
Bakery's Main Window.
Definition: App.h:60
virtual bool on_document_load()
override this to show document contents.
virtual Document * get_document()
static_cast<> or dynamic_cast<> this pointer to the correct type.
bool m_bCloseAfterSave
Definition: App_WithDoc.h:164
bool open_document_from_data(const guchar *data, std::size_t length)
Open the document using the supplied document contents.
virtual Glib::ustring ui_file_select_open(const Glib::ustring &ui_file_select_open=Glib::ustring())=0
virtual void on_menu_edit_copy()
virtual void close_mark_or_destroy()
destroy it or mark it for destruction.
virtual enumSaveChanges ui_offer_to_save_changes()=0
virtual void cancel_close_or_exit()
Stop the File|Close or the File|Exit.
virtual void after_successful_save()
std::list< Glib::ustring > type_list_strings
Definition: App_WithDoc.h:167
virtual bool open_document(const Glib::ustring &file_uri)
Open the document from a file at a URI.
virtual void document_history_remove(const Glib::ustring &file_uri)
virtual void on_menu_edit_paste()
virtual void ui_warning(const Glib::ustring &text, const Glib::ustring &secondary_text)=0
virtual void on_menu_file_open()