Share via


Command Handling

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Your editor can define new commands. Commands are typically displayed in a menu, on a tool bar, or in a context menu.

For more information about defining commands and menus, see Commands, Menus, and Toolbars.

A language service can control what context menus are shown in the editor, by intercepting the VSConstants.VSStd2KCmdID enumeration. Alternately, you can control the context menu on a per-marker basis. For more information see Important Commands for Language Service Filters.

Adding Commands to the Editor Context Menu

To add a command to the context menu, you must first define a set of menu commands belonging to a specific group. The following example is taken from the .vsct file generated as a part of the walkthrough Walkthrough: Adding Features to a Custom Editor:

<Menu guid="guidCustomEditorCmdSet" id="IDMX_RTF" priority="0x0000" type="Context">

<Parent guid="guidCustomEditorCmdSet" id="0"/>

<Strings>

<ButtonText>CustomEditor Context Menu</ButtonText>

<CommandName>CustomEditorContextMenu</CommandName>

</Strings>

</Menu>

</Menus>

The above text adds a context menu command with the text CustomEditor Context Menu. The Menu GUID is that of the command set that is created with this editor, and the type is "Context".

You can also use predefined commands that do not need to be defined in the .vsct file. For example, if you examine the EditorPane.cs file generated by the Visual Studio Package template, you find that a set of predefined commands, such as VSConstants.VSStd97CmdID defined by GUID_VSStandardCommandSet97, are handled in command handlers such as the onSelectAll method.

See Also

Commands, Menus, and Toolbars