Answer How to make Multiple Views

  • Tuesday, June 28, 2005 10:29 AM
    Moderator
     
     

    We would like to have multiple views of the same store, each one in different document windows. Do you guys support this scenario? I know there's a foundation for multiple views so I would imaging that give the document in the RDT would be enough. What would it be the best approach?

     Thanks,

    ~fw
    --------------------

    Hi,
    I would like to know more about support for multiple views of the same diagram inside Visual Studio.  For example, I would like open up split windows with one type of view of the diagram in one window and another view of the same diagram in the other window.  How is this possible and can the different views exchange data with each other?

    - Andy 

Answers

  • Tuesday, June 28, 2005 10:31 AM
    Moderator
     
     Answer

    (Usual caveats about some of this stuff will change during the year - Alan)
    --------------

    Hi Andy,

     

    To answer your multiple-view-related questions:  1)  We don’t support the splitter within a single VS document window, that is a feature that is specific to the VS code editor.  So you’d be on your own in terms of writing code to do this, but it would be possible by deriving from the DiagramDocView class.  2)  VS also supports creating splitter groups containing multiple VS document windows, so it might be sufficient to open the views in separate document windows, and rely on this built-in support to provide the splitter functionality.  In that case, the item below has some info on implementing multiple views.  The APIs involved could be improved (and we’re looking at ways to do it), but if you’re familiar with VS multiple view concepts, it should make sense.

     

    As for exchanging data, this is possible because your views will share the same underlying DocData object, and thus the same Store.  So communication happens via events, etc. fired from the common Store.

     

    Thanks,
    Grayson
    ------------

    Hi Fabian,

     

    Yes, the plumbing is in place for this.  There’s a helper method on our DocData class you can call called OpenView, which takes two arguments, a logicalView guid and an extra viewContext object (may be null).  This is mainly a wrapper for IVsUIShellOpenDocument::OpenDocumentViaProject (you could call this yourself and it would work as well).  Sequence to implement multiple views goes like this:

     

    1. Retrieve the existing DocData from the RDT (or via some other mechanism).
    2. Call OpenView(<logicalView>, null)
    3. Your editor factory will get a call on MapLogicalView; here you translate the logicalView GUID into some string (called the physical view).  Often this is the string that appears in brackets next to the document name, e.g., [Design] or [Code].  If you want this behavior set the out parameter in the CreateDocView method in your editor factory (see next step).
    4. Your editor factory will get a call on CreateDocView; create a new view of the correct type here, you will get passed the physical view string so you can determine the type of view to create.
    5. Your newly created view will get a call on LoadView().  At this point it will be hooked up to the existing DocData object, so you can call this.DocData.Store to get access to the store.  You can then look through it to find the appropriate data to initialize your view; for instance, if there’s a particular diagram type that corresponds to this view, you can find it and hook it up here; if this were a SingleDiagramDocView (or derived), you would set the this.Diagram property to the diagram you found in the store.

     

    Hope this gets you started.  There are some alternatives that will work, as well, for instance, it would also be appropriate to initialize the view directly in CreateDocView (if, for instance, you don’t have your own derived view class where you can override LoadView).  One thing to make sure, though, is that you don’t rely on MapLogicalView getting called.  In scenarios where the user closes a project while multiple views are open, and then reopens it, the shell persists the physical view string in the .suo file, and then reopens all the views by calling directly on CreateDocView, rather than via MapLogicalView.

     

    Thanks,

    Grayson

All Replies

  • Tuesday, June 28, 2005 10:31 AM
    Moderator
     
     Answer

    (Usual caveats about some of this stuff will change during the year - Alan)
    --------------

    Hi Andy,

     

    To answer your multiple-view-related questions:  1)  We don’t support the splitter within a single VS document window, that is a feature that is specific to the VS code editor.  So you’d be on your own in terms of writing code to do this, but it would be possible by deriving from the DiagramDocView class.  2)  VS also supports creating splitter groups containing multiple VS document windows, so it might be sufficient to open the views in separate document windows, and rely on this built-in support to provide the splitter functionality.  In that case, the item below has some info on implementing multiple views.  The APIs involved could be improved (and we’re looking at ways to do it), but if you’re familiar with VS multiple view concepts, it should make sense.

     

    As for exchanging data, this is possible because your views will share the same underlying DocData object, and thus the same Store.  So communication happens via events, etc. fired from the common Store.

     

    Thanks,
    Grayson
    ------------

    Hi Fabian,

     

    Yes, the plumbing is in place for this.  There’s a helper method on our DocData class you can call called OpenView, which takes two arguments, a logicalView guid and an extra viewContext object (may be null).  This is mainly a wrapper for IVsUIShellOpenDocument::OpenDocumentViaProject (you could call this yourself and it would work as well).  Sequence to implement multiple views goes like this:

     

    1. Retrieve the existing DocData from the RDT (or via some other mechanism).
    2. Call OpenView(<logicalView>, null)
    3. Your editor factory will get a call on MapLogicalView; here you translate the logicalView GUID into some string (called the physical view).  Often this is the string that appears in brackets next to the document name, e.g., [Design] or [Code].  If you want this behavior set the out parameter in the CreateDocView method in your editor factory (see next step).
    4. Your editor factory will get a call on CreateDocView; create a new view of the correct type here, you will get passed the physical view string so you can determine the type of view to create.
    5. Your newly created view will get a call on LoadView().  At this point it will be hooked up to the existing DocData object, so you can call this.DocData.Store to get access to the store.  You can then look through it to find the appropriate data to initialize your view; for instance, if there’s a particular diagram type that corresponds to this view, you can find it and hook it up here; if this were a SingleDiagramDocView (or derived), you would set the this.Diagram property to the diagram you found in the store.

     

    Hope this gets you started.  There are some alternatives that will work, as well, for instance, it would also be appropriate to initialize the view directly in CreateDocView (if, for instance, you don’t have your own derived view class where you can override LoadView).  One thing to make sure, though, is that you don’t rely on MapLogicalView getting called.  In scenarios where the user closes a project while multiple views are open, and then reopens it, the shell persists the physical view string in the .suo file, and then reopens all the views by calling directly on CreateDocView, rather than via MapLogicalView.

     

    Thanks,

    Grayson

  • Friday, May 23, 2008 8:12 AM
     
     

     

    Hi, Grayson

     

    I have a solution with multiple projects. And we opened these DocViews.

    How to reponse these Docview focuse changed?

    How to know which docview is on focuse and lost focus?

    Where to response this event?

    Thanks.

     

    I am Youni.

     

  • Wednesday, January 14, 2009 1:00 PM
     
     Proposed Answer
    Hi, 

    As soon as 2005, Alan Cameron Wills reported a way to put in place a support of multiple views on a single model for dsl tools.

    However, while the answer clearly paved the way of the solution presented here, he omitted a few steps when describing the procedure. In conjunction with the sparse level of documentation available around this area, this probably explains why no one came up with a complete solution yet.

    So, we're coming to publish an article about it that lists our proposed recipe.

    You can find it here:
    http://www.netfxfactory.org/blogs/papers/archive/2009/01/13/multiply-dsl-points-of-view.aspx

    A screencast as well as a pdf version of the article are available on the site. And of course, the source code is downloadable.

    If this article ignites some vocations in contributing to this project, Codeplex would be a place of choice to extend on this.

    Rgds,
    Pascal.


    http://www.netfxfactory.org/
    • Proposed As Answer by raskal Wednesday, January 14, 2009 1:01 PM
    •