/// <summary> /// Initializes a new instance of the <see cref="ErrorReportingToolWindowCommand"/> class. /// Adds our command handlers for menu (commands must exist in the command table file) /// </summary> /// <param name="package">Owner package, not null.</param> private ErrorReportingToolWindowCommand(Package package) { if (package == null) { throw new ArgumentNullException("package"); } _package = package; IMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as IMenuCommandService; if (commandService != null) { var menuCommandID = new CommandID(CommandSet, CommandId); var menuItem = new OleMenuCommand( (sender, e) => { ToolWindowCommandUtils.ShowToolWindow <ErrorReportingToolWindow>(); EventsReporterWrapper.ReportEvent(ErrorsViewerOpenEvent.Create()); }, menuCommandID); menuItem.BeforeQueryStatus += ToolWindowCommandUtils.EnableMenuItemOnValidProjectId; commandService.AddCommand(menuItem); } }
/// <summary> /// Initializes the singleton instance of the command. /// </summary> /// <param name="package">Owner package, not null.</param> /// <param name="token">The token to cancel adding the command.</param> public static async Task InitializeAsync(IGoogleCloudExtensionPackage package, CancellationToken token) { package.ThrowIfNull(nameof(package)); IMenuCommandService commandService = await package.GetServiceAsync <IMenuCommandService, IMenuCommandService>(); await package.JoinableTaskFactory.SwitchToMainThreadAsync(token); var menuCommandID = new CommandID(CommandSet, CommandId); var menuItem = new OleMenuCommand( async(sender, e) => { await ToolWindowCommandUtils.ShowToolWindowAsync <ErrorReportingToolWindow>(); EventsReporterWrapper.ReportEvent(ErrorsViewerOpenEvent.Create()); }, menuCommandID); menuItem.BeforeQueryStatus += ToolWindowCommandUtils.EnableMenuItemOnValidProjectId; commandService.AddCommand(menuItem); }