Class CommandHandler

The Diagram#commandHandler implements various commands such as CommandHandler#deleteSelection or CommandHandler#redo. The CommandHandler includes keyboard event handling to interpret key presses as commands.

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(): CommandHandler

The constructor produces a CommandHandler with the default key bindings.

Returns

CommandHandler

Properties

public archetypeGroupData: Object

Gets or sets a data object that is copied by #groupSelection when creating a new Group.

public copiesTree: boolean

Gets or sets whether #copySelection should also copy subtrees.

public deletesTree: boolean

Gets or sets whether #deleteSelection should also delete subtrees.

public diagram: Diagram

Gets the Diagram that is using this CommandHandler.

public memberValidation: (g: go.Group, p: go.Part) => boolean

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

public zoomFactor: number

Gets or sets the amount by which #decreaseZoom and #increaseZoom change the Diagram#scale; default is 1.05.

Methods

public addTopLevelParts(coll: Iterable, check?: boolean): boolean

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

Parameters

  • coll: Iterable

    a collection of Parts.

  • check?: boolean optional

    whether to call #isValidMember to confirm that changing the Part to be a top-level Part is valid.

Returns

boolean

public canCollapseSubGraph(group?: Group): boolean

This predicate controls whether the user can collapse expanded Groups.

Parameters

  • group?: Group optional

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

Returns

boolean

public canCollapseTree(node?: Node): boolean

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

Parameters

  • node?: Node optional

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

Returns

boolean

public canCopySelection(): boolean

This predicate controls whether or not the user can invoke the #copySelection command.

Returns

boolean

public canCutSelection(): boolean

This predicate controls whether or not the user can invoke the #cutSelection command.

Returns

boolean

public canDecreaseZoom(factor?: number): boolean

This predicate controls whether or not the user can invoke the #decreaseZoom command.

Parameters

  • factor?: number optional

    This defaults to 1/#zoomFactor. The value should be less than one.

Returns

boolean

public canDeleteSelection(): boolean

This predicate controls whether or not the user can invoke the #deleteSelection command.

Returns

boolean

public canEditTextBlock(textblock?: TextBlock): boolean

This predicate controls whether or not the user can invoke the #editTextBlock command.

Parameters

  • textblock?: TextBlock optional

    the TextBlock to consider editing.

Returns

boolean

public canExpandSubGraph(group?: Group): boolean

This predicate controls whether the user can expand collapsed Groups.

Parameters

  • group?: Group optional

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

Returns

boolean

public canExpandTree(node?: Node): boolean

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

Parameters

  • node?: Node optional

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

Returns

boolean

public canGroupSelection(): boolean

This predicate controls whether or not the user can invoke the #groupSelection command.

Returns

boolean

public canIncreaseZoom(factor?: number): boolean

This predicate controls whether or not the user can invoke the #increaseZoom command.

Parameters

  • factor?: number optional

    This defaults to #zoomFactor. The value should be greater than one.

Returns

boolean

public canPasteSelection(): boolean

This predicate controls whether or not the user can invoke the #pasteSelection command.

Returns

boolean

public canRedo(): boolean

This predicate controls whether or not the user can invoke the #redo command.

Returns

boolean

public canResetZoom(newscale?: number): boolean

This predicate controls whether or not the user can invoke the #resetZoom command.

Parameters

  • newscale?: number optional

    This defaults to 1. The value should be greater than zero.

Returns

boolean

public canSelectAll(): boolean

This predicate controls whether or not the user can invoke the #selectAll command.

Returns

boolean

public canStopCommand(): boolean

This predicate controls whether the user may stop the current tool.

Returns

boolean

public canUndo(): boolean

This predicate controls whether or not the user can invoke the #undo command.

Returns

boolean

public canUngroupSelection(group?: Group): boolean

This predicate controls whether or not the user can invoke the #ungroupSelection command.

Parameters

  • group?: Group optional

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

Returns

boolean

public canZoomToFit(): boolean

This predicate controls whether or not the user can invoke the #zoomToFit command.

Returns

boolean

public collapseSubGraph(group?: Group): any

Collapse all expanded selected Groups.

Parameters

  • group?: Group optional

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

Returns

any

public collapseTree(node?: Node): any

Collapse all expanded selected Nodes.

Parameters

  • node?: Node optional

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

Returns

any

public copySelection(): any

Copy the currently selected parts, Diagram#selection, from the Diagram into the clipboard.

Returns

any

public copyToClipboard(coll: Iterable): any

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

Parameters

Returns

any

public cutSelection(): any

Execute a #copySelection followed by a #deleteSelection.

Returns

any

public decreaseZoom(factor?: number): any

Decrease the Diagram#scale by a given factor.

Parameters

  • factor?: number optional

    This defaults to 1/#zoomFactor. The value should be less than one.

Returns

any

public deleteSelection(): any

Delete the currently selected parts from the diagram.

Returns

any

public doKeyDown(): any

This is called by tools to handle keyboard commands.

Returns

any

public doKeyUp(): any

This is called by tools to handle keyboard commands.

Returns

any

public editTextBlock(textblock?: TextBlock): any

Start in-place editing of a TextBlock in the selected Part.

Parameters

  • textblock?: TextBlock optional

    the TextBlock to start editing.

Returns

any

public expandSubGraph(group?: Group): any

Expand all collapsed selected Groups.

Parameters

  • group?: Group optional

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

Returns

any

public expandTree(node?: Node): any

Expand all collapsed selected Nodes.

Parameters

  • node?: Node optional

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

Returns

any

public groupSelection(): any

Add a copy of #archetypeGroupData and add it to the diagram's model to create a new Group and then add the selected Parts to that new group.

Returns

any

public increaseZoom(factor?: Number): any

Increase the Diagram#scale by a given factor.

Parameters

  • factor?: Number optional

    This defaults to #zoomFactor. The value should be greater than one.

Returns

any

public isValidMember(group: Group, part: Part): boolean

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

Parameters

  • 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

boolean

public pasteFromClipboard(): Set

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

Returns

Set

public pasteSelection(pos?: Point): any

Copy the contents of the clipboard into this diagram, and make those new parts the new selection.

Parameters

  • pos?: Point optional

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

Returns

any

public redo(): any

Call UndoManager#redo.

Returns

any

public resetZoom(newscale?: number): any

Set the Diagram#scale to a new scale value, by default 1.

Parameters

  • newscale?: number optional

    This defaults to 1. The value should be greater than zero.

Returns

any

public selectAll(): any

Select all of the selectable Parts in the diagram.

Returns

any

public stopCommand(): any

Cancel the operation of the current tool.

Returns

any

public undo(): any

Call UndoManager#undo.

Returns

any

public ungroupSelection(group?: Group): any

Remove the group from the diagram without removing its members from the diagram.

Parameters

  • group?: Group optional

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

Returns

any

public zoomToFit(): any

Change the Diagram#scale so that the Diagram#documentBounds fits within the viewport.

Returns

any