locked
VS Custom Tool Window, how to set currently active document? RRS feed

  • Question

  • Developing in VS 2017 on Windows 10 x64, created a new project with the "VSIX Project" template, then added a custom tool window.  In the custom tool window, I register for running doc table events and have access to the running doc table interface.

    I'm able to enumerate the open docs and track which one is active (using the "before show" event callback).

    What I can't figure out is how to change the active document.  My tool window is a custom document well implementation which renders a list of the open documents.  When clicking one of those, I'd like the editor to switch to that document.  I can't seem to find the call to set the active document to one having a specified doc cookie from the running doc table interface.

    Any ideas?

    Sunday, November 26, 2017 2:19 AM

Answers

  • Got an answer for this from the Microsoft/extendvs Gitter chat room (https://gitter.im/Microsoft/extendvs).  Michał Kostrzewski replied and provided the following info.

    ----------------------

    Here are two ways to do it:
    1. IVsTextManager.NavigateToPosition- when you navigate to a position within then IVsTextBuffer, VS activates the view that contains this buffer.
    2. IVsWindowFrame.Show and IVsUIShellOpenDocument.IsDocumentOpen - you can use IsDocumentOpen to get the document's IVsWindowFrame.

    ----------------------

    As for how to get the IVsUIShellOpenDocument interface for the document, the same user also replied with:

    (Package.GetGlobalService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument) - this is not created per document, it's a service provided by VS

    ----------------------

    I used #2 in the original reply and it worked!

    • Marked as answer by Dave Calkins Monday, November 27, 2017 8:26 PM
    Monday, November 27, 2017 8:25 PM

All replies

  • Hi Dave Calkins,

    >> I can't seem to find the call to set the active document to one having a specified doc cookie from the running doc table interface.

    According to your description, it seems that you want to open a Custom Tool Window on Visual Studio via programmatically.

    You could use IVsWindowFrame.Show method to show your custom ToolWindow:

    ToolWindowPane window = this.package.FindToolWindow(typeof(YourcustomWindow), 0, true);
    IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
    windowFrame.Show();

    Best regards,

    Zhanglong Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 27, 2017 9:27 AM
  • Thanks for the reply, but that is not what I'm trying to do.  I'm not trying to open a custom tool window, I'm trying to activate one of the already open documents from the running doc table.
    Monday, November 27, 2017 8:22 PM
  • Got an answer for this from the Microsoft/extendvs Gitter chat room (https://gitter.im/Microsoft/extendvs).  Michał Kostrzewski replied and provided the following info.

    ----------------------

    Here are two ways to do it:
    1. IVsTextManager.NavigateToPosition- when you navigate to a position within then IVsTextBuffer, VS activates the view that contains this buffer.
    2. IVsWindowFrame.Show and IVsUIShellOpenDocument.IsDocumentOpen - you can use IsDocumentOpen to get the document's IVsWindowFrame.

    ----------------------

    As for how to get the IVsUIShellOpenDocument interface for the document, the same user also replied with:

    (Package.GetGlobalService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument) - this is not created per document, it's a service provided by VS

    ----------------------

    I used #2 in the original reply and it worked!

    • Marked as answer by Dave Calkins Monday, November 27, 2017 8:26 PM
    Monday, November 27, 2017 8:25 PM