CommandSet.GetMenuCommands Method

Displays the commands on the shortcut menu.

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

Syntax

'Declaration
Protected Overrides Function GetMenuCommands As IList(Of MenuCommand)
protected override IList<MenuCommand> GetMenuCommands()
protected:
virtual IList<MenuCommand^>^ GetMenuCommands() override
abstract GetMenuCommands : unit -> IList<MenuCommand> 
override GetMenuCommands : unit -> IList<MenuCommand> 
protected override function GetMenuCommands() : IList<MenuCommand>

Return Value

Type: System.Collections.Generic.IList<MenuCommand>
The list of menu commands.

Remarks

You can override this method and add your own commands. To add your own commands, define them in a custom .vsct file and call them in a custom .cs file.

Note

Do not add your changes to the CommandSet.cs file. This file is regenerated every time that you build the generated designer.

Examples

This example adds a custom command to the shortcut menu. When a user builds a solution in the generated designer and right-clicks the diagram, one additional command, Validate, appears in the shortcut menu.

In the Commands.vsct file, the following line appears after the include statements.

#define AssociationSortValidate 0x801

In the Commands.vsct file, the following line appears after GENERATED_BUTTONS.

guidCmdSet:AssociationSortValidate, guidCmdSet:grpidContextMain, 0x0100, OI_NOID, BUTTON, DIS_DEF, "&Validate";

Within the VsctComponents folder, the following .cs file is available. The namespace and some of the methods have the name of the project, MenuSample, in them.

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.Design;
using Microsoft.VisualStudio.Modeling;
using Microsoft.VisualStudio.Modeling.Shell;

namespace MS.MenuSample
{
    internal partial class MenuSampleCommandSet
    {

        // Define the command. This must be unique and match the value in Commands.vsct.
        private const int AssociationSortValidate = 0x801;

        // Register event handlers for menu commands when the Domain-Specific Language Designer starts.
        // Get the commands defined in the generated code.
        protected override IList<System.ComponentModel.Design.MenuCommand> GetMenuCommands()
        {
            global::System.Collections.Generic.IList<global::System.ComponentModel.Design.MenuCommand> commands = base.GetMenuCommands();
            commands.Add(new DynamicStatusMenuCommand(
                new EventHandler(OnStatusChangeAssociationSort),
                new EventHandler(OnMenuChangeAssociationSort),
                CustomCommandId(AssociationSortValidate)));
            return commands;
        }

        // Set whether a command should appear in the shortcut menu by default.
        internal void OnStatusChangeAssociationSort(object sender, EventArgs e)
        {
            MenuCommand command = sender as MenuCommand;
            command.Visible = command.Enabled = true;
        }

        // Perform an Association Sort command on the current selection.
        internal void OnMenuChangeAssociationSort(object sender, EventArgs e)
        {
            MenuCommand command = sender as MenuCommand;
        }

        // Create local command IDs that are unique.
        private CommandID CustomCommandId(int command)
        {
            return new CommandID(new Guid(Constants.MenuSampleCommandSetId), command);
        }
    }
}

.NET Framework Security

See Also

Reference

CommandSet Class

Microsoft.VisualStudio.Modeling.Shell Namespace