// Support backward/forward navigation via extended mouse buttons. // Derived from https://github.com/tunnelvisionlabs/MouseNavigation/blob/master/Tvl.VisualStudio.MouseNavigation/MouseNavigationProcessor.cs. public override void PostprocessMouseUp(MouseButtonEventArgs e) { if (_vsUIShell == null) { return; } uint cmdId; if (e.ChangedButton == MouseButton.XButton1) { cmdId = (uint)VSConstants.VSStd97CmdID.ShellNavBackward; } else if (e.ChangedButton == MouseButton.XButton2) { cmdId = (uint)VSConstants.VSStd97CmdID.ShellNavForward; } else { return; } object obj = null; _vsUIShell.PostExecCommand(VSConstants.GUID_VSStandardCommandSet97, cmdId, (uint)OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref obj); e.Handled = true; }
protected override void Handle() { IVsUIShell shell = VsAppShell.Current.GetGlobalService <IVsUIShell>(typeof(SVsUIShell)); object o = null; shell.PostExecCommand(ref _shellGroup, _shellCmdId, 0, ref o); }
public static void OnCommand(object sender, EventArgs args) { if (MessageButtons.Yes == VsAppShell.Current.ShowMessage(Resources.Warning_SettingsReset, MessageButtons.YesNo)) { IVsUIShell shell = VsAppShell.Current.GetGlobalService <IVsUIShell>(typeof(SVsUIShell)); Guid group = VSConstants.CMDSETID.StandardCommandSet2K_guid; string asmDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetAssemblyPath()); string settingsFilePath1 = Path.Combine(asmDirectory, @"Profiles\", "R.vssettings"); //string settingsFilePath2 = Path.Combine(asmDirectory, @"Profiles\", "RStudioKeyboard.vssettings"); if (!File.Exists(settingsFilePath1)) { string ideFolder = asmDirectory.Substring(0, asmDirectory.IndexOf(@"\Extensions", StringComparison.OrdinalIgnoreCase)); settingsFilePath1 = Path.Combine(ideFolder, @"Profiles\", "R.vssettings"); } object arguments = string.Format(CultureInfo.InvariantCulture, "-import:\"{0}\"", settingsFilePath1); shell.PostExecCommand(ref group, (uint)VSConstants.VSStd2KCmdID.ManageUserSettings, 0, ref arguments); //if (MessageButtons.Yes == VsAppShell.Current.ShowMessage(Resources.Warning_RStudioKeyboardShortcuts, MessageButtons.YesNo)) { // arguments = string.Format(CultureInfo.InvariantCulture, "-import:\"{0}\"", settingsFilePath2); // shell.PostExecCommand(ref group, (uint)VSConstants.VSStd2KCmdID.ManageUserSettings, 0, ref arguments); //} } }
/// <include file='doc\OleMenuCommandService.uex' path='docs/doc[@for="OleMenuCommandService.GlobalInvoke1"]/*' /> /// <devdoc> /// Invokes a command on the local form or in the global environment. /// The local form is first searched for the given command ID. If it is /// found, it is invoked. Otherwise the the command ID is passed to the /// global environment command handler, if one is available. /// </devdoc> public override bool GlobalInvoke(CommandID commandID, object arg) { // is it local? if (base.GlobalInvoke(commandID, arg)) { return(true); } // pass it to the global handler IVsUIShell uiShellSvc = GetService(typeof(SVsUIShell)) as IVsUIShell; if (uiShellSvc == null) { return(false); } try { Object dummy = arg; Guid tmpGuid = commandID.Guid; if (NativeMethods.Failed(uiShellSvc.PostExecCommand(ref tmpGuid, (uint)commandID.ID, 0, ref dummy))) { return(false); } return(true); } catch (COMException) { } return(false); }
/// <summary> /// Sets the expanded state of the folder. /// </summary> /// <param name="expanded">Flag that indicates the expanded state of the folder. /// This should be 'true' for expanded and 'false' for collapsed state.</param> protected void SetExpanded(bool expanded) { IsExpanded = expanded; SetProperty((int)__VSHPROPID.VSHPROPID_Expanded, expanded); // If we are in automation mode then skip the ui part if (Utilities.IsInAutomationFunction(ProjectMgr.Site)) { return; } IVsUIHierarchyWindow uiWindow = UIHierarchyUtilities.GetUIHierarchyWindow(ProjectMgr.Site, SolutionExplorer); int result = uiWindow.ExpandItem(ProjectMgr, ID, expanded ? EXPANDFLAGS.EXPF_ExpandFolder : EXPANDFLAGS.EXPF_CollapseFolder); ErrorHandler.ThrowOnFailure(result); // then post the expand command to the shell. Folder verification and creation will // happen in the setlabel code... IVsUIShell shell = (IVsUIShell)ProjectMgr.GetService(typeof(IVsUIShell)); object dummy = null; Guid cmdGroup = VsMenus.guidStandardCommandSet97; result = shell.PostExecCommand(ref cmdGroup, (uint)(expanded ? VsCommands.Expand : VsCommands.Collapse), 0, ref dummy); ErrorHandler.ThrowOnFailure(result); }
private void ShowOptionsPage() { // GUID of our options page, defined in ToolsOptionsPage.cs object targetGUID = "2819C3B6-FC75-4CD5-8C77-877903DE864C"; Guid toolsGroupGuid = VSConstants.GUID_VSStandardCommandSet97; _vsUIShell.PostExecCommand(ref toolsGroupGuid, VSConstants.cmdidToolsOptions, 0, ref targetGUID); }
/// <summary> /// Writes text directly to the VS Output window. /// </summary> public static void Write(string message, string pane = DefaultOutputPane) { ThreadHelper.JoinableTaskFactory.RunAsync(async delegate { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); try { // Get the Output window IVsOutputWindow outputWindow = outputWindowLazy.Value; if (outputWindow == null) { return; } // Get the pane guid PaneInfo paneInfo; if (!panes.TryGetValue(pane, out paneInfo)) { // Pane didn't exist, create it paneInfo = new PaneInfo(Guid.NewGuid()); panes.Add(pane, paneInfo); } // Get the pane IVsOutputWindowPane outputPane; if (outputWindow.GetPane(ref paneInfo.paneId, out outputPane) != VSConstants.S_OK) { // Failed to get the pane - might need to create it first outputWindow.CreatePane(ref paneInfo.paneId, pane, fInitVisible: 1, fClearWithSolution: 1); outputWindow.GetPane(ref paneInfo.paneId, out outputPane); } // The first time we output text to a pane, ensure it's visible if (!paneInfo.Shown) { paneInfo.Shown = true; // Switch to the pane of the Output window outputPane.Activate(); // Show the output window IVsUIShell shell = shellLazy.Value; if (shell != null) { object inputVariant = null; shell.PostExecCommand(VSConstants.GUID_VSStandardCommandSet97, (uint)VSConstants.VSStd97CmdID.OutputWindow, 0, ref inputVariant); } } // Output the text outputPane.OutputString(message); } catch (Exception) { Debug.Fail("Failed to write to output pane."); } }).FileAndForget("VS/Diagnostics/Debugger/SSHDebugPS/VsOutputWindowWrapper/Write"); }
private static void Execute(IVsUIShell uiShell) { ThreadHelper.ThrowIfNotOnUIThread(); Guid guid = typeof(VSConstants.VSStd11CmdID).GUID; var id = (uint)VSConstants.VSStd11CmdID.SolutionExplorerSyncWithActiveDocument; uiShell.PostExecCommand(guid, id, 0, null); }
/// <summary> /// Executes a command asynchronously. /// </summary> private void PostExecCommand(Guid guid, uint id, object argument) { IVsUIShell shell = (IVsUIShell)GetService(typeof(SVsUIShell)); shell.PostExecCommand(ref guid, id, (uint)vsCommandExecOption.vsCommandExecOptionDoDefault, ref argument); }
private void HandleF1Help(RCompletionController controller) { IVsUIShell uiShell = VsAppShell.Current.GetGlobalService <IVsUIShell>(typeof(SVsUIShell)); Guid gmdSet = RGuidList.RCmdSetGuid; object o = new object(); // Post interrupt command which knows if it can interrupt R or not uiShell.PostExecCommand(ref gmdSet, RPackageCommandId.icmdHelpOnCurrent, 0, ref o); }
public void ShowTaskList() { IVsUIShell shell = _serviceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell; object dummy = null; Guid cmdSetGuid = VSConstants.GUID_VSStandardCommandSet97; int hr = shell.PostExecCommand(ref cmdSetGuid, (int)VSConstants.VSStd97CmdID.TaskListWindow, 0, ref dummy); Debug.Assert(hr == VSConstants.S_OK, "SetActiveProvider did not return S_OK."); }
private static void Execute(IVsUIShell uiShell) { ThreadHelper.ThrowIfNotOnUIThread(); Guid guid = typeof(VSConstants.VSStd97CmdID).GUID; var id = (uint)VSConstants.VSStd97CmdID.NewWindow; uiShell.PostExecCommand(guid, id, 0, null); }
/// <summary> /// 执行未知的命令 /// </summary> /// <param name="guid"></param> /// <param name="cmd"></param> public static void ExecuteCommand(Guid guid, int cmd) { IVsUIShell shell = Package.GetGlobalService(typeof(IVsUIShell)) as IVsUIShell; if (shell != null) { object arg = null; shell.PostExecCommand(ref guid, (uint)cmd, 0, ref arg); } }
public override void Invoke(CancellationToken cancellationToken) { vsUiShell.PostExecCommand( Commands.IssueVisualizationToolWindowCommand.CommandSet, Commands.IssueVisualizationToolWindowCommand.ViewToolWindowCommandId, 0, 0); selectionService.SelectedIssue = Issue; }
public static void Execute(IVsUIShell shell, DTE2 dte) { ThreadHelper.ThrowIfNotOnUIThread(); if (_map.TryGetValue(dte.ActiveDocument?.Language, out var guid)) { Guid cmdGuid = VSConstants.GUID_VSStandardCommandSet97; object guidObject = guid; shell.PostExecCommand(ref cmdGuid, VSConstants.cmdidToolsOptions, 1, ref guidObject); } }
private static void OnBuildBegin(vsBuildScope Scope, vsBuildAction Action) { ThreadHelper.ThrowIfNotOnUIThread(); if (Options.Instance.SaveAllOnBuild) { Guid guid = typeof(VSConstants.VSStd97CmdID).GUID; var id = (uint)VSConstants.VSStd97CmdID.SaveSolution; _uiShell.PostExecCommand(guid, id, 0, null); } }
/// <summary> /// 执行一些系统内置的命令 /// </summary> /// <param name="cmd">通常在VSConstants.VSStd2KCmdID这个里面</param> public static void ExecuteCommand(uint cmd) { IVsUIShell shell = Package.GetGlobalService(typeof(IVsUIShell)) as IVsUIShell; if (shell != null) { Guid std2k = VSConstants.VSStd2K; object arg = null; shell.PostExecCommand(ref std2k, cmd, 0, ref arg); } }
private void WindowEvents_WindowActivated(Window gotFocus, Window lostFocus) { // We might could check the VS setting in this.dte.Properties["Environment", "Startup"], // but there's little point in it. We just need a bool for our purpose. // https://social.msdn.microsoft.com/Forums/vstudio/en-US/4f59de7c-715e-4f42-93d4-5e13efd626e3 (...) // /visual-studio-2017-disable-start-page?forum=visualstudiogeneral // Could also use IVsSolutionEvents like: // https://github.com/jlattimer/VSReopenStartPage/blob/master/VSReopenStartPage/VsSolutionEvents.cs if (this.options.AutoCloseStartPage && Guid.TryParse(gotFocus.ObjectKind, out Guid focusedKind) && focusedKind == StartPageKind) { Debug.WriteLine("Start Page activated"); // We can't immediately call gotFocus.Close() during the WindowActivated handler. System.Threading.Tasks.Task.Run(() => { bool closed = false; const int MaxAttempts = 5; for (int attempt = 1; attempt <= MaxAttempts; attempt++) { try { gotFocus.Close(); closed = true; Debug.WriteLine("Start Page closed"); break; } catch (InvalidOperationException) { Debug.WriteLine($"Start Page close attempt {attempt} failed"); System.Threading.Thread.Sleep(attempt); } } if (!closed && gotFocus.Visible && this.dte.ActiveWindow == gotFocus) { // If we use IVsUIShell.PostExecCommand to invoke the Window.CloseToolWindow // command, it usually works, but we can't specify an argument. So there's a race // condition around focus change, which sucks. // Based on example from http://stackoverflow.com/a/20243377/1882616. Debug.WriteLine("Attempting to close Start Page via Window.CloseToolWindow"); IVsUIShell shell = (IVsUIShell)this.GetService(typeof(SVsUIShell)); var command = this.dte.Commands.Item("Window.CloseToolWindow", 0); Guid guid = new Guid(command.Guid); object input = null; int hr = shell.PostExecCommand(ref guid, (uint)command.ID, 0, ref input); if (ErrorHandler.Failed(hr)) { Debug.WriteLine("Could not close Start Page tool window"); } } }); } }
private static void Execute(object sender = null, EventArgs e = null) { ThreadHelper.ThrowIfNotOnUIThread(); if (Options.Instance.FocusSolutionExplorerOnProjectLoad) { Guid guid = typeof(VSConstants.VSStd97CmdID).GUID; var id = (uint)VSConstants.VSStd97CmdID.ProjectExplorer; _uiShell.PostExecCommand(guid, id, 0, null); } }
private void OpenInSolutionExplorer(string folderPath) { var res = MessageBox.Show(Strings.OpenInSolutionExplorerQuestion, Strings.ProductTitle, MessageBoxButton.YesNo, MessageBoxImage.Question); if (res != MessageBoxResult.Yes) { return; } _uiShell.PostExecCommand(ref openFolderCommandGroupGuid, OpenFolderCommandId, 0, folderPath); _dte.Windows.Item(vsWindowKindSolutionExplorer)?.Activate(); }
void ProcessComments(bool comment) { IVsUIShell shell = Package.GetGlobalService(typeof(IVsUIShell)) as IVsUIShell; if (shell != null) { Guid std2k = VSConstants.VSStd2K; uint cmdId = comment ? (uint)VSConstants.VSStd2KCmdID.COMMENT_BLOCK : (uint)VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK; object arg = null; shell.PostExecCommand(ref std2k, cmdId, 0, ref arg); } }
internal override void Execute(EmacsCommandContext context) { IVsUIShell service = context.Manager.ServiceProvider.GetService <SVsUIShell, IVsUIShell>(); if (service == null) { return; } Guid guid = typeof(VSConstants.VSStd97CmdID).GUID; object pvaIn = 0; service.PostExecCommand(ref guid, 429U, 0U, ref pvaIn); }
private static void OnKeyUp(object sender, KeyEventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); if ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) == ModifierKeys.Control && Options.Instance.CloseTabOnControlW && e.Key == Key.W) { Guid guid = typeof(VSConstants.VSStd97CmdID).GUID; var id = (uint)VSConstants.VSStd97CmdID.FileClose; _uiShell.PostExecCommand(guid, id, 0, null); } }
private async Task ShowOptionsPageAsync(string optionsPageGuid) { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); object targetGuid = optionsPageGuid; var toolsGroupGuid = VSConstants.GUID_VSStandardCommandSet97; IVsUIShell vsUIShell = await _vsUIShell.GetValueAsync(); vsUIShell.PostExecCommand( ref toolsGroupGuid, (uint)VSConstants.cmdidToolsOptions, (uint)0, ref targetGuid); }
private void NavigationRequested(object sender, OsbideResourceInterceptor.ResourceInterceptorEventArgs e) { IServiceProvider provider = (_vsPackage as System.IServiceProvider); IVsUIShell uiShell = provider.GetService(typeof(SVsUIShell)) as IVsUIShell; Guid commandSet = CommonGuidList.guidOSBIDE_VSPackageCmdSet; object inputParameters = null; if (uiShell == null) { return; } _cache[e.Component.ToString()] = e.Url; switch (e.Component) { case OsbideVsComponent.AskTheProfessor: _askTheProfessorVm.Url = e.Url; uiShell.PostExecCommand(ref commandSet, CommonPkgCmdIDList.cmdidOsbideAskTheProfessor, 0, ref inputParameters); break; case OsbideVsComponent.CreateAccount: _createAccountVm.Url = e.Url; uiShell.PostExecCommand(ref commandSet, CommonPkgCmdIDList.cmdidOsbideCreateAccountTool, 0, ref inputParameters); break; case OsbideVsComponent.Chat: _chatVm.Url = e.Url; uiShell.PostExecCommand(ref commandSet, CommonPkgCmdIDList.cmdidOsbideChatTool, 0, ref inputParameters); break; case OsbideVsComponent.FeedDetails: _activityFeedDetailsVm.Url = e.Url; uiShell.PostExecCommand(ref commandSet, CommonPkgCmdIDList.cmdidOsbideActivityFeedDetailsTool, 0, ref inputParameters); break; case OsbideVsComponent.FeedOverview: _activityFeedVm.Url = e.Url; uiShell.PostExecCommand(ref commandSet, CommonPkgCmdIDList.cmdidOsbideActivityFeedTool, 0, ref inputParameters); break; case OsbideVsComponent.UserProfile: _profileVm.Url = e.Url; uiShell.PostExecCommand(ref commandSet, CommonPkgCmdIDList.cmdidOsbideUserProfileTool, 0, ref inputParameters); break; case OsbideVsComponent.GenericComponent: _genericWindowVm.Url = e.Url; uiShell.PostExecCommand(ref commandSet, CommonPkgCmdIDList.cmdidOsbideGenericToolWindow, 0, ref inputParameters); break; } }
public static void ResetSettingsViaPostExecCmd() { IVsUIShell shell = (IVsUIShell)Package.GetGlobalService(typeof(SVsUIShell)); if (shell == null) { return; } var group = VSConstants.CMDSETID.StandardCommandSet2K_guid; object arguments = "-reset"; // NOTE: Call to PostExecCommand could fail. Callers should consider catching the exception. Otherwise, UI will show the error in a messagebox. shell.PostExecCommand(ref group, (uint)VSConstants.VSStd2KCmdID.ManageUserSettings, 0, ref arguments); MessageBox.Show($"Keyboard shortcuts Reset", MSG_CAPTION_RESET); }
private void RestoreVsKeybindings() { AssertIsForeground(); if (_uiShell == null) { _uiShell = _serviceProvider.GetService <IVsUIShell, SVsUIShell>(); } ErrorHandler.ThrowOnFailure(_uiShell.PostExecCommand( VSConstants.GUID_VSStandardCommandSet97, (uint)VSConstants.VSStd97CmdID.CustomizeKeyboard, (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, null)); KeybindingsResetLogger.Log("KeybindingsReset"); _workspace.Options = _workspace.Options.WithChangedOption(KeybindingResetOptions.NeedsReset, false); }
private void ShowUpdatesTabInExtensionManager() { if (_vsUIShell != null) { // first, bring up the extension manager. Guid toolsGroupGuid = VSConstants.VsStd2010; const int extensionManagerCommandId = 0xBB8; object pvaIn = null; _vsUIShell.PostExecCommand(ref toolsGroupGuid, extensionManagerCommandId, 0, ref pvaIn); // The Extension Manager dialog may take a while to load. Use dispatcher timer to poll it until it shows up. DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(100), Tag = 0 // store the number of pollings completed }; timer.Tick += OnTimerTick; timer.Start(); } }
public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { ThreadHelper.ThrowIfNotOnUIThread(); if (pguidCmdGroup == typeof(VSConstants.VSStd2KCmdID).GUID) { switch (nCmdID) { case (uint)VSConstants.VSStd2KCmdID.CAPTUREKEYSTROKE: case (uint)VSConstants.VSStd2KCmdID.SELECTCURRENTWORD: if (Options.Instance.CloseTabOnControlW) { Guid guid = typeof(VSConstants.VSStd97CmdID).GUID; var id = (uint)VSConstants.VSStd97CmdID.FileClose; _uiShell.PostExecCommand(guid, id, 0, null); } break; } } return((int)Microsoft.VisualStudio.OLE.Interop.Constants.MSOCMDERR_E_FIRST); }
/// <summary> /// Sets the expanded state of the folder. /// </summary> /// <param name="expanded">Flag that indicates the expanded state of the folder. /// This should be 'true' for expanded and 'false' for collapsed state.</param> protected void SetExpanded(bool expanded) { this.IsExpanded = expanded; this.SetProperty((int)__VSHPROPID.VSHPROPID_Expanded, expanded); // If we are in automation mode then skip the ui part if (!Utilities.IsInAutomationFunction(this.ProjectMgr.Site)) { IVsUIHierarchyWindow uiWindow = UIHierarchyUtilities.GetUIHierarchyWindow(this.ProjectMgr.Site, SolutionExplorer); if (null != uiWindow) { ErrorHandler.ThrowOnFailure(uiWindow.ExpandItem(this.ProjectMgr, this.ID, expanded ? EXPANDFLAGS.EXPF_ExpandFolder : EXPANDFLAGS.EXPF_CollapseFolder)); } // then post the expand command to the shell. Folder verification and creation will // happen in the setlabel code... IVsUIShell shell = WixHelperMethods.GetService <IVsUIShell, SVsUIShell>(this.ProjectMgr.Site); object dummy = null; Guid cmdGroup = VsMenus.guidStandardCommandSet97; ErrorHandler.ThrowOnFailure(shell.PostExecCommand(ref cmdGroup, (uint)(expanded ? VsCommands.Expand : VsCommands.Collapse), 0, ref dummy)); } }