Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
|
The UndoList class manages a list of undoable commands. More...
#include <FXUndoList.h>
Public Types | |
enum | { ID_CLEAR =FXWindow::ID_LAST, ID_REVERT, ID_UNDO, ID_REDO, ID_UNDO_ALL, ID_REDO_ALL, ID_UNDO_COUNT, ID_REDO_COUNT, ID_ALT_HISTORY, ID_DUMP_STATS, ID_LAST } |
Public Member Functions | |
long | onCmdUndo (FXObject *, FXSelector, void *) |
long | onUpdUndo (FXObject *, FXSelector, void *) |
long | onCmdRedo (FXObject *, FXSelector, void *) |
long | onUpdRedo (FXObject *, FXSelector, void *) |
long | onCmdClear (FXObject *, FXSelector, void *) |
long | onUpdClear (FXObject *, FXSelector, void *) |
long | onCmdRevert (FXObject *, FXSelector, void *) |
long | onUpdRevert (FXObject *, FXSelector, void *) |
long | onCmdUndoAll (FXObject *, FXSelector, void *) |
long | onCmdRedoAll (FXObject *, FXSelector, void *) |
long | onUpdUndoCount (FXObject *, FXSelector, void *) |
long | onUpdRedoCount (FXObject *, FXSelector, void *) |
long | onCmdAltHistory (FXObject *, FXSelector, void *) |
long | onUpdAltHistory (FXObject *, FXSelector, void *) |
long | onCmdDumpStats (FXObject *, FXSelector, void *) |
FXUndoList () | |
Make new empty undo list, initially unmarked. | |
FXbool | busy () const |
Return true if currently inside undo or redo operation; this is useful to avoid generating another undo command while inside an undo operation. | |
FXbool | cut () |
If alternate history mode is in effect, remember the alternate history, moving all the redo-commands into the undolist followed by their corresponding undo-commands, in reverse order. More... | |
FXbool | add (FXCommand *cmd, FXbool doit=false, FXbool merge=true) |
Add new command, executing it if desired. More... | |
FXbool | begin (FXCommandGroup *command) |
Begin undo command sub-group. More... | |
FXbool | end () |
End undo command sub-group. More... | |
FXbool | abort () |
Abort the current command sub-group being compiled. More... | |
virtual void | undo () |
Undo last command. More... | |
virtual void | redo () |
Redo next command. More... | |
void | undoAll () |
Undo all commands. | |
void | redoAll () |
Redo all commands. | |
void | revert () |
Revert to marked. | |
FXbool | canUndo () const |
Can we undo more commands. | |
FXbool | canRedo () const |
Can we redo more commands. | |
FXbool | canRevert () const |
Can revert to marked. | |
FXCommand * | current () const |
Current top undo command. | |
virtual FXString | undoName () const |
Return name of the first undo command available; if no undo command available this will return the empty string. | |
virtual FXString | redoName () const |
Return name of the first redo command available; if no Redo command available this will return the empty string. | |
virtual FXuval | size () const |
Size of undo information. | |
virtual void | clear () |
Clear list. | |
FXint | undoCount () const |
Number of undo records. | |
FXint | redoCount () const |
Number of redo records. | |
void | trimCount (FXint nc) |
Trim undo list down, starting from the oldest commands, until no more than nc commands are left in the undo list. More... | |
void | trimSize (FXuval sz) |
Trim undo list down, starting from the oldest commands, until total memory used drops below size sz. More... | |
void | trimMark () |
Trim undo list down, starting from the oldest commands, until reaching the marked ("clean" state) point. More... | |
void | mark () |
Mark the current state of the undo list, which is initially unmarked. More... | |
void | unmark () |
Unmark the marked state. | |
FXbool | marked () const |
Check if the current state was marked, if the application has returned to the previously marked state. | |
void | setAlternateHistory (FXbool flag) |
Enable or disable alternate history mode. More... | |
FXbool | getAlternateHistory () const |
Returns true if alternate history mode is in effect. | |
void | dumpStats () |
Dump statistics. | |
virtual | ~FXUndoList () |
Destroy. | |
Public Member Functions inherited from FX::FXCommandGroup | |
FXCommandGroup () | |
Construct initially empty undo command group. | |
FXbool | empty () |
Return true if empty. | |
virtual | ~FXCommandGroup () |
Delete undo command and sub-commands. | |
Public Member Functions inherited from FX::FXCommand | |
FXival | nrefs () const |
void | ref () |
void | unref () |
virtual FXbool | canMerge () const |
Return true if this command could possibly be merged with a previous undo command. More... | |
virtual FXuint | mergeWith (FXCommand *command) |
Called by the undo system to try and merge the new incoming command with this command. More... | |
Public Member Functions inherited from FX::FXObject | |
const FXchar * | getClassName () const |
Get class name of some object. | |
FXbool | isMemberOf (const FXMetaClass *metaclass) const |
Check if object is member of metaclass. | |
virtual long | tryHandle (FXObject *sender, FXSelector sel, void *ptr) |
Try handle message safely, catching certain exceptions. | |
virtual long | onDefault (FXObject *, FXSelector, void *) |
Called for unhandled messages. | |
virtual void | save (FXStream &store) const |
Save object to stream. | |
virtual void | load (FXStream &store) |
Load object from stream. | |
virtual | ~FXObject () |
Virtual destructor. | |
The UndoList class manages a list of undoable commands.
When performing an undo, the document is regressed from its current state to an earlier state. Likewise, performing a redo, a document is advanced from an earlier state to a later state.
A document state may be marked, i.e. a special designated state may be identified. Typically, a freshly loaded document is marked as "clean". Also, any time a document is saved back to disk, the latest state could be marked as "clean".
You can go back to the marked state by invoking revert(). The revert() API will call a sequence of undo's or redo's, depending on whether one need to go to older or newer state of the document.
UndoList can directly receive SEL_UPDATE and SEL_COMMAND messages from widgets. For example, sending ID_UNDO command will invoke the undo() API and cause an undo operation.
FXbool FX::FXUndoList::abort | ( | ) |
Abort the current command sub-group being compiled.
All commands already added to the sub-groups undo list will be discarded. Intermediate command groups will be left intact.
FXbool FX::FXUndoList::add | ( | FXCommand * | cmd, |
FXbool | doit = false , |
||
FXbool | merge = true |
||
) |
Add new command, executing it if desired.
The new command will be merged with the previous command if merge is true and we're not at a marked position and the commands are mergeable. Otherwise the new command will be appended after the last undo command in the currently active undo group. If the new command is successfully merged, it will be deleted.
FXbool FX::FXUndoList::begin | ( | FXCommandGroup * | command | ) |
FXbool FX::FXUndoList::cut | ( | ) |
If alternate history mode is in effect, remember the alternate history, moving all the redo-commands into the undolist followed by their corresponding undo-commands, in reverse order.
The sequence has a net zero effect on the document, as each undo is paired up with a corresponding redo. If alternate history is not in effect, simply delete the redo- commands. This is automatically invoked when a new undo command is added, and not typically called by the user directly.
FXbool FX::FXUndoList::end | ( | ) |
End undo command sub-group.
If the sub-group is still empty, it will be deleted; otherwise, the sub-group will be added as a new command into parent group. A matching begin() must have been called previously.
void FX::FXUndoList::mark | ( | ) |
Mark the current state of the undo list, which is initially unmarked.
There can be only one active mark at any time. Call mark() at any time when you know your document to be "clean"; for example when you save the document to disk. If you don't need to undo past this marked point, consider calling trimMark() to delete all undo commands for states prior to the mark.
|
virtual |
Redo next command.
This will move the command back to the undo list.
Reimplemented from FX::FXCommandGroup.
|
inline |
Enable or disable alternate history mode.
In alternate history mode, adding a new command after performing a number of undo's will remember the alternate history, and allow a sequence of undo's and redo's to navigate back through this alternate history.
void FX::FXUndoList::trimCount | ( | FXint | nc | ) |
Trim undo list down, starting from the oldest commands, until no more than nc commands are left in the undo list.
Call this periodically to prevent the undo-list from growing beyond a certain number of records.
void FX::FXUndoList::trimMark | ( | ) |
Trim undo list down, starting from the oldest commands, until reaching the marked ("clean" state) point.
If no mark was set this does nothing.
void FX::FXUndoList::trimSize | ( | FXuval | sz | ) |
Trim undo list down, starting from the oldest commands, until total memory used drops below size sz.
Call this periodically to prevent the undo-list from growing beyond a certain maximum amount of memory.
|
virtual |
Undo last command.
This will move the command to the redo list.
Reimplemented from FX::FXCommandGroup.
Copyright © 1997-2022 Jeroen van der Zijp |