Export (0) Print
Expand All

CommandSet Class

Represents a subset of the commands that are available in the menus of a domain-specific language. Override methods in YourLanguageCommandSet to modify how these commands are processed.

This API is not CLS-compliant. 

Namespace:  Microsoft.VisualStudio.Modeling.Shell
Assembly:  Microsoft.VisualStudio.Modeling.Sdk.Shell.12.0 (in Microsoft.VisualStudio.Modeling.Sdk.Shell.12.0.dll)

[CLSCompliantAttribute(false)]
public abstract class CommandSet : CommandSetLibrary

The CommandSet type exposes the following members.

  NameDescription
Protected methodCommandSetInitializes a new instance of the CommandSet class.
Top

  NameDescription
Protected propertyCurrentDocData (Inherited from CommandSetLibrary.)
Protected propertyCurrentDocumentSelection (Inherited from CommandSetLibrary.)
Protected propertyCurrentDocViewGets the view for the active document window.
Protected propertyCurrentModelingDocView (Inherited from CommandSetLibrary.)
Protected propertyCurrentSelection (Inherited from CommandSetLibrary.)
Protected propertyMenuService (Inherited from CommandSetLibrary.)
Protected propertyMonitorSelection (Inherited from CommandSetLibrary.)
Protected propertyServiceProvider (Inherited from CommandSetLibrary.)
Protected propertySingleDocumentSelection (Inherited from CommandSetLibrary.)
Protected propertySingleSelection (Inherited from CommandSetLibrary.)
Top

  NameDescription
Protected methodCanDeleteSelectedItemsReturns true if the selected items can be deleted. (Inherited from CommandSetLibrary.)
Public methodCreateObjRefSecurity Critical. Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Protected methodDeleteSelectedItemsDelete the selected items. (Inherited from CommandSetLibrary.)
Public methodEqualsDetermines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetLifetimeServiceSecurity Critical. Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodGetMenuCommandsDisplays the commands on the shortcut menu. (Overrides CommandSetLibrary.GetMenuCommands().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeInitialize the command set. Calls GetMenuCommands and caches the result. (Inherited from CommandSetLibrary.)
Public methodInitializeLifetimeServiceSecurity Critical. Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodIsAnyDocumentSelectionCompartmentTrue if any of the items in the selection list is a compartment. (Inherited from CommandSetLibrary.)
Protected methodIsAnyDocumentSelectionMoveableHostShapeTrue if any of the items in the selection list is a moveable host shape, which cannot be deleted. (Inherited from CommandSetLibrary.)
Protected methodIsAnyDocumentSelectionUndeletableTrue if any of the shape items in the selection list cannot be deleted. (Inherited from CommandSetLibrary.)
Protected methodIsCurrentDiagramEmptyTrue if the diagram has no children. (Inherited from CommandSetLibrary.)
Protected methodIsDiagramSelectedTrue if the diagram is selected. (Inherited from CommandSetLibrary.)
Protected methodIsExpandableShapeVerifies whether a user can expand the shape to reveal domain properties.
Protected methodIsSingleDocumentSelectionTrue if there is only one selected item on the active document. (Inherited from CommandSetLibrary.)
Protected methodIsSingleSelectionTrue if there is only one selected item on the active document window or tool window. (Inherited from CommandSetLibrary.)
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Protected methodProcessOnMenuDeleteCommandCalled when the user clicks the Delete command or presses the Delete key. Deletes an item. Override this method to alter this behavior.
Protected methodProcessOnMenuEditCompartmentItemCommandCalled when the user clicks the Edit menu command on an item in a compartment shape. Enters the text edit state. Override this method to alter this behavior.
Protected methodProcessOnMenuExpandCollapseCommandCalled when the user Expands or collapses a list of properties that is assigned to a shape.
Protected methodProcessOnMenuPageSetupCommandOpens the Page Setup dialog box. Override this method to alter this behavior.
Protected methodProcessOnMenuPrintCommandOpens the Print dialog box. Override this method to alter this behavior.
Protected methodProcessOnMenuPrintPreviewCommandOpens the print preview window. Override this method to alter this behavior.
Protected methodProcessOnMenuRerouteLineCommandRestores the default position of a connector between two shapes. Override this method to alter this behavior.
Protected methodProcessOnMenuResetDecoratorLocationCommandOverride this method to process the Reset Decorator Location menu command.
Protected methodProcessOnMenuResetDecoratorSizeCommandOverride this method to process the Reset Decorator Size menu command.
Protected methodProcessOnMenuSelectAllCommandCalled when the user clicks the Select All command on the Edit menu, or presses ctrl-A. Selects all shapes in a diagram. Override the method to alter this behavior.
Protected methodProcessOnStatusDeleteCommandDetermines whether the Delete command appears on the context menu. Called when the user right-clicks over the diagram.
Protected methodProcessOnStatusEditCompartmentItemCommandDetermines whether the Edit command appears on the context menu.
Protected methodProcessOnStatusExpandCollapseCommandDetermines whether the Expand or Collapse command appears on the context menu. Called when the user right-clicks over the diagram.
Protected methodProcessOnStatusPageSetupCommandDetermines whether the Page Setup command appears on the File menu. Called when the user clicks the File menu while the diagram is active.
Protected methodProcessOnStatusPrintCommandDetermines whether the Print command appears on the File menu. Called when the user clicks the File menu while the diagram is active.
Protected methodProcessOnStatusPrintPreviewCommandDetermines whether the Print Preview command appears on the menu. Called when the user clicks the File menu while the diagram is active.
Protected methodProcessOnStatusRerouteLineCommandDetermines whether the Reroute command appears on the context menu. Called when the user right-clicks over the diagram.
Protected methodProcessOnStatusResetDecoratorLocationCommandDetermines whether the Rest Decorator Location command appears on the context menu. Called when the user right-clicks over the diagram.
Protected methodProcessOnStatusResetDecoratorSizeCommandDetermines whether the Reset Decorator Size command appears on the menu. Called when the user right-clicks over the diagram.
Protected methodProcessOnStatusSelectAllCommandDetermines whether the Select All command appears on the menu. Called when the user clicks the Edit menu while the diagram is active.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

You can modify how your DSL responds to some menu commands. The commands you can modify include the commands on the shortcut menu, and some commands on the File and Edit menus.

In your DslPackage project, you will find a generated file called CommandSet.cs, containing a partial declaration of a class called <YourLanguageName>CommandSet. To modify the behavior of the standard menu commands, add another file with a partial definition of the same class.

In this class, you can override the methods defined in the base class.

NoteNote

Verify that the namespace in your new file is the same as the namespace in the generated CommandSet.cs. In your new file, when you type "override " within the class declaration, you should see a list of the methods that you can override.

Each command has a ProcessOnStatus... method and a ProcessOnMenu... method. The ProcessOnStatus... method determines whether the command appears on the right-click menu. Set the Visible property of the command parameter to determine whether the command is visible, and set the Enabled property to determine whether the menu item is enabled or greyed out.

The ProcessOnMenu... method performs the command when the user clicks the menu item.

NoteNote

You can define additional commands in the Commands.vsct file.

For more information, see How to: Add a Command to the Shortcut Menu.

This file is added to the DslPackage project. It prevents users of the DSL from deleting more than one element at a time.

// In the DslPackage project.
namespace Company.Language1 // Check this is correct after creating the file.
{
  internal partial class Language1CommandSet // Same class as the generated class.
  {
    /// <summary>
    /// Called when user right-clicks on the diagram or clicks the Edit menu.
    /// </summary>
    /// <param name="command"></param>
    protected override void ProcessOnStatusDeleteCommand(System.ComponentModel.Design.MenuCommand command)
    {
      if (this.CurrentSelection.Count > 1)
      {
        // If user has selected more than one item, Delete is greyed out.
        command.Enabled = false;
      }
      else
      {
        // Otherwise, default behavior.
        base.ProcessOnStatusDeleteCommand(command);
      }
    }
    /// <summary>
    /// Called when user presses Delete key or clicks the Delete command on a menu.
    /// </summary>
    protected override void ProcessOnMenuDeleteCommand()
    {
      // Allow users to delete only one thing at a time.
      if (this.CurrentSelection.Count <= 1)
      {
        base.ProcessOnMenuDeleteCommand();
      }
    }
  }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2015 Microsoft