00001
00021
00022
00023
00024
00025 #ifndef __SYNFIGAPP_ACTIONSYSTEM_H
00026 #define __SYNFIGAPP_ACTIONSYSTEM_H
00027
00028
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
00038
00039
00040
00041
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 };
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
00094
00095
00096 public:
00097
00098
00099
00100
00101
00102 public:
00103
00104
00105
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
00137
00138
00139 private:
00140
00141 bool undo_(etl::handle<UIInterface> uim);
00142 bool redo_(etl::handle<UIInterface> uim);
00143
00144
00145
00146
00147
00148 private:
00149
00150
00151
00152
00153
00154 public:
00155
00156 System();
00157 ~System();
00158
00159
00160
00161
00162
00163
00164
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
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 };
00243
00244
00245 };
00246 };
00247
00248
00249
00250 #endif