Пример #1
0
        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);
        }
        internal Guid GetGuidProperty(IVsWindowFrame frame, int propertyID)
        {
            Guid result = Guid.Empty;

            ErrorHandler.ThrowOnFailure(frame.GetGuidProperty(propertyID, out result));
            return(result);
        }
        private bool TryGetScope(IVsWindowFrame vsWindowFrame, __VSFPROPID propId, out string scope)
        {
            scope = default(string);
            Guid guid;

            return(ErrorHandler.Succeeded(vsWindowFrame.GetGuidProperty((int)propId, out guid)) &&
                   this.scopeDefinitions.TryGetValue(guid, out scope));
        }
Пример #4
0
        /// <summary>
        /// Gets the editor type id from a window frame.
        /// </summary>
        /// <param name="window">Window frame.</param>
        /// <returns>Editor type id.</returns>
        public static Guid GetEditorTypeId(IVsWindowFrame window)
        {
            Guid guid;

            window.GetGuidProperty((int)__VSFPROPID.VSFPROPID_guidEditorType, out guid);

            return(guid);
        }
Пример #5
0
        /// <summary>
        /// Gets the persistence slot id from a window frame.
        /// </summary>
        /// <param name="window">Window frame.</param>
        /// <returns>Persistence slot id.</returns>
        public static Guid GetPersistenceSlot(IVsWindowFrame window)
        {
            Guid guid;

            window.GetGuidProperty((int)__VSFPROPID.VSFPROPID_GuidPersistenceSlot, out guid);

            return(guid);
        }
Пример #6
0
        private Guid GetGuid(__VSFPROPID __VSFPROPID)
        {
            if (_frame == null)
            {
                throw new InvalidOperationException();
            }

            Guid value;

            Marshal.ThrowExceptionForHR((_frame.GetGuidProperty((int)__VSFPROPID, out value)));

            return(value);
        }
        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 the editor type id from a window frame.
        /// </summary>
        /// <param name="window">Window frame.</param>
        /// <returns>Editor type id.</returns>
        public static Guid GetEditorTypeId(IVsWindowFrame window)
        {
            Guid guid;
            window.GetGuidProperty((int)__VSFPROPID.VSFPROPID_guidEditorType, out guid);

            return guid;
        }
        /// <summary>
        /// Gets the persistence slot id from a window frame.
        /// </summary>
        /// <param name="window">Window frame.</param>
        /// <returns>Persistence slot id.</returns>
        public static Guid GetPersistenceSlot(IVsWindowFrame window)
        {
            Guid guid;
            window.GetGuidProperty((int)__VSFPROPID.VSFPROPID_GuidPersistenceSlot, out guid);

            return guid;
        }
Пример #10
0
 internal Guid GetGuidProperty(IVsWindowFrame frame, int propertyID)
 {
     Guid result = Guid.Empty;
     ErrorHandler.ThrowOnFailure(frame.GetGuidProperty(propertyID, out result));
     return result;
 }
Пример #11
0
 // --------------------------------------------------------------------------------------------
 /// <summary>
 /// Returns a window frame property based on a supplied GUID.
 /// </summary>
 /// <param name="propid">
 /// Identifier of the property whose values are taken from the __VSFPROPID enumeration.
 /// </param>
 /// <param name="pguid">Pointer to the unique identifier of the property.</param>
 /// <returns>
 /// If the method succeeds, it returns S_OK. If it fails, it returns an error code.
 /// </returns>
 // --------------------------------------------------------------------------------------------
 int IVsWindowFrame.GetGuidProperty(int propid, out Guid pguid)
 {
     return(_Frame.GetGuidProperty(propid, out pguid));
 }
Пример #12
0
 public static void OpenDocumentWithSpecificEditor(IServiceProvider provider, string fullPath, Guid editorType, string physicalView, Guid logicalView, out IVsUIHierarchy hierarchy, uint[] itemID, out IVsWindowFrame windowFrame) {
   windowFrame = null;
   hierarchy = null;
   //open document
   IVsUIShellOpenDocument shellOpenDoc = provider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
   IVsRunningDocumentTable pRDT = provider.GetService(typeof(IVsRunningDocumentTable)) as IVsRunningDocumentTable;
   if (pRDT != null) {
     IntPtr punkDocData;
     uint docCookie;
     uint pitemid;
     IVsHierarchy ppIVsHierarchy;
     pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, fullPath, out ppIVsHierarchy, out pitemid, out punkDocData, out docCookie);
     if (punkDocData != IntPtr.Zero) {
       Marshal.Release(punkDocData);
       int pfOpen;
       shellOpenDoc.IsDocumentOpen((IVsUIHierarchy)ppIVsHierarchy, pitemid, fullPath, ref logicalView, (uint)__VSIDOFLAGS.IDO_IgnoreLogicalView, out hierarchy, itemID, out windowFrame, out pfOpen);
       hierarchy = null;
       if (windowFrame != null) {
         Guid currentEditor;
         windowFrame.GetGuidProperty((int)__VSFPROPID.VSFPROPID_guidEditorType, out currentEditor);
         object currentView;
         windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_pszPhysicalView, out currentView);
         if (currentEditor == editorType && currentView != null && physicalView == currentView.ToString()) {
           windowFrame.Show();
           return;
         }
       }
       //windowFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_PromptSave);
       windowFrame = null;
     } 
     IOleServiceProvider psp;
     uint itemid;
     uint editorFlags = (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_UseEditor;
     shellOpenDoc.OpenDocumentViaProjectWithSpecific(fullPath, editorFlags, ref editorType, physicalView, ref logicalView, out psp, out hierarchy, out itemid, out windowFrame);
     if (windowFrame != null)
       windowFrame.Show();
     psp = null;
   }
 }
Пример #13
0
    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;
      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 && punkDocDataExisting.ToInt64() != -1L) {
          fullPath = VsShell.GetFilePath(punkDocDataExisting);
        } 
        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);          
          // todo: what if the path is a URL?
          fullPath = dir != null ? Path.Combine(dir,(string)pvar) : (string)pvar;
        }

        HierarchyNode node = pHierarchy as HierarchyNode;
        IVsUIHierarchy pRootHierarchy = node == null ? (IVsUIHierarchy) pHierarchy : node.projectMgr;
        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;
					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;
            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 = new uint[1];
          int pfOpen;      
          doc.IsDocumentOpen(pVsUIHierarchy, itemid, fullPath, ref logicalView, (uint)__VSIDOFLAGS.IDO_ActivateIfOpen, out ppHierOpen, pitemidOpen, out windowFrame, out pfOpen);
          if (pfOpen == 1 && editorType != Guid.Empty) {
            if (windowFrame != null) {
              Guid currentEditor;
              windowFrame.GetGuidProperty((int)__VSFPROPID.VSFPROPID_guidEditorType, out currentEditor);
              if (currentEditor == editorType) {
                goto done;
              }
            }
            windowFrame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_PromptSave);
            windowFrame = null;
            pfOpen = 0;
          }
          if (pfOpen != 1) {
            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;
            if (editorType != Guid.Empty) {
              doc.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, pRootHierarchy, hierarchyId, docData, psp, out windowFrame);
            } else {
              openFlags |= OSE_ChooseBestStdEditor;
              doc.OpenStandardEditor(openFlags, fullPath, ref logicalView, caption, pRootHierarchy, hierarchyId, docData, psp, out windowFrame);
            }
            if (windowFrame != null) {
              if (newFile) {
                object var;
                windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var);
                IVsPersistDocData ppd = (IVsPersistDocData)var;
                ppd.SetUntitledDocPath(fullPath);
              }
            }
          }
        }
      done:
        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 (e != null) {
#if DEBUG
        MessageBox.Show(e.Message);
#endif
        }
        if (docData != punkDocDataExisting && docData != IntPtr.Zero) {
          Marshal.Release(docData);
        }
      }
    }