コード例 #1
0
        /// <summary>
        /// Private CTOR
        /// Add command(s) as menu item(s) to VS
        /// </summary>
        /// <param name="package">Package the command handler belongs to</param>
        /// <param name="commandService">Menu Command service used to extend the VS menu</param>
        /// <param name="dteService">DTE service used to manipulate the VS</param>
        private RadProjectsExtensionCommands(RadProjectsExtensionPackage package, OleMenuCommandService commandService, DTE2 dteService)
        {
            this.package   = package ?? throw new ArgumentNullException(nameof(package));
            commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
            dte            = dteService ?? throw new ArgumentNullException(nameof(dteService));

            //Extend the VS menu
            package.Output("Initializing commands...");
            var menuItem1 = new MenuCommand(ExecuteRadCmdApplyTemplate, new CommandID(CommandSet, RadCmdApplyTemplateId));

            commandService.AddCommand(menuItem1);

            var menuItem2 = new MenuCommand(ExecuteRadCmdSolutionConsole, new CommandID(CommandSet, RadCmdSolutionConsoleId));

            commandService.AddCommand(menuItem2);

            var menuItem3 = new MenuCommand(ExecuteRadCmdChecklists, new CommandID(CommandSet, RadCmdChecklistsId));

            commandService.AddCommand(menuItem3);

            var menuItem4 = new MenuCommand(ExecuteRadCmdVersion, new CommandID(CommandSet, RadCmdVersionId));

            commandService.AddCommand(menuItem4);

            package.Output("Initialized commands");
        }
コード例 #2
0
        /// <summary>
        /// Initialize commands (called form <see cref="RadProjectsExtensionPackage.InitializeAsync"/>)
        /// Get the MemuCommand and DTE services and creates the command handler <see cref="Instance"/>
        /// </summary>
        /// <param name="package">Package the command handler belongs to</param>
        /// <returns>Async task</returns>
        public static async Task InitializeAsync(RadProjectsExtensionPackage package)
        {
            // Switch to the main thread - the call to AddCommand in RadSolutionCommand's constructor requires
            // the UI thread.
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);

            var commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;

            var dteService = await package.GetServiceAsync(typeof(EnvDTE.DTE)) as DTE2;

            Instance = new RadProjectsExtensionCommands(package, commandService, dteService);
        }