]>
git.saurik.com Git - wxWidgets.git/blob - interface/cmdproc.h
4807c006c7e598ec62a804c3f93e8a61f353cba1
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxCommand class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 wxCommand is a base class for modelling an application command,
14 which is an action usually performed by selecting a menu item, pressing
15 a toolbar button or any other means provided by the application to
16 change the data or view.
24 class wxCommand
: public wxObject
28 Constructor. wxCommand is an abstract class, so you will need to derive
29 a new class and call this constructor from your own constructor.
31 @e canUndo tells the command processor whether this command is undo-able. You
32 can achieve the same functionality by overriding the CanUndo member function
34 the criteria for undoability is context-dependent).
36 @e name must be supplied for the command processor to display the command name
37 in the application's edit menu.
39 wxCommand(bool canUndo
= @
false, const wxString
& name
= @NULL
);
47 Returns @true if the command can be undone, @false otherwise.
52 Override this member function to execute the appropriate action when called.
53 Return @true to indicate that the action has taken place, @false otherwise.
54 Returning @false will indicate to the command processor that the action is
55 not undoable and should not be added to the command history.
57 #define bool Do() /* implementation is private */
60 Returns the command name.
65 Override this member function to un-execute a previous Do.
66 Return @true to indicate that the action has taken place, @false otherwise.
67 Returning @false will indicate to the command processor that the action is
68 not redoable and no change should be made to the command history.
70 How you implement this command is totally application dependent, but typical
73 Perform an inverse operation on the last modified piece of
74 data in the document. When redone, a copy of data stored in command
75 is pasted back or some operation reapplied. This relies on the fact that
76 you know the ordering of Undos; the user can never Undo at an arbitrary position
77 in the command history.
78 Restore the entire document state (perhaps using document transactioning).
79 Potentially very inefficient, but possibly easier to code if the user interface
80 and data are complex, and an 'inverse execute' operation is hard to write.
82 The docview sample uses the first method, to remove or restore segments
90 @class wxCommandProcessor
93 wxCommandProcessor is a class that maintains a history of wxCommands,
94 with undo/redo functionality built-in. Derive a new class from this
95 if you want different behaviour.
101 @ref overview_wxcommandprocessoroverview "wxCommandProcessor overview",
104 class wxCommandProcessor
: public wxObject
110 @e maxCommands may be set to a positive integer to limit the number of
111 commands stored to it, otherwise (and by default) the list of commands can grow
114 wxCommandProcessor(int maxCommands
= -1);
119 ~wxCommandProcessor();
122 Returns @true if the currently-active command can be undone, @false otherwise.
124 virtual bool CanUndo();
127 Deletes all commands in the list and sets the current command pointer to @c
130 virtual void ClearCommands();
133 Returns the list of commands.
135 wxList
GetCommands();
138 Returns the edit menu associated with the command processor.
140 wxMenu
* GetEditMenu();
143 Returns the maximum number of commands that the command processor stores.
145 int GetMaxCommands();
148 Returns the string that will be appended to the Redo menu item.
150 const wxString
GetRedoAccelerator();
153 Returns the string that will be shown for the redo menu item.
155 wxString
GetRedoMenuLabel();
158 Returns the string that will be appended to the Undo menu item.
160 const wxString
GetUndoAccelerator();
163 Returns the string that will be shown for the undo menu item.
165 wxString
GetUndoMenuLabel();
168 Initializes the command processor, setting the current command to the
169 last in the list (if any), and updating the edit menu (if one has been
172 virtual void Initialize();
175 Returns a boolean value that indicates if changes have been made since
176 the last save operation. This only works if
178 is called whenever the project is saved.
180 virtual bool IsDirty();
183 You must call this method whenever the project is saved if you plan to use
186 virtual void MarkAsSaved();
189 Executes (redoes) the current command (the command that has just been undone if
195 Tells the command processor to update the Undo and Redo items on this
196 menu as appropriate. Set this to @NULL if the menu is about to be
197 destroyed and command operations may still be performed, or the command
198 processor may try to access an invalid pointer.
200 void SetEditMenu(wxMenu
* menu
);
203 Sets the menu labels according to the currently set menu and the current
206 void SetMenuStrings();
209 Sets the string that will be appended to the Redo menu item.
211 void SetRedoAccelerator(const wxString
& accel
);
214 Sets the string that will be appended to the Undo menu item.
216 void SetUndoAccelerator(const wxString
& accel
);
219 Submits a new command to the command processor. The command processor
220 calls wxCommand::Do to execute the command; if it succeeds, the command
221 is stored in the history list, and the associated edit menu (if any) updated
222 appropriately. If it fails, the command is deleted
223 immediately. Once Submit has been called, the passed command should not
224 be deleted directly by the application.
226 @e storeIt indicates whether the successful command should be stored
229 virtual bool Submit(wxCommand
* command
, bool storeIt
= @
true);
232 Undoes the command just executed.