Views
Foundation Package API Reference Guide
Product Documentation:
Views Documentation Home
List of all members | Public Member Functions
IlvCommand Class Reference

Defines actions that can be undone. More...

#include <ilviews/base/command.h>

Inheritance diagram for IlvCommand:
IlvAction IlvChangeValueCommand IlvMacroCommand

Public Member Functions

 IlvCommand (IlvActionHistory *h=0, IlvUndoabilityReason u=notImplemented, IlBoolean ps=IlFalse, IlBoolean r=IlTrue, IlBoolean p=IlFalse)
 Constructor. More...
 
IlBoolean isPseudoCommand () const
 Is set to IlTrue if the command is a pseudocommand. More...
 
IlvUndoabilityReason isUndoable () const
 Indicates whether the command can be undone, and tells why if it cannot. More...
 
virtual void redo ()
 Redoes a command that was previously undone. More...
 
virtual void undo ()
 Undoes a command. More...
 
virtual void undoIt ()
 Implements the undo behavior. More...
 
- Public Member Functions inherited from IlvAction
 IlvAction (const IlvAction &action)
 Copy constructor used to repeat actions. More...
 
 IlvAction (IlvActionHistory *history=0, IlBoolean repeatable=IlTrue, IlBoolean persistent=IlFalse)
 Constructor. More...
 
virtual ~IlvAction ()
 Destructor.
 
virtual IlvActionduplicate () const
 Must be implemented in subclasses for the action to be repeatable. More...
 
virtual IlString errorMessage (IlUInt &severity) const
 Returns an error message. More...
 
virtual void execute ()
 Executes the action. More...
 
virtual void executeIt ()=0
 Executes the action (internal interface). More...
 
IlvActionHistorygetContext () const
 Returns the action history of the action or command. More...
 
IlBoolean isCommand () const
 Indicates whether an action is an IlvCommand object. More...
 
IlBoolean isDone () const
 Indicates whether the execute() method has already been called for this action. More...
 
IlBoolean isRepeatable () const
 Indicates whether an action can be repeated. More...
 
virtual void setContext (IlvActionHistory *history)
 Sets the execution context and the history of an action. More...
 
void setDone (IlBoolean d=IlTrue)
 Specifies whether a command or action should be considered as being executed. More...
 
virtual IlString userName () const
 Returns the name of the action in a readable form. More...
 

Additional Inherited Members

- Public Attributes inherited from IlvAction
IlvActionFlags _flags
 Action flags. Can be set directly by subclasses to change the status of the action.
 

Detailed Description

Defines actions that can be undone.

Library: views

The class IlvCommand defines actions that can be undone. They are generally used to implement the real changes that objects undergo in an application in response to user input.

This class cannot be directly instantiated. For a command to be executed, you must override its executeIt and undoIt methods in subclasses.

See also
IlvActionHistory, IlvCommandHistory, IlvMacroCommand, IlvChanveValueCommand

Constructor & Destructor Documentation

◆ IlvCommand()

IlvCommand::IlvCommand ( IlvActionHistory h = 0,
IlvUndoabilityReason  u = notImplemented,
IlBoolean  ps = IlFalse,
IlBoolean  r = IlTrue,
IlBoolean  p = IlFalse 
)

Constructor.

Parameters
hThe action history that serves as the execution context of the command. If you do not set this parameter, this will be done when the command is added to an action history.
uA Boolean value specifying whether the command can be undone. As a precaution, it is set by default to notImplemented. Consequently, you must not forget to set it to IlTrue when the undoIt method is implemented.
psA Boolean value specifying whether the command is a pseudocommand.
rA Boolean value specifying whether the command can be repeated.
pA Boolean value specifying whether the command is persistent. The persistence of commands is not yet implemented.

Member Function Documentation

◆ isPseudoCommand()

IlBoolean IlvCommand::isPseudoCommand ( ) const

Is set to IlTrue if the command is a pseudocommand.

A pseudocommand is an action that does not actually modify the application objects, but that can be undone for practical purposes. Selection and navigation commands, such as panning and zooming, are pseudocommands. This is a flag that is statically defined for each command and not a parameter, since, depending on the application, you may consider actions, such as zooming, to be real commands. (A real command is one whose result is to be saved with the file.)
Typically, this flag is used by IlvModifiedFlagObserver to determine whether the document corresponding to a given command history should be considered as modified or not.

See also
IlvModifiedFlagObserver

◆ isUndoable()

IlvUndoabilityReason IlvCommand::isUndoable ( ) const

Indicates whether the command can be undone, and tells why if it cannot.

Returns
undoable if the command can be undone. It can also return another value, that indicates why this command cannot be undone.

◆ redo()

virtual void IlvCommand::redo ( )
virtual

Redoes a command that was previously undone.

By default, its implementation calls the execute method. However, for efficiency reasons, you may wish to implement a specific version that performs less checks by assuming that executeIt has already been called once.

◆ undo()

virtual void IlvCommand::undo ( )
virtual

Undoes a command.

Usually, this method is invoked by the command history and does not have to be called or redefined. In addition to calling undoIt, this method sets the done flag to IlFalse and informs its class observers that the command has been undone.

◆ undoIt()

virtual void IlvCommand::undoIt ( )
virtual

Implements the undo behavior.

This method should be redefined in subclasses to cancel the executeIt method.

Reimplemented in IlvChangeValueCommand, and IlvMacroCommand.