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.

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
[CLSCompliantAttribute(false)]
public ref class CommandSet abstract : CommandSetLibrary
[<AbstractClass>]
[<CLSCompliantAttribute(false)>]
type CommandSet = 
    class
        inherit CommandSetLibrary
    end
<CLSCompliantAttribute(False)>
Public MustInherit Class CommandSet
	Inherits CommandSetLibrary
NameDescription
System_CAPS_protmethod CommandSet

Initializes a new instance of the CommandSet class.

NameDescription
System_CAPS_protproperty

(Inherited from CommandSetLibrary.)

System_CAPS_protproperty

(Inherited from CommandSetLibrary.)

System_CAPS_protproperty

Gets the view for the active document window.

System_CAPS_protproperty

(Inherited from CommandSetLibrary.)

System_CAPS_protproperty

(Inherited from CommandSetLibrary.)

System_CAPS_protproperty

(Inherited from CommandSetLibrary.)

System_CAPS_protproperty

(Inherited from CommandSetLibrary.)

System_CAPS_protproperty

(Inherited from CommandSetLibrary.)

System_CAPS_protproperty

(Inherited from CommandSetLibrary.)

System_CAPS_protproperty

(Inherited from CommandSetLibrary.)

NameDescription
System_CAPS_protmethod CanDeleteSelectedItems

Returns true if the selected items can be deleted.(Inherited from CommandSetLibrary.)

System_CAPS_pubmethod CreateObjRef

(Inherited from MarshalByRefObject.)

System_CAPS_protmethod DeleteSelectedItems

Delete the selected items.(Inherited from CommandSetLibrary.)

System_CAPS_pubmethod Equals

(Inherited from Object.)

System_CAPS_protmethod Finalize

(Inherited from Object.)

System_CAPS_pubmethod GetHashCode

(Inherited from Object.)

System_CAPS_pubmethod GetLifetimeService

(Inherited from MarshalByRefObject.)

System_CAPS_protmethod GetMenuCommands

Displays the commands on the shortcut menu.(Overrides CommandSetLibraryGetMenuCommands.)

System_CAPS_pubmethod GetType

(Inherited from Object.)

System_CAPS_pubmethod Initialize

Initialize the command set. Calls GetMenuCommands and caches the result.(Inherited from CommandSetLibrary.)

System_CAPS_pubmethod InitializeLifetimeService

(Inherited from MarshalByRefObject.)

System_CAPS_protmethod IsAnyDocumentSelectionCompartment

True if any of the items in the selection list is a compartment.(Inherited from CommandSetLibrary.)

System_CAPS_protmethod IsAnyDocumentSelectionMoveableHostShape

True if any of the items in the selection list is a moveable host shape, which cannot be deleted.(Inherited from CommandSetLibrary.)

System_CAPS_protmethod IsAnyDocumentSelectionUndeletable

True if any of the shape items in the selection list cannot be deleted. (Inherited from CommandSetLibrary.)

System_CAPS_protmethod IsCurrentDiagramEmpty

True if the diagram has no children.(Inherited from CommandSetLibrary.)

System_CAPS_protmethod IsDiagramSelected

True if the diagram is selected.(Inherited from CommandSetLibrary.)

System_CAPS_protmethod IsExpandableShape

Verifies whether a user can expand the shape to reveal domain properties.

System_CAPS_protmethod IsSingleDocumentSelection

True if there is only one selected item on the active document.(Inherited from CommandSetLibrary.)

System_CAPS_protmethod IsSingleSelection

True if there is only one selected item on the active document window or tool window.(Inherited from CommandSetLibrary.)

System_CAPS_protmethod MemberwiseClone

(Inherited from Object.)

System_CAPS_protmethod MemberwiseClone

(Inherited from MarshalByRefObject.)

System_CAPS_protmethod ProcessOnMenuDeleteCommand

Called when the user clicks the Delete command or presses the Delete key. Deletes an item. Override this method to alter this behavior.

System_CAPS_protmethod ProcessOnMenuEditCompartmentItemCommand

Called 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.

System_CAPS_protmethod ProcessOnMenuExpandCollapseCommand

Called when the user Expands or collapses a list of properties that is assigned to a shape.

System_CAPS_protmethod ProcessOnMenuPageSetupCommand

Opens the Page Setup dialog box. Override this method to alter this behavior.

System_CAPS_protmethod ProcessOnMenuPrintCommand

Opens the Print dialog box. Override this method to alter this behavior.

System_CAPS_protmethod ProcessOnMenuPrintPreviewCommand

Opens the print preview window. Override this method to alter this behavior.

System_CAPS_protmethod ProcessOnMenuRerouteLineCommand

Restores the default position of a connector between two shapes. Override this method to alter this behavior.

System_CAPS_protmethod ProcessOnMenuResetDecoratorLocationCommand

Override this method to process the Reset Decorator Location menu command.

System_CAPS_protmethod ProcessOnMenuResetDecoratorSizeCommand

Override this method to process the Reset Decorator Size menu command.

System_CAPS_protmethod ProcessOnMenuSelectAllCommand

Called 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.

System_CAPS_protmethod ProcessOnStatusDeleteCommand

Determines whether the Delete command appears on the context menu. Called when the user right-clicks over the diagram.

System_CAPS_protmethod ProcessOnStatusEditCompartmentItemCommand

Determines whether the Edit command appears on the context menu.

System_CAPS_protmethod ProcessOnStatusExpandCollapseCommand

Determines whether the Expand or Collapse command appears on the context menu. Called when the user right-clicks over the diagram.

System_CAPS_protmethod ProcessOnStatusPageSetupCommand

Determines whether the Page Setup command appears on the File menu. Called when the user clicks the File menu while the diagram is active.

System_CAPS_protmethod ProcessOnStatusPrintCommand

Determines whether the Print command appears on the File menu. Called when the user clicks the File menu while the diagram is active.

System_CAPS_protmethod ProcessOnStatusPrintPreviewCommand

Determines whether the Print Preview command appears on the menu. Called when the user clicks the File menu while the diagram is active.

System_CAPS_protmethod ProcessOnStatusRerouteLineCommand

Determines whether the Reroute command appears on the context menu. Called when the user right-clicks over the diagram.

System_CAPS_protmethod ProcessOnStatusResetDecoratorLocationCommand

Determines whether the Rest Decorator Location command appears on the context menu. Called when the user right-clicks over the diagram.

System_CAPS_protmethod ProcessOnStatusResetDecoratorSizeCommand

Determines whether the Reset Decorator Size command appears on the menu. Called when the user right-clicks over the diagram.

System_CAPS_protmethod ProcessOnStatusSelectAllCommand

Determines whether the Select All command appears on the menu. Called when the user clicks the Edit menu while the diagram is active.

System_CAPS_pubmethod ToString

(Inherited from Object.)

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.

System_CAPS_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.

System_CAPS_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.

Return to top