/// <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> ConvertVBToCSCommand(REConverterPackage package) { this._package = package ?? throw new ArgumentNullException(nameof(package)); _codeConversion = new CodeConversion(package, package.VsWorkspace, () => package.Options); OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (commandService != null) { // Command in main menu var menuCommandId = new CommandID(CommandSet, MainMenuCommandId); var menuItem = new OleMenuCommand(CodeEditorMenuItemCallback, menuCommandId); menuItem.BeforeQueryStatus += CodeEditorMenuItem_BeforeQueryStatus; commandService.AddCommand(menuItem); // Command in code editor's context menu var ctxMenuCommandId = new CommandID(CommandSet, CtxMenuCommandId); var ctxMenuItem = new OleMenuCommand(CodeEditorMenuItemCallback, ctxMenuCommandId); ctxMenuItem.BeforeQueryStatus += CodeEditorMenuItem_BeforeQueryStatus; commandService.AddCommand(ctxMenuItem); // Command in project item context menu var projectItemCtxMenuCommandId = new CommandID(CommandSet, ProjectItemCtxMenuCommandId); var projectItemCtxMenuItem = new OleMenuCommand(ProjectItemMenuItemCallback, projectItemCtxMenuCommandId); projectItemCtxMenuItem.BeforeQueryStatus += ProjectItemMenuItem_BeforeQueryStatus; commandService.AddCommand(projectItemCtxMenuItem); // Command in project context menu var solutionOrProjectCtxMenuCommandId = new CommandID(CommandSet, SolutionOrProjectCtxMenuCommandId); var solutionOrProjectCtxMenuItem = new OleMenuCommand(SolutionOrProjectMenuItemCallback, solutionOrProjectCtxMenuCommandId); solutionOrProjectCtxMenuItem.BeforeQueryStatus += SolutionOrProjectMenuItem_BeforeQueryStatus; commandService.AddCommand(solutionOrProjectCtxMenuItem); } }
/// <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> ConvertCSToVBCommand(REConverterPackage package, CodeConversion codeConversion, OleMenuCommandService commandService) { this._package = package ?? throw new ArgumentNullException(nameof(package)); _codeConversion = codeConversion; if (commandService != null) { // Command in main menu var menuCommandId = new CommandID(CommandSet, MainMenuCommandId); var menuItem = new BlockingOleMenuCommand(CodeEditorMenuItemCallbackAsync, menuCommandId); menuItem.BeforeQueryStatus += CodeEditorMenuItem_BeforeQueryStatusAsync; commandService.AddCommand(menuItem); // Command in code editor's context menu var ctxMenuCommandId = new CommandID(CommandSet, CtxMenuCommandId); var ctxMenuItem = new BlockingOleMenuCommand(CodeEditorMenuItemCallbackAsync, ctxMenuCommandId); ctxMenuItem.BeforeQueryStatus += CodeEditorMenuItem_BeforeQueryStatusAsync; commandService.AddCommand(ctxMenuItem); // Command in project item context menu var projectItemCtxMenuCommandId = new CommandID(CommandSet, ProjectItemCtxMenuCommandId); var projectItemCtxMenuItem = new BlockingOleMenuCommand(ProjectItemMenuItemCallbackAsync, projectItemCtxMenuCommandId); projectItemCtxMenuItem.BeforeQueryStatus += ProjectItemMenuItem_BeforeQueryStatusAsync; commandService.AddCommand(projectItemCtxMenuItem); // Command in project context menu var solutionOrProjectCtxMenuCommandId = new CommandID(CommandSet, SolutionOrProjectCtxMenuCommandId); var solutionOrProjectCtxMenuItem = new BlockingOleMenuCommand(SolutionOrProjectMenuItemCallbackAsync, solutionOrProjectCtxMenuCommandId); solutionOrProjectCtxMenuItem.BeforeQueryStatus += SolutionOrProjectMenuItem_BeforeQueryStatusAsync; commandService.AddCommand(solutionOrProjectCtxMenuItem); } }
/// <summary> /// Initializes the singleton instance of the command. /// </summary> /// <param name="package">Owner package, not null.</param> public static async Task InitializeAsync(REConverterPackage package) { var codeConversion = await CodeConversion.CreateAsync(package, package.VsWorkspace, package.GetOptionsAsync); var oleMenuCommandService = await package.GetServiceAsync <IMenuCommandService, OleMenuCommandService>(); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); Instance = new ConvertVBToCSCommand(package, codeConversion, oleMenuCommandService); }
/// <summary> /// Initializes the singleton instance of the command. /// </summary> /// <param name="package">Owner package, not null.</param> public static async Task InitializeAsync(REConverterPackage package) { CodeConversion codeConversion = await CodeConversion.CreateAsync(package, package.VsWorkspace, package.GetOptionsAsync); Instance = new ConvertCSToVBCommand(package, codeConversion, await package.GetServiceAsync <IMenuCommandService, OleMenuCommandService>()); }
/// <summary> /// Initializes the singleton instance of the command. /// </summary> /// <param name="package">Owner package, not null.</param> public static void Initialize(REConverterPackage package) { Instance = new ConvertVBToCSCommand(package); }
/// <remarks> /// Must be called from UI thread /// </remarks> public static void Initialize(REConverterPackage package, OleMenuCommandService menuCommandService, CodeConversion codeConversion) { ThreadHelper.ThrowIfNotOnUIThread(); Instance = new ConvertCSToVBCommand(package, codeConversion, menuCommandService); }
public static async Task <CodeConversion> CreateAsync(REConverterPackage serviceProvider, VisualStudioWorkspace visualStudioWorkspace, Func <Task <ConverterOptionsPage> > getOptions) { return(new CodeConversion(serviceProvider, serviceProvider.JoinableTaskFactory, visualStudioWorkspace, getOptions, await OutputWindow.CreateAsync())); }