Capturing the events regarding switching between code /design view

Hi again

I have defined a custom Design view for my own Xml files, as in the VS SDK sample SampleDocViewEditor for Addin files.
This sample provides immediate sinchronization between the 2 views thru the text buffers, but I want a solution similar to the VS Forms Designer, where synchronization (view drawing /code generation) happens when the views get focus or the tabs are selected.

I tried to capture focus events on the design view with no success, althou I know this is not the best solution (kind of a Form.Activate event would be better, but I have no forms, only Controls on my views)

How can I do this using the VS integration in the best way
Ideas are welcome...

Thanks

j.g.


Answer this question

Capturing the events regarding switching between code /design view

  • philippel

    Hi Joao,

    I'm trying to change SampleDocViewEditor extension from .ADDIN to .SXVID, that I think is what You have done.

    After changing the extension, I can open the new item in the VS 2005, but I can't see the View Code/View Designer menu items from the solution explorer context menu.

    I have renamed ADDIN.ADDIN file to SXVID.ADDIN file and the ADDIN.ICO to SXVID.ICO and more the .VSDIR file initial content from ADDIN.ADDIN to SXVID.SXVID.

    Any hints

    Thank You


  • Lorenzom

    Hi Joao,

    You should be able to implement IVsWindowFrameNotify.OnShow to determine when the editor in question is activated. OnShow will be called with the FRAMESHOW_TabActivated value.

    Another possible option would be to implement IVsSelectionEvents.OnCmdUIContextChanged and look to see if the context cookie corresponds to either of the views you wish to support. I'd probably opt for implementing IVsWindowFrameNotify on my editor object, and call IVsWindowFrame2.Advise() from the editor's SetSite implementation. The IOleServiceProvider passed to your editor's IVsWindowPane.SetSite, can be used to retrieve the IVsWindowFrame via the SVsWindowFrame service.

    Something along the lines of :


    public int SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider psp)
    {
       vsServiceProvider = new ServiceProvider(psp);   
       IVsWindowFrame vsWindowFrame = vsServiceProvider.GetService(typeof(SVsFrameWindow)) as IVsWindowFrame;
       IVsWindowFrame2 vsWindowFrame2 = vsWindowFrame as IVsWindowFrame2;

       vsWindowFrame2.Advise(this, out winframeCookie);

       return VSConstants.S_OK;
    }

     




  • Josh K

    How would I do this for an add-in C# I want to be notified when the user is switching between the different code views so that I can update my addin to reflect the contents of that codeview that is open.

    Thanks,

    Kenneth

  • jandizon

    The DTE object supports the IServiceProvider interface, so you will be able to cast the DTE object to IServiceProvider, then use code similar to what Ed posted to connect to the event.

    Craig

  • Ankur Goel

    If you are extending it like the sample, you need to modify the extension being registered as an "XML" filetype.

    Otherwise, you need to change the projectitem subtype to "Designer" via code or in a template ala

    <ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.SXVID" SubType="Designer">File1.SXVID</ProjectItem>



  • Joltan

    Hi Craig,

    I'm trying to change SampleDocViewEditor extension from .ADDIN to .SXVID.

    After changing the extension, I can open the new item in the VS 2005, but I can't see the View Code/View Designer menu items from the solution explorer context menu.

    I have renamed ADDIN.ADDIN file to SXVID.ADDIN file and the ADDIN.ICO to SXVID.ICO and more the .VSDIR file initial content from ADDIN.ADDIN to SXVID.SXVID.

    Any hints

    Thank You


  • Capturing the events regarding switching between code /design view