private bool IsSolutionExistsAndNotDebuggingAndNotBuilding() { int pfActive; var result = _vsMonitorSelection.IsCmdUIContextActive(_solutionNotBuildingAndNotDebuggingContextCookie, out pfActive); return(result == VSConstants.S_OK && pfActive > 0); }
internal SelectionData() { ThreadHelper.ThrowIfNotOnUIThread(); selectionMonitor = Package.GetGlobalService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; InitializeSelectionItems(); InitializeContextDictionary(); IVsSettingsManager userSettings = Package.GetGlobalService(typeof(SVsSettingsManager)) as IVsSettingsManager; userSettings.GetReadOnlySettingsStore((uint)__VsSettingsScope.SettingsScope_UserSettings, out var settingsStore); LoadContextIDList(settingsStore, FavoriteContexts, "Favorites"); // at the point where we are created, we don't know what contexts are live so we need to look // for all of them that we know about. foreach (uint contextID in contextIDNames.Keys) { if (ErrorHandler.Succeeded(selectionMonitor.IsCmdUIContextActive(contextID, out var active)) && active != 0) { // Add the item to the live contexts LiveContexts.Add(contextIDNames[contextID]); contextIDNames[contextID].Enabled = true; } } selectionMonitor.AdviseSelectionEvents(this, out selectionEventsCookie); }
/// <summary> /// Returns the AppId setting for the given AppId guid /// </summary> internal static bool GetAppidSetting(IServiceProvider provider, Guid setting) { ThreadHelper.ThrowIfNotOnUIThread(); int isActive = 0; // Get the command UI context from the monitor service IVsMonitorSelection monitor = provider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; if (monitor != null) { uint cookie = 0; if (monitor.GetCmdUIContextCookie(ref setting, out cookie) == VSConstants.S_OK) { int hr = monitor.IsCmdUIContextActive(cookie, out isActive); if (VSConstants.S_OK != hr) { Debug.Fail("IVsMonitorSelection.IsCmdUIContextActive failed."); // If the call fails then default to the context not being active. isActive = 0; } } } return(isActive != 0); }
private void MenuItem_BeforeQueryStatus(object sender, EventArgs e) { var cmd = ( OleMenuCommand )sender; int active = 0; ErrorHandler.ThrowOnFailure(SelectionService.IsCmdUIContextActive(DebuggingContextCookie, out active)); cmd.Visible = active != 0; }
internal void Reload(IVsMonitorSelection monitor) { ThreadHelper.ThrowIfNotOnUIThread(); int active; _active = VSErr.Succeeded(monitor.IsCmdUIContextActive(_cookie, out active)) && active != 0; }
private bool IsSolutionExistsAndNotDebuggingAndNotBuilding() { ThreadHelper.ThrowIfNotOnUIThread(); var hr = _vsMonitorSelection.IsCmdUIContextActive( _solutionExistsAndFullyLoadedContextCookie, out var pfActive); if (ErrorHandler.Succeeded(hr) && pfActive > 0) { hr = _vsMonitorSelection.IsCmdUIContextActive( _solutionNotBuildingAndNotDebuggingContextCookie, out pfActive); return(ErrorHandler.Succeeded(hr) && pfActive > 0); } return(false); }
private bool IsIDEInDebuggingOrBuildingContext() { int pfActive; int result = _vsMonitorSelection.IsCmdUIContextActive(_debuggingContextCookie, out pfActive); if (result == VSConstants.S_OK && pfActive > 0) { return(true); } result = _vsMonitorSelection.IsCmdUIContextActive(_solutionBuildingContextCookie, out pfActive); if (result == VSConstants.S_OK && pfActive > 0) { return(true); } return(false); }
/// <summary> /// Is Visual Studio in design mode. /// </summary> /// <param name="site">The service provider.</param> /// <returns>true if visual studio is in design mode</returns> public static bool IsVisualStudioInDesignMode(IServiceProvider site) { IVsMonitorSelection selectionMonitor = site.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection; uint cookie = 0; int active = 0; Guid designContext = VSConstants.UICONTEXT_DesignMode; ErrorHandler.ThrowOnFailure(selectionMonitor.GetCmdUIContextCookie(ref designContext, out cookie)); ErrorHandler.ThrowOnFailure(selectionMonitor.IsCmdUIContextActive(cookie, out active)); return active != 0; }
public static Result <bool> IsCmdUIContextActive(this IVsMonitorSelection selection, Guid cmdId) { var hresult = selection.GetCmdUIContextCookie(ref cmdId, out uint cookie); if (ErrorHandler.Failed(hresult)) { return(Result.CreateError(hresult)); } hresult = selection.IsCmdUIContextActive(cookie, out int active); return(Result.CreateSuccessOrError(active != 0, hresult)); }
private bool GetUIContext(IVsMonitorSelection monitorSelection, Guid contextGuid) { ThreadHelper.ThrowIfNotOnUIThread(); ErrorHandler.ThrowOnFailure(monitorSelection.GetCmdUIContextCookie(contextGuid, out uint cookie)); if (cookie != 0) { ErrorHandler.ThrowOnFailure(monitorSelection.IsCmdUIContextActive(cookie, out int isActive)); return(isActive != 0); } return(false); }
private static bool GetUIContext(IVsMonitorSelection monitorSelection, Guid contextGuid) { uint cookie = 0; int isActive = 0; ErrorHandler.ThrowOnFailure(monitorSelection.GetCmdUIContextCookie(contextGuid, out cookie)); if (cookie != 0) { ErrorHandler.ThrowOnFailure(monitorSelection.IsCmdUIContextActive(cookie, out isActive)); } return(isActive != 0); }
void ToggleStatusClicked(object sender, RoutedEventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); UIContextInformation item; item = SelectedInfo(); if (item != null) { IVsMonitorSelection selectionMonitor = Package.GetGlobalService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; selectionMonitor.IsCmdUIContextActive(item.ID, out var active); selectionMonitor.SetCmdUIContext(item.ID, (active == 0) ? 1 : 0); } }
internal void ErrorListQueryStatus(object sender, EventArgs e) { try { if (monitorSelection.IsCmdUIContextActive(uiContextCookie, out var isActive) == VSConstants.S_OK) { ErrorListMenuItem.Visible = isActive == 1; } } catch (Exception ex) when(!ErrorHandler.IsCriticalException(ex)) { logger.WriteLine(string.Format(Resources.ERR_QueryStatusVisualizationToolWindowCommand, ex)); } }
private bool IsDebugging() { if (_monitorSelection == null) { return(false); } int fActive; if (ErrorHandler.Succeeded(_monitorSelection.IsCmdUIContextActive(_debugUIContextCookie, out fActive))) { return(fActive != 0); } return(false); }
public int IsCmdUIContextActive(uint dwCmdUICookie, out int pfActive) { return(_selection.IsCmdUIContextActive(dwCmdUICookie, out pfActive)); }
private void CompileCommandCallback(object sender, EventArgs args) { ThreadHelper.ThrowIfNotOnUIThread(); //var mainWindow = System.Windows.Application.Current.MainWindow; //var contentControl = mainWindow?.Template?.FindName("PART_SccStatusBarHost", mainWindow) as System.Windows.Controls.ContentControl; //var statusbar = contentControl?.Content as System.Windows.Controls.Primitives.StatusBar; //statusbar.Items.Add(new System.Windows.Controls.Button() { Content = "U++test" }); Interlocked.Exchange(ref package.IsCompiling, 1); if (package.dte2.Solution.SolutionBuild.BuildState != vsBuildState.vsBuildStateInProgress) { var projs = new List <Project>(); var selitems = package.dte2.ToolWindows.SolutionExplorer.SelectedItems as Array; if (selitems != null) { foreach (var selitem in selitems) { var uiitem = selitem as UIHierarchyItem; if (uiitem != null) { var proj = uiitem.Object as Project; if (proj != null) { projs.Add(proj); } } } } UPPCompiler.RaiseReported(null, new CompilerReportedEventArgs(null)); package.JoinableTaskFactory.RunAsyncAsVsTask(VsTaskRunContext.UIThreadBackgroundPriority, async cancellationToken => { await package.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsMonitorSelection monitorSelection = await package.GetServiceAsync(typeof(IVsMonitorSelection)) as IVsMonitorSelection; Assumes.Present(monitorSelection); var sol_build_guid = VSConstants.UICONTEXT_SolutionBuilding; uint sol_build_cookie = 0; monitorSelection.GetCmdUIContextCookie(ref sol_build_guid, out sol_build_cookie); int uiactive = -1; monitorSelection.IsCmdUIContextActive(sol_build_cookie, out uiactive); if (uiactive == 0) { monitorSelection.SetCmdUIContext(sol_build_cookie, 1); } IVsStatusbar statusBar = await package.GetServiceAsync(typeof(SVsStatusbar)) as IVsStatusbar; object icon = (short)Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_Build; statusBar?.SetText("开始编译..."); statusBar?.Animation(1, ref icon); var tasks = package.Compile(projs); statusBar?.SetText("编译..."); await TaskScheduler.Default; await Task.WhenAll(tasks.Select(vtask => vtask.WaitForFinishedAsync())); await package.JoinableTaskFactory.SwitchToMainThreadAsync(); statusBar?.SetText("链接源文件..."); tasks.ForEach(task => task.ReLink()); statusBar?.Animation(0, ref icon); Interlocked.Exchange(ref package.IsCompiling, 0); uiactive = -1; monitorSelection.IsCmdUIContextActive(sol_build_cookie, out uiactive); if (uiactive == 1) { monitorSelection.SetCmdUIContext(sol_build_cookie, 0); } statusBar?.SetText("已完成"); statusBar?.Clear(); return(VSConstants.S_OK); }); } }
internal void Reload(IVsMonitorSelection monitor) { int active; _active = VSErr.Succeeded(monitor.IsCmdUIContextActive(_cookie, out active)) && active != 0; }
public CmdStateCacheItem(IVsMonitorSelection monitor, uint cookie) { if (monitor == null) throw new ArgumentNullException("monitor"); _cookie = cookie; int active; _active = ErrorHandler.Succeeded(monitor.IsCmdUIContextActive(_cookie, out active)) && active != 0; }
private static bool GetUIContext(IVsMonitorSelection monitorSelection, Guid contextGuid) { uint cookie = 0; int isActive = 0; ErrorHandler.ThrowOnFailure(monitorSelection.GetCmdUIContextCookie(contextGuid, out cookie)); if (cookie != 0) { ErrorHandler.ThrowOnFailure(monitorSelection.IsCmdUIContextActive(cookie, out isActive)); } return isActive != 0; }