public static Result <List <IVsWindowFrame> > GetDocumentWindowFrames(this IVsUIShell vsShell) { IEnumWindowFrames enumFrames; var hr = vsShell.GetDocumentWindowEnum(out enumFrames); return(ErrorHandler.Failed(hr) ? Result.CreateError(hr) : enumFrames.GetContents()); }
/// <summary> /// Gets the <c>IVsWindowFrame</c> associated with given window of an DTE object. /// </summary> public static IVsWindowFrame GetWindowFrame(DTE2 appObject, Window window) { IEnumWindowFrames frames; uint count = (uint)appObject.Windows.Count; IVsWindowFrame[] elems = new IVsWindowFrame[count]; IVsUIShell shell = ShellHelper.GetShellService(appObject) as IVsUIShell; if (shell == null) { return(null); } // get handles for all currently opened documents: ErrorHandler.ThrowOnFailure(shell.GetDocumentWindowEnum(out frames)); frames.Next(count, elems, out count); // visit all active frames: for (uint i = 0; i < count; i++) { // and check if they are associated with given window: if (window == GetWindowForFrame(elems[i])) { return(elems[i]); } } return(null); }
public static void RenameDocument(ServiceProvider site, string oldName, string newName) { IVsRunningDocumentTable pRDT = (IVsRunningDocumentTable)site.QueryService(VsConstants.SID_SVsRunningDocumentTable, typeof(IVsRunningDocumentTable)); IVsUIShellOpenDocument doc = (IVsUIShellOpenDocument)site.QueryService(VsConstants.SID_VsUIShellOpenDocument, typeof(IVsUIShellOpenDocument)); IVsUIShell uiShell = (IVsUIShell)site.QueryService(VsConstants.guidShellIID, typeof(IVsUIShell)); if (pRDT == null || doc == null) { return; } IVsHierarchy pIVsHierarchy; uint itemId; IntPtr docData; uint uiVsDocCookie; pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, oldName, out pIVsHierarchy, out itemId, out docData, out uiVsDocCookie); if (docData != IntPtr.Zero) { IntPtr pUnk = Marshal.GetIUnknownForObject(pIVsHierarchy); Guid iid = typeof(IVsHierarchy).GUID; IntPtr pHier; Marshal.QueryInterface(pUnk, ref iid, out pHier); try { pRDT.RenameDocument(oldName, newName, pHier, itemId); } finally { Marshal.Release(pHier); Marshal.Release(pUnk); } string newCaption = Path.GetFileName(newName); // now we need to tell the windows to update their captions. IEnumWindowFrames ppenum; uiShell.GetDocumentWindowEnum(out ppenum); IVsWindowFrame[] rgelt = new IVsWindowFrame[1]; uint fetched; while (ppenum.Next(1, rgelt, out fetched) == 0 && fetched == 1) { IVsWindowFrame windowFrame = rgelt[0]; object data; windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out data); IntPtr ptr = Marshal.GetIUnknownForObject(data); if (ptr == docData) { windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_OwnerCaption, newCaption); } Marshal.Release(ptr); } Marshal.Release(docData); } }
/// <summary> /// Updates all of the open windows that are editing this node's files to update their captions. /// </summary> /// <param name="newCaption">The new caption.</param> protected void UpdateOpenWindowCaptions(string newCaption) { // Get the environment's UI shell in preparation for enumerating the window frames. IVsUIShell uiShell = this.ServiceProvider.GetVsUIShell(classType, "UpdateOpenWindowCaptions"); IEnumWindowFrames enumerator; NativeMethods.ThrowOnFailure(uiShell.GetDocumentWindowEnum(out enumerator)); IVsWindowFrame[] windowFrames = new IVsWindowFrame[1]; uint fetchCount; // Get the document data for this node (don't find by cookie because the document cookie // could have changed on a rename). DocumentInfo docInfo = Package.Instance.Context.RunningDocumentTable.FindByPath(this.AbsolutePath); if (docInfo == null) { // There's no need to rename any captions if the document isn't open. return; } IntPtr docData = Marshal.GetIUnknownForObject(docInfo.DocumentData); try { // Tell all of the windows to update their caption to the new file name. while (enumerator.Next(1, windowFrames, out fetchCount) == NativeMethods.S_OK && fetchCount == 1) { IVsWindowFrame windowFrame = windowFrames[0]; object documentDataObject; NativeMethods.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out documentDataObject)); IntPtr pUnknownDocData = Marshal.GetIUnknownForObject(documentDataObject); try { // We found a window frame that contains the document to rename. if (pUnknownDocData == docData) { NativeMethods.ThrowOnFailure(windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_OwnerCaption, newCaption)); } } finally { if (pUnknownDocData != IntPtr.Zero) { Marshal.Release(pUnknownDocData); } } } } finally { if (docData != IntPtr.Zero) { Marshal.Release(docData); } } }
internal static List <IVsWindowFrame> GetDocumentWindowFrames(this IVsUIShell vsShell) { IEnumWindowFrames enumFrames; var hr = vsShell.GetDocumentWindowEnum(out enumFrames); if (ErrorHandler.Failed(hr) || enumFrames == null) { return(new List <IVsWindowFrame>()); } return(enumFrames.GetContents()); }
void ForEachWindowFrame(WindowFrameDelegate windowFrameDelegate) { IEnumWindowFrames windowsEnum; if (uiShell.GetDocumentWindowEnum(out windowsEnum) != VSConstants.S_OK) { return; } for (;;) { IVsWindowFrame[] frames = new IVsWindowFrame[10]; uint count = 0; if (windowsEnum.Next(10, frames, out count) != VSConstants.S_OK) { break; } for (uint i = 0; i < count; ++i) { IVsWindowFrame w = frames[i]; object o = null; if (w.GetProperty((int)__VSFPROPID.VSFPROPID_pszMkDocument, out o) == VSConstants.S_OK) { string dm = o as string; if (dm != null) { DocumentState ds = DocumentState.Unknown; o = null; if (w.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out o) == VSConstants.S_OK) { if (o != null) { ds = DocumentState.DocumentOpened; } else { ds = DocumentState.DocumentClosed; } } windowFrameDelegate(dm, ds); } } } if (count < 10) { break; } } }
//===================================================================== /// <summary> /// This is used to get information from token, content layout, and site map files open in editors /// so that current information is displayed for them in the entity references control. /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void ucEntityReferences_FileContentNeeded(object sender, FileContentNeededEventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); IVsUIShell uiShell = Utility.GetServiceFromPackage <IVsUIShell, SVsUIShell>(true); IEnumWindowFrames enumFrames; IVsWindowFrame[] frames = new IVsWindowFrame[1]; object docView; uint frameCount; ContentLayoutEditorPane contentLayoutPane; SiteMapEditorPane siteMapPane; TokenEditorPane tokenFilePane; if (uiShell.GetDocumentWindowEnum(out enumFrames) == VSConstants.S_OK) { while (enumFrames.Next(1, frames, out frameCount) == VSConstants.S_OK && frameCount == 1) { if (frames[0].GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView) == VSConstants.S_OK) { contentLayoutPane = docView as ContentLayoutEditorPane; if (contentLayoutPane != null) { e.ContentLayoutFiles.Add(contentLayoutPane.Filename, contentLayoutPane.Topics); } else { siteMapPane = docView as SiteMapEditorPane; if (siteMapPane != null) { e.SiteMapFiles.Add(siteMapPane.Filename, siteMapPane.Topics); } else { tokenFilePane = docView as TokenEditorPane; if (tokenFilePane != null) { e.TokenFiles.Add(tokenFilePane.Filename, tokenFilePane.Tokens); } } } } } } }
public static IEnumerable<IVsWindowFrame> GetDocumentWindows(IVsUIShell uiShell) { IEnumWindowFrames documentWindowEnumerator; var hr = uiShell.GetDocumentWindowEnum(out documentWindowEnumerator); if (documentWindowEnumerator == null) { yield break; } IVsWindowFrame[] windowFrames = new IVsWindowFrame[1]; uint frameCount; while (documentWindowEnumerator.Next(1, windowFrames, out frameCount) == VSConstants.S_OK && frameCount == 1) { yield return windowFrames[0]; } }
/// <summary> /// Updates the caption for all windows associated to the document. /// </summary> /// <param name="site">The service provider.</param> /// <param name="caption">The new caption.</param> /// <param name="docData">The IUnknown interface to a document data object associated with a registered document.</param> public static void UpdateCaption(IServiceProvider site, string caption, IntPtr docData) { if (site == null) { throw new ArgumentNullException("site"); } if (String.IsNullOrEmpty(caption)) { throw new ArgumentException(SR.GetString(SR.ParameterCannotBeNullOrEmpty, CultureInfo.CurrentUICulture), "caption"); } IVsUIShell uiShell = site.GetService(typeof(SVsUIShell)) as IVsUIShell; // We need to tell the windows to update their captions. IEnumWindowFrames windowFramesEnum; ErrorHandler.ThrowOnFailure(uiShell.GetDocumentWindowEnum(out windowFramesEnum)); IVsWindowFrame[] windowFrames = new IVsWindowFrame[1]; uint fetched; while (windowFramesEnum.Next(1, windowFrames, out fetched) == VSConstants.S_OK && fetched == 1) { IVsWindowFrame windowFrame = windowFrames[0]; object data; ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out data)); IntPtr ptr = Marshal.GetIUnknownForObject(data); try { if (ptr == docData) { ErrorHandler.ThrowOnFailure(windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_OwnerCaption, caption)); } } finally { if (ptr != IntPtr.Zero) { Marshal.Release(ptr); } } } }
public static IEnumerable <IVsWindowFrame> GetDocumentWindows(IVsUIShell uiShell) { IEnumWindowFrames documentWindowEnumerator; int hr = uiShell.GetDocumentWindowEnum(out documentWindowEnumerator); if (documentWindowEnumerator == null) { yield break; } IVsWindowFrame[] windowFrames = new IVsWindowFrame[1]; uint frameCount; while (documentWindowEnumerator.Next(1, windowFrames, out frameCount) == VSConstants.S_OK && frameCount == 1) { yield return(windowFrames[0]); } }
private IEnumerable <IVsWindowFrame> EnumDocumentWindows(IVsUIShell uiShell) { IEnumWindowFrames ppenum; int hr = uiShell.GetDocumentWindowEnum(out ppenum); if (ppenum == null) { yield break; } IVsWindowFrame[] windowFrames = new IVsWindowFrame[1]; uint frameCount; while (ppenum.Next(1, windowFrames, out frameCount) == VSConstants.S_OK && frameCount == 1) { yield return(windowFrames[0]); } }
public static IEnumerable<IVsWindowFrame> GetDocumentWindows(IVsUIShell uiShell) { ThreadHelper.ThrowIfNotOnUIThread(); IEnumWindowFrames documentWindowEnumerator; var hr = uiShell.GetDocumentWindowEnum(out documentWindowEnumerator); if (documentWindowEnumerator == null) { yield break; } var windowFrames = new IVsWindowFrame[1]; uint frameCount; while (documentWindowEnumerator.Next(1, windowFrames, out frameCount) == VSConstants.S_OK && frameCount == 1) { yield return windowFrames[0]; } }
/// <summary> /// returns an enumerable to both tool and document IVsWindowFrames /// </summary> /// <param name="package"></param> /// <returns></returns> public static List <IVsFrameView> GetIVsWindowFramesEnumerator(AsyncPackage package) { ThreadHelper.ThrowIfNotOnUIThread(); IVsUIShell uiShell = UtilityMethods.GetIVsUIShell(package); List <IVsFrameView> genericFrames = new List <IVsFrameView>(); IEnumWindowFrames toolFramesEnum; ErrorHandler.ThrowOnFailure(uiShell.GetToolWindowEnum(out toolFramesEnum)); genericFrames = ExtractFrames(toolFramesEnum).ToList(); IEnumWindowFrames documentFramesEnum; ErrorHandler.ThrowOnFailure(uiShell.GetDocumentWindowEnum(out documentFramesEnum)); genericFrames.AddRange(ExtractFrames(documentFramesEnum).ToList()); return(genericFrames); }
private static IEnumerable <IVsWindowFrame> EnumerateDocumentWindowFrames() { IVsUIShell shell = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell; if (shell != null) { IEnumWindowFrames framesEnum; int hr = shell.GetDocumentWindowEnum(out framesEnum); if (hr == VSConstants.S_OK && framesEnum != null) { IVsWindowFrame[] frames = new IVsWindowFrame[1]; uint fetched; while (framesEnum.Next(1, frames, out fetched) == VSConstants.S_OK && fetched == 1) { yield return(frames[0]); } } } }