Partager via


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. 

Inheritance Hierarchy

System.Object
  System.MarshalByRefObject
    Microsoft.VisualStudio.Modeling.Shell.CommandSetLibrary
      Microsoft.VisualStudio.Modeling.Shell.CommandSet

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

Syntax

'Declaration
<CLSCompliantAttribute(False)> _
Public MustInherit Class CommandSet _
    Inherits CommandSetLibrary
[CLSCompliantAttribute(false)]
public abstract class CommandSet : CommandSetLibrary
[CLSCompliantAttribute(false)]
public ref class CommandSet abstract : public CommandSetLibrary
[<AbstractClass>]
[<CLSCompliantAttribute(false)>]
type CommandSet =  
    class 
        inherit CommandSetLibrary 
    end
public abstract class CommandSet extends CommandSetLibrary

The CommandSet type exposes the following members.

Constructors

  Name Description
Protected method CommandSet Initializes a new instance of the CommandSet class.

Top

Properties

  Name Description
Protected property CurrentDocData (Inherited from CommandSetLibrary.)
Protected property CurrentDocumentSelection (Inherited from CommandSetLibrary.)
Protected property CurrentDocView Gets the view for the active document window.
Protected property CurrentModelingDocView (Inherited from CommandSetLibrary.)
Protected property CurrentSelection (Inherited from CommandSetLibrary.)
Protected property MenuService (Inherited from CommandSetLibrary.)
Protected property MonitorSelection (Inherited from CommandSetLibrary.)
Protected property ServiceProvider (Inherited from CommandSetLibrary.)
Protected property SingleDocumentSelection (Inherited from CommandSetLibrary.)
Protected property SingleSelection (Inherited from CommandSetLibrary.)

Top

Methods

  Name Description
Protected method CanDeleteSelectedItems Returns true if the selected items can be deleted. (Inherited from CommandSetLibrary.)
Public method CreateObjRef Security 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 method DeleteSelectedItems Delete the selected items. (Inherited from CommandSetLibrary.)
Public method Equals Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as the default hash function. (Inherited from Object.)
Public method GetLifetimeService Security Critical. Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method GetMenuCommands Displays the commands on the shortcut menu. (Overrides CommandSetLibrary.GetMenuCommands().)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method Initialize Initialize the command set. Calls GetMenuCommands and caches the result. (Inherited from CommandSetLibrary.)
Public method InitializeLifetimeService Security Critical. Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method IsAnyDocumentSelectionCompartment True if any of the items in the selection list is a compartment. (Inherited from CommandSetLibrary.)
Protected method IsAnyDocumentSelectionMoveableHostShape True if any of the items in the selection list is a moveable host shape, which cannot be deleted. (Inherited from CommandSetLibrary.)
Protected method IsAnyDocumentSelectionUndeletable True if any of the shape items in the selection list cannot be deleted. (Inherited from CommandSetLibrary.)
Protected method IsCurrentDiagramEmpty True if the diagram has no children. (Inherited from CommandSetLibrary.)
Protected method IsDiagramSelected True if the diagram is selected. (Inherited from CommandSetLibrary.)
Protected method IsExpandableShape Verifies whether a user can expand the shape to reveal domain properties.
Protected method IsSingleDocumentSelection True if there is only one selected item on the active document. (Inherited from CommandSetLibrary.)
Protected method IsSingleSelection True if there is only one selected item on the active document window or tool window. (Inherited from CommandSetLibrary.)
Protected method MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method MemberwiseClone(Boolean) Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Protected method ProcessOnMenuDeleteCommand Called when the user clicks the Delete command or presses the Delete key. Deletes an item. Override this method to alter this behavior.
Protected method 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.
Protected method ProcessOnMenuExpandCollapseCommand Called when the user Expands or collapses a list of properties that is assigned to a shape.
Protected method ProcessOnMenuPageSetupCommand Opens the Page Setup dialog box. Override this method to alter this behavior.
Protected method ProcessOnMenuPrintCommand Opens the Print dialog box. Override this method to alter this behavior.
Protected method ProcessOnMenuPrintPreviewCommand Opens the print preview window. Override this method to alter this behavior.
Protected method ProcessOnMenuRerouteLineCommand Restores the default position of a connector between two shapes. Override this method to alter this behavior.
Protected method ProcessOnMenuResetDecoratorLocationCommand Override this method to process the Reset Decorator Location menu command.
Protected method ProcessOnMenuResetDecoratorSizeCommand Override this method to process the Reset Decorator Size menu command.
Protected method 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.
Protected method ProcessOnStatusDeleteCommand Determines whether the Delete command appears on the context menu. Called when the user right-clicks over the diagram.
Protected method ProcessOnStatusEditCompartmentItemCommand Determines whether the Edit command appears on the context menu.
Protected method ProcessOnStatusExpandCollapseCommand Determines whether the Expand or Collapse command appears on the context menu. Called when the user right-clicks over the diagram.
Protected method 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.
Protected method ProcessOnStatusPrintCommand Determines whether the Print command appears on the File menu. Called when the user clicks the File menu while the diagram is active.
Protected method ProcessOnStatusPrintPreviewCommand Determines whether the Print Preview command appears on the menu. Called when the user clicks the File menu while the diagram is active.
Protected method ProcessOnStatusRerouteLineCommand Determines whether the Reroute command appears on the context menu. Called when the user right-clicks over the diagram.
Protected method ProcessOnStatusResetDecoratorLocationCommand Determines whether the Rest Decorator Location command appears on the context menu. Called when the user right-clicks over the diagram.
Protected method ProcessOnStatusResetDecoratorSizeCommand Determines whether the Reset Decorator Size command appears on the menu. Called when the user right-clicks over the diagram.
Protected method ProcessOnStatusSelectAllCommand Determines whether the Select All command appears on the menu. Called when the user clicks the Edit menu while the diagram is active.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

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.

Note

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.

Note

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

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

Examples

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();
      }
    }
  }
}

Thread Safety

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

See Also

Reference

Microsoft.VisualStudio.Modeling.Shell Namespace

Other Resources

How to: Add a Command to the Shortcut Menu