Led 3.0 Class Library Documentation

Module Command


Classes and Global Functions Index

Module Description:

Module for supporting UNDO. Command objects encapsulate a sequence of operations the user has done, and the information needed to undo/redo them. These objects are organized, and kept track of by a CommandHandler object. Two sorts of CommandHandlers are provided, SingleUndoCommandHandler, and MultiLevelUndoCommandHandler - depending on whether you want to support multilevel undo or not.


Class: Command [public]

Description:
An abstraction for a user action, which is undoable. These objects, when created, are posted to a CommandHandler via CommandHandler::Post ().

Member Details

Command::Command [public]

Command::Command (bool done):

Construct a Command object. The constructor takes an optional bool arg done because sometimes commands are created already done (but this defaults to false).

Command::Do [public]

void Command::Do ()

Perform the actual commands action.

Command::GetDone [public]

bool Command::GetDone () const

The done, and redone states are considered identical. This returns true if the command has either been done, or redone (not most recently undone).

Command::GetName [public]

const Led_SDK_Char* Command::GetName () const

Returns the name associated with a command. This is used for UI purposes in constructing the text of the Undo command name.

Command::ReDo [public]

void Command::ReDo ()

Redo a command which has been done (or perhaps redone), and more recently undone.

Command::UnDo [public]

void Command::UnDo ()

Undo an already done command.


Class: CommandHandler [public]

Description:

This is the guy you post new Commands to, and ask for the text of the undo message, etc. You call undo/redo on him to get actual undo/redo etc to happen. It is responsable for committing commands, and disposing of them. Typically, you would have one of this in your TextInteractor to handle undo.

Member Details

CommandHandler::BreakInGroupedCommands [public]

virtual void BreakInGroupedCommands () = 0;

Some commands are plausibly chunked together. These are mostly tying, insert-character commands. But, in principle, we could bundle together other commands as well. Call this method to signify that previous commands should not be chunked together with commads about to be posted (CommandHandler::Post).

CommandHandler::CanRedo [public]

virtual bool CanRedo () = 0;

Are there commands which have been undone, which can now be redone?

CommandHandler::CanUndo [public]

virtual bool CanUndo () = 0;

Are there commands posted which can be undone?

CommandHandler::Commit [public]

virtual void Commit () = 0; // Commit all commands currently owned - something has happened to invalidate them...

Commit all currently done actions. This means no further undo will be possible (deletes the currently done/redone objects). This can be called when low on memory, to retrive some. Or when some logical user-action happens which would prevent further undos (save?).

CommandHandler::DoRedo [public]

virtual void DoRedo () = 0;

Redo the last undone action. See CommandHandler::DoUndo () for more details.

CommandHandler::DoUndo [public]

virtual void DoUndo () = 0;

Perform a single undo action. This will undo all the command objects in the current group of commands (or all, depending on the subtype of this CommandHandler; see SingleUndoCommandHandler and MultiLevelUndoCommandHandler for details).

CommandHandler::GetUndoRedoWhatMessageText [public]

virtual size_t GetUndoRedoWhatMessageText (char* buf, size_t bufSize); // return nbytes - not NUL term string...

Retreives the text associated with each command to denote in a UI what command is being undone, or redone.

CommandHandler::Post [public]

virtual void Post (Command* newCommand) = 0;

Notify the CommandHandler of a newly created (and done) Command. This command object is now owned by the CommandHandler. And it will call delete on it, when it is through with the object. The lifetime of this object is totally under the control of the CommandHandler. It can be deleted at any time. No assumptions should be made about this.


Class: InteractiveReplaceCommand [public]

Base Classes: Command
Description:

This subsumes basic typing and cut/paste type commands. Grab the text range BEFORE the command, and externize it. Do the command, and then grab the range of text AFTER the command and externalize that. The before/after text/ranges allow us to undo and redo. Note we 'externalize' before/after text so we get font info, and any embeddings...

Member Details

InteractiveReplaceCommand::InteractiveReplaceCommand [public]

InteractiveReplaceCommand::InteractiveReplaceCommand (TextInteractor* textInteractor, SavedTextRep* beforeRegion,

This constructor takes a TextInteractor where the command was done, and a InteractiveReplaceCommand::SavedTextRep for BEFORE and AFTER. It also takes as argument - an 'at' parameter - specifying where the NEW/OLD text (for DO and UNDO) will get inserted. For the length overwritten - we use the size from the SavedTextRep itself. This CTOR also takes a command name to be saved with the command (not used intenrally - but saved as an attribute so menu handling code can report what is to be UNDONE).


Class: InteractiveReplaceCommand::PlainTextRep [public]

Base Classes: InteractiveReplaceCommand::SavedTextRep
Description:

Keep track of only the text, and no font, or misc embedding info.


Class: InteractiveReplaceCommand::SavedTextRep [public]

Description:

Abstraction for what to keep track of in a typical text editing command.

Note: This fSelStart/fSelEnd refers to the users selection in the text. It has NOTHING todo with the region of text which is saved.

Member Details

InteractiveReplaceCommand::SavedTextRep::GetLength [public]

virtual size_t GetLength () const = 0;

Return the length of the region preserved in this text saved object.

InteractiveReplaceCommand::SavedTextRep::InsertSelf [public]

virtual void InsertSelf (TextInteractor* imager, size_t at, size_t nBytesToOverwrite) = 0;

Insert text saved in this object at position 'at' and replacing 'nBytesToOverwrite' Led_tChars worth of text.

Class: MultiLevelUndoCommandHandler [public]

Base Classes: CommandHandler
Description:

CommandHandler which allows for undo the last command several commands. The number of undo levels is specified in a constructor argument.

Member Details

MultiLevelUndoCommandHandler::GetMaxUnDoLevels [public]

size_t MultiLevelUndoCommandHandler::GetMaxUnDoLevels ()

Gets the maximum number of undo levels the MultiLevelUndoCommandHandler will support. Zero is a valid # - disabling the keeping of undo information. One is a valid number - implying basicly the same behavior as SingleUndoCommandHandler - except that Undo isn't treated as Redo after an Undo.

See MultiLevelUndoCommandHandler::SetMaxUnDoLevels

MultiLevelUndoCommandHandler::SetMaxUnDoLevels [public]

void MultiLevelUndoCommandHandler::SetMaxUnDoLevels (size_t maxUndoLevels)

See MultiLevelUndoCommandHandler::GetMaxUnDoLevels


Class: SingleUndoCommandHandler [public]

Base Classes: CommandHandler
Description:

CommandHandler which only allows for undo the last command.


Class: SnoopingCommandHandler [public]

Base Classes: CommandHandler
Description:

Useful for things like recording keyboard macros. Simply install this as your command handler, and hand it as argument the OLD one. Later, when you are done recording, re-install the old and extract the accumulated commands from this one.

Basicily all this does is delegate to the given REAL command handler, and call the Snoop () method YOU provide in your subclass. There - you can extract what information you like from the argument Command object.


Return to Led Page Return to Led ClassLib Documentation Index Return to Led Reference Manual Index
Last Updated 2001-10-20