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 EnvDTEProjectItems.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 DocumentOpeningand 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.