private void CreateInfoBar(IVsInfoBarUIFactory factory, IVsWindowFrame frame, string message, ErrorReportingUI[] items) { if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out var unknown))) { return; } var textSpans = new List<IVsInfoBarTextSpan>() { new InfoBarTextSpan(message) }; // create action item list var actionItems = new List<IVsInfoBarActionItem>(); foreach (var item in items) { switch (item.Kind) { case ErrorReportingUI.UIKind.Button: actionItems.Add(new InfoBarButton(item.Title)); break; case ErrorReportingUI.UIKind.HyperLink: actionItems.Add(new InfoBarHyperlink(item.Title)); break; case ErrorReportingUI.UIKind.Close: break; default: throw ExceptionUtilities.UnexpectedValue(item.Kind); } } var infoBarModel = new InfoBarModel( textSpans, actionItems.ToArray(), KnownMonikers.StatusInformation, isCloseButtonVisible: true); if (!TryCreateInfoBarUI(factory, infoBarModel, out var infoBarUI)) { return; } uint? infoBarCookie = null; var eventSink = new InfoBarEvents(items, () => { // run given onClose action if there is one. items.FirstOrDefault(i => i.Kind == ErrorReportingUI.UIKind.Close).Action?.Invoke(); if (infoBarCookie.HasValue) { infoBarUI.Unadvise(infoBarCookie.Value); } }); infoBarUI.Advise(eventSink, out var cookie); infoBarCookie = cookie; var host = (IVsInfoBarHost)unknown; host.AddInfoBar(infoBarUI); }
public void InitializeEditor(VSEditorControl form, IVsUIHierarchy hier, IVsWindowFrame frame, uint docid) { VSDocumentFormPane pane = null; object value; if (ErrorHandler.Succeeded(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out value))) { pane = value as VSDocumentFormPane; } if (pane != null) ((IVSEditorControlInit)form).InitializedForm(hier, docid, frame, pane.Host); }
public PartViewHelper(PackageEditorPane editor, IVsWindowFrame windowFrame) { this.windowFrame = windowFrame; this.editor = editor; justOpened = true; object data; ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out data)); textLines = (IVsTextLines)data; AdviseTextLinesEvents(true); }
private void CreateInfoBar(IVsInfoBarUIFactory factory, IVsWindowFrame frame, string title, Action onClose, Action onEnableClicked = null, Action onEnableAndIgnoreClicked = null) { object unknown; if (frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out unknown) == VSConstants.S_OK) { var textSpans = new List<IVsInfoBarTextSpan>() { new InfoBarTextSpan(title) }; // create action item list var actionItems = new List<IVsInfoBarActionItem>(); if (onEnableClicked != null) { actionItems.Add(s_enableItem); } if (onEnableAndIgnoreClicked != null) { actionItems.Add(s_enableAndIgnoreItem); } var infoBarModel = new InfoBarModel( textSpans, actionItems.ToArray(), KnownMonikers.StatusInformation, isCloseButtonVisible: true); IVsInfoBarUIElement infoBarUI; if (TryCreateInfoBarUI(factory, infoBarModel, out infoBarUI)) { uint? infoBarCookie = null; InfoBarEvents eventSink = new InfoBarEvents(() => { onClose(); if (infoBarCookie.HasValue) { infoBarUI.Unadvise(infoBarCookie.Value); } }, onEnableClicked, onEnableAndIgnoreClicked); uint cookie; infoBarUI.Advise(eventSink, out cookie); infoBarCookie = cookie; IVsInfoBarHost host = (IVsInfoBarHost)unknown; host.AddInfoBar(infoBarUI); } } }
private static bool GetPhysicalPathFromFrame(IVsWindowFrame frame, out string frameFilePath) { object propertyValue; int hr = frame.GetProperty((int)__VSFPROPID.VSFPROPID_pszMkDocument, out propertyValue); if (hr == VSConstants.S_OK && propertyValue != null) { frameFilePath = propertyValue.ToString(); return true; } frameFilePath = null; return false; }
// Gets the package manager control hosted in the window frame. public static Control GetDeployConfigurationControl(IVsWindowFrame windowFrame) { object property; var hr = windowFrame.GetProperty( (int)__VSFPROPID.VSFPROPID_DocView, out property); var windowPane = property as WindowPane; if (windowPane == null) { return null; } var packageManagerControl = windowPane.Content as Control; return packageManagerControl; }
public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame) { var currentDoc = CurrentDoc; if (CookieDocumentMap.ContainsKey(docCookie)) { CurrentDoc = CookieDocumentMap[docCookie]; MonitorSelection.SetCmdUIContext(MarkdownModeUIContextCookie, 1); CommandsEnabled = true; } else { string fullname = GetDocFullname(docCookie); if (IsUDNDocument(fullname)) { object codeWindow; pFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out codeWindow); IVsTextView view; (codeWindow as IVsCodeWindow).GetPrimaryView(out view); var wpfView = EditorAdaptersFactoryService.GetWpfTextView(view); var docView = new UDNDocView(fullname, wpfView, pFrame, package, UIShell); CookieDocumentMap[docCookie] = docView; docView.ParsingResultsCache.AfterParsingEvent += PassResultsToChangedEvent; CurrentDoc = CookieDocumentMap[docCookie]; MonitorSelection.SetCmdUIContext(MarkdownModeUIContextCookie, 1); CommandsEnabled = true; } else { MonitorSelection.SetCmdUIContext(MarkdownModeUIContextCookie, 0); CommandsEnabled = false; } } if (currentDoc != CurrentDoc) { CurrentUDNDocView.ParsingResultsCache.AsyncReparseIfDirty(); } return VSConstants.S_OK; }
private static IVsTextView GetActiveView(IVsWindowFrame windowFrame) { if (windowFrame == null) throw new ArgumentNullException("windowFrame"); object pvar; ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out pvar)); var textView = pvar as IVsTextView; if (textView == null) { var codeWin = pvar as IVsCodeWindow; if (codeWin != null) ErrorHandler.ThrowOnFailure(codeWin.GetLastActiveView(out textView)); } return textView; }
private void CreateInfoBar(string name, Action onEnableClicked, Action onEnableAndIgnoreClicked, Action onClose, IVsWindowFrame frame, IVsInfoBarUIFactory factory) { object unknown; if (frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out unknown) == VSConstants.S_OK) { var textSpans = new List<IVsInfoBarTextSpan>() { new InfoBarTextSpan(string.Format(ServicesVSResources.CodefixOrRefactoringEncounteredError, name)), }; var infoBarModel = new InfoBarModel( textSpans, new IVsInfoBarActionItem[] { s_enableItem, s_enableAndIgnoreItem }, KnownMonikers.StatusInformation, isCloseButtonVisible: true); IVsInfoBarUIElement infoBarUI; if (TryCreateInfoBarUI(factory, infoBarModel, out infoBarUI)) { uint? infoBarCookie = null; InfoBarEvents eventSink = new InfoBarEvents(onEnableClicked, onEnableAndIgnoreClicked, () => { onClose(); if (infoBarCookie.HasValue) { infoBarUI.Unadvise(infoBarCookie.Value); } }); uint cookie; infoBarUI.Advise(eventSink, out cookie); infoBarCookie = cookie; IVsInfoBarHost host = (IVsInfoBarHost)unknown; host.AddInfoBar(infoBarUI); } } }
private static IVsTextView GetVsTextView(IVsWindowFrame windowFrame) { if (windowFrame == null) throw new ArgumentNullException("windowFrame"); object obj; if (ErrorHandler.Failed(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out obj))) return null; var vsTextView = obj as IVsTextView; if (vsTextView != null) return vsTextView; var vsCodeWindow = obj as IVsCodeWindow; if (vsCodeWindow == null) return null; if (ErrorHandler.Failed(vsCodeWindow.GetPrimaryView(out vsTextView))) return null; return vsTextView; }
private IInteractiveWindowVisualComponent GetComponent(IVsWindowFrame frame) { if (frame == null) { return null; } Guid property; if (ErrorHandler.Failed(frame.GetGuidProperty((int)__VSFPROPID.VSFPROPID_GuidPersistenceSlot, out property)) || property != RGuidList.ReplInteractiveWindowProviderGuid) { return null; } object docView; if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView))) { return null; } var interactiveWindow = (docView as IVsInteractiveWindow)?.InteractiveWindow; if (interactiveWindow == null) { return null; } IInteractiveWindowVisualComponent component; return interactiveWindow.Properties.TryGetProperty(typeof(IInteractiveWindowVisualComponent), out component) ? component : null; }
/// <summary> /// Gets if the given window frame is a document or a tool frame. /// </summary> /// <param name="window">Window frame.</param> /// <returns>True for document frame. False for tool frame.</returns> public static bool IsDocumentFrame(IVsWindowFrame window) { object pvar; window.GetProperty((int)__VSFPROPID.VSFPROPID_Type, out pvar); if ((int)pvar == 1) return true; else return false; }
/// <summary> /// Gets the editor view helper from a window frame. /// </summary> /// <param name="window">Window frame.</param> /// <returns>Editor view helper is it is a ModelDocView. Null otherwise.</returns> public static ModelDocView GetEditorViewHelper(IVsWindowFrame window) { object view; window.GetProperty((int)__VSFPROPID.VSFPROPID_ViewHelper, out view); if (view is ModelDocView) return (ModelDocView)view; return null; }
public static void OpenItem(ServiceProvider site, bool newFile, bool openWith, ref Guid logicalView, IntPtr punkDocDataExisting, IVsHierarchy pHierarchy, uint hierarchyId, out IVsWindowFrame windowFrame) { windowFrame = null; IntPtr docData = punkDocDataExisting; try { uint itemid = hierarchyId; object pvar; pHierarchy.GetProperty(hierarchyId, (int)__VSHPROPID.VSHPROPID_Caption, out pvar); string caption = (string)pvar; string fullPath = null; if (punkDocDataExisting != IntPtr.Zero) { try { // if interface is not supported, return null IPersistFileFormat pff = (IPersistFileFormat)Marshal.GetTypedObjectForIUnknown(punkDocDataExisting, typeof(IPersistFileFormat)); uint format; pff.GetCurFile(out fullPath, out format); } catch { }; } if (fullPath == null) { string dir; pHierarchy.GetProperty((uint)VsConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectDir, out pvar); dir = (string)pvar; pHierarchy.GetProperty(hierarchyId, (int)__VSHPROPID.VSHPROPID_SaveName, out pvar); fullPath = dir != null?Path.Combine(dir, (string)pvar) : (string)pvar; } IVsUIHierarchy pRootHierarchy = null; pHierarchy.GetProperty((uint)VsConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_Root, out pvar); IntPtr ptr; if (pvar == null) { pRootHierarchy = (IVsUIHierarchy)pHierarchy; } else { ptr = (IntPtr)pvar; pRootHierarchy = (IVsUIHierarchy)Marshal.GetTypedObjectForIUnknown(ptr, typeof(IVsUIHierarchy)); Marshal.Release(ptr); } IVsUIHierarchy pVsUIHierarchy = pRootHierarchy; IVsUIShellOpenDocument doc = (IVsUIShellOpenDocument)site.QueryService(VsConstants.SID_VsUIShellOpenDocument, typeof(IVsUIShellOpenDocument)); const uint OSE_ChooseBestStdEditor = 0x20000000; const uint OSE_UseOpenWithDialog = 0x10000000; const uint OSE_OpenAsNewFile = 0x40000000; if (openWith) { doc.OpenStandardEditor(OSE_UseOpenWithDialog, fullPath, ref logicalView, caption, pVsUIHierarchy, itemid, docData, site.Unwrap(), out windowFrame); } else { // First we see if someone else has opened the requested view of the file and if so, // simply activate that view. IVsRunningDocumentTable pRDT = (IVsRunningDocumentTable)site.QueryService(VsConstants.SID_SVsRunningDocumentTable, typeof(IVsRunningDocumentTable)); if (pRDT != null) { uint docCookie; IVsHierarchy ppIVsHierarchy; pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, fullPath, out ppIVsHierarchy, out itemid, out docData, out docCookie); if (ppIVsHierarchy != null && docCookie != VsConstants.VSDOCCOOKIE_NIL && pHierarchy != ppIVsHierarchy && pVsUIHierarchy != ppIVsHierarchy) { // not opened by us, so call IsDocumentOpen with the right IVsUIHierarchy so we avoid the // annoying "This document is opened by another project" message prompt. pVsUIHierarchy = (IVsUIHierarchy)ppIVsHierarchy; itemid = (uint)VsConstants.VSITEMID_SELECTION; } ppIVsHierarchy = null; } IVsUIHierarchy ppHierOpen; uint pitemidOpen; int pfOpen; doc.IsDocumentOpen(pVsUIHierarchy, itemid, fullPath, ref logicalView, (uint)__VSIDOFLAGS.IDO_ActivateIfOpen, out ppHierOpen, out pitemidOpen, out windowFrame, out pfOpen); if (pfOpen != 1) { uint openFlags = OSE_ChooseBestStdEditor; if (newFile) { openFlags |= OSE_OpenAsNewFile; } //NOTE: we MUST pass the IVsProject in pVsUIHierarchy and the itemid // of the node being opened, otherwise the debugger doesn't work. doc.OpenStandardEditor(openFlags, fullPath, ref logicalView, caption, pRootHierarchy, hierarchyId, docData, site.Unwrap(), out windowFrame); if (windowFrame != null) { if (newFile) { object var; windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var); IVsPersistDocData ppd = (IVsPersistDocData)var; ppd.SetUntitledDocPath(fullPath); } } } } if (windowFrame != null) { windowFrame.Show(); } } catch (COMException e) { if ((uint)e.ErrorCode != (uint)OleErrors.OLE_E_PROMPTSAVECANCELLED) { #if DEBUG MessageBox.Show(e.Message); #endif } } catch (Exception e) { #if DEBUG MessageBox.Show(e.Message); #endif } if (docData != punkDocDataExisting) { Marshal.Release(docData); } }
private static IVsTextView GetVsTextView(IVsWindowFrame windowFrame) { Validate.IsNotNull(windowFrame, nameof(windowFrame)); object docView; int hresult = windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView); if (ErrorHandler.Failed(hresult)) { return null; } IVsTextView viewAdapter = docView as IVsTextView; if (viewAdapter != null) { return viewAdapter; } IVsCodeWindow codeWindow = docView as IVsCodeWindow; if (codeWindow != null) { IVsTextView codeView; if (ErrorHandler.Succeeded(codeWindow.GetPrimaryView(out codeView)) && codeView != null) { return codeView; } } return null; }
public static bool GetIUnknownProperty(this IVsWindowFrame windowFrame, __VSFPROPID propid, out object result) { result = null; windowFrame?.GetProperty((int)propid, out result); return(result != null); }
/// <include file='doc\Hierarchy.uex' path='docs/doc[@for="HierarchyNode.OpenItem3"]/*' /> public static void OpenItem(IServiceProvider site, bool newFile, bool openWith, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr punkDocDataExisting, IVsHierarchy pHierarchy, uint hierarchyId, out IVsWindowFrame windowFrame) { windowFrame = null; IntPtr docData = punkDocDataExisting; Exception error = null; try { uint itemid = hierarchyId; object pvar; NativeMethods.ThrowOnFailure(pHierarchy.GetProperty(hierarchyId, (int)__VSHPROPID.VSHPROPID_Caption, out pvar)); string caption = (string)pvar; string fullPath = null; if (punkDocDataExisting != IntPtr.Zero) { fullPath = VsShell.GetFilePath(punkDocDataExisting); } if (fullPath == null) { string dir; NativeMethods.ThrowOnFailure(pHierarchy.GetProperty(NativeMethods.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectDir, out pvar)); dir = (string)pvar; NativeMethods.ThrowOnFailure(pHierarchy.GetProperty(hierarchyId, (int)__VSHPROPID.VSHPROPID_SaveName, out pvar)); // todo: what if the path is a URL? fullPath = dir != null ? Path.Combine(dir, (string)pvar) : (string)pvar; } IVsUIHierarchy pRootHierarchy = null; NativeMethods.ThrowOnFailure(pHierarchy.GetProperty(NativeMethods.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_Root, out pvar)); IntPtr ptr; if (pvar == null) { pRootHierarchy = (IVsUIHierarchy)pHierarchy; } else { ptr = (IntPtr)pvar; pRootHierarchy = (IVsUIHierarchy)Marshal.GetTypedObjectForIUnknown(ptr, typeof(IVsUIHierarchy)); Marshal.Release(ptr); } IVsUIHierarchy pVsUIHierarchy = pRootHierarchy; IVsUIShellOpenDocument doc = site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; const uint OSE_ChooseBestStdEditor = 0x20000000; const uint OSE_UseOpenWithDialog = 0x10000000; const uint OSE_OpenAsNewFile = 0x40000000; if (openWith) { IOleServiceProvider psp = site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider; NativeMethods.ThrowOnFailure(doc.OpenStandardEditor(OSE_UseOpenWithDialog, fullPath, ref logicalView, caption, pVsUIHierarchy, itemid, docData, psp, out windowFrame)); } else { // First we see if someone else has opened the requested view of the file. IVsRunningDocumentTable pRDT = site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; if (pRDT != null) { uint docCookie; IVsHierarchy ppIVsHierarchy; NativeMethods.ThrowOnFailure(pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, fullPath, out ppIVsHierarchy, out itemid, out docData, out docCookie)); if (ppIVsHierarchy != null && docCookie != (uint)ShellConstants.VSDOCCOOKIE_NIL && pHierarchy != ppIVsHierarchy && pVsUIHierarchy != ppIVsHierarchy) { // not opened by us, so call IsDocumentOpen with the right IVsUIHierarchy so we avoid the // annoying "This document is opened by another project" message prompt. pVsUIHierarchy = (IVsUIHierarchy)ppIVsHierarchy; itemid = (uint)NativeMethods.VSITEMID_SELECTION; } ppIVsHierarchy = null; } uint openFlags = 0; if (newFile) openFlags |= OSE_OpenAsNewFile; //NOTE: we MUST pass the IVsProject in pVsUIHierarchy and the itemid // of the node being opened, otherwise the debugger doesn't work. IOleServiceProvider psp = site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider; int retryCount = 1; while (retryCount > 0) { try { if (editorType != Guid.Empty) { NativeMethods.ThrowOnFailure(doc.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, pRootHierarchy, hierarchyId, docData, psp, out windowFrame)); } else { openFlags |= OSE_ChooseBestStdEditor; NativeMethods.ThrowOnFailure(doc.OpenStandardEditor(openFlags, fullPath, ref logicalView, caption, pRootHierarchy, hierarchyId, docData, psp, out windowFrame)); } break; } catch (Exception e) { if (e is COMException) { COMException ce = (COMException)e; if (ce.ErrorCode == NativeMethods.OLE_E_PROMPTSAVECANCELLED) { break; } } // perhaps the editor is not compatible with an existing one. // try OpenStandardEditor. if (editorType != Guid.Empty) { editorType = Guid.Empty; } else { throw e; } } } } if (windowFrame != null) { if (newFile) { object var; NativeMethods.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var)); IVsPersistDocData ppd = (IVsPersistDocData)var; NativeMethods.ThrowOnFailure(ppd.SetUntitledDocPath(fullPath)); } } if (windowFrame != null) NativeMethods.ThrowOnFailure(windowFrame.Show()); } catch (Exception e) { error = e; } if (error != null) { string msg = error.Message; if (logicalView != Guid.Empty) { if (editorType != Guid.Empty) { msg = String.Format(SR.GetString(SR.EditorViewError), logicalView.ToString(), editorType.ToString()) + "\r\n" + msg; } else { msg = String.Format(SR.GetString(SR.StandardEditorViewError), logicalView.ToString()) + "\r\n" + msg; } } else if (editorType != Guid.Empty) { msg = String.Format(SR.GetString(SR.StandardEditorViewError), logicalView.ToString()) + "\r\n" + msg; } MessageBox.Show(msg, SR.GetString(SR.Error), MessageBoxButtons.OK, MessageBoxIcon.Error); if (windowFrame != null) { try { NativeMethods.ThrowOnFailure(windowFrame.CloseFrame(0)); } catch { } windowFrame = null; } } if (docData != punkDocDataExisting && docData != IntPtr.Zero) { Marshal.Release(docData); } }
internal static IVsTextView GetTextView(IVsWindowFrame windowFrame) { if (windowFrame != null) { object docView; windowFrame.Show(); windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView); if (docView != null) { IVsTextView textView = docView as IVsTextView; if (textView == null) { IVsCodeWindow codeWindow = docView as IVsCodeWindow; if (codeWindow != null) { codeWindow.GetPrimaryView(out textView); } } return textView; } } return null; }
/// <summary> /// Implements <see cref="IVsWindowFrameNotify3.OnShow"/> /// </summary> protected int OnShow(int fShow) { FrameVisibilityFlags flags = myFrameVisibility; FrameVisibilityFlags startFlags = flags & ~(FrameVisibilityFlags.FrameVisibilityMask | FrameVisibilityFlags.PersistentFlagsMask); myFrameVisibility &= FrameVisibilityFlags.FrameVisibilityMask | FrameVisibilityFlags.PersistentFlagsMask; switch ((__FRAMESHOW)fShow) { case (__FRAMESHOW)__FRAMESHOW2.FRAMESHOW_BeforeWinHidden: myFrameVisibility |= FrameVisibilityFlags.PendingHiddenMeansClosed; break; case __FRAMESHOW.FRAMESHOW_WinMinimized: case __FRAMESHOW.FRAMESHOW_TabDeactivated: // VS2010 is sending a BeforeWinHidden/TabDeactivated/Hidden, which results in a covered state // with a closed window. If closed is already pending, don't degrade to cover pending instead. myFrameVisibility |= 0 != (startFlags & FrameVisibilityFlags.PendingHiddenMeansClosed) ? FrameVisibilityFlags.PendingHiddenMeansClosed : FrameVisibilityFlags.PendingHiddenMeansCovered; break; case __FRAMESHOW.FRAMESHOW_DestroyMultInst: case __FRAMESHOW.FRAMESHOW_WinClosed: ClearContents(); break; case __FRAMESHOW.FRAMESHOW_WinHidden: bool cover = false; object frameModeObj; VSFRAMEMODE frameMode = (VSFRAMEMODE)(-1); IVsWindowFrame frame = myFrame; if (frame != null && VSConstants.S_OK == frame.GetProperty((int)__VSFPROPID.VSFPROPID_FrameMode, out frameModeObj)) { // VS is changing the framemode during a hide request without telling us, always check and reset // at this point so that a move on a hidden window does not reshow it. myLastFrameMode = frameMode = (VSFRAMEMODE)frameModeObj; } if (0 != (startFlags & FrameVisibilityFlags.PendingHiddenMeansCovered)) { cover = true; } else if (0 == (startFlags & FrameVisibilityFlags.PendingHiddenMeansClosed)) { cover = frameMode == VSFRAMEMODE.VSFM_MdiChild; } if (cover) { myFrameVisibility = FrameVisibilityFlags.Covered | (flags & FrameVisibilityFlags.PersistentFlagsMask); } else { ClearContents(); } break; case __FRAMESHOW.FRAMESHOW_AutoHideSlideBegin: case __FRAMESHOW.FRAMESHOW_WinMaximized: case __FRAMESHOW.FRAMESHOW_WinRestored: case __FRAMESHOW.FRAMESHOW_WinShown: ShowContents(); break; } return(VSConstants.S_OK); }
private int Open(bool newFile, bool openWith, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction) { windowFrame = null; if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed) { return(VSConstants.E_FAIL); } Debug.Assert(this.Node != null, "No node has been initialized for the document manager"); Debug.Assert(this.Node.ProjectMgr != null, "No project manager has been initialized for the document manager"); Debug.Assert(this.Node is FileNode, "Node is not FileNode object"); int returnValue = VSConstants.S_OK; string caption = this.GetOwnerCaption(); string fullPath = this.GetFullPathForDocument(); // Make sure that the file is on disk before we open the editor and display message if not found if (!((FileNode)this.Node).IsFileOnDisk(true)) { // Bail since we are not able to open the item // Do not return an error code otherwise an internal error message is shown. The scenario for this operation // normally is already a reaction to a dialog box telling that the item has been removed. return(VSConstants.S_FALSE); } IVsUIShellOpenDocument uiShellOpenDocument = this.Node.ProjectMgr.Site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; IOleServiceProvider serviceProvider = this.Node.ProjectMgr.Site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider; try { this.Node.ProjectMgr.OnOpenItem(fullPath); int result = VSConstants.E_FAIL; if (openWith) { result = uiShellOpenDocument.OpenStandardEditor((uint)__VSOSEFLAGS.OSE_UseOpenWithDialog, fullPath, ref logicalView, caption, Node.ProjectMgr.InteropSafeIVsUIHierarchy, this.Node.ID, docDataExisting, serviceProvider, out windowFrame); } else { __VSOSEFLAGS openFlags = 0; if (newFile) { openFlags |= __VSOSEFLAGS.OSE_OpenAsNewFile; } //NOTE: we MUST pass the IVsProject in pVsUIHierarchy and the itemid // of the node being opened, otherwise the debugger doesn't work. if (editorType != Guid.Empty) { result = uiShellOpenDocument.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, Node.ProjectMgr.InteropSafeIVsUIHierarchy, this.Node.ID, docDataExisting, serviceProvider, out windowFrame); } else { openFlags |= __VSOSEFLAGS.OSE_ChooseBestStdEditor; result = uiShellOpenDocument.OpenStandardEditor((uint)openFlags, fullPath, ref logicalView, caption, Node.ProjectMgr.InteropSafeIVsUIHierarchy, this.Node.ID, docDataExisting, serviceProvider, out windowFrame); } } if (result != VSConstants.S_OK && result != VSConstants.S_FALSE && result != VSConstants.OLE_E_PROMPTSAVECANCELLED) { return(result); } if (windowFrame != null) { object var; if (newFile) { ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var)); IVsPersistDocData persistDocData = (IVsPersistDocData)var; ErrorHandler.ThrowOnFailure(persistDocData.SetUntitledDocPath(fullPath)); } var = null; ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var)); this.Node.DocCookie = (uint)(int)var; if (windowFrameAction == WindowFrameShowAction.Show) { ErrorHandler.ThrowOnFailure(windowFrame.Show()); } else if (windowFrameAction == WindowFrameShowAction.ShowNoActivate) { ErrorHandler.ThrowOnFailure(windowFrame.ShowNoActivate()); } else if (windowFrameAction == WindowFrameShowAction.Hide) { ErrorHandler.ThrowOnFailure(windowFrame.Hide()); } } } catch (COMException e) { Trace.WriteLine("Exception e:" + e.Message); returnValue = e.ErrorCode; this.CloseWindowFrame(ref windowFrame); } return(returnValue); }
/// <summary> /// Gets the currently active text view(s) from Visual Studio. /// </summary> /// <returns> /// Zero, one or two active <see cref="ITextView"/> objects. /// </returns> /// <remarks> /// This method will return a single text view for a normal code window, or a pair of text /// views if the currently active text view is a difference view in side by side mode, with /// the first item being the side that currently has focus. If there is no active text view, /// an empty collection will be returned. /// </remarks> protected IEnumerable <ITextView> GetCurrentTextViews() { var serviceProvider = Package; var monitorSelection = (IVsMonitorSelection)serviceProvider.GetService(typeof(SVsShellMonitorSelection)); if (monitorSelection == null) { yield break; } object curDocument; if (ErrorHandler.Failed(monitorSelection.GetCurrentElementValue((uint)VSConstants.VSSELELEMID.SEID_DocumentFrame, out curDocument))) { yield break; } IVsWindowFrame frame = curDocument as IVsWindowFrame; if (frame == null) { yield break; } object docView = null; if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView))) { yield break; } if (docView is IVsDifferenceCodeWindow) { var diffWindow = (IVsDifferenceCodeWindow)docView; switch (diffWindow.DifferenceViewer.ViewMode) { case DifferenceViewMode.Inline: yield return(diffWindow.DifferenceViewer.InlineView); break; case DifferenceViewMode.SideBySide: switch (diffWindow.DifferenceViewer.ActiveViewType) { case DifferenceViewType.LeftView: yield return(diffWindow.DifferenceViewer.LeftView); yield return(diffWindow.DifferenceViewer.RightView); break; case DifferenceViewType.RightView: yield return(diffWindow.DifferenceViewer.RightView); yield return(diffWindow.DifferenceViewer.LeftView); break; } yield return(diffWindow.DifferenceViewer.LeftView); break; case DifferenceViewMode.RightViewOnly: yield return(diffWindow.DifferenceViewer.RightView); break; } } else if (docView is IVsCodeWindow) { IVsTextView textView; if (ErrorHandler.Failed(((IVsCodeWindow)docView).GetPrimaryView(out textView))) { yield break; } var model = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); var adapterFactory = model.GetService <IVsEditorAdaptersFactoryService>(); var wpfTextView = adapterFactory.GetWpfTextView(textView); yield return(wpfTextView); } }
/// <include file='doc\VsShellUtilities.uex' path='docs/doc[@for="VsShellUtilities.GetTextView"]/*' /> /// <devdoc> /// Get primary view for a window frame. /// </devdoc> /// <param name="windowFrame">The window frame</param> /// <returns>A reference to an IVsTextView if successful. Otherwise null.</returns> public static IVsTextView GetTextView(IVsWindowFrame windowFrame) { if (windowFrame == null) { throw new ArgumentException("windowFrame"); } object pvar; ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out pvar)); IVsTextView textView = pvar as IVsTextView; if (textView == null) { IVsCodeWindow codeWin = pvar as IVsCodeWindow; if (codeWin != null) { ErrorHandler.ThrowOnFailure(codeWin.GetPrimaryView(out textView)); } } return textView; }
internal object GetProperty(IVsWindowFrame frame, int propertyID) { object result = null; ErrorHandler.ThrowOnFailure(frame.GetProperty(propertyID, out result)); return result; }
/// <include file='doc\Utilities.uex' path='docs/doc[@for="VsShell.GetTextView"]/*' /> public static IVsTextView GetTextView(IVsWindowFrame windowFrame) { IVsTextView textView = null; object pvar; NativeMethods.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out pvar)); if (pvar is IVsTextView) { textView = (IVsTextView)pvar; } else if (pvar is IVsCodeWindow) { IVsCodeWindow codeWin = (IVsCodeWindow)pvar; try { NativeMethods.ThrowOnFailure(codeWin.GetPrimaryView(out textView)); } catch (Exception) { // perhaps the code window doesn't use IVsTextWindow? textView = null; } } return textView; }
/// <include file='doc\Hierarchy.uex' path='docs/doc[@for="HierarchyNode.OpenItem2"]/*' /> public virtual void OpenItem(bool newFile, bool openWith, ref Guid logicalView, IntPtr punkDocDataExisting, out IVsWindowFrame windowFrame){ this.ProjectMgr.OnOpenItem(this.FullPath); windowFrame = null; Guid editorType = Guid.Empty; VsShell.OpenItem(this.projectMgr.Site, newFile, openWith, 0, ref editorType, null, ref logicalView, punkDocDataExisting, (IVsHierarchy)this, this.hierarchyId, out windowFrame); if (windowFrame != null){ object var; windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var); this.docCookie = (IntPtr)VsConstants.ForceCast((int)var); } }
public static IDifferenceViewer GetDiffViewer(IVsWindowFrame frame) { ThreadHelper.ThrowIfNotOnUIThread(); return(ErrorHandler.Succeeded(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out object docView)) ? (docView as IVsDifferenceCodeWindow)?.DifferenceViewer : null); }
/// <include file='doc\Hierarchy.uex' path='docs/doc[@for="HierarchyNode.OpenItemWithSpecific"]/*' /> public virtual void OpenItemWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr punkDocDataExisting, out IVsWindowFrame windowFrame){ this.ProjectMgr.OnOpenItem(this.FullPath); windowFrame = null; VsShell.OpenItem(this.projectMgr.Site, false, false, editorFlags, ref editorType, physicalView, ref logicalView, punkDocDataExisting, (IVsHierarchy)this, this.hierarchyId, out windowFrame); if (windowFrame != null){ object var; windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var); this.docCookie = (IntPtr)VsConstants.ForceCast((int)var); } }
/// <include file='doc\Hierarchy.uex' path='docs/doc[@for="HierarchyNode.OpenItemWithSpecific"]/*' /> public virtual void OpenItemWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr punkDocDataExisting, out IVsWindowFrame windowFrame) { this.ProjectMgr.OnOpenItem(this.Url); windowFrame = null; HierarchyNode.OpenItem(this.projectMgr.Site, false, false, editorFlags, ref editorType, physicalView, ref logicalView, punkDocDataExisting, (IVsHierarchy)this, this.hierarchyId, out windowFrame); if (windowFrame != null) { object var; NativeMethods.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var)); this.docCookie = new IntPtr((int)var); } }
private bool IsToolWindow(IVsWindowFrame frame) { object obj2; int num = 0; NativeMethods.ThrowOnFailure(frame.GetProperty(-3000, out obj2)); if (obj2 is int) { num = (int) obj2; } return (num == 2); }
protected override void GotoSource(VSOBJGOTOSRCTYPE gotoType) { // We do not support the "Goto Reference" if (VSOBJGOTOSRCTYPE.GS_REFERENCE == gotoType) { return; } // There is no difference between definition and declaration, so here we // don't check for the other flags. IVsWindowFrame frame = null; IntPtr documentData = FindDocDataFromRDT(); try { // Now we can try to open the editor. We assume that the owner hierarchy is // a project and we want to use its OpenItem method. IVsProject3 project = ownerHierarchy as IVsProject3; if (null == project) { return; } Guid viewGuid = VSConstants.LOGVIEWID_Code; ErrorHandler.ThrowOnFailure(project.OpenItem(fileId, ref viewGuid, documentData, out frame)); } finally { if (IntPtr.Zero != documentData) { Marshal.Release(documentData); documentData = IntPtr.Zero; } } // Make sure that the document window is visible. ErrorHandler.ThrowOnFailure(frame.Show()); // Get the code window from the window frame. object docView; ErrorHandler.ThrowOnFailure(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView)); IVsCodeWindow codeWindow = docView as IVsCodeWindow; if (null == codeWindow) { object docData; ErrorHandler.ThrowOnFailure(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData)); codeWindow = docData as IVsCodeWindow; if (null == codeWindow) { return; } } // Get the primary view from the code window. IVsTextView textView; ErrorHandler.ThrowOnFailure(codeWindow.GetPrimaryView(out textView)); // Set the cursor at the beginning of the declaration. ErrorHandler.ThrowOnFailure(textView.SetCaretPos(sourceSpan.iStartLine, sourceSpan.iStartIndex)); // Make sure that the text is visible. TextSpan visibleSpan = new TextSpan(); visibleSpan.iStartLine = sourceSpan.iStartLine; visibleSpan.iStartIndex = sourceSpan.iStartIndex; visibleSpan.iEndLine = sourceSpan.iStartLine; visibleSpan.iEndIndex = sourceSpan.iStartIndex + 1; ErrorHandler.ThrowOnFailure(textView.EnsureSpanVisible(visibleSpan)); }
/// <include file='doc\VsShellUtilities.uex' path='docs/doc[@for="VsShellUtilities.GetWindowObject"]/*' /> /// <devdoc> /// Get Window interface for the window frame. /// </devdoc> /// <param name="windowFrame">The window frame.</param> /// <returns>A reference to the Window interaface if succesfull. Otherwise null.</returns> public static EnvDTE.Window GetWindowObject(IVsWindowFrame windowFrame) { if (windowFrame == null) { throw new ArgumentException("windowFrame"); } EnvDTE.Window window = null; object pvar; ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_ExtWindowObject, out pvar)); if (pvar is EnvDTE.Window) { window = (EnvDTE.Window)pvar; } return window; }
private static bool TryGetInfoBarHost(IVsWindowFrame frame, out IVsInfoBarHost infoBarHost) { object infoBarHostObj; if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out infoBarHostObj))) { infoBarHost = null; return false; } infoBarHost = infoBarHostObj as IVsInfoBarHost; return infoBarHost != null; }
private int OpenItem(bool newFile, bool openWith, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame frame, WindowFrameShowAction windowFrameAction) { frame = null; if (this.ProjectMgr == null || this.ProjectMgr.IsClosed) { return VSConstants.E_FAIL; } int result = VSConstants.S_OK; uint[] ppItemId = new uint[1]; ppItemId[0] = this.ID; int open; IVsUIHierarchy project; string fullPath = GetMkDocument(); // check if the file exists if (!System.IO.File.Exists(fullPath)) { // TODO Inform clients that we have an invalid item (wrong icon) //// Inform clients that we have an invalid item (wrong icon) //this.Node.OnInvalidateItems(this.Node.Parent); return VSConstants.S_FALSE; } IVsUIShellOpenDocument sod = (this.ProjectMgr as CogaenEditProject).Site.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument; if (sod != null) { try { // try to get hold of the open file sod.IsDocumentOpen(this.ProjectMgr , this.ID , GetMkDocument() , ref logicalView /* LOGVIEWID_Code to show xml behind */ , (uint)__VSIDOFLAGS.IDO_ActivateIfOpen , out project , ppItemId , out frame , out open); // file is not open if (open == 0) { // TODO load doc data Load(fullPath, 0, 0); docDataExisting = Marshal.GetIUnknownForObject(ObjectBuilder); if (openWith) { result = sod.OpenStandardEditor((uint)__VSOSEFLAGS.OSE_UseOpenWithDialog//(uint)__VSOSEFLAGS.OSE_ChooseBestStdEditor , GetMkDocument() , ref logicalView /* VSConstants.LOGVIEWID.Code_guid for xml behind*/ , Caption , this.ProjectMgr , this.ID // TODO pass docData!!!! , docDataExisting , this.ProjectMgr.Site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider , out frame); } else { __VSOSEFLAGS openFlags = 0; if (newFile) { openFlags |= __VSOSEFLAGS.OSE_OpenAsNewFile; } openFlags |= __VSOSEFLAGS.OSE_ChooseBestStdEditor; if (editorType != Guid.Empty) { result = sod.OpenSpecificEditor(editorFlags , fullPath , ref editorType , physicalView , ref logicalView , Caption , this.ProjectMgr , this.ID , docDataExisting , this.ProjectMgr.Site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider , out frame); } else { result = sod.OpenStandardEditor((uint)openFlags , GetMkDocument() , ref logicalView /* VSConstants.LOGVIEWID.Code_guid for xml behind*/ , Caption , this.ProjectMgr , this.ID , docDataExisting , this.ProjectMgr.Site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider , out frame); } } if (result != VSConstants.S_OK && result != VSConstants.S_FALSE && result != VSConstants.OLE_E_PROMPTSAVECANCELLED) { ErrorHandler.ThrowOnFailure(result); } // eventually show window if (frame != null) { object var; if (newFile) { ErrorHandler.ThrowOnFailure(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var)); IVsPersistDocData persistDocData = (IVsPersistDocData)var; ErrorHandler.ThrowOnFailure(persistDocData.SetUntitledDocPath(fullPath)); } var = null; ErrorHandler.ThrowOnFailure(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var)); this.DocCookie = (uint)(int)var; if (windowFrameAction == WindowFrameShowAction.Show) { ErrorHandler.ThrowOnFailure(frame.Show()); } else if (windowFrameAction == WindowFrameShowAction.ShowNoActivate) { ErrorHandler.ThrowOnFailure(frame.ShowNoActivate()); } else if (windowFrameAction == WindowFrameShowAction.Hide) { ErrorHandler.ThrowOnFailure(frame.Hide()); } } } // file is already open else { ObjectBuilder = Marshal.GetObjectForIUnknown(docDataExisting) as ObjectBuilder; Marshal.Release(docDataExisting); if (frame != null) { if (windowFrameAction == WindowFrameShowAction.Show) { ErrorHandler.ThrowOnFailure(frame.Show()); } else if (windowFrameAction == WindowFrameShowAction.ShowNoActivate) { ErrorHandler.ThrowOnFailure(frame.ShowNoActivate()); } else if (windowFrameAction == WindowFrameShowAction.Hide) { ErrorHandler.ThrowOnFailure(frame.Hide()); } } } } catch (COMException e) { Trace.WriteLine("Exception e:" + e.Message); result = e.ErrorCode; CloseWindowFrame(ref frame); } } return result; }
/// <summary> /// Docks the specified frame window if it is currently floating. /// </summary> /// <remarks>Works in VS2010, does not appear to work in VS2008.</remarks> /// <param name="frame">The frame.</param> private static void DockWindowIfFloating(IVsWindowFrame frame) { // Get the current tool window frame mode. object currentFrameMode; frame.GetProperty((int)__VSFPROPID.VSFPROPID_FrameMode, out currentFrameMode); // If currently floating, switch to dock mode. if ((VSFRAMEMODE)currentFrameMode == VSFRAMEMODE.VSFM_Float) { frame.SetProperty((int)__VSFPROPID.VSFPROPID_FrameMode, VSFRAMEMODE.VSFM_Dock); } }
internal static IVsTextLines GetTextLines(IVsWindowFrame windowFrame) { if (windowFrame != null) { object docData; windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData); return docData as IVsTextLines; } else { return null; } }
/// <include file='doc\Hierarchy.uex' path='docs/doc[@for="HierarchyNode.OpenItem2"]/*' /> public virtual void OpenItem(bool newFile, bool openWith, ref Guid logicalView, IntPtr punkDocDataExisting, out IVsWindowFrame windowFrame) { this.ProjectMgr.OnOpenItem(this.Url); windowFrame = null; Guid editorType = Guid.Empty; HierarchyNode.OpenItem(this.projectMgr.Site, newFile, openWith, 0, ref editorType, null, ref logicalView, punkDocDataExisting, (IVsHierarchy)this, this.hierarchyId, out windowFrame); if (windowFrame != null) { object var; NativeMethods.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var)); this.docCookie = new IntPtr((int)var); } }
private int Open(bool newFile, bool openWith, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction) { windowFrame = null; if(this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed) { return VSConstants.E_FAIL; } Debug.Assert(this.Node != null, "No node has been initialized for the document manager"); Debug.Assert(this.Node.ProjectMgr != null, "No project manager has been initialized for the document manager"); Debug.Assert(this.Node is FileNode, "Node is not FileNode object"); int returnValue = VSConstants.S_OK; string caption = this.GetOwnerCaption(); string fullPath = this.GetFullPathForDocument(); // Make sure that the file is on disk before we open the editor and display message if not found if(!((FileNode)this.Node).IsFileOnDisk(true)) { // Inform clients that we have an invalid item (wrong icon) this.Node.OnInvalidateItems(this.Node.Parent); // Bail since we are not able to open the item // Do not return an error code otherwise an internal error message is shown. The scenario for this operation // normally is already a reaction to a dialog box telling that the item has been removed. return VSConstants.S_FALSE; } IVsUIShellOpenDocument uiShellOpenDocument = this.Node.ProjectMgr.Site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; IOleServiceProvider serviceProvider = this.Node.ProjectMgr.Site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider; try { this.Node.ProjectMgr.OnOpenItem(fullPath); int result = VSConstants.E_FAIL; if(openWith) { result = uiShellOpenDocument.OpenStandardEditor((uint)__VSOSEFLAGS.OSE_UseOpenWithDialog, fullPath, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame); } else { __VSOSEFLAGS openFlags = 0; if(newFile) { openFlags |= __VSOSEFLAGS.OSE_OpenAsNewFile; } //NOTE: we MUST pass the IVsProject in pVsUIHierarchy and the itemid // of the node being opened, otherwise the debugger doesn't work. if(editorType != Guid.Empty) { result = uiShellOpenDocument.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame); } else { openFlags |= __VSOSEFLAGS.OSE_ChooseBestStdEditor; result = uiShellOpenDocument.OpenStandardEditor((uint)openFlags, fullPath, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame); } } if(result != VSConstants.S_OK && result != VSConstants.S_FALSE && result != VSConstants.OLE_E_PROMPTSAVECANCELLED) { ErrorHandler.ThrowOnFailure(result); } if(windowFrame != null) { object var; if(newFile) { ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var)); IVsPersistDocData persistDocData = (IVsPersistDocData)var; ErrorHandler.ThrowOnFailure(persistDocData.SetUntitledDocPath(fullPath)); } var = null; ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var)); this.Node.DocCookie = (uint)(int)var; if(windowFrameAction == WindowFrameShowAction.Show) { ErrorHandler.ThrowOnFailure(windowFrame.Show()); } else if(windowFrameAction == WindowFrameShowAction.ShowNoActivate) { ErrorHandler.ThrowOnFailure(windowFrame.ShowNoActivate()); } else if(windowFrameAction == WindowFrameShowAction.Hide) { ErrorHandler.ThrowOnFailure(windowFrame.Hide()); } } } catch(COMException e) { Trace.WriteLine("Exception e:" + e.Message); returnValue = e.ErrorCode; CloseWindowFrame(ref windowFrame); } return returnValue; }
/// <summary> /// Gets the currently active text view(s) from Visual Studio. /// </summary> /// <returns> /// Zero, one or two active <see cref="ITextView"/> objects. /// </returns> /// <remarks> /// This method will return a single text view for a normal code window, or a pair of text /// views if the currently active text view is a difference view in side by side mode, with /// the first item being the side that currently has focus. If there is no active text view, /// an empty collection will be returned. /// </remarks> public CurrentTextViews GetCurrentTextViews() { ThreadHelper.ThrowIfNotOnUIThread(); CurrentTextViews results = null; try { var monitorSelection = (IVsMonitorSelection)_serviceProvider.GetService(typeof(SVsShellMonitorSelection)); if (monitorSelection == null) { return(results); } object curDocument; if (ErrorHandler.Failed(monitorSelection.GetCurrentElementValue((uint)VSConstants.VSSELELEMID.SEID_DocumentFrame, out curDocument))) { return(results); } IVsWindowFrame frame = curDocument as IVsWindowFrame; if (frame == null) { return(results); } object docView = null; if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView))) { return(results); } results = new CurrentTextViews { DocumentView = docView }; var textViews = new List <ITextView>(); if (docView is IVsDifferenceCodeWindow) { var diffWindow = (IVsDifferenceCodeWindow)docView; switch (diffWindow.DifferenceViewer.ViewMode) { case DifferenceViewMode.Inline: textViews.Add(diffWindow.DifferenceViewer.InlineView); break; case DifferenceViewMode.SideBySide: switch (diffWindow.DifferenceViewer.ActiveViewType) { case DifferenceViewType.LeftView: textViews.Add(diffWindow.DifferenceViewer.LeftView); textViews.Add(diffWindow.DifferenceViewer.RightView); break; case DifferenceViewType.RightView: textViews.Add(diffWindow.DifferenceViewer.RightView); textViews.Add(diffWindow.DifferenceViewer.LeftView); break; } textViews.Add(diffWindow.DifferenceViewer.LeftView); break; case DifferenceViewMode.RightViewOnly: textViews.Add(diffWindow.DifferenceViewer.RightView); break; } } else if (docView is IVsCodeWindow) { if (ErrorHandler.Failed(((IVsCodeWindow)docView).GetPrimaryView(out var textView))) { return(results); } var model = (IComponentModel)_serviceProvider.GetService(typeof(SComponentModel)); Assumes.Present(model); var adapterFactory = model.GetService <IVsEditorAdaptersFactoryService>(); var wpfTextView = adapterFactory.GetWpfTextView(textView); textViews.Add(wpfTextView); } results.TextViews = textViews; return(results); } catch (Exception e) { Log.Error(e, nameof(GetCurrentTextViews)); } return(results); }