2013-10-16 52 views
0

我在扩展使用的代码(从here看到的)这一点,我的建筑:(根据岗位)VSPackage的未激活文件

  IVsUIShellOpenDocument openDoc = Package.GetGlobalService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument; 
      if (openDoc == null) { 
       return; 
      } 

      IVsWindowFrame frame; 
      Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp; 
      IVsUIHierarchy hier; 
      uint itemid; 
      Guid logicalView = VSConstants.LOGVIEWID_Code; 
      if (ErrorHandler.Failed(openDoc.OpenDocumentViaProject(path, ref logicalView, out sp, out hier, out itemid, out frame)) || frame == null) { 
       return; 
      } 

      object docData; 
      frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData); 

      // Get the VsTextBuffer 
      VsTextBuffer buffer = docData as VsTextBuffer; 
      if (buffer == null) { 
       IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider; 
       if (bufferProvider != null) { 
        IVsTextLines lines; 
        ErrorHandler.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines)); 
        buffer = lines as VsTextBuffer; 
        Debug.Assert(buffer != null, "IVsTextLines does not implement IVsTextBuffer"); 

        if (buffer == null) { 
         return; 
        } 
       } 
      } 

      // Finally, perform the navigation. 
      IVsTextManager mgr = Package.GetGlobalService(typeof(VsTextManagerClass)) as IVsTextManager; 
      if (mgr == null) { 
       return; 
      } 
      mgr.NavigateToLineAndColumn(buffer, ref logicalView, line, column, line, column); 

其中,应打开我的文档,如果还没有,并将文档集中,将光标放在指定位置。虽然这一切都有效,但似乎没有工作的东西是文档的焦点,我的ToolWindow仍然具有活动焦点(即黄色突出显示的头部栏),我试图在NavigateToLineAndColumn之后放置此行,以查看它是否存在我所期望的,但仍然没有骰子:

frame.Show()

它根据MSDN

呈现该窗口可见,将窗口顶部,并激活窗口。

我需要做更多的工作,才能使这项活动集中于打开的文档?

回答

0

想通了这个问题,是无关的给定的代码,这是我不handling做这引发关闭此代码的可能性,并因此事件冒泡到父TreeViewItem,并试图将RoutedEvent将其折叠,最后ToolWindow重新聚焦。