locked
Addin/VSPackage: Custom UI for VS file RRS feed

  • Question

  • I have a Visual Studio Addin that works with a particular type of (already defined) project type (not a custom project type). Need to add custom files for the project type (with a predefined extension, e.g. filename.XXX). This can be done using the EnvDTE ProjectItems.AddFromFile method and works. The new file is visible in the Solution Explorer and added to the project.

    The contents of the file will be stored as XML.  But when the user opens the file, I don't want to show the default text editor in Visual Studio.  Instead, I want to load a custom form that takes the file contents as input.  The form has its own UI and allows the user to make changes and save back to the file.

    What is the best way of doing this?  I tried the EnvDTE.DocumentEvents DocumentOpening and DocumentOpened event handlers.  They allow me to interecept the user opening the file, but I don't think they can prevent opening with the default editor and specify a custom form instead.  I expected to see something like a "cancel" parameter for the DocumentOpening event handler, which I could set to true (and then open the custom form instead), but no such parameter exists.

    I could of course do the following, but it seems a bit of a hack.

    • In the DocumentOpened event handler, check the extension of the file and close it as soon as it's opened.  Then reopen it with the custom form instead.

    Is there a better way of doing this?

    As a side note, I'm looking to convert the addin to a VS package in the future.  If there are any glaring differences in how this works with packages, please let me know.

    • Edited by bulldog___ Friday, September 5, 2014 12:37 AM
    Thursday, September 4, 2014 8:47 PM

Answers

  • Hi,

    See:

    Creating Custom Text Editors and Designers
    http://msdn.microsoft.com/en-us/library/bb166329.aspx

    You need to convert your add-in to package ASAP to use custom editors and because VS "14" will remove add-ins.


    * My new blog about VSX: http://www.visualstudioextensibility.com * Twitter: https://twitter.com/VSExtensibility * MZ-Tools productivity extension for Visual Studio: http://www.mztools.com.


    Friday, September 5, 2014 9:52 AM

All replies

  • Hi,

    See:

    Creating Custom Text Editors and Designers
    http://msdn.microsoft.com/en-us/library/bb166329.aspx

    You need to convert your add-in to package ASAP to use custom editors and because VS "14" will remove add-ins.


    * My new blog about VSX: http://www.visualstudioextensibility.com * Twitter: https://twitter.com/VSExtensibility * MZ-Tools productivity extension for Visual Studio: http://www.mztools.com.


    Friday, September 5, 2014 9:52 AM
  • Thanks - I'll start looking at converting it into a VSPackage
    Friday, September 5, 2014 3:11 PM