none
Creating a Custom Editor for new File Type RRS feed

  • Question

  • So,

    This should be relatively simple, and to start I'll provide an analogous comparison:

    An XSD file is an XML formatted document that contains schema data.  In Visual Studio you can view the XSD format in the XML Editor.  You can also, given the correct circumstances and data in the file, open the XSD in the DataSet visual editor.  The DataSet editor is a separate editor for what is basically a non-code text document.

    Now, I have created a custom system that utilizes an XML file that produces code from it, just like the DataSet editor uses an XSD to generate code.  I have already figured out all the parts necessary to create my own custom generator and how to register it so when the editor closes it generates code from the source data.  My current successes involved replacing the default DataSetGenerator to produce my own version from the same XSD file.

    I also have worked with TemplateWizards.  So, when I go to "add item to project", I can select my own custom template for this new "DMXML" file, and an editor (windows form) pops up before file creation and allows me to configure it.  However, once it is created in the project, if I double click on the DMXML file, it sends me to the XML Editor.  I want the option to reload that file in the very same form editor I used when creating it.

    How do I take my UserContol or Windows Form, and associate it with the specific file extension .dmxml as that extensions editor, just like the DataSet editor is associated with the xsd extension?  I want to double click on my dmxml file and have my editor for that file pop up, the same as the Forms Editor, and the DataSet editor do for their associated files.

    I figure I have to register the editor somehow, probably requiring some form of editor class, interface, attributes or some combination therein, which I can "install" into Visual Studio. This is the only part of this process of VS extensibility that I have not been able to figure out, and my questions over the years have not yet yielded helpful results. 

    Thanks

    Jaeden "Sifo Dyas" al'Raec Ruiner


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.

    Saturday, April 27, 2019 4:24 PM

Answers

  • Well,

    With the overall available time, or lack there of, i was hoping for the quick fix. 

    I like the idea of the Dataset Designer, and the Forms Designer, that the first answer provides a means to achieve.  I am using a UserControl that is normally attached to a form, but could be bound inside a window of some sort to marshal back to the Visual Studio.

    In the meantime, however, i have an external forms application that accepts a file path as the initial parameter.  I have found that I can right click on an item, choose "Open With", and add my external application as the editor for that file.  I can even set it to the default. I was hoping that it would be more global set so i can assure that my extension runs that editor, but so far using this method, every time i add a new one of these templates, it adds the file and when i double click on the file it opens it in the editor.  When you first add the template it doubles up, and shows the editor twice, which is annoying, but easily dealt with in defernece to the speed of development these templates and editors offer us.

    This simple solution, though not the perfect ideal, is an excellent stop gap measure until I can implement the Visual Studio extensions.

    Thanks

    J"SD"a'RR


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.


    Saturday, May 4, 2019 1:15 AM

All replies

  • Hi friend,

    Welcome to MSDN forum.

    Maybe you can get some help from this sample.

    It demonstrates how to create an extension with a WPF-based Visual Designer for editing XML files with a specific schema (XSD) in coordination with the Visual Studio XML Editor. In this sample we implement a basic view for .vstemplate files.

    Best Regards

    Lance


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 29, 2019 9:26 AM
  • I may be able to interpret from that project, which is better than nothing, however i am currently working in windows forms, so I was wondering if there was an example that uses Windows Forms instead of WPF?

    Thanks

    J"SD"a'RR

    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.

    Friday, May 3, 2019 2:03 AM
  • Hi friend,

    For now, if we create a new vsix project. We can go Add=>Item=>Custom ToolWindow to add our UI component, and that Item Template is similar to WPF structure, so we always use this item to develop extensions with UI. Which makes it more convenient to develop UI extensions with WPF.

    Which make it hard for us to find a winform designer vsx sample. Sorry for this inconvenience.

    Instead, you can trying using ToolWindow Item for your developing. Hope this document helps.

    Best Regards

    Lance


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 3, 2019 11:23 AM
  • Well,

    With the overall available time, or lack there of, i was hoping for the quick fix. 

    I like the idea of the Dataset Designer, and the Forms Designer, that the first answer provides a means to achieve.  I am using a UserControl that is normally attached to a form, but could be bound inside a window of some sort to marshal back to the Visual Studio.

    In the meantime, however, i have an external forms application that accepts a file path as the initial parameter.  I have found that I can right click on an item, choose "Open With", and add my external application as the editor for that file.  I can even set it to the default. I was hoping that it would be more global set so i can assure that my extension runs that editor, but so far using this method, every time i add a new one of these templates, it adds the file and when i double click on the file it opens it in the editor.  When you first add the template it doubles up, and shows the editor twice, which is annoying, but easily dealt with in defernece to the speed of development these templates and editors offer us.

    This simple solution, though not the perfect ideal, is an excellent stop gap measure until I can implement the Visual Studio extensions.

    Thanks

    J"SD"a'RR


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.


    Saturday, May 4, 2019 1:15 AM
  • I've uploaded a very simple custom editor example to:

        https://github.com/EdDore/VSXArcana/tree/master/SimpleEditor

    It's a very simple extension, that shows how to implement either a Winform or WPF based editor/designer for .simple files. Most custom editor/designer implementations use the Microsoft.VisualStudio.Shell.WindowPane to implement the DocView object, which in turn hosts a Winform or WPF based window. To keep things simple use the same object for the DocData as well.

    The key to use the WindowPane's Content property to host a WPF control, and to override the Window property to set the IWin32Window property, to use a WinForm control; as demonstrated in the SimpleEditorPane.cs.

    The sample doesn't really do much of anything, doesn't actually read the file content, with each editor/designer just displaying a button that displays a message box. To switch from the WPF based editor to the WinForm based editor, just uncomment the _WINFORM_BASED definition at the top of the SimpleEditorPane.cs file.

    Stepping through that code should give you a better idea on how these are constructed at the most basic level. Hopefully, that'll make things a little easier to understand.

    Sincerely,



    Ed Dore

    Sunday, May 5, 2019 12:58 AM
    Moderator
  • Hi JaedenRuiner,

    Thanks for sharing your solution here,which benefit other community members with similar issue.

    Also you can check if ED's answer helps, he's quite experienced on this topic. Many thanks to ED's help!

    Sincerely

    Lance


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 6, 2019 1:53 AM
  • I've uploaded a very simple custom editor example to:

        https://github.com/EdDore/VSXArcana/tree/master/SimpleEditor

    It's a very simple extension, that shows how to implement either a Winform or WPF based editor/designer for .simple files. Most



    Ed Dore

    This is awesome.  Exactly the template I need to move in the direction i want to.

    One problem:

    using Microsoft.VisualStudio;
    using Microsoft.VisualStudio.Shell;
    using Microsoft.VisualStudio.OLE.Interop;
    using Microsoft.VisualStudio.Shell.Interop;

    Where do I find these assemblies?  We have VS2017 Enterprise edition, with VS SDK Extensibility package installed, but i can't find the correct dlls locally.  There are quite a few Microsoft.VisualStudio.* packages available on NuGet, but i was hoping to limit the amount of things i was dependent upon via the NuGet system.  If i can do it locally, i would prefer that.

    If not, which versions should i check out of which nuget packages?

    Thanks

    J"SD"a'RR


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.

    Wednesday, May 15, 2019 10:15 PM
  • >>Where do I find these assemblies?

    Ed's project uses packageReference(in xx.csproj) to install these three nuget packages.

    <ItemGroup>
        <PackageReference Include="Madskristensen.VisualStudio.SDK">
          <Version>15.8.81-pre</Version>
        </PackageReference>
        <PackageReference Include="Microsoft.VisualStudio.SDK.Analyzers">
          <Version>15.8.36</Version>
        </PackageReference>
        <PackageReference Include="Microsoft.VSSDK.BuildTools">
          <Version>15.9.3041</Version>
        </PackageReference>
      </ItemGroup>

    Please check this link, for the packageReference format nuget packages, the assemblies will locate at C:\Users\xxx\.nuget\packages.

    You can find the corresponding assemblies there. 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 16, 2019 5:50 AM
  • So they don't exist on the hard drive anywhere with the VS2017 Enterprise install or VSSDK install?

    (i know i can use NuGet, i wanted to know if there were local copies that came with VS)

    As well, i can't be using any "Madskristnesen" code or packages.  I have to stay within the VS default packages, 3rd party code is a very complicated issue where I work.

    Thanks

    J"SD"a'RR


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.


    Sunday, May 19, 2019 6:17 AM