Ejemplo n.º 1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ConvertCSToVBCommand" /> class.
        ///     Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="codeConversion"></param>
        /// <param name="commandService"></param>
        /// <remarks>Must be called on the UI thread due to VS 2017's implementation of AddCommand which calls GetService</remarks>
        private ConvertCSToVBCommand(CodeConverterPackage package, CodeConversion codeConversion,
                                     OleMenuCommandService commandService)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            _package        = package ?? throw new ArgumentNullException(nameof(package));
            _codeConversion = codeConversion;

            if (commandService != null)
            {
                // Command in main menu
                var menuCommandId = new CommandID(CommandSet, MainMenuCommandId);
                var menuItem      = package.CreateCommand(CodeEditorMenuItemCallbackAsync, menuCommandId);
                menuItem.BeforeQueryStatus += MainEditMenuItem_BeforeQueryStatusAsync;
                commandService.AddCommand(menuItem);

                // Command in code editor's context menu
                var ctxMenuCommandId = new CommandID(CommandSet, CtxMenuCommandId);
                var ctxMenuItem      = package.CreateCommand(CodeEditorMenuItemCallbackAsync, ctxMenuCommandId);
                ctxMenuItem.BeforeQueryStatus += CodeEditorMenuItem_BeforeQueryStatusAsync;
                commandService.AddCommand(ctxMenuItem);

                // Command in project item context menu
                var projectItemCtxMenuCommandId = new CommandID(CommandSet, ProjectItemCtxMenuCommandId);
                var projectItemCtxMenuItem      =
                    package.CreateCommand(ProjectItemMenuItemCallbackAsync, projectItemCtxMenuCommandId);
                projectItemCtxMenuItem.BeforeQueryStatus += ProjectItemMenuItem_BeforeQueryStatusAsync;
                commandService.AddCommand(projectItemCtxMenuItem);

                // Command in project context menu
                var projectCtxMenuCommandId = new CommandID(CommandSet, ProjectCtxMenuCommandId);
                var projectCtxMenuItem      =
                    package.CreateCommand(SolutionOrProjectMenuItemCallbackAsync, projectCtxMenuCommandId);
                projectCtxMenuItem.BeforeQueryStatus += SolutionOrProjectMenuItem_BeforeQueryStatusAsync;
                commandService.AddCommand(projectCtxMenuItem);

                // Command in project context menu
                var solutionCtxMenuCommandId = new CommandID(CommandSet, SolutionCtxMenuCommandId);
                var solutionCtxMenuItem      =
                    package.CreateCommand(SolutionOrProjectMenuItemCallbackAsync, solutionCtxMenuCommandId);
                solutionCtxMenuItem.BeforeQueryStatus += SolutionOrProjectMenuItem_BeforeQueryStatusAsync;
                commandService.AddCommand(solutionCtxMenuItem);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="PasteAsVB" /> class.
        ///     Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="codeConversion">Instance of the code converter, not null.</param>
        /// <param name="commandService">Command service to add command to, not null.</param>
        private PasteAsVB(CodeConverterPackage package, CodeConversion codeConversion,
                          OleMenuCommandService commandService)
        {
            this._package   = package ?? throw new ArgumentNullException(nameof(package));
            _codeConversion = codeConversion;
            commandService  = commandService ?? throw new ArgumentNullException(nameof(commandService));

            var menuCommandID = new CommandID(CommandSet, MainMenuCommandId);
            var menuItem      = package.CreateCommand(CodeEditorMenuItemCallbackAsync, menuCommandID);

            menuItem.BeforeQueryStatus += MainEditMenuItem_BeforeQueryStatusAsync;
            commandService.AddCommand(menuItem);
        }