]>
git.saurik.com Git - wxWidgets.git/blob - interface/cmdproc.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxCommand
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.
23 class wxCommand
: public wxObject
27 Constructor. wxCommand is an abstract class, so you will need to derive
28 a new class and call this constructor from your own constructor.
29 @a canUndo tells the command processor whether this command is undo-able. You
30 can achieve the same functionality by overriding the CanUndo member function
32 the criteria for undoability is context-dependent).
33 @a name must be supplied for the command processor to display the command name
34 in the application's edit menu.
36 wxCommand(bool canUndo
= false, const wxString
& name
= NULL
);
44 Returns @true if the command can be undone, @false otherwise.
49 Override this member function to execute the appropriate action when called.
50 Return @true to indicate that the action has taken place, @false otherwise.
51 Returning @false will indicate to the command processor that the action is
52 not undoable and should not be added to the command history.
57 Returns the command name.
62 Override this member function to un-execute a previous Do.
63 Return @true to indicate that the action has taken place, @false otherwise.
64 Returning @false will indicate to the command processor that the action is
65 not redoable and no change should be made to the command history.
66 How you implement this command is totally application dependent, but typical
68 Perform an inverse operation on the last modified piece of
69 data in the document. When redone, a copy of data stored in command
70 is pasted back or some operation reapplied. This relies on the fact that
71 you know the ordering of Undos; the user can never Undo at an arbitrary position
72 in the command history.
73 Restore the entire document state (perhaps using document transactioning).
74 Potentially very inefficient, but possibly easier to code if the user interface
75 and data are complex, and an 'inverse execute' operation is hard to write.
76 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.
95 @see @ref overview_wxcommandprocessoroverview "wxCommandProcessor overview",
98 class wxCommandProcessor
: public wxObject
103 @a maxCommands may be set to a positive integer to limit the number of
104 commands stored to it, otherwise (and by default) the list of commands can grow
107 wxCommandProcessor(int maxCommands
= -1);
112 ~wxCommandProcessor();
115 Returns @true if the currently-active command can be undone, @false otherwise.
117 virtual bool CanUndo();
120 Deletes all commands in the list and sets the current command pointer to @c
123 virtual void ClearCommands();
126 Returns the list of commands.
128 wxList
GetCommands() const;
131 Returns the edit menu associated with the command processor.
133 wxMenu
* GetEditMenu() const;
136 Returns the maximum number of commands that the command processor stores.
138 int GetMaxCommands() const;
141 Returns the string that will be appended to the Redo menu item.
143 const wxString
GetRedoAccelerator() const;
146 Returns the string that will be shown for the redo menu item.
148 wxString
GetRedoMenuLabel() const;
151 Returns the string that will be appended to the Undo menu item.
153 const wxString
GetUndoAccelerator() const;
156 Returns the string that will be shown for the undo menu item.
158 wxString
GetUndoMenuLabel() const;
161 Initializes the command processor, setting the current command to the
162 last in the list (if any), and updating the edit menu (if one has been
165 virtual void Initialize();
168 Returns a boolean value that indicates if changes have been made since
169 the last save operation. This only works if
171 is called whenever the project is saved.
173 virtual bool IsDirty();
176 You must call this method whenever the project is saved if you plan to use
179 virtual void MarkAsSaved();
182 Executes (redoes) the current command (the command that has just been undone if
188 Tells the command processor to update the Undo and Redo items on this
189 menu as appropriate. Set this to @NULL if the menu is about to be
190 destroyed and command operations may still be performed, or the command
191 processor may try to access an invalid pointer.
193 void SetEditMenu(wxMenu
* menu
);
196 Sets the menu labels according to the currently set menu and the current
199 void SetMenuStrings();
202 Sets the string that will be appended to the Redo menu item.
204 void SetRedoAccelerator(const wxString
& accel
);
207 Sets the string that will be appended to the Undo menu item.
209 void SetUndoAccelerator(const wxString
& accel
);
212 Submits a new command to the command processor. The command processor
213 calls wxCommand::Do to execute the command; if it succeeds, the command
214 is stored in the history list, and the associated edit menu (if any) updated
215 appropriately. If it fails, the command is deleted
216 immediately. Once Submit has been called, the passed command should not
217 be deleted directly by the application.
218 @a storeIt indicates whether the successful command should be stored
221 virtual bool Submit(wxCommand
* command
, bool storeIt
= true);
224 Undoes the command just executed.