![]() |
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 Member Functions | |
| long | onCmdUndo (FXObject *, FXSelector, void *) |
| long | onUpdUndo (FXObject *, FXSelector, void *) |
| long | onCmdRedo (FXObject *, FXSelector, void *) |
| long | onUpdRedo (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 *) |
| long | onCmdTrimMark (FXObject *, FXSelector, void *) |
| long | onCmdTrimSize (FXObject *, FXSelector, void *) |
| long | onCmdTrimWrinkles (FXObject *, FXSelector, void *) |
| long | onCmdTrimCount (FXObject *, FXSelector, void *) |
| long | onCmdClear (FXObject *, FXSelector, void *) |
| long | onUpdClear (FXObject *, FXSelector, void *) |
| long | onUpdSize (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. | |
| 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. | |
| FXbool | add (FXCommand *cmd, FXbool doit=false, FXbool merge=true) |
| Add undo command, executing it if desired. More... | |
| FXbool | begin (FXCommandGroup *command) |
| Begin undo command sub-group. More... | |
| FXbool | abort () |
| Abort the current command sub-group being compiled. More... | |
| FXbool | end () |
| End undo command sub-group. More... | |
| virtual FXbool | cut () override |
| If alternate history mode is in effect, remember the alternate history. More... | |
| virtual void | undo () override |
| Undo last command. More... | |
| virtual void | redo () override |
| Redo next command. More... | |
| void | undoAll () |
| Undo all recorded commands. | |
| void | redoAll () |
| Redo all recorded commands. | |
| void | revert () |
| Revert to marked state; this will perform a sequence of undos (or redos), and return the document to the marked state. | |
| 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 override |
| Return name of the first undo command available; if no undo command available this will return the empty string. | |
| virtual FXString | redoName () const override |
| Return name of the first redo command available; if no Redo command available this will return the empty string. | |
| FXint | undoCount () const |
| Number of undo records. | |
| FXint | redoCount () const |
| Number of redo records. | |
| virtual FXuval | size () const override |
| Return total amount of space used by undo/redo commands. | |
| void | trimMark () |
| Trim undo list down, starting from the oldest commands, until reaching the marked ("clean" state) point. More... | |
| void | trimSize (FXuval sz) |
| Trim undo list down, starting from the oldest commands, until total memory used drops below size sz. More... | |
| void | trimWrinkles (FXuval sz) |
| Trim undo list down, starting from the oldest commands. More... | |
| 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... | |
| virtual void | clear () override |
| Clear all undo information, releasing all commands and markers. | |
| 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 () const |
| 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 to disk, one can mark that state 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.
Alternate history, when enabled, allows one to revert to any prior state, even back to the path not taken. Supposed we've issued a sequence of commands such as:
A - B - C - D - E - F
If issue undos until we're back at C, and then do commands G,H,I:
A - B - C - G - H - I
Prior to "alternate history" support, we would have permanently lost access to D,E,F. With alternate hostory, however, the undo-buffer would look as follows:
A - B - C - D - E - F - F - E - D - G - H - I
Where overbar indicates a reversed-redo command; notice that the sequence:
D - E - F - F - E - D
has no net effect, it is a sequences of redo's followed by a sequence [in reverse order] of reversed-redo's.
Implementation detail: an redo and the corresponding reversed-redo are one and the same record; the special marked pointer type keeps track of the reversals. Thus, while the undo-buffer can grow quite a lot, the major amount of memory, which lives in the redo-records themselves, may be heavily reused.
| 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 undo 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 | ) |
|
overridevirtual |
If alternate history mode is in effect, remember the alternate history.
All commands on the redo-list are paired up with their inverses, then transferred to the undo list. A sequence of commands:
C1 C2 C3 ... CN CN ... C3 C2 C1
Has no effect on the state of the document; however, moving backwards and forwards allows every state in the edit-history of the document to be reached.
If alternate history is not in effect, simply delete the commands on the redo-list.
This is automatically invoked when a new undo command is added, and not typically called by the user directly.
Reimplemented from FX::FXCommandGroup.
| 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.
|
overridevirtual |
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.
| void FX::FXUndoList::trimWrinkles | ( | FXuval | sz | ) |
Trim undo list down, starting from the oldest commands.
Unlike trimSize(), trimWrinkles() will try bring down space usage by linearizing wrinkles in the command-history, i.e. removing matching command-pairs in sequences like:
C1 C2 C3 ... CN CN ... C3 C2 C1 __ starting from CN - CN moving outward, until the desired aount of space is reclaimed, or until all such "wrinkles" of alternate history have been removed and only linear edit history remains.
If alternate history is not in effect, or there is no alternate history to be removed, this command reclaims no space at all.
|
overridevirtual |
Undo last command.
This will move the command to the redo list.
Reimplemented from FX::FXCommandGroup.
|
|