/// <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++;
            }
        }
        protected override void Initialize()
        {
            // Trace the beginning of this method and call the base implementation.
            Trace.WriteLine(String.Format(CultureInfo.CurrentUICulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            // 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)
            {
                // 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(GuidsList.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(GuidsList.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(GuidsList.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(GuidsList.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(GuidsList.guidMenuAndCommandsCmdSet, PkgCmdIDList.cmdidDynVisibility1);
                dynamicVisibilityCommand1 = new OleMenuCommand(new EventHandler(DynamicVisibilityCallback), id);
                mcs.AddCommand(dynamicVisibilityCommand1);

                id = new CommandID(GuidsList.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 visble
                // property to false because the default value of this property for every object derived
                // from MenuCommand is true.
                dynamicVisibilityCommand2.Visible = false;
                mcs.AddCommand(dynamicVisibilityCommand2);
            }
        }
Example #3
0
        /// <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 += 10;

                MainForm mainForm = new MainForm();
                mainForm.ShowDialog();
            }
        }
Example #4
0
        /// <summary>
        /// Initialization of the package; this is the place where you can put all the initialization
        /// code that relies on services provided by Visual Studio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // 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)
            {
                // 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(GuidsList.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(GuidsList.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(GuidsList.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(GuidsList.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(GuidsList.guidMenuAndCommandsCmdSet, PkgCmdIDList.cmdidDynVisibility1);
                dynamicVisibilityCommand1 = new OleMenuCommand(new EventHandler(DynamicVisibilityCallback), id);
                mcs.AddCommand(dynamicVisibilityCommand1);

                id = new CommandID(GuidsList.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 visble
                // property to false because the default value of this property for every object derived
                // from MenuCommand is true.
                dynamicVisibilityCommand2.Visible = false;
                mcs.AddCommand(dynamicVisibilityCommand2);
            }
        }