- Main Page
- Related Pages
- Namespaces
- Classes
- Files

# action_system.h

Go to the documentation of this file.

    00001 /* === S Y N F I G ========================================================= */
    00021 /* ========================================================================= */
    00022
    00023 /* === S T A R T =========================================================== */
    00024
    00025 #ifndef __SYNFIGAPP_ACTIONSYSTEM_H
    00026 #define __SYNFIGAPP_ACTIONSYSTEM_H
    00027
    00028 /* === H E A D E R S ======================================================= */
    00029
    00030 #include "action.h"
    00031 #include <sigc++/signal.h>
    00032 #include <sigc++/object.h>
    00033 #include <ETL/handle>
    00034 #include <synfig/canvas.h>
    00035 #include "uimanager.h"
    00036
    00037 /* === M A C R O S ========================================================= */
    00038
    00039 /* === T Y P E D E F S ===================================================== */
    00040
    00041 /* === C L A S S E S & S T R U C T S ======================================= */
    00042
    00043 namespace synfigapp {
    00044
    00045 class CanvasInterface;
    00046
    00047 namespace Action {
    00048
    00049
    00050
    00051
    00052
    00053 class System;
    00054
    00056 class PassiveGrouper
    00057 {
    00058     etl::loose_handle<System> instance_;
    00059     synfig::String name_;
    00060     bool redraw_requested_;
    00061     int depth_;
    00062     etl::handle<CanvasInterface> canvas_interface_;
    00063 public:
    00064
    00065     PassiveGrouper(etl::loose_handle<System> instance_,synfig::String name_);
    00066
    00067     ~PassiveGrouper();
    00068
    00069     const synfig::String &get_name()const { return name_; }
    00070
    00071     void set_name(const synfig::String &x) { name_=x; }
    00072
    00073     etl::loose_handle<System> get_instance() { return instance_; }
    00074
    00075     void request_redraw(etl::handle<CanvasInterface>);
    00076
    00077     void cancel();
    00078
    00079     void inc_depth() { depth_++; }
    00080
    00081     void dec_depth() { depth_--; }
    00082
    00083     const int &get_depth()const { return depth_; }
    00084 }; // END of class Action::PassiveGrouper
    00085
    00086 typedef std::list< etl::handle<Action::Undoable> > Stack;
    00087
    00088 class System : public etl::shared_object, public sigc::trackable
    00089 {
    00090     friend class PassiveGrouper;
    00091
    00092     /*
    00093  -- ** -- P U B L I C   T Y P E S ---------------------------------------------
    00094     */
    00095
    00096 public:
    00097
    00098     /*
    00099  -- ** -- P U B L I C  D A T A ------------------------------------------------
    00100     */
    00101
    00102 public:
    00103
    00104     /*
    00105  -- ** -- P R I V A T E   D A T A ---------------------------------------------
    00106     */
    00107
    00108 private:
    00109
    00110     Stack undo_action_stack_;
    00111     Stack redo_action_stack_;
    00112
    00113     etl::handle<Action::Base> most_recent_action_;
    00114
    00115     std::list<PassiveGrouper*> group_stack_;
    00116
    00117     sigc::signal<void,bool> signal_undo_status_;
    00118     sigc::signal<void,bool> signal_redo_status_;
    00119     sigc::signal<void,etl::handle<Action::Undoable> > signal_new_action_;
    00120     sigc::signal<void> signal_undo_stack_cleared_;
    00121     sigc::signal<void> signal_redo_stack_cleared_;
    00122     sigc::signal<void> signal_undo_;
    00123     sigc::signal<void> signal_redo_;
    00124     sigc::signal<void,etl::handle<Action::Undoable> > signal_action_status_changed_;
    00125
    00126     mutable sigc::signal<void,bool> signal_unsaved_status_changed_;
    00127
    00129     mutable int action_count_;
    00130
    00131     etl::handle<UIInterface> ui_interface_;
    00132
    00133     bool clear_redo_stack_on_new_action_;
    00134
    00135     /*
    00136  -- ** -- P R I V A T E   M E T H O D S ---------------------------------------
    00137     */
    00138
    00139 private:
    00140
    00141     bool undo_(etl::handle<UIInterface> uim);
    00142     bool redo_(etl::handle<UIInterface> uim);
    00143
    00144     /*
    00145  -- ** -- S I G N A L   T E R M I N A L S -------------------------------------
    00146     */
    00147
    00148 private:
    00149
    00150     /*
    00151  -- ** -- P U B L I C   M E T H O D S -----------------------------------------
    00152     */
    00153
    00154 public:
    00155
    00156     System();
    00157     ~System();
    00158
    00159     /*
    00160     template <typename T> bool
    00161     perform_action(T x)
    00162     {
    00163         etl::handle<Action::Base> action((Action::Base*)new T(x));
    00164         return perform_action(action);
    00165     }
    00166     */
    00167
    00168     const etl::handle<Action::Base>& get_most_recent_action() { return most_recent_action_; }
    00169
    00170     bool get_clear_redo_stack_on_new_action()const { return clear_redo_stack_on_new_action_; }
    00171
    00172     void set_clear_redo_stack_on_new_action(bool x) { clear_redo_stack_on_new_action_=x; }
    00173
    00174     bool perform_action(etl::handle<Action::Base> action);
    00175
    00176     bool set_action_status(etl::handle<Action::Undoable> action, bool x);
    00177
    00178     const Stack &undo_action_stack()const { return undo_action_stack_; }
    00179
    00180     const Stack &redo_action_stack()const { return redo_action_stack_; }
    00181
    00183     bool undo();
    00184
    00186     bool redo();
    00187
    00189     void clear_undo_stack();
    00190
    00192     void clear_redo_stack();
    00193
    00195
    00197     void inc_action_count()const;
    00198
    00200
    00202     void dec_action_count()const;
    00203
    00205
    00207     void reset_action_count()const;
    00208
    00210
    00211     int get_action_count()const { return action_count_; }
    00212
    00213     void set_ui_interface(const etl::handle<UIInterface> &uim) { assert(uim); ui_interface_=uim; }
    00214     void unset_ui_interface() { ui_interface_=new DefaultUIInterface(); }
    00215     const etl::handle<UIInterface> &get_ui_interface() { return ui_interface_; }
    00216
    00217     /*
    00218  -- ** -- S I G N A L   I N T E R F A C E S -----------------------------------
    00219     */
    00220
    00221 public:
    00222
    00223     sigc::signal<void,bool>& signal_unsaved_status_changed() { return signal_unsaved_status_changed_; }
    00224
    00225     sigc::signal<void,bool>& signal_undo_status() { return signal_undo_status_; }
    00226
    00227     sigc::signal<void,bool>& signal_redo_status() { return signal_redo_status_; }
    00228
    00229     sigc::signal<void>& signal_undo_stack_cleared() { return signal_undo_stack_cleared_; }
    00230
    00231     sigc::signal<void>& signal_redo_stack_cleared() { return signal_redo_stack_cleared_; }
    00232
    00233     sigc::signal<void>& signal_undo() { return signal_undo_; }
    00234
    00235     sigc::signal<void>& signal_redo() { return signal_redo_; }
    00236
    00238     sigc::signal<void,etl::handle<Action::Undoable> >& signal_new_action() { return signal_new_action_; }
    00239
    00240     sigc::signal<void,etl::handle<Action::Undoable> >& signal_action_status_changed() { return signal_action_status_changed_; }
    00241
    00242 }; // END of class Action::System
    00243
    00244
    00245 }; // END of namespace synfigapp::Action
    00246 }; // END of namespace synfigapp
    00247
    00248 /* === E N D =============================================================== */
    00249
    00250 #endif