コード例 #1
0
ファイル: TaskItem.cs プロジェクト: hesam/SketchSharp
 public TaskProvider(ServiceProvider site) {
   this.site = site;
   this.taskList = (IVsTaskList)this.site.QueryService(VsConstants.SID_SVsTaskList, typeof(IVsTaskList));
   items = new ArrayList();
   RegisterProvider();
   taskTokens = new TaskTokens(site);
   taskTokens.Refresh();
 }
コード例 #2
0
ファイル: TaskItem.cs プロジェクト: hesam/SketchSharp
 public void Close() {
   ClearErrors();
   if (this.taskList != null && dwCookie != 0) {
     OnTaskListFinalRelease(this.taskList);
   }
   this.site = null;
   this.taskList = null;
 }
コード例 #3
0
ファイル: TaskItem.cs プロジェクト: hesam/SketchSharp
 public TaskTokens( ServiceProvider site) {
   this.site = site;
 }
コード例 #4
0
ファイル: TaskItem.cs プロジェクト: hesam/SketchSharp
 public TaskItem(ServiceProvider site, IVsTextLineMarker textLineMarker, string fileName, string text, bool readOnly, VSTASKCATEGORY cat, VSTASKPRIORITY pri, _vstaskbitmap bitmap, string helpKeyword) {
   this.site = site;
   this.text = text;
   this.fileName = fileName;
   this.textLineMarker = textLineMarker;
   this.helpKeyword = helpKeyword;
   this.category = cat;
   this.priority = pri;
   this.bitmap = bitmap;
   this.readOnly = readOnly;
 }
コード例 #5
0
ファイル: Utilities.cs プロジェクト: hesam/SketchSharp
 public SuspendFileChanges(ServiceProvider site, string strDocument) {
   this.site = site;
   this.strDocumentFileName = strDocument;
   this.fSuspending = false;
   this.fileChangeControl = null;
 }
コード例 #6
0
ファイル: ViewFilter.cs プロジェクト: hesam/SketchSharp
    public TextTipData(ServiceProvider site) {
      Debug.Assert(site != null);

      //this.textView = view;
      // Create our method tip window (through the local registry)
      this.textTipWindow = (IVsTextTipWindow)VsShell.CreateInstance(site, ref VsConstants.CLSID_VsTextTipWindow, ref VsConstants.IID_IVsTextTipWindow, typeof(IVsTextTipWindow));
      if (this.textTipWindow == null)
        NativeHelpers.RaiseComError(HResult.E_FAIL);

      textTipWindow.SetTextTipData(this);
    }
コード例 #7
0
ファイル: EditorView.cs プロジェクト: hesam/SketchSharp
    public virtual int SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider site){
      this.site = new ServiceProvider(site);

      // register our independent view with the IVsTextManager so that it knows
      // the user is working with a view over the text buffer. this will trigger
      // the text buffer to prompt the user whether to reload the file if it is
      // edited outside of the development Environment.
      IVsTextManager textManager = (IVsTextManager)this.site.QueryService(VsConstants.SID_SVsTextManager, typeof(IVsTextManager));
      if (textManager != null) {
        IVsWindowPane windowPane = (IVsWindowPane)this;
        textManager.RegisterIndependentView(this, (VsTextBuffer)this.buffer);
      }

      //register with ComponentManager for Idle processing
      this.componentManager = (IOleComponentManager)this.site.QueryService(VsConstants.SID_SOleComponentManager, typeof(IOleComponentManager));
      if (componentID == 0){
        OLECRINFO[]   crinfo = new OLECRINFO[1];
        crinfo[0].cbSize   = (uint)Marshal.SizeOf(typeof(OLECRINFO));
        crinfo[0].grfcrf   = (uint)OLECRF.olecrfNeedIdleTime |
          (uint)OLECRF.olecrfNeedPeriodicIdleTime; 
        crinfo[0].grfcadvf = (uint)OLECADVF.olecadvfModal |
          (uint)OLECADVF.olecadvfRedrawOff |
          (uint)OLECADVF.olecadvfWarningsOff;
        crinfo[0].uIdleTimeInterval = 1000;
        this.componentManager.FRegisterComponent(this, crinfo, out this.componentID);
      }
      return 0;
    }
コード例 #8
0
ファイル: Package.cs プロジェクト: hesam/SketchSharp
    public virtual void Close()	{
      if (this.site != null) {
        if (this.editorFactory != null) {
          Guid editorGuid = this.editorFactory.GetType().GUID;
          IVsRegisterEditors vre = (IVsRegisterEditors)site.QueryService( VsConstants.SID_SVsRegisterEditors, typeof(IVsRegisterEditors));
          vre.UnregisterEditor(this.editorFactoryCookie);
          this.editorFactory.Close();
          this.editorFactory = null;
        }
        if (this.projectFactory != null) {
          IVsRegisterProjectTypes rpt = (IVsRegisterProjectTypes)this.site.QueryService(VsConstants.SID_IVsRegisterProjectTypes, typeof(IVsRegisterProjectTypes));
          if (rpt != null) {
            rpt.UnregisterProjectType(this.projectFactoryCookie);          
          }
          this.projectFactoryCookie = 0;
          this.projectFactory.Close();
          this.projectFactory = null;
        }

      }
      foreach (ILanguageService svc in this.languageServices.Values) {
        svc.Done();
      }
      this.languageServices.Clear();
      
      if (this.componentID != 0) {
        this.componentManager.FRevokeComponent(this.componentID);
        this.componentID = 0;
      }
      this.componentManager = null;

      if (site != null) site.Dispose();
      this.site = null;
      GC.Collect();
    }
コード例 #9
0
ファイル: EditorFactory.cs プロジェクト: hesam/SketchSharp
    public virtual void SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider psp){
      this.site = new ServiceProvider(psp); 

      extensions = new Hashtable();
      ILocalRegistry3 localRegistry = (ILocalRegistry3)site.QueryService( VsConstants.SID_SLocalRegistry, typeof(ILocalRegistry3));
      string root = null;        
      if (localRegistry != null) {
        localRegistry.GetLocalRegistryRoot(out root);
      }
      using (RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(root)) {
        if (rootKey != null) {
          string relpath = "Editors\\{"+this.GetType().GUID.ToString()+"}\\Extensions";
          using (RegistryKey key = rootKey.OpenSubKey(relpath,false)) {
            if (key != null) {
              foreach (string ext in key.GetValueNames()) {
                extensions.Add(ext.ToLower(),ext);
              }           
            }
          }
        }
      }
    } 
コード例 #10
0
ファイル: ProjectFactory.cs プロジェクト: hesam/SketchSharp
 public virtual void Close()
 {
   CCITracing.TraceCall();
   this.site.Dispose();
   this.site = null;
 }
コード例 #11
0
ファイル: Utilities.cs プロジェクト: hesam/SketchSharp
    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);
      }      
    }   
コード例 #12
0
ファイル: Utilities.cs プロジェクト: hesam/SketchSharp
    public static uint GetProviderLocale( ServiceProvider provider ) {
      CultureInfo ci = CultureInfo.CurrentCulture;
      uint lcid = (uint)ci.LCID;

      if (provider != null) {
        try {
          IUIHostLocale locale = (IUIHostLocale)provider.QueryService( VsConstants.SID_SUIHostLocale, typeof(IUIHostLocale)); 
          locale.GetUILocale(out lcid );
        } catch (Exception) {
        }
      }
      return lcid;
    }
コード例 #13
0
ファイル: Utilities.cs プロジェクト: hesam/SketchSharp
    public static object CreateInstance( ServiceProvider provider, ref Guid clsid, ref Guid iid, Type t) {
      ILocalRegistry3 localRegistry = (ILocalRegistry3)provider.QueryService(VsConstants.SID_SLocalRegistry, typeof(ILocalRegistry3));

      IntPtr pUnk;
      localRegistry.CreateInstance( clsid, null, ref iid, VsConstants.CLSCTX_INPROC_SERVER, out pUnk);
      localRegistry = null;

      object result = Marshal.GetTypedObjectForIUnknown(pUnk, t);
      Marshal.Release(pUnk);
      return result;
    }
コード例 #14
0
ファイル: Utilities.cs プロジェクト: hesam/SketchSharp
    public static void OpenDocument(ServiceProvider provider, string path) {
      IVsUIHierarchy hierarchy;
      uint itemID;
      IVsWindowFrame windowFrame;
      IVsTextView view;

      VsShell.OpenDocument(provider, path, out hierarchy, out itemID, out windowFrame, out view);      
    }
コード例 #15
0
ファイル: Utilities.cs プロジェクト: hesam/SketchSharp
    public static void OpenDocument( ServiceProvider provider, string fullPath, out IVsUIHierarchy hierarchy,
      out uint itemID, out IVsWindowFrame windowFrame, out IVsTextView view) { 
      view    = null;
      windowFrame = null;
      itemID      = VsConstants.VSITEMID_NIL;
      hierarchy   = null;

      //open document
      IVsUIShellOpenDocument shellOpenDoc = (IVsUIShellOpenDocument)provider.QueryService(VsConstants.SID_SVsUIShellOpenDocument, typeof(IVsUIShellOpenDocument));
      IVsRunningDocumentTable pRDT = (IVsRunningDocumentTable)provider.QueryService(VsConstants.SID_SVsRunningDocumentTable, typeof(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) {
          Microsoft.VisualStudio.OLE.Interop.IServiceProvider psp;
          uint itemid;
          Guid logicalView = Guid.Empty;
          shellOpenDoc.OpenDocumentViaProject(fullPath, ref logicalView, out psp, out hierarchy, out itemid, out windowFrame);
          if (windowFrame != null) 
            windowFrame.Show();          
          psp = null;

        } else {
          Marshal.Release(punkDocData);

          Guid logicalView = Guid.Empty;
          int pfOpen;

          shellOpenDoc.IsDocumentOpen((IVsUIHierarchy)ppIVsHierarchy, pitemid, fullPath,
            ref logicalView, (uint)__VSIDOFLAGS.IDO_IgnoreLogicalView, 
            out hierarchy, out itemID, out windowFrame, out pfOpen);

          if (windowFrame != null)
            windowFrame.Show();
        }
      }        
 
      //return objects
      WindowFrameGetTextView( windowFrame, out view );
    }      
コード例 #16
0
ファイル: ProjectFactory.cs プロジェクト: hesam/SketchSharp
 public virtual void SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider site)
 {
   CCITracing.TraceCall();
   this.site = new ServiceProvider(site);
 }
コード例 #17
0
 public override void Init(ServiceProvider site, ref Guid languageGuid, uint lcid, string extensions){
   base.Init(site, ref languageGuid, lcid, extensions);
   this.scLanguageService.culture = this.culture;
   this.vsLanguagePreferences = new SpecSharpLanguagePreferences(site, typeof(VsLanguageService).GUID, this.LanguageShortName);
   this.EnableDropDownCombos = true;
 }
コード例 #18
0
ファイル: EditorFactory.cs プロジェクト: hesam/SketchSharp
 public virtual void Close() {      
   this.site = null;
   this.package = null;
   GC.Collect();
 }
コード例 #19
0
 public SpecSharpLanguagePreferences(ServiceProvider site, Guid guid, string editorName) 
   : base(site, guid, editorName){
 }
コード例 #20
0
ファイル: Package.cs プロジェクト: hesam/SketchSharp
    public virtual void SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider site){

      this.site = new ServiceProvider(site);
      this.editorFactory = CreateEditorFactory();
      if (this.editorFactory != null) {
        this.editorFactory.SetSite(site);
        Guid editorGuid = this.editorFactory.GetType().GUID;
        IVsRegisterEditors vre = (IVsRegisterEditors)this.site.QueryService( VsConstants.SID_SVsRegisterEditors, typeof(IVsRegisterEditors));
        vre.RegisterEditor(ref editorGuid, editorFactory, out this.editorFactoryCookie);
      }

      this.projectFactory = CreateProjectFactory();
      if (this.projectFactory != null) {
        this.projectFactory.SetSite(site);
        IVsRegisterProjectTypes rpt = (IVsRegisterProjectTypes)this.site.QueryService(VsConstants.SID_IVsRegisterProjectTypes, typeof(IVsRegisterProjectTypes));
        if (rpt != null) {
          Guid projectType = this.projectFactory.GetType().GUID;
          rpt.RegisterProjectType(ref projectType, this.projectFactory, out this.projectFactoryCookie);          
        }
      }

      uint lcid = VsShell.GetProviderLocale(this.site);
      
      languageServices = new Hashtable();
      string thisPackage = "{"+this.GetType().GUID.ToString() + "}";
      ServiceProvider thisSite = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)this);

      ILocalRegistry3 localRegistry = (ILocalRegistry3)this.site.QueryService( VsConstants.SID_SLocalRegistry, typeof(ILocalRegistry3));
      string root = null;        
      if (localRegistry != null) {
        localRegistry.GetLocalRegistryRoot(out root);
      }      
      using (RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(root)) {
        if (rootKey != null) {
          using (RegistryKey languages = rootKey.OpenSubKey("Languages\\Language Services")) {
            if (languages != null) {
              foreach (string languageName in languages.GetSubKeyNames()) {
                using (RegistryKey langKey = languages.OpenSubKey(languageName)) {
                  object pkg = langKey.GetValue("Package");
                  if (pkg is string && string.Compare((string)pkg, thisPackage, false) == 0) {
                    object guid = langKey.GetValue(null);
                    if (guid is string) {
                      Guid langGuid = new Guid((string)guid);
                      if (!this.languageServices.Contains(langGuid.ToString())){
                        ILanguageService svc = CreateLanguageService(ref langGuid);
                        if (svc != null) {
                          svc.Init(thisSite, ref langGuid, lcid, GetFileExtensions(rootKey, (string)guid));
                          this.languageServices.Add(langGuid.ToString(), svc);
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }

      //register with ComponentManager for Idle processing
      this.componentManager = (IOleComponentManager)this.site.QueryService(VsConstants.SID_SOleComponentManager, typeof(IOleComponentManager));
      if (componentID == 0)
      {
          OLECRINFO[]   crinfo = new OLECRINFO[1];
          crinfo[0].cbSize   = (uint)Marshal.SizeOf(typeof(OLECRINFO));
          crinfo[0].grfcrf   = (uint)OLECRF.olecrfNeedIdleTime |
                               (uint)OLECRF.olecrfNeedPeriodicIdleTime; 
          crinfo[0].grfcadvf = (uint)OLECADVF.olecadvfModal |
                               (uint)OLECADVF.olecadvfRedrawOff |
                               (uint)OLECADVF.olecadvfWarningsOff;
          crinfo[0].uIdleTimeInterval = 1000;
          this.componentManager.FRegisterComponent(this, crinfo, out componentID);
      }

    }
コード例 #21
0
ファイル: LanguageService.cs プロジェクト: hesam/SketchSharp
    /// <summary>
    /// Initialize the shell and uiShell objects, initialize the user preferences object,
    /// get the CultureInfo, and register the language service with VS.
    /// </summary>
    public virtual void Init(ServiceProvider site, ref Guid languageGuid, uint lcid, string extensions){
      this.culture = lcid == 0 ? CultureInfo.InvariantCulture : new CultureInfo((int)lcid);
      this.site = site;      

      // Register this language service with VS.
      // should be: 0xCB728B20, 0xF786, 0x11ce, { 0x92, 0xAD, 0x00, 0xAA, 0x00, 0xA7, 0x4C, 0xD0 }
      IProfferService proffer = (IProfferService)this.site.QueryService(VsConstants.SID_ProfferService, typeof(IProfferService));
      proffer.ProfferService(ref languageGuid, this.site.Unwrap(), out this.langServiceCookie);      
    }
コード例 #22
0
ファイル: EditorView.cs プロジェクト: hesam/SketchSharp
 // the Controls must also be an IDesigner.
 public EditorControl(ServiceProvider site, IVsTextLines buffer, Control ctrl) : base(buffer){
   this.control = ctrl;
   this.site = site;
   if (ctrl is IDesigner) {
     this.designer = (IDesigner)ctrl;
   }           
 }
コード例 #23
0
ファイル: LanguageService.cs プロジェクト: hesam/SketchSharp
    /// <summary>
    /// Cleanup the sources, uiShell, shell, preferences and imageList objects
    /// and unregister this language service with VS.
    /// </summary>
    public virtual void Done(){
      this.StopThread();
      if (this.sources != null){
        foreach (Source s in this.sources.Values) s.Close();
      }
      this.sources = null;

      if (this.langServiceCookie != 0){
        IProfferService proffer = (IProfferService)this.site.QueryService( VsConstants.SID_ProfferService, typeof(IProfferService));
        if (proffer != null){
          proffer.RevokeService(this.langServiceCookie);
        }
	    this.langServiceCookie = 0;
      }
      this.site = null;            
      this.preferences = null;
      if (this.imageList != null) this.imageList.Dispose();
      this.imageList = null;
      GC.Collect();
    }
コード例 #24
0
ファイル: Source.cs プロジェクト: hesam/SketchSharp
 public MethodData(ServiceProvider site) {
   this.provider = site;
   this.methodTipWindow = (IVsMethodTipWindow)VsShell.CreateInstance( provider, ref VsConstants.CLSID_VsMethodTipWindow, ref VsConstants.IID_IVsMethodTipWindow, typeof(IVsMethodTipWindow));
   if (this.methodTipWindow != null) {  
     methodTipWindow.SetMethodData( this );
   }
 }
コード例 #25
0
ファイル: Utilities.cs プロジェクト: hesam/SketchSharp
    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);        
      }
    }