Esempio n. 1
0
        public static async Task <CodeConversion> CreateAsync(CodeConverterPackage serviceProvider, VisualStudioWorkspace visualStudioWorkspace, Func <Task <ConverterOptionsPage> > getOptions)
        {
            var options = await getOptions();

            AppDomain.CurrentDomain.UseVersionAgnosticAssemblyResolution(options.BypassAssemblyLoadingErrors);

            return(new CodeConversion(serviceProvider, serviceProvider.JoinableTaskFactory, serviceProvider.PackageCancellation, visualStudioWorkspace,
                                      getOptions, await OutputWindow.CreateAsync()));
        }
Esempio 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);
        }
Esempio n. 3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ConvertVBToCSCommand" /> 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 ConvertVBToCSCommand(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);

                var nodeItemCtxMenuCommandId = new CommandID(CommandSet, NodeItemCtxMenuCommandId);
                var nodeItemCtxMenuItem      = package.CreateCommand(ProjectItemMenuItemCallbackAsync, nodeItemCtxMenuCommandId);
                nodeItemCtxMenuItem.BeforeQueryStatus += ProjectItemMenuItem_BeforeQueryStatusAsync;
                commandService.AddCommand(nodeItemCtxMenuItem);
            }
        }
Esempio n. 4
0
 /// <remarks>
 ///     Must be called from UI thread
 /// </remarks>
 public static void Initialize(CodeConverterPackage package, OleMenuCommandService menuCommandService,
                               CodeConversion codeConversion)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     Instance = new PasteAsVB(package, codeConversion, menuCommandService);
 }
Esempio n. 5
0
 public static async Task <CodeConversion> CreateAsync(CodeConverterPackage serviceProvider, VisualStudioWorkspace visualStudioWorkspace, Func <Task <ConverterOptionsPage> > getOptions)
 {
     return(new CodeConversion(serviceProvider, serviceProvider.JoinableTaskFactory, serviceProvider.PackageCancellation, visualStudioWorkspace,
                               getOptions, await OutputWindow.CreateAsync()));
 }