NShape Concepts
Commands

<< Click to Display Table of Contents >>

Navigation:  Concepts >

NShape Concepts
Commands

Previous pageReturn to chapter overviewNext page

When manipulating shapes and diagrams, a program will usually use their methods and properties like in the following example.

shape.X = 50;
shape.Y = 30;
shape.Angle = 1800;

However, when the user edits a diagram, his actions must be checked against his permissions, all modifications must be notified to the repository and we want those operations to be undoable. These features are implemented in the command classes, which are used for implementing user actions. Using command objects, the above sequence looks like this:

project.Execute(new ShapeMoveToCommand(shape, 50, 50));
project.Execute(new ShapeRotateTo(Command(shape, 1800));

Every command object encapsulates all information necessary to execute the command.

 

The Project.ExecuteCommand method checks whether the current user has the required permissions, executes the command but does not add it to the history. Please note that it's not a good idea to modify (non-temporary) shapes using a command that is not added to the history.

The Project.ExecuteAndAddCommand method also checks permissions and executes the command but also adds it to the history for later undo/redo.

 

Most of the controller components provide methods for creating commands for most standard use cases.