I have a window which works like the Visual Studio designer. Each document has two views:
- Source View,
- Designer View.
I have a toolbar that can issue different commands. The toolbar button has a CommandId string property that store the Id of the command, such as:
- Cut, Copy, Paste;
- Insert Grid,
- Auto Format
- ...
I am having trouble designing the command pattern where the execution of the command is different depending on the view.
For an obvious example, the Copy Command will copy the selected text when in the Source View, but will copy the selected control when in the Designer View.
I am currently mapping the commandId string to a CopyCommand object, but since the execution of the command is different depending on the view, I am not sure how this should be implemented.
Should each view supplies a list of concrete command that it understand (and thus having two CopyCommand like SourceCopyCommand and DesignCopyCommand that share the same id)?
Or should each command be unique, but the view has a big mapping function that change the behavior depending on the command id?