private bool IsSolutionExistsAndNotDebuggingAndNotBuilding() { int pfActive; int result = MonitorSelection.IsCmdUIContextActive(_solutionNotBuildingAndNotDebuggingContextCookie, out pfActive); return(result == VSConstants.S_OK && pfActive > 0); }
/// <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 Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { // 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 this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); _uiCtx = SynchronizationContext.Current; // get the solution not building and not debugging cookie Guid guid = VSConstants.UICONTEXT.SolutionExistsAndNotBuildingAndNotDebugging_guid; MonitorSelection.GetCmdUIContextCookie(ref guid, out _solutionNotBuildingAndNotDebuggingContextCookie); AuditManager.Initialize(); // Add our command handlers for menu (commands must exist in the .vsct file) AddMenuCommandHandlers(); bool isSolutionLoaded = await IsSolutionLoadedAsync(); if (isSolutionLoaded) { AuditManager.QueueAuditSolutionPackages(); } // Listen for subsequent solution events SolutionEvents.OnAfterOpenSolution += HandleOpenSolution; }
/// <summary> /// Unadvises the selection events. /// </summary> public void UnadviseSelectionEvents() { if (MonitorSelection != null && _selectionEventsCookie != 0) { MonitorSelection.UnadviseSelectionEvents(_selectionEventsCookie); } }
private void SetCmdUIContext(Guid context, bool enabled) { uint cookie; ErrorHandler.ThrowOnFailure(MonitorSelection.GetCmdUIContextCookie(ref context, out cookie)); if (cookie != 0) { ErrorHandler.ThrowOnFailure(MonitorSelection.SetCmdUIContext(cookie, (enabled ? 1 : 0))); } }
public int OnAfterDocumentWindowHide(uint docCookie, IVsWindowFrame pFrame) { if (CookieDocumentMap.ContainsKey(docCookie)) { MonitorSelection.SetCmdUIContext(MarkdownModeUIContextCookie, 0); CommandsEnabled = false; } return(VSConstants.S_OK); }
private bool IsCmdUIContextActive(Guid context) { uint cookie; ErrorHandler.ThrowOnFailure(MonitorSelection.GetCmdUIContextCookie(ref context, out cookie)); int active = 0; if (cookie != 0) { ErrorHandler.ThrowOnFailure(MonitorSelection.IsCmdUIContextActive(cookie, out active)); } return(active != 0); }
/// <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> protected override void Initialize() { base.Initialize(); _uiCtx = SynchronizationContext.Current; // get the solution not building and not debugging cookie Guid guid = VSConstants.UICONTEXT.SolutionExistsAndNotBuildingAndNotDebugging_guid; MonitorSelection.GetCmdUIContextCookie(ref guid, out _solutionNotBuildingAndNotDebuggingContextCookie); AuditManager.Initialize(); // Add our command handlers for menu (commands must exist in the .vsct file) AddMenuCommandHandlers(); }
public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame) { var currentDoc = CurrentDoc; if (CookieDocumentMap.ContainsKey(docCookie)) { CurrentDoc = CookieDocumentMap[docCookie]; MonitorSelection.SetCmdUIContext(MarkdownModeUIContextCookie, 1); CommandsEnabled = true; } else { string fullname = GetDocFullname(docCookie); if (IsUDNDocument(fullname)) { object codeWindow; pFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out codeWindow); IVsTextView view; (codeWindow as IVsCodeWindow).GetPrimaryView(out view); var wpfView = EditorAdaptersFactoryService.GetWpfTextView(view); var docView = new UDNDocView(fullname, wpfView, pFrame, package, UIShell); CookieDocumentMap[docCookie] = docView; docView.ParsingResultsCache.AfterParsingEvent += PassResultsToChangedEvent; CurrentDoc = CookieDocumentMap[docCookie]; MonitorSelection.SetCmdUIContext(MarkdownModeUIContextCookie, 1); CommandsEnabled = true; } else { MonitorSelection.SetCmdUIContext(MarkdownModeUIContextCookie, 0); CommandsEnabled = false; } } if (currentDoc != CurrentDoc) { CurrentUDNDocView.ParsingResultsCache.AsyncReparseIfDirty(); } return(VSConstants.S_OK); }
/// <summary> /// Registers a VSPackage for selection event notification. /// </summary> /// <param name="package"> /// Pointer to the Microsoft.VisualStudio.Shell.Interop.IVsSelectionEvents interface of the VSPackage /// registering for selection event notification. /// </param> /// <returns> /// If the method succeeds, it returns <see cref="Microsoft.VisualStudio.VSConstants.S_OK" />. If it fails, it /// returns an error code. /// </returns> public int?AdviseSelectionEvents(Package package) { return(MonitorSelection?.AdviseSelectionEvents(package, out _selectionEventsCookie)); }
/// <summary> /// Advises the debugging events. /// </summary> /// <param name="package">The package.</param> public void AdviseDebuggingEvents(Package package) { MonitorSelection?.GetCmdUIContextCookie(VSConstants.UICONTEXT.Debugging_guid, out _debuggingCookie); }