private IVsUIHierarchyWindow GetSolutionExplorerToolWindow() { IVsUIHierarchyWindow uiHierarchyWindow = (IVsUIHierarchyWindow)null; IVsUIShell service = this.ServiceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell; if (service != null) { uint grfFTW = 0; Guid rguidPersistenceSlot = new Guid("{3AE79031-E1BC-11D0-8F78-00A0C9110057}"); IVsWindowFrame ppWindowFrame = (IVsWindowFrame)null; service.FindToolWindow(grfFTW, ref rguidPersistenceSlot, out ppWindowFrame); if (ppWindowFrame != null) { object pvar = (object)null; ppWindowFrame.GetProperty(-3001, out pvar); if (pvar != null) { uiHierarchyWindow = pvar as IVsUIHierarchyWindow; } } } return(uiHierarchyWindow); }
private void Button1_Click(object sender, RoutedEventArgs e) { string id = ObjectId.Text; ScriptFactory.Instance.CreateNewBlankScript(ScriptType.Sql); var dte = BaseCommand.Instance.ServiceProvider.GetService(typeof(DTE)) as DTE; if (dte != null) { var doc = (TextDocument)dte.Application.ActiveDocument.Object(null); //var query = Services.QueryService.GetSelectQuery(BaseCommand.CurrentTableName, id); //doc.EndPoint.CreateEditPoint().Insert(query); } IVsUIShell vsUIShell = (IVsUIShell)Package.GetGlobalService(typeof(SVsUIShell)); Guid guid = typeof(QueryWindow).GUID; IVsWindowFrame windowFrame; int result = vsUIShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fFindFirst, ref guid, out windowFrame); // Find MyToolWindow windowFrame.CloseFrame((int)__FRAMECLOSE.FRAMECLOSE_NoSave); }
/// <summary> /// Get reference to IVsUIHierarchyWindow interface from guid persistence slot. /// </summary> /// <param name="serviceProvider">The service provider.</param> /// <param name="persistenceSlot">Unique identifier for a tool window created using IVsUIShell::CreateToolWindow. /// The caller of this method can use predefined identifiers that map to tool windows if those tool windows /// are known to the caller. </param> /// <returns>A reference to an IVsUIHierarchyWindow interface.</returns> public static IVsUIHierarchyWindow GetUIHierarchyWindow(IServiceProvider serviceProvider, Guid persistenceSlot) { if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } IVsUIShell shell = serviceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell; Debug.Assert(shell != null, "Could not get the ui shell from the project"); if (shell == null) { throw new InvalidOperationException(); } object pvar = null; IVsWindowFrame frame = null; IVsUIHierarchyWindow uiHierarchyWindow = null; try { if (0 == shell.FindToolWindow(0, ref persistenceSlot, out frame)) { ErrorHandler.ThrowOnFailure(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out pvar)); } } finally { if (pvar != null) { uiHierarchyWindow = (IVsUIHierarchyWindow)pvar; } } return(uiHierarchyWindow); }
/// <summary> /// Get reference to IVsUIHierarchyWindow interface from guid persistence slot. /// </summary> /// <param name="serviceProvider">The service provider.</param> /// <param name="persistenceSlot">Unique identifier for a tool window created using IVsUIShell::CreateToolWindow. /// The caller of this method can use predefined identifiers that map to tool windows if those tool windows /// are known to the caller. </param> /// <returns>A reference to an IVsUIHierarchyWindow interface.</returns> public static IVsUIHierarchyWindow GetUIHierarchyWindow(IServiceProvider serviceProvider, Guid persistenceSlot) { if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } IVsUIShell shell = serviceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell; if (shell == null) { throw new InvalidOperationException("Could not get the UI shell from the project"); } object pvar; if (ErrorHandler.Succeeded(shell.FindToolWindow(0, ref persistenceSlot, out IVsWindowFrame frame)) && ErrorHandler.Succeeded(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out pvar))) { return(pvar as IVsUIHierarchyWindow); } return(null); }
private IVsUIHierarchyWindow GetSolutionExplorerToolWindow() { IVsUIHierarchyWindow window = null; IVsUIShell service = this.ServiceProvider.GetService <SVsUIShell>() as IVsUIShell; if (service != null) { uint grfFTW = 0; Guid rguidPersistenceSlot = new Guid("{3AE79031-E1BC-11D0-8F78-00A0C9110057}"); IVsWindowFrame ppWindowFrame = null; service.FindToolWindow(grfFTW, ref rguidPersistenceSlot, out ppWindowFrame); if (ppWindowFrame != null) { object pvar = null; ppWindowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out pvar); if (pvar != null) { window = pvar as IVsUIHierarchyWindow; } } } return(window); }
public override void OnExecute(CommandEventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); AnkhMessageBox mb = new AnkhMessageBox(e.Context); // Cache items to avoid problems when selection changes by opening editor List <SvnItem> items = new List <SvnItem>(e.Selection.GetSelectedSvnItems(false)); foreach (SvnItem item in items) { if (!item.Exists) { continue; } bool selectInSolutionExplorer = false; try { switch (e.Command) { case AnkhCommand.ItemOpenVisualStudio: IProjectFileMapper mapper = e.GetService <IProjectFileMapper>(); if (mapper.IsProjectFileOrSolution(item.FullPath)) { selectInSolutionExplorer = true; break; } if (item.IsDirectory) { goto case AnkhCommand.ItemOpenWindows; } VsShellUtilities.OpenDocument(e.Context, item.FullPath); break; case AnkhCommand.ItemOpenTextEditor: { IVsUIHierarchy hier; IVsWindowFrame frame; uint id; if (!item.IsFile) { continue; } VsShellUtilities.OpenDocument(e.Context, item.FullPath, VSConstants.LOGVIEWID_TextView, out hier, out id, out frame); } break; case AnkhCommand.ItemOpenWindows: System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(item.FullPath); psi.Verb = "open"; System.Diagnostics.Process.Start(psi); break; } } catch (IOException ee) { mb.Show(ee.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (COMException ee) { mb.Show(ee.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (InvalidOperationException ee) { mb.Show(ee.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (System.ComponentModel.Win32Exception ee) { mb.Show(ee.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (selectInSolutionExplorer) { IVsUIHierarchyWindow hierWindow = VsShellUtilities.GetUIHierarchyWindow(e.Context, new Guid(ToolWindowGuids80.SolutionExplorer)); IVsProject project = VsShellUtilities.GetProject(e.Context, item.FullPath) as IVsProject; if (hierWindow != null) { int found; uint id; VSDOCUMENTPRIORITY[] prio = new VSDOCUMENTPRIORITY[1]; if (project != null && VSErr.Succeeded(project.IsDocumentInProject(item.FullPath, out found, prio, out id)) && found != 0) { hierWindow.ExpandItem(project as IVsUIHierarchy, id, EXPANDFLAGS.EXPF_SelectItem); } else if (string.Equals(item.FullPath, e.Selection.SolutionFilename, StringComparison.OrdinalIgnoreCase)) { hierWindow.ExpandItem(e.GetService <IVsUIHierarchy>(typeof(SVsSolution)), VSItemId.Root, EXPANDFLAGS.EXPF_SelectItem); } // Now try to activate the solution explorer IVsWindowFrame solutionExplorer; Guid solutionExplorerGuid = new Guid(ToolWindowGuids80.SolutionExplorer); IVsUIShell shell = e.GetService <IVsUIShell>(typeof(SVsUIShell)); if (shell != null) { shell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref solutionExplorerGuid, out solutionExplorer); if (solutionExplorer != null) { solutionExplorer.Show(); } } } } } }
public override void OnExecute(CommandEventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); SvnItem node = EnumTools.GetFirst(e.Selection.GetSelectedSvnItems(false)); IAnkhCommandService cmd = e.GetService <IAnkhCommandService>(); switch (e.Command) { case AnkhCommand.ItemSelectInRepositoryExplorer: if (node == null || node.Uri == null) { return; } if (cmd != null) { cmd.DirectlyExecCommand(AnkhCommand.RepositoryBrowse, node.FullPath); } break; case AnkhCommand.ItemSelectInWorkingCopyExplorer: if (node == null || !node.Exists) { return; } if (cmd != null) { cmd.DirectlyExecCommand(AnkhCommand.WorkingCopyBrowse, node.FullPath); } break; case AnkhCommand.ItemSelectInFileExplorer: if (node == null || !node.Exists) { return; } SelectInFileExplorer(node.FullPath); break; case AnkhCommand.ItemSelectInSolutionExplorer: if (node == null) { return; } IVsUIHierarchyWindow hierWindow = VsShellUtilities.GetUIHierarchyWindow(e.Context, new Guid(ToolWindowGuids80.SolutionExplorer)); IVsProject project = VsShellUtilities.GetProject(e.Context, node.FullPath) as IVsProject; if (hierWindow != null) { int found; uint id; VSDOCUMENTPRIORITY[] prio = new VSDOCUMENTPRIORITY[1]; if (project != null && VSErr.Succeeded(project.IsDocumentInProject(node.FullPath, out found, prio, out id)) && found != 0) { hierWindow.ExpandItem(project as IVsUIHierarchy, id, EXPANDFLAGS.EXPF_SelectItem); } else if (string.Equals(node.FullPath, e.Selection.SolutionFilename, StringComparison.OrdinalIgnoreCase)) { hierWindow.ExpandItem(e.GetService <IVsUIHierarchy>(typeof(SVsSolution)), VSItemId.Root, EXPANDFLAGS.EXPF_SelectItem); } // Now try to activate the solution explorer IVsWindowFrame solutionExplorer; Guid solutionExplorerGuid = new Guid(ToolWindowGuids80.SolutionExplorer); IVsUIShell shell = e.GetService <IVsUIShell>(typeof(SVsUIShell)); if (shell != null) { shell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref solutionExplorerGuid, out solutionExplorer); if (solutionExplorer != null) { solutionExplorer.Show(); } } } break; } }