'quit -> "want to save?" -> yes -> cancel' should go back to working on the unsaved...
[synfig.git] / synfig-studio / trunk / src / gtkmm / instance.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file gtkmm/instance.h
3 **      \brief writeme
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_STUDIO_INSTANCE_H
26 #define __SYNFIG_STUDIO_INSTANCE_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include <ETL/handle>
31 #include <gtkmm/treeview.h>
32 #include <gtkmm/treestore.h>
33 #include <synfigapp/instance.h>
34 #include <sigc++/object.h>
35 #include <synfigapp/value_desc.h>
36 #include "historytreestore.h"
37 #include <synfig/canvas.h>
38
39 /* === M A C R O S ========================================================= */
40 #define DEFAULT_FILENAME_PREFIX _("Synfig Animation ") // will be followed by a different number for each document
41
42 /* === T Y P E D E F S ===================================================== */
43
44 /* === C L A S S E S & S T R U C T S ======================================= */
45
46 namespace Gtk { class Menu; class ActionGroup; };
47
48 namespace studio {
49
50 class CanvasView;
51
52
53 class Instance : public synfigapp::Instance
54 {
55 public:
56         typedef std::list< etl::handle<CanvasView> > CanvasViewList;
57
58         enum Status
59         {
60                 STATUS_OK,
61                 STATUS_ERROR,
62                 STATUS_CANCEL
63         };
64
65         class CanvasTreeModel : public Gtk::TreeModel::ColumnRecord
66         {
67         public:
68                 Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > icon;
69                 Gtk::TreeModelColumn<Glib::ustring> label;
70                 Gtk::TreeModelColumn<Glib::ustring> name;
71                 Gtk::TreeModelColumn<Glib::ustring> id;
72
73                 Gtk::TreeModelColumn<synfig::Canvas::Handle> canvas;
74                 Gtk::TreeModelColumn<bool> is_canvas;
75
76                 Gtk::TreeModelColumn<synfig::ValueNode::Handle> value_node;
77                 Gtk::TreeModelColumn<bool> is_value_node;
78                 Gtk::TreeModelColumn<synfig::ValueBase> value;
79                 Gtk::TreeModelColumn<Glib::ustring> type;
80                 Gtk::TreeModelColumn<int> link_id;
81                 Gtk::TreeModelColumn<int> link_count;
82
83                 Gtk::TreeModelColumn<bool> is_editable;
84
85                 Gtk::TreeModelColumn<synfigapp::ValueDesc> value_desc;
86
87                 CanvasTreeModel()
88                 {
89                         add(value);
90                         add(name);
91                         add(label);
92                         add(icon);
93                         add(type);
94                         add(id);
95                         add(canvas);
96                         add(value_node);
97                         add(is_canvas);
98                         add(is_value_node);
99
100                         add(is_editable);
101                         add(value_desc);
102                         add(link_count);
103                         add(link_id);
104                 }
105         } canvas_tree_model;
106
107 private:
108
109         sigc::signal<void,CanvasView*> signal_canvas_view_created_;
110         sigc::signal<void,CanvasView*> signal_canvas_view_deleted_;
111
112         sigc::signal<void> signal_undo_redo_status_changed_;
113
114         //! Tree containing the canvases -- used for the "canvas browser"
115         Glib::RefPtr<Gtk::TreeStore> canvas_tree_store_;
116
117         //! Tree containing the actions -- used for the "canvas browser"
118         Glib::RefPtr<HistoryTreeStore> history_tree_store_;
119
120         //! Instance number
121         int     id_;
122
123         //! Used to calculate instance ID
124         static int instance_count_;
125
126         //! List of canvas view windows
127         CanvasViewList canvas_view_list_;
128
129         bool undo_status_;
130         bool redo_status_;
131
132         void set_undo_status(bool x);
133         void set_redo_status(bool x);
134
135         static void _revert(Instance *);
136
137 protected:
138
139         Instance(synfig::Canvas::Handle);
140
141 public:
142
143         sigc::signal<void>& signal_undo_redo_status_changed() { return signal_undo_redo_status_changed_; }
144
145         ~Instance();
146
147         sigc::signal<void,CanvasView*>& signal_canvas_view_created() { return signal_canvas_view_created_; }
148         sigc::signal<void,CanvasView*>& signal_canvas_view_deleted() { return signal_canvas_view_deleted_; }
149
150         bool get_undo_status()const { return undo_status_; }
151
152         bool get_redo_status()const { return redo_status_; }
153
154         int get_visible_canvases()const;
155
156         Glib::RefPtr<Gtk::TreeStore> canvas_tree_store() { return canvas_tree_store_; }
157
158         Glib::RefPtr<const Gtk::TreeStore> canvas_tree_store()const { return canvas_tree_store_; }
159
160         Glib::RefPtr<HistoryTreeStore> history_tree_store() { return history_tree_store_; }
161
162         Glib::RefPtr<const HistoryTreeStore> history_tree_store()const { return history_tree_store_; }
163
164         //! Returns the number of instances that are currently open in the program
165         static int get_count() { return instance_count_; }
166
167         //etl::handle<synfig::Canvas> get_canvas()const { return synfigapp::Instance::get_canvas(); }
168
169         etl::handle<CanvasView> find_canvas_view(etl::handle<synfig::Canvas> canvas);
170
171         //! Sets the focus to a specific canvas
172         void focus(etl::handle<synfig::Canvas> canvas);
173
174         CanvasViewList & canvas_view_list() { return canvas_view_list_; }
175
176         const CanvasViewList & canvas_view_list()const { return canvas_view_list_; }
177
178         bool save_as(const synfig::String &filename);
179
180         //! Opens a "Save As" dialog, and then saves the composition to that file
181         //! returns true if the save was successful
182         bool dialog_save_as();
183
184         Status save();
185
186         void dialog_cvs_commit();
187
188         void dialog_cvs_add();
189
190         void dialog_cvs_update();
191
192         void dialog_cvs_revert();
193
194         //! Closes the instance of this composition
195         void close();
196
197         void revert();
198
199         void update_all_titles();
200
201         void refresh_canvas_tree();
202
203         bool safe_revert();
204         bool safe_close();
205
206         void add_actions_to_menu(Gtk::Menu *menu,   const synfigapp::Action::ParamList &param_list, synfigapp::Action::Category category=synfigapp::Action::CATEGORY_ALL)const;
207         void add_actions_to_menu(Gtk::Menu *menu, const synfigapp::Action::ParamList &param_list1,const synfigapp::Action::ParamList &param_list2, synfigapp::Action::Category category=synfigapp::Action::CATEGORY_ALL)const;
208
209         void add_actions_to_group(const Glib::RefPtr<Gtk::ActionGroup>& action_group, synfig::String& ui_info,   const synfigapp::Action::ParamList &param_list, synfigapp::Action::Category category=synfigapp::Action::CATEGORY_ALL)const;
210
211         void process_action(synfig::String name, synfigapp::Action::ParamList param_list);
212
213         void make_param_menu(Gtk::Menu *menu,synfig::Canvas::Handle canvas, synfigapp::ValueDesc value_desc, float location=0.5f);
214
215         void make_param_menu(Gtk::Menu *menu,synfig::Canvas::Handle canvas,const std::list<synfigapp::ValueDesc>& value_desc_list);
216
217
218         static void edit_waypoint(synfigapp::ValueDesc value_desc,synfig::Waypoint waypoint);
219
220 private:
221         void insert_canvas(Gtk::TreeRow row,synfig::Canvas::Handle canvas);
222
223 public:
224         static etl::handle<Instance> create(synfig::Canvas::Handle canvas);
225 }; // END class Instance
226
227 }; // END namespace studio
228
229 /* === E N D =============================================================== */
230
231 #endif