Domain-Specific Language Tools Reference
CommandSet.GetMenuCommands Method

Displays the commands on the shortcut menu.

This method is not CLS-compliant.  

Namespace: Microsoft.VisualStudio.Modeling.Shell
Assembly: Microsoft.VisualStudio.Modeling.Sdk.Shell (in microsoft.visualstudio.modeling.shell.dll)

Syntax

Visual Basic (Declaration)
Protected Overridable Function GetMenuCommands As IList(Of MenuCommand)
Visual Basic (Usage)
Dim returnValue As IList(Of MenuCommand)

returnValue = Me.GetMenuCommands
C#
protected virtual IList<MenuCommand> GetMenuCommands ()
C++
protected:
virtual IList<MenuCommand^>^ GetMenuCommands ()
J#
protected IList<MenuCommand> GetMenuCommands ()
JScript
protected function GetMenuCommands () : IList<MenuCommand>

Return Value

The list of menu commands.
Remarks

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

NoteNote

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

Example

This example adds a custom command to the shortcut menu. When an end 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.ctc file, the following line appears after the include statements.

C#
#define AssociationSortValidate 0x801

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

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

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

C#
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.ctc.
        private const int AssociationSortValidate = 0x801;

        // Register event handlers for menu commands when DSL 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);
        }
    }
}
See Also

Tags :


Page view tracker