/// <summary> /// Set VS UI context into active /// </summary> /// <param name="uiContextCookie">DWORD representation of the GUID identifying the command UI context</param> public static void ActivateUiContext(uint uiContextCookie) { if (_monitorSelectionService != null) { _monitorSelectionService.SetCmdUIContext(uiContextCookie, 1); // 1 for 'active' } }
private void NotifyLoaded(bool started) { ThreadHelper.ThrowIfNotOnUIThread(); // We set the user context AnkhLoadCompleted active when we are loaded // This event can be used to trigger loading other packages that depend on AnkhSVN // // When the use: // [ProvideAutoLoad(AnkhId.AnkhLoadCompleted)] // On their package, they load automatically when we are completely loaded // IVsMonitorSelection ms = GetService <IVsMonitorSelection>(); if (ms != null) { Guid gAnkhLoaded = new Guid(started ? AnkhId.AnkhRuntimeStarted : AnkhId.AnkhServicesAvailable); uint cky; if (VSErr.Succeeded(ms.GetCmdUIContextCookie(ref gAnkhLoaded, out cky))) { ms.SetCmdUIContext(cky, 1); } } }
private void UpdateCommandVisibilityContext(bool enabled) { IVsMonitorSelection selMon = (IVsMonitorSelection)GetService(typeof(SVsShellMonitorSelection)); uint cmdUIContextXenko; var cmdSet = GuidList.guidXenko_VisualStudio_PackageCmdSet; if (selMon.GetCmdUIContextCookie(ref cmdSet, out cmdUIContextXenko) == VSConstants.S_OK) selMon.SetCmdUIContext(cmdUIContextXenko, enabled ? 1 : 0); }
private static void SetUIContext(IVsMonitorSelection monitorSelection, Guid contextGuid, bool value) { uint cookie = 0; ErrorHandler.ThrowOnFailure(monitorSelection.GetCmdUIContextCookie(contextGuid, out cookie)); if (cookie != 0) { ErrorHandler.ThrowOnFailure(monitorSelection.SetCmdUIContext(cookie, value ? 1 : 0)); } }
private void SetUIContext(IVsMonitorSelection monitorSelection, Guid contextGuid, bool value) { ThreadHelper.ThrowIfNotOnUIThread(); ErrorHandler.ThrowOnFailure(monitorSelection.GetCmdUIContextCookie(contextGuid, out uint cookie)); if (cookie != 0) { ErrorHandler.ThrowOnFailure(monitorSelection.SetCmdUIContext(cookie, value ? 1 : 0)); } }
private void UpdateCommandVisibilityContext(bool enabled) { IVsMonitorSelection selectionMonitor = (IVsMonitorSelection)GetService(typeof(SVsShellMonitorSelection)); var cmdSet = GuidList.guidStride_VisualStudio_PackageCmdSet; if (selectionMonitor.GetCmdUIContextCookie(ref cmdSet, out uint cmdUIContextStride) == VSConstants.S_OK) { selectionMonitor.SetCmdUIContext(cmdUIContextStride, enabled ? 1 : 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); } }
/// <summary> /// Sets the current UI context. /// </summary> /// <param name="uiContextGuid">The GUID to uniquely identify the UI context.</param> /// <param name="isActive">Determines if the UI context is active or not.</param> public async Task SetUIContextAsync(Guid uiContextGuid, bool isActive) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsMonitorSelection svc = await VS.Services.GetMonitorSelectionAsync(); int cookieResult = svc.GetCmdUIContextCookie(uiContextGuid, out uint cookie); ErrorHandler.ThrowOnFailure(cookieResult); int setContextResult = svc.SetCmdUIContext(cookie, isActive ? 1 : 0); ErrorHandler.ThrowOnFailure(setContextResult); }
public int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew) { bool isUnderSourceControl = false; if (pHierNew != null) { object fileName; pHierNew.GetProperty(itemidNew, (int)__VSHPROPID.VSHPROPID_Name, out fileName); if (fileName != null && fileName is String) { isUnderSourceControl = _locator((string)fileName); } } SelectionService.SetCmdUIContext(ContextCookie, Convert.ToInt32(isUnderSourceControl)); return(VSConstants.S_OK); }
public int OnElementValueChanged(uint elementid, object varValueOld, object varValueNew) { //Watch the active toolwindow in the shell, if it becomes us or was us then toggle our command UI context //to be active (if we are becoming the selected toolwindow) or inactive (if we are losing our status //as the selected toolwindow). if ((VSConstants.VSSELELEMID)elementid == VSConstants.VSSELELEMID.SEID_WindowFrame) { if (varValueOld == this.Frame || varValueNew == this.Frame) { IVsMonitorSelection selMon = (IVsMonitorSelection)GetService(typeof(SVsShellMonitorSelection)); int isActive = ((varValueNew == this.Frame) ? 1 : 0); ErrorHandler.ThrowOnFailure(selMon.SetCmdUIContext(this.cmdUIContextCookie, isActive)); } } return(VSConstants.S_OK); }
private void ActivateDebugEngine() { // The debug engine will not work unless we enable a CmdUIContext using the engine's GUID. if (debugEngineCmdUICookie == 0) { IVsMonitorSelection monitorSelection = ServiceProvider.GlobalProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; if (monitorSelection == null) { throw new InvalidOperationException(String.Format("Missing service {0}!", typeof(IVsMonitorSelection).FullName)); } Guid guidDebugEngine = CorDebug.EngineGuid;//DebuggerGuids.EngineId; // int hr = monitorSelection.GetCmdUIContextCookie(ref guidDebugEngine, out debugEngineCmdUICookie); if (ErrorHandler.Succeeded(hr)) { ErrorHandler.ThrowOnFailure(monitorSelection.SetCmdUIContext(debugEngineCmdUICookie, 1)); } else { // GetCmdUIContextCookie is expected to fail if the IDE has been launched // in command line mode. Verify that it's unexpected before throwing. IVsShell vsShell = ServiceProvider.GlobalProvider.GetService(typeof(SVsShell)) as IVsShell; if (vsShell != null) { object inCmdLineMode; ErrorHandler.ThrowOnFailure(vsShell.GetProperty((int)__VSSPROPID.VSSPROPID_IsInCommandLineMode, out inCmdLineMode)); if (inCmdLineMode is bool) { if ((bool)inCmdLineMode) { hr = VSConstants.S_OK; } } } // Reset hr to S_OK to avoid throwing here if the failure was expected. ErrorHandler.ThrowOnFailure(hr); } } }
int IVsSelectionEvents.OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew) { if (pHierNew != null) { string itemName; //pHierNew.GetProperty(itemidNew, (int)__VSHPROPID.VSHPROPID_Name, out itemName); pHierNew.GetCanonicalName(itemidNew, out itemName); bool activectx = itemName != null && (itemName.ToString().Contains("Views") || itemName.ToString().Contains("views")); if (activectx) { object temp; hierarchy = pHierNew; pHierNew.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectDir, out temp); projectDir = temp.ToString(); //root = projectFullName.Substring(0, projectFullName.LastIndexOf('\\') + 1); pHierNew.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectName, out temp); projectName = temp.ToString(); viewsFolderName = itemName.ToString(); } int factive = (activectx)? 1 : 0; SelectionService.SetCmdUIContext(contextCookie, factive); } return(VSConstants.S_OK); }
private void SetBoundSolutionUIContext() { var isContextActive = !CurrentConfiguration.Equals(BindingConfiguration.Standalone); vsMonitorSelection.SetCmdUIContext(boundSolutionContextCookie, isContextActive ? 1 : 0); }
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); }); } }
public int SetCmdUIContext(uint dwCmdUICookie, int fActive) { return(_selection.SetCmdUIContext(dwCmdUICookie, fActive)); }