Class CommandHandler

GoDiagram®
v10.0.12
by Northwoods Software®

The CommandHandler implements various commands such as DeleteSelection() or Redo(). The CommandHandler includes keyboard event handling to interpret key presses as commands.

Inheritance
CommandHandler
Namespace: Northwoods.Go
Assembly: Northwoods.GoDiagram.Avalonia.dll
Syntax
public class CommandHandler
Remarks

CommandHandlers cannot be shared amongst multiple Diagrams.

You may define a CommandHandler subclass and override methods. However you must seriously consider calling the base method in order to get its default behavior. There may be situations where not calling the base method may cause subtle bugs, but that depends on the method. Please read the Introduction page on Extensions for how to override methods and how to call a base method.

There is an example custom CommandHandler in the extensions directory: DrawCommandHandler.cs, which provides alignment commands and additional behaviors for the arrow keys.

For additional discussion, please read the Introduction page on Commands.

Keyboard Shortcuts

The CommandHandler implements the following command bindings for keyboard input in DoKeyDown():

On a Macintosh the Command key is used as the modifier instead of the Control key.

On touch devices there is a default context menu that shows many commonly-used commands when you hold a finger down on the diagram.

Constructors

CommandHandler()

The constructor produces a CommandHandler with the default key bindings.

Declaration
public CommandHandler()

Properties

ArchetypeGroupData

Gets or sets a data object that is copied by GroupSelection() when creating a new Group.

Declaration
public object ArchetypeGroupData { get; set; }
Property Value
Type Description
object
Remarks

The default value is null. If you set this to an Object, be sure that IsGroupForData(object) is true for that object. Setting this property does not raise any events.

Gets or sets whether CopySelection() should also copy Links that connect with selected Nodes.

Declaration
public bool CopiesConnectedLinks { get; set; }
Property Value
Type Description
bool

The default value is true. Setting this property does not raise any events.

The CopiesEffectiveCollection property serves a similar role for the DraggingTool when the user holds down the control key to modify the drag into a copy operation.

CopiesGroupKey

Gets or sets whether CopySelection() and CopyToClipboard(IEnumerable<Part>) copy the node data property whose value is the containing group data's key.

Declaration
public bool CopiesGroupKey { get; set; }
Property Value
Type Description
bool
Remarks

Set this property to true if you want a copy/paste of a node to automatically have the new node be a member of the original group. Warning: this only has an effect if the Diagram's Model is an Northwoods.Go.Models.IGroupModel.

The default value is false.

CopiesParentKey

Gets or sets whether CopySelection() and CopyToClipboard(IEnumerable<Part>) copy the node data property whose value is the tree-parent node data's key.

Declaration
public bool CopiesParentKey { get; set; }
Property Value
Type Description
bool
Remarks

Set this property to true if you want a copy/paste of a node to automatically have the new node be a tree-child of the original tree-parent node. Warning: this only has an effect if the Diagram's Model is an Northwoods.Go.Models.ITreeModel.

The default value is false.

CopiesTree

Gets or sets whether CopySelection() should also copy subtrees.

Declaration
public bool CopiesTree { get; set; }
Property Value
Type Description
bool
Remarks

The default value is false. Setting this property does not raise any events.

The DragsTree property serves a similar role for the DraggingTool for both moving and copying operations.

Gets or sets whether DeleteSelection() should also delete links that are connected to nodes that are deleted.

Declaration
public bool DeletesConnectedLinks { get; set; }
Property Value
Type Description
bool

The default value is true. Setting this property does not raise any events.

DeletesTree

Gets or sets whether DeleteSelection() should also delete subtrees.

Declaration
public bool DeletesTree { get; set; }
Property Value
Type Description
bool
Remarks

The default value is false. Setting this property does not raise any events.

Diagram

This read-only property returns the Diagram that is using this CommandHandler, after CommandHandler has been set to this object.

Declaration
public Diagram Diagram { get; }
Property Value
Type Description
Diagram

MemberValidation

Gets or sets the predicate that determines whether or not a node may become a member of a group.

Declaration
public Func<Group, Part, bool> MemberValidation { get; set; }
Property Value
Type Description
Func<Group, Part, bool>
Remarks

This predicate is called in addition to any existing group's MemberValidation predicate. The default predicate is null, which is equivalent to simply returning true. The predicate may be called passing null as the first argument (the Group) -- this asks whether it is OK to make the second argument (the Part, but not a Link) a top-level Part of the diagram.

For a more general discussion of validation, see Introduction to Validation.

The function, if supplied, must not have any side-effects.

ZoomFactor

Gets or sets the amount by which DecreaseZoom(double) and IncreaseZoom(double) change the Scale.

Declaration
public double ZoomFactor { get; set; }
Property Value
Type Description
double
Remarks

The default value is 1.05 (5%). The value must be a double larger than 1.0. Setting this property does not raise any events.

Methods

AddTopLevelParts(IEnumerable<Part>, bool)

Make sure all of the unnested Parts in the given collection are removed from any containing Groups.

Declaration
public virtual bool AddTopLevelParts(IEnumerable<Part> coll, bool check = false)
Parameters
Type Name Description
IEnumerable<Part> coll

a collection of Parts.

bool check

check whether to call IsValidMember(Group, Part) to confirm that changing the Part to be a top-level Part is valid.

Returns
Type Description
bool

true if all non-Links were changed to be top-level Parts in this Diagram; false if some Parts or Nodes were not able to be added.

Remarks

This sets ContainingGroup to null on each Part that is not a member of another Part in the argument collection. If the check argument to this method is supplied and true, this will call IsValidMember(Group, Part) on each part, passing null as the first argument.

This functionality is similar to UngroupSelection(Group), except that this is not a command (there is no transaction and this does not raise a DiagramEvent) and the parts are necessarily becoming top-level parts (whereas ungrouping would add them to the Group containing the Group being ungrouped).

This function is typically called in a MouseDrop event handler in order to remove the selected Parts from whatever Group they had been in.

If you want to add Parts to be members of a Group, call AddMembers(IEnumerable<Part>, bool). If you want to remove Parts completely from a Diagram, call RemoveParts(IEnumerable<Part>, bool).

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

CanCollapseSubGraph(Group)

This predicate controls whether the user can collapse expanded Groups.

Declaration
public virtual bool CanCollapseSubGraph(Group group = null)
Parameters
Type Name Description
Group group

if supplied, ignore the selection and consider collapsing this particular Group.

Returns
Type Description
bool
Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanCollapseTree(Node)

This predicate controls whether the user can collapse expanded subtrees of Nodes.

Declaration
public virtual bool CanCollapseTree(Node node = null)
Parameters
Type Name Description
Node node

if supplied, ignore the selection and consider collapsing this particular Node.

Returns
Type Description
bool
Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanCopySelection()

This predicate controls whether or not the user can invoke the CopySelection() command.

Declaration
public virtual bool CanCopySelection()
Returns
Type Description
bool

This returns true: if AllowCopy is true, if AllowClipboard is true, and if there are some selected Parts.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanCutSelection()

This predicate controls whether or not the user can invoke the CutSelection() command.

Declaration
public virtual bool CanCutSelection()
Returns
Type Description
bool

This returns true: if the diagram is not IsReadOnly, if AllowCopy is true, if AllowDelete is true, if AllowClipboard is true, and if there are some selected Parts.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanDecreaseZoom(double)

This predicate controls whether or not the user can invoke the DecreaseZoom(double) command.

Declaration
public virtual bool CanDecreaseZoom(double factor = -1)
Parameters
Type Name Description
double factor

This defaults to 1/ZoomFactor. The value should be less than one and greater than zero.

Returns
Type Description
bool

This returns true if AllowZoom is true and if the new scale is within the range of MinScale and MaxScale.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanDeleteSelection()

This predicate controls whether or not the user can invoke the DeleteSelection() command.

Declaration
public virtual bool CanDeleteSelection()
Returns
Type Description
bool

This returns true: if the diagram is not IsReadOnly, if AllowDelete is true, and if there are some selected Parts.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanEditTextBlock(TextBlock)

This predicate controls whether or not the user can invoke the EditTextBlock(TextBlock) command.

Declaration
public virtual bool CanEditTextBlock(TextBlock textblock = null)
Parameters
Type Name Description
TextBlock textblock

the TextBlock to consider editing.

Returns
Type Description
bool

This returns true: if the diagram is not IsReadOnly, if AllowTextEdit is true, if there is a TextEditingTool, and if there is any selected Part for which CanEdit() is true.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanExpandSubGraph(Group)

This predicate controls whether the user can expand collapsed Groups.

Declaration
public virtual bool CanExpandSubGraph(Group group = null)
Parameters
Type Name Description
Group group

if supplied, ignore the selection and consider expanding this particular Group.

Returns
Type Description
bool
Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanExpandTree(Node)

This predicate controls whether the user can expand collapsed subtrees of Nodes.

Declaration
public virtual bool CanExpandTree(Node node = null)
Parameters
Type Name Description
Node node

if supplied, ignore the selection and consider expanding this particular Node.

Returns
Type Description
bool
Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanGroupSelection()

This predicate controls whether or not the user can invoke the GroupSelection() command.

Declaration
public virtual bool CanGroupSelection()
Returns
Type Description
bool

This returns true: if the ArchetypeGroupData is not null, if the diagram is not IsReadOnly, if AllowInsert is true, if AllowGroup is true, if Model is a GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>, and if there is any selected Part that can be CanGroup()ed.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanIncreaseZoom(double)

This predicate controls whether or not the user can invoke the IncreaseZoom(double) command.

Declaration
public virtual bool CanIncreaseZoom(double factor = -1)
Parameters
Type Name Description
double factor

This defaults to ZoomFactor. The value should be greater than one.

Returns
Type Description
bool

This returns true if AllowZoom is true and if the new scale is within the range of MinScale and MaxScale.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanPasteSelection(Point?)

This predicate controls whether or not the user can invoke the PasteSelection(Point?) command.

Declaration
public virtual bool CanPasteSelection(Point? pos = null)
Parameters
Type Name Description
Point? pos

Point at which to center the newly pasted parts; if not present the parts would not be moved.

Returns
Type Description
bool

This returns true: if the diagram is not IsReadOnly, if AllowInsert is true, if AllowClipboard is true, and if the clipboard has parts in it.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanRedo()

This predicate controls whether or not the user can invoke the Redo() command.

Declaration
public virtual bool CanRedo()
Returns
Type Description
bool

This returns true: if the diagram is not IsReadOnly, if AllowUndo is true, and if the CanRedo() predicate returns true.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanResetZoom(double)

This predicate controls whether or not the user can invoke the ResetZoom(double) command.

Declaration
public virtual bool CanResetZoom(double newscale = -1)
Parameters
Type Name Description
double newscale

This defaults to DefaultScale, which is normally 1.0. The value should be greater than zero.

Returns
Type Description
bool

This returns true if AllowZoom is true. and if the new scale is within the range of MinScale and MaxScale.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanScrollToPart(Part)

This predicate controls whether or not the user can invoke the ScrollToPart(Part) command. This returns false if there is no argument Part and there are no selected Parts.

Declaration
public virtual bool CanScrollToPart(Part part = null)
Parameters
Type Name Description
Part part

This defaults to the first selected Part of Selection

Returns
Type Description
bool

This returns true if AllowHorizontalScroll and AllowVerticalScroll are true.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanSelectAll()

This predicate controls whether or not the user can invoke the SelectAll() command.

Declaration
public virtual bool CanSelectAll()
Returns
Type Description
bool

true if AllowSelect is true.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanShowContextMenu(IHasContextMenu)

This predicate controls whether or not the user can invoke the ShowContextMenu(IHasContextMenu) command.

Declaration
public virtual bool CanShowContextMenu(IHasContextMenu obj = null)
Parameters
Type Name Description
IHasContextMenu obj

a GraphObject or Diagram with a ContextMenu defined. If none is given, this method will use the first selected object, or else the Diagram.

Returns
Type Description
bool
Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanStopCommand()

This predicate controls whether the user may stop the current tool. This just returns true.

Declaration
public virtual bool CanStopCommand()
Returns
Type Description
bool

true.

Remarks

This method may be overridden, but probably should not be overridden. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanUndo()

This predicate controls whether or not the user can invoke the Undo() command.

Declaration
public virtual bool CanUndo()
Returns
Type Description
bool

This returns true: if the diagram is not IsReadOnly, if AllowUndo is true, and if the CanUndo() predicate returns true.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanUngroupSelection(Group)

This predicate controls whether or not the user can invoke the UngroupSelection(Group) command.

Declaration
public virtual bool CanUngroupSelection(Group group = null)
Parameters
Type Name Description
Group group

if supplied, ignore the selection and consider ungrouping this particular Group.

Returns
Type Description
bool

This returns true: if the diagram is not IsReadOnly, if AllowDelete is true, if AllowUngroup is true, if Model is a GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>, and if there are any selected Groups that are Ungroupable.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CanZoomToFit()

This predicate controls whether or not the user can invoke the ZoomToFit() command.

Declaration
public virtual bool CanZoomToFit()
Returns
Type Description
bool

This returns true if AllowZoom is true.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. This method must not have any side-effects. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CollapseSubGraph(Group)

This command collapses all expanded selected Groups. This currently has no default keyboard shortcut.

Declaration
public virtual void CollapseSubGraph(Group group = null)
Parameters
Type Name Description
Group group

if supplied, ignore the selection and collapse this particular Group.

Remarks

This operation is performed within a "Collapse SubGraph" transaction. Just before the end of the transaction this raises the "SubGraphCollapsed" DiagramEvent, with a collection of collapsed Groups as the subject.

This calls CollapseSubGraph() to perform the collapse, which will set IsSubGraphExpanded to false. You may want to save the collapsed/expanded state to the model by using a TwoWay Binding on the "IsSubGraphExpanded" property of your Groups, and perhaps also on the WasSubGraphExpanded property.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CollapseTree(Node)

This command collapses all expanded selected Nodes. This currently has no default keyboard shortcut.

Declaration
public virtual void CollapseTree(Node node = null)
Parameters
Type Name Description
Node node

if supplied, ignore the selection and collapse this particular Node subtree.

Remarks

This operation is performed within a "Collapse Tree" transaction. Just before the end of the transaction this raises the "TreeCollapsed" DiagramEvent, with a collection of collapsed Nodes as the subject.

This calls CollapseTree(int) to perform the collapse, which will set IsTreeExpanded to false. You may want to save the collapsed/expanded state to the model by using a TwoWay Binding on the "IsTreeExpanded" property of your Nodes, and perhaps also on the WasTreeExpanded property.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

ComputeEffectiveCollection(IEnumerable<Part>, DraggingOptions)

Find the actual collection of nodes and links to be moved or copied, given an initial collection.

Declaration
public virtual IDictionary<Part, DraggingInfo> ComputeEffectiveCollection(IEnumerable<Part> parts, DraggingOptions options = null)
Parameters
Type Name Description
IEnumerable<Part> parts

A collection of Parts.

DraggingOptions options

Potential options for the collection computation. If not specified, this uses the DraggingTool's drag options.

Returns
Type Description
IDictionary<Part, DraggingInfo>

a Dictionary mapping Parts to DraggingInfos that have a "point" property remembering the original location of that Part.

Remarks

This includes links that connected at both ends to nodes being moved or copied, members of Groups, and if DragsTree is true, this includes nodes and links that are "tree" descendants from selected nodes.

Note that this does not return a simple collection of Parts, but a Dictionary associating a chosen Part with a DraggingInfo holding its original location Points as the value of the "Point" property.

This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

CopySelection()

This command copies the currently selected parts, Selection, from the Diagram into the clipboard. This is normally invoked by the Ctrl-C keyboard shortcut.

Declaration
public virtual void CopySelection()
Remarks

This makes a copy of the current selection by calling CopyToClipboard(IEnumerable<Part>). This also raises the "ClipboardChanged" diagram event.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CopyToClipboard(IEnumerable<Part>)

Make a copy of the given collection of Parts and stores it in a static variable acting as the clipboard.

Declaration
public virtual void CopyToClipboard(IEnumerable<Part> coll)
Parameters
Type Name Description
IEnumerable<Part> coll

A collection of Parts. If the value is null, the clipboard is cleared of all data.

Remarks

The clipboard is initially null. It can hold a collection of copied Parts. It also remembers the DataFormat of the diagram from which the parts were copied.

This calls CopyParts(IEnumerable<Part>, Diagram, bool) in order to make a copy of the Parts for the clipboard. The values of CopiesParentKey and CopiesGroupKey affect whether a copied node data remembers its tree parent node (if in a TreeModel<TNodeData, TNodeKey, TSharedData>) or its containing group (if in a GraphLinksModel<TNodeData, TNodeKey, TSharedData, TLinkData, TLinkKey, TPort>).

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

CutSelection()

This command executes a CopySelection() followed by a DeleteSelection(). This is normally invoked by the Ctrl-X keyboard shortcut.

Declaration
public virtual void CutSelection()
Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

DecreaseZoom(double)

This command decreases the Scale by a given factor. This is normally invoked by the Ctrl-- and Keypad-- keyboard shortcuts.

Declaration
public virtual void DecreaseZoom(double factor = -1)
Parameters
Type Name Description
double factor

This defaults to 1/ZoomFactor. The value should be less than one and greater than zero.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

DeleteSelection()

This command deletes the currently selected parts from the diagram. This is normally invoked by the Del keyboard shortcut.

Declaration
public virtual void DeleteSelection()
Remarks

This will first start a "Delete" transaction, then raise the "SelectionDeleting" DiagramEvent, call RemoveParts(IEnumerable<Part>, bool) on a perhaps extended collection of selected Parts, raise the "SelectionDeleted" diagram event, and finally commit the transaction.

Because this command changes the selection, this method also raises the "ChangingSelection" and "ChangedSelection" diagram events. Changes are performed within a transaction, but the selection events are raised outside the transaction.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

DoKeyDown()

This is called by tools to handle keyboard commands.

Declaration
public virtual void DoKeyDown()
Remarks

For most commands, this calls the "Can..." predicate; if that returns true it calls the command method. If GoDiagram handles a key-down event as a keyboard command, the underlying event will not bubble.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

There is an example custom CommandHandler in the extensions directory: DrawCommandHandler.cs, which implements additional behaviors for the arrow keys by overriding this method. For additional discussion, please read the Introduction page on Commands.

DoKeyUp()

This is called by tools to handle keyboard commands.

Declaration
public virtual void DoKeyUp()
Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

EditTextBlock(TextBlock)

This command starts in-place editing of a TextBlock in the selected Part. This is normally invoked by the F2 keyboard shortcut.

Declaration
public virtual void EditTextBlock(TextBlock textblock = null)
Parameters
Type Name Description
TextBlock textblock

the TextBlock to start editing.

Remarks

This starts the TextEditingTool to have the user enter or modify the text string and finally set the Text. You may want to save the new string to the model by using a TwoWay Binding on the "Text" property of your TextBlock.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

ExpandSubGraph(Group)

This command expands all collapsed selected Groups. This currently has no default keyboard shortcut.

Declaration
public virtual void ExpandSubGraph(Group group = null)
Parameters
Type Name Description
Group group

if supplied, ignore the selection and expand this particular Group.

Remarks

This operation is performed within an "Expand SubGraph" transaction. Just before the end of the transaction this raises the "SubGraphExpanded" DiagramEvent, with a collection of expanded Groups as the subject.

This calls ExpandSubGraph() to perform the collapse, which will set IsSubGraphExpanded to true. You may want to save the collapsed/expanded state to the model by using a TwoWay Binding on the "IsSubGraphExpanded" property of your Groups, and perhaps also on the WasSubGraphExpanded property.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

ExpandTree(Node)

This command expands all collapsed selected Nodes. This currently has no default keyboard shortcut.

Declaration
public virtual void ExpandTree(Node node = null)
Parameters
Type Name Description
Node node

if supplied, ignore the selection and collapse this particular Node subtree.

Remarks

This operation is performed within an "Expand Tree" transaction. Just before the end of the transaction this raises the "TreeExpanded" DiagramEvent, with a collection of expanded Nodes as the subject.

This calls ExpandTree(int) to perform the expand, which will set IsTreeExpanded to true. You may want to save the collapsed/expanded state to the model by using a TwoWay Binding on the "IsTreeExpanded" property of your Nodes, and perhaps also on the WasTreeExpanded property.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

GroupSelection()

This command adds a copy of ArchetypeGroupData to the diagram's model to create a new Group and then adds the selected Parts to that new group. This is normally invoked by the Ctrl-G keyboard shortcut.

Declaration
public virtual void GroupSelection()
Remarks

This creates a new Group by adding a copy of the ArchetypeGroupData to the model. Each of the selected parts for which CanGroup() is true and for which IsValidMember(Group, Part) is true is made a member of that new group. If all of the selected groupable parts were members of a pre-existing group, the new group also becomes a member of that pre-existing group, if IsValidMember(Group, Part) is true for that existing group with the new group. The new group becomes the only selected part. This raises the "SelectionGrouped" diagram event. This method also raises the "ChangingSelection" and "ChangedSelection" diagram events. Changes are performed in a "Group" transaction, but the selection events are raised outside the transaction.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

IncreaseZoom(double)

This command increases the Scale by a given factor. This is normally invoked by the Ctrl-+ and Keypad-+ keyboard shortcuts.

Declaration
public virtual void IncreaseZoom(double factor = -1)
Parameters
Type Name Description
double factor

This defaults to ZoomFactor. The value should be greater than one.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

IsValidMember(Group, Part)

This predicate is called to determine whether a Node may be added as a member of a Group.

Declaration
public virtual bool IsValidMember(Group group, Part part)
Parameters
Type Name Description
Group group

this may be null if the node is being added as a top-level node.

Part part

a Part, usually a Node, possibly another Group, but not a Link or an Adornment.

Returns
Type Description
bool

true if OK to add the node to the group.

Remarks

This always checks to make sure no group might become a member of itself, either directly or indirectly. If the Group has a MemberValidation predicate and if it returns false, this method returns false. If this CommandHandler has a MemberValidation predicate and if it returns false, this method returns false. Otherwise this will return true.

For a more general discussion of validation, see Introduction to Validation.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

PasteFromClipboard()

If the clipboard holds a collection of Parts, and if the DataFormat matches that stored in the clipboard, this makes a copy of the clipboard's parts and adds the copies to this Diagram.

Declaration
public virtual IReadOnlyCollection<Part> PasteFromClipboard()
Returns
Type Description
IReadOnlyCollection<Part>

a collection of the newly pasted Parts, or an empty Set if there was no data in the clipboard.

Remarks

This calls CopyParts(IEnumerable<Part>, Diagram, bool) in order to make a copy of the Parts in the clipboard and add them to this diagram.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

PasteSelection(Point?)

This command copies the contents of the clipboard into this diagram and makes those new parts the new selection. This is normally invoked by the Ctrl-V keyboard shortcut.

Declaration
public virtual void PasteSelection(Point? pos = null)
Parameters
Type Name Description
Point? pos

Point at which to center the newly pasted parts; if not present the parts are not moved.

Remarks

This calls PasteFromClipboard() to add copies of Parts into this diagram, and then selects all of the newly created parts. This also raises the "ClipboardPasted" diagram event. This method raises the "ChangingSelection" and "ChangedSelection" diagram events. Changes are performed in a transaction, but the selection events are raised outside the transaction.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

Redo()

This command calls Redo(). This is normally invoked by the Ctrl-Y keyboard shortcut.

Declaration
public virtual void Redo()
Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

ResetZoom(double)

This command sets the Scale to a new scale value, by default 1. This is normally invoked by the Ctrl-0 keyboard shortcut.

Declaration
public virtual void ResetZoom(double newscale = -1)
Parameters
Type Name Description
double newscale

This defaults to DefaultScale, which is normally 1.0. The value should be greater than zero.

Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

ScrollToPart(Part)

This command scrolls the diagram to make a highlighted or selected Part visible in the viewport. This is normally invoked by the Space keyboard shortcut.

Declaration
public virtual void ScrollToPart(Part part = null)
Parameters
Type Name Description
Part part

This defaults to the first highlighted Part of Highlighteds, or, if there are no highlighted Parts, the first selected Part.

Remarks

Call this command repeatedly to cycle through the Highlighteds collection, if there are any Parts in that collection, or else in the Selection collection, scrolling to each one in turn by calling CenterRect(Rect).

This method animates to the scrolled part, and ScrollToRect(Rect) does not.

If there is no argument and there is no highlighted or selected Part, this command does nothing.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

SelectAll()

This command selects all of the selectable Parts in the diagram by setting IsSelected to true on each one. This is normally invoked by the Ctrl-A keyboard shortcut.

Declaration
public virtual void SelectAll()
Remarks

This method raises the "ChangingSelection" and "ChangedSelection" diagram events. This ignores all parts in temporary layers.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

ShowContextMenu(IHasContextMenu)

This command opens the context menu for a selected Part or given GraphObject, or else for the whole Diagram. This is normally invoked by the Menu keyboard shortcut.

Declaration
public virtual void ShowContextMenu(IHasContextMenu obj = null)
Parameters
Type Name Description
IHasContextMenu obj

a GraphObject or Diagram with a contextMenu defined. If none is given, this method will use the first selected object, or else the Diagram. The method will simulate a right-button click at the middle of the GraphObject or, if a Diagram, at the current mouse position if it is in the viewport.

Remarks

The given GraphObject must have a ContextMenu defined in order to show anything.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

StopCommand()

This command cancels the operation of the current tool. This is typically called when the user presses ESCAPE.

Declaration
public virtual void StopCommand()
Remarks

If the current tool is a ToolManager, this clears the diagram's selection. This then calls DoCancel() on the current tool.

See Also

Undo()

This command calls Undo(). This is normally invoked by the Ctrl-Z keyboard shortcut.

Declaration
public virtual void Undo()
Remarks

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

UngroupSelection(Group)

This command removes selected groups from the diagram without removing their members from the diagram. This is normally invoked by the Ctrl-Shift-G keyboard shortcut.

Declaration
public virtual void UngroupSelection(Group group = null)
Parameters
Type Name Description
Group group

if supplied, ignore the selection and consider ungrouping this particular Group.

Remarks

For the given group, or if not supplied, each selected Group that is Ungroupable, expand the subgraph and change all of its member parts to be members of the group that the selected group node is in. (If the selected group is a top-level node, i.e. not a member of any group node, its members become top-level parts too.) All of those selected groups are deleted. All of the reparented member parts are selected.

This raises the "SelectionUngrouped" diagram event. This method also raises the "ChangingSelection" and "ChangedSelection" diagram events. Changes are performed in an "Ungroup" transaction, but the selection events are raised outside the transaction.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also

ZoomToFit()

This command changes the Scale so that the DocumentBounds fits within the viewport. This is normally invoked by the Shift-Z keyboard shortcut.

Declaration
public virtual void ZoomToFit()
Remarks

This animates zooming by default. ZoomToFit() does not animate.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

See Also