]>
git.saurik.com Git - wxWidgets.git/blob - interface/cmdproc.h
89cd956dfdf9085423d9386ecc490b1636fb1948
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.
30 @a canUndo tells the command processor whether this command is undo-able. You
31 can achieve the same functionality by overriding the CanUndo member function
33 the criteria for undoability is context-dependent).
34 @a name must be supplied for the command processor to display the command name
35 in the application's edit menu.
37 wxCommand(bool canUndo
= false, const wxString
& name
= NULL
);
45 Returns @true if the command can be undone, @false otherwise.
50 Override this member function to execute the appropriate action when called.
51 Return @true to indicate that the action has taken place, @false otherwise.
52 Returning @false will indicate to the command processor that the action is
53 not undoable and should not be added to the command history.
58 Returns the command name.
63 Override this member function to un-execute a previous Do.
64 Return @true to indicate that the action has taken place, @false otherwise.
65 Returning @false will indicate to the command processor that the action is
66 not redoable and no change should be made to the command history.
67 How you implement this command is totally application dependent, but typical
69 Perform an inverse operation on the last modified piece of
70 data in the document. When redone, a copy of data stored in command
71 is pasted back or some operation reapplied. This relies on the fact that
72 you know the ordering of Undos; the user can never Undo at an arbitrary position
73 in the command history.
74 Restore the entire document state (perhaps using document transactioning).
75 Potentially very inefficient, but possibly easier to code if the user interface
76 and data are complex, and an 'inverse execute' operation is hard to write.
77 The docview sample uses the first method, to remove or restore segments
85 @class wxCommandProcessor
88 wxCommandProcessor is a class that maintains a history of wxCommands,
89 with undo/redo functionality built-in. Derive a new class from this
90 if you want different behaviour.
96 @ref overview_wxcommandprocessoroverview "wxCommandProcessor overview",
99 class wxCommandProcessor
: public wxObject
104 @a maxCommands may be set to a positive integer to limit the number of
105 commands stored to it, otherwise (and by default) the list of commands can grow
108 wxCommandProcessor(int maxCommands
= -1);
113 ~wxCommandProcessor();
116 Returns @true if the currently-active command can be undone, @false otherwise.
118 virtual bool CanUndo();
121 Deletes all commands in the list and sets the current command pointer to @c
124 virtual void ClearCommands();
127 Returns the list of commands.
129 wxList
GetCommands();
132 Returns the edit menu associated with the command processor.
134 wxMenu
* GetEditMenu();
137 Returns the maximum number of commands that the command processor stores.
139 int GetMaxCommands();
142 Returns the string that will be appended to the Redo menu item.
144 const wxString
GetRedoAccelerator();
147 Returns the string that will be shown for the redo menu item.
149 wxString
GetRedoMenuLabel();
152 Returns the string that will be appended to the Undo menu item.
154 const wxString
GetUndoAccelerator();
157 Returns the string that will be shown for the undo menu item.
159 wxString
GetUndoMenuLabel();
162 Initializes the command processor, setting the current command to the
163 last in the list (if any), and updating the edit menu (if one has been
166 virtual void Initialize();
169 Returns a boolean value that indicates if changes have been made since
170 the last save operation. This only works if
172 is called whenever the project is saved.
174 virtual bool IsDirty();
177 You must call this method whenever the project is saved if you plan to use
180 virtual void MarkAsSaved();
183 Executes (redoes) the current command (the command that has just been undone if
189 Tells the command processor to update the Undo and Redo items on this
190 menu as appropriate. Set this to @NULL if the menu is about to be
191 destroyed and command operations may still be performed, or the command
192 processor may try to access an invalid pointer.
194 void SetEditMenu(wxMenu
* menu
);
197 Sets the menu labels according to the currently set menu and the current
200 void SetMenuStrings();
203 Sets the string that will be appended to the Redo menu item.
205 void SetRedoAccelerator(const wxString
& accel
);
208 Sets the string that will be appended to the Undo menu item.
210 void SetUndoAccelerator(const wxString
& accel
);
213 Submits a new command to the command processor. The command processor
214 calls wxCommand::Do to execute the command; if it succeeds, the command
215 is stored in the history list, and the associated edit menu (if any) updated
216 appropriately. If it fails, the command is deleted
217 immediately. Once Submit has been called, the passed command should not
218 be deleted directly by the application.
219 @a storeIt indicates whether the successful command should be stored
222 virtual bool Submit(wxCommand
* command
, bool storeIt
= true);
225 Undoes the command just executed.