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