public static void Initialize(DocumentManager documentManager, OleMenuCommandService commandService) { var command = new CleanTabsCommand(documentManager); var menuCommandID = new CommandID(CommandSet, CommandId); var menuItem = new MenuCommand(command.Execute, menuCommandID); commandService.AddCommand(menuItem); }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param> /// <param name="progress">A provider for progress updates.</param> /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns> protected override async TasksTask InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(false); try { var commandService = await GetServiceAsync(typeof(IMenuCommandService)).ConfigureAwait(false) as OleMenuCommandService; _dte = (DTE) await GetServiceAsync(typeof(DTE)).ConfigureAwait(false); _visualStudio = await GetServiceAsync(typeof(SDTE)).ConfigureAwait(false) as DTE2; // When initialized asynchronously, the current thread may be a background thread at this point. // Do any initialization that requires the UI thread after switching to the UI thread. await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); _settings = SettingsProvider.Initialize(GetWritableSettingsStore(this)); _documentManager = new DocumentManager(this, _visualStudio, _settings); CleanTabsCommand.Initialize(_documentManager, commandService); _windowEvents = _dte.Events.WindowEvents; _documentEvents = _dte.Events.DocumentEvents; _textEditorEvents = _dte.Events.TextEditorEvents; _solutionEvents = _dte.Events.SolutionEvents; _buildEvents = _dte.Events.BuildEvents; _documentEvents.DocumentOpened += OnDocumentEvent; _documentEvents.DocumentSaved += OnDocumentEvent; _windowEvents.WindowActivated += OnWindowActivated; _textEditorEvents.LineChanged += OnLineChanged; _solutionEvents.Opened += OnSolutionOpened; _solutionEvents.BeforeClosing += OnSolutionClosing; _buildEvents.OnBuildBegin += OnBuildBegin; LoadSolution(); } catch (Exception e) { ActivityLog.TryLogError("KeepingTabs", e.Message); Console.WriteLine(e.ToString()); throw; } }