1 /* === S Y N F I G ========================================================= */
2 /*! \file action_system.h
3 ** \brief Template Header
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === S T A R T =========================================================== */
25 #ifndef __SYNFIGAPP_ACTIONSYSTEM_H
26 #define __SYNFIGAPP_ACTIONSYSTEM_H
28 /* === H E A D E R S ======================================================= */
31 #include <sigc++/signal.h>
32 #include <sigc++/object.h>
34 #include <synfig/canvas.h>
35 #include "uimanager.h"
37 /* === M A C R O S ========================================================= */
39 /* === T Y P E D E F S ===================================================== */
41 /* === C L A S S E S & S T R U C T S ======================================= */
45 class CanvasInterface;
55 //! Passive action grouping class
58 etl::loose_handle<System> instance_;
60 bool redraw_requested_;
62 etl::handle<CanvasInterface> canvas_interface_;
65 PassiveGrouper(etl::loose_handle<System> instance_,synfig::String name_);
69 const synfig::String &get_name()const { return name_; }
71 void set_name(const synfig::String &x) { name_=x; }
73 etl::loose_handle<System> get_instance() { return instance_; }
75 void request_redraw(etl::handle<CanvasInterface>);
79 void inc_depth() { depth_++; }
81 void dec_depth() { depth_--; }
83 const int &get_depth()const { return depth_; }
84 }; // END of class Action::PassiveGrouper
86 typedef std::list< etl::handle<Action::Undoable> > Stack;
88 class System : public etl::shared_object, public sigc::trackable
90 friend class PassiveGrouper;
93 -- ** -- P U B L I C T Y P E S ---------------------------------------------
99 -- ** -- P U B L I C D A T A ------------------------------------------------
105 -- ** -- P R I V A T E D A T A ---------------------------------------------
110 Stack undo_action_stack_;
111 Stack redo_action_stack_;
113 etl::handle<Action::Base> most_recent_action_;
115 std::list<PassiveGrouper*> group_stack_;
117 sigc::signal<void,bool> signal_undo_status_;
118 sigc::signal<void,bool> signal_redo_status_;
119 sigc::signal<void,etl::handle<Action::Undoable> > signal_new_action_;
120 sigc::signal<void> signal_undo_stack_cleared_;
121 sigc::signal<void> signal_redo_stack_cleared_;
122 sigc::signal<void> signal_undo_;
123 sigc::signal<void> signal_redo_;
124 sigc::signal<void,etl::handle<Action::Undoable> > signal_action_status_changed_;
126 mutable sigc::signal<void,bool> signal_unsaved_status_changed_;
128 //! If this is non-zero, then the changes have not yet been saved.
129 mutable int action_count_;
131 etl::handle<UIInterface> ui_interface_;
133 bool clear_redo_stack_on_new_action_;
136 -- ** -- P R I V A T E M E T H O D S ---------------------------------------
141 bool undo_(etl::handle<UIInterface> uim);
142 bool redo_(etl::handle<UIInterface> uim);
145 -- ** -- S I G N A L T E R M I N A L S -------------------------------------
151 -- ** -- P U B L I C M E T H O D S -----------------------------------------
160 template <typename T> bool
163 etl::handle<Action::Base> action((Action::Base*)new T(x));
164 return perform_action(action);
168 const etl::handle<Action::Base>& get_most_recent_action() { return most_recent_action_; }
170 bool get_clear_redo_stack_on_new_action()const { return clear_redo_stack_on_new_action_; }
172 void set_clear_redo_stack_on_new_action(bool x) { clear_redo_stack_on_new_action_=x; }
174 bool perform_action(etl::handle<Action::Base> action);
176 bool set_action_status(etl::handle<Action::Undoable> action, bool x);
178 const Stack &undo_action_stack()const { return undo_action_stack_; }
180 const Stack &redo_action_stack()const { return redo_action_stack_; }
182 //! Undoes the last action
185 //! Redoes the last undone action
188 //! Clears the undo stack.
189 void clear_undo_stack();
191 //! Clears the redo stack.
192 void clear_redo_stack();
194 //! Increments the action counter
195 /*! \note You should not have to call this under normal circumstances.
196 ** \see dec_action_count(), reset_action_count(), get_action_count() */
197 void inc_action_count()const;
199 //! Decrements the action counter
200 /*! \note You should not have to call this under normal circumstances.
201 ** \see inc_action_count(), reset_action_count(), get_action_count() */
202 void dec_action_count()const;
204 //! Resets the action counter
205 /*! \note You should not have to call this under normal circumstances.
206 ** \see inc_action_count(), dec_action_count(), get_action_count() */
207 void reset_action_count()const;
209 //! Returns the number of actions performed since last save.
210 /*! \see inc_action_count(), dec_action_count(), reset_action_count() */
211 int get_action_count()const { return action_count_; }
213 void set_ui_interface(const etl::handle<UIInterface> &uim) { assert(uim); ui_interface_=uim; }
214 void unset_ui_interface() { ui_interface_=new DefaultUIInterface(); }
215 const etl::handle<UIInterface> &get_ui_interface() { return ui_interface_; }
218 -- ** -- S I G N A L I N T E R F A C E S -----------------------------------
223 sigc::signal<void,bool>& signal_unsaved_status_changed() { return signal_unsaved_status_changed_; }
225 sigc::signal<void,bool>& signal_undo_status() { return signal_undo_status_; }
227 sigc::signal<void,bool>& signal_redo_status() { return signal_redo_status_; }
229 sigc::signal<void>& signal_undo_stack_cleared() { return signal_undo_stack_cleared_; }
231 sigc::signal<void>& signal_redo_stack_cleared() { return signal_redo_stack_cleared_; }
233 sigc::signal<void>& signal_undo() { return signal_undo_; }
235 sigc::signal<void>& signal_redo() { return signal_redo_; }
237 //! Called whenever an undoable action is processed and added to the stack.
238 sigc::signal<void,etl::handle<Action::Undoable> >& signal_new_action() { return signal_new_action_; }
240 sigc::signal<void,etl::handle<Action::Undoable> >& signal_action_status_changed() { return signal_action_status_changed_; }
242 }; // END of class Action::System
245 }; // END of namespace synfigapp::Action
246 }; // END of namespace synfigapp
248 /* === E N D =============================================================== */