/// <summary> /// This is the function that is called when the user clicks on the menu command. /// It will check that the selected object is actually an instance of this class and /// increment its click counter. /// </summary> private static void ClickCallback(object sender, EventArgs args) { DynamicTextCommand cmd = sender as DynamicTextCommand; if (null != cmd) { cmd.clickCount++; } }
private void initMenus() { // Now get the OleCommandService object provided by the MPF; this object is the one // responsible for handling the collection of commands implemented by the package. OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null == mcs) { AsmDudeToolsStatic.Output("WARNING: could not retrieve the IMenuCommandService."); } else { AsmDudeToolsStatic.Output("INFO: retrieved the IMenuCommandService."); // Now create one object derived from MenuCommand for each command defined in // the VSCT file and add it to the command service. // For each command we have to define its id that is a unique Guid/integer pair. CommandID id = new CommandID(Guids.guidMenuAndCommandsCmdSet, PkgCmdIDList.cmdidMyCommand); // Now create the OleMenuCommand object for this command. The EventHandler object is the // function that will be called when the user will select the command. OleMenuCommand command = new OleMenuCommand(new EventHandler(MenuCommandCallback), id); // Add the command to the command service. mcs.AddCommand(command); // Create the MenuCommand object for the command placed in the main toolbar. id = new CommandID(Guids.guidMenuAndCommandsCmdSet, PkgCmdIDList.cmdidMyGraph); command = new OleMenuCommand(new EventHandler(GraphCommandCallback), id); mcs.AddCommand(command); // Create the MenuCommand object for the command placed in our toolbar. id = new CommandID(Guids.guidMenuAndCommandsCmdSet, PkgCmdIDList.cmdidMyZoom); command = new OleMenuCommand(new EventHandler(ZoomCommandCallback), id); mcs.AddCommand(command); // Create the DynamicMenuCommand object for the command defined with the TextChanges // flag. id = new CommandID(Guids.guidMenuAndCommandsCmdSet, PkgCmdIDList.cmdidDynamicTxt); command = new DynamicTextCommand(id, VsPackage.ResourceManager.GetString("DynamicTextBaseText")); mcs.AddCommand(command); // Now create two OleMenuCommand objects for the two commands with dynamic visibility id = new CommandID(Guids.guidMenuAndCommandsCmdSet, PkgCmdIDList.cmdidDynVisibility1); dynamicVisibilityCommand1 = new OleMenuCommand(new EventHandler(DynamicVisibilityCallback), id); mcs.AddCommand(dynamicVisibilityCommand1); id = new CommandID(Guids.guidMenuAndCommandsCmdSet, PkgCmdIDList.cmdidDynVisibility2); dynamicVisibilityCommand2 = new OleMenuCommand(new EventHandler(DynamicVisibilityCallback), id); // This command is the one that is invisible by default, so we have to set its visible // property to false because the default value of this property for every object derived // from MenuCommand is true. dynamicVisibilityCommand2.Visible = false; mcs.AddCommand(dynamicVisibilityCommand2); } }