locked
Interaction between editor and tool window RRS feed

  • Question

  • I want to create a personalized error list as a tool window (no, the standard one built in VS does not suffice). The scenario is:

    • User requests explicitly verification of data in editor;
    • Editor performs the verification and creates a report
    • The report is being transfered to a tool window (which should be earlier displayed)
    • Tool window presents the report in a nice way
    • When user doubleclicks a report item, the focus is transferred to the editor again to display the specific faulty part of my data.

    The only way I currently can think of is to take advantage of the chain:

    ToolWindow -> Package -> Factory -> Pane -> Editor/Document (and the other way).

    This does not seem a good solution, because a lot classes on the way doesn't care about internal cooperation between editor and a toolwindow.

    What is the proper way of solving this problem?

    Tuesday, February 18, 2014 11:51 AM

Answers

  • Hi Wojciech,

    A single instance toolwindow is fine if that's the sort of UI you require. There is nothing stopping you from implementing a private communication mechanism between your editors and the toolwindow.

    From a VS specific standpoint, I'd recommend you implement and proffer a service in conjunction with your toolwindow, perhaps one that implements an event handler. That way your service would get the verification events fired by your editor windows, and the toolwindow (if displayed) would render them.

    This would allow you to readily extend your verification report to additional editors in the future, if so desired.

    Sincerely,


    Ed Dore

    Saturday, March 15, 2014 6:44 AM

All replies

  • You need to define the desired relationship between the Toolwindow and the Editor here.

    Do you want just the one Toolwindow, or do you want a separate Toolwindow for each document that you have run this verification operation on? Are you using a custom editor here, or the VS code editor?

    If you want a single Toolwindow to work with potentially multiple documents, I would have the Toolwindow display it's data based on the currently selected document.  Implement IVsSelectionEvents.OnElementValueChanged, looking for SEID_DocumentFrame changes.

    Then it's just a matter of asking your editor for the verification data the Toolwindow needs to update itself with.

    Sincerely, 


    Ed Dore

    Tuesday, February 18, 2014 8:04 PM
  • Thanks for the reply!

    The tool window will be in only one instance and will be shared among different editors. The flow is in both directions:

    1. One of editors at some point (possibly by explicit user request) generates the verification data, which shall be displayed in that tool window;

    2. User doubleclicks an element of the verification report, which should get him to the editor, which generated it.

    As I understand, I should avoid linking the tool window with editor(s) using my mechanisms and use ones built in the shell instead?

    Wednesday, February 19, 2014 7:03 AM
  • When the error is raised, include the EnvDTE.ProjectItem (or just the file name and figure out the project item later on the click event) that represents the document in the Hierarchy in the Object that contains your error. 

    You can get the ProjectItem with something like this:

        Dim projItem As EnvDTE.ProjectItem
        Dim dte As EnvDTE.DTE = CType(GetService(GetType(EnvDTE.DTE)), EnvDTE.DTE)
        projItem = dte.Solution.FindProjectItem(fileName)

    Then you can load the editor using the following:

    Dim window As EnvDTE.Window = projItem.Open(Microsoft.VisualStudio.VSConstants.LOGVIEWID_Primary.ToString())
    If window IsNot Nothing Then
        window.Activate()
    End If

    Hope that is useful.




    • Proposed as answer by FBNitro Wednesday, February 19, 2014 7:15 PM
    • Edited by FBNitro Wednesday, February 19, 2014 7:15 PM
    • Marked as answer by Anna Cc Thursday, February 27, 2014 9:31 AM
    • Unmarked as answer by Ed DoreMicrosoft employee Saturday, March 15, 2014 6:37 AM
    Wednesday, February 19, 2014 5:21 PM
  • Hi Wojciech,

    A single instance toolwindow is fine if that's the sort of UI you require. There is nothing stopping you from implementing a private communication mechanism between your editors and the toolwindow.

    From a VS specific standpoint, I'd recommend you implement and proffer a service in conjunction with your toolwindow, perhaps one that implements an event handler. That way your service would get the verification events fired by your editor windows, and the toolwindow (if displayed) would render them.

    This would allow you to readily extend your verification report to additional editors in the future, if so desired.

    Sincerely,


    Ed Dore

    Saturday, March 15, 2014 6:44 AM