none
custom file extension is not always working

    Question

  • Hello,

    I added two own file extensions and attached own editors to it.

    One editor is workin fine, the other not.

    The reason seems to me that the files with the working file format are plain text files,
    the files with the not working file format are also text file, but contain XML Structure.

    Instead of showing my own editor the XML is shown.
    If I changed the content to random text my editor is shown.

    How can I force VS to use my editor and not the default one ?


    best regards Stephan Hartmann ML-Software GmbH

    Friday, July 19, 2013 10:01 PM

Answers

All replies

  • Hi,

    First, thank you for posting in the MSDN forum!

    Here are some steps about how to change the default editor for an existing file,Please have a try.

    1. On the File menu in Visual Studio, choose Open and then select File.
    2. In the Open File dialog box, select a file of the type you want to change.For example, if you want to change the default editor for text files, select a .txt file.
    3. Still in the Open File dialog box, click the down arrow next to the Open button, and then select Open With.
    4. In the Open With dialog box, choose an editor from the Select a program to open list.
    5. Click the Set as Default button and then click the Open button to open the file.

    Hope this infomation would be useful for you!


    Sophia<br/> MSDN Community Support | <a href="mailto:msdnmg@microsoft.com">Feedback to us</a><br/> <a href="http://blogs.msdn.com/b/win8devsupport/"><font color="red">Develop and promote your apps in Windows Store</font></a><br/> Please remember to mark the replies as answers if they help and unmark them if they provide no help.<br/>


    Monday, July 22, 2013 1:46 AM
    Moderator
  • Hi, Sorry, I think my first post is incomplete.

    I forgot to mention that I wrote a vsix package where I registered both extensions.

    My Problem is that I don't want that the user of the package needs to do anything.
    It works as long as it does not detect that the file content is XML ...
    It's not clear for me why visual studio ignores my definition and prefers its own detection in that case.

    In the package.cs I added

        [ProvideEditorFactory(typeof(IColorTableEditorFactory), 120)]
        [ProvideEditorExtension(typeof(IColorTableEditorFactory), ".gcs", 32, NameResourceID = 120)] 

    this is the factory code

      [Guid(GuidStrings.guidColorTableFactory)]
        class IColorTableEditorFactory : IVsEditorFactory
        {
            private Package parentPackage;
            private IOleServiceProvider serviceProvider;
            public IColorTableEditorFactory(Package parentPackage)
            {
                this.parentPackage = parentPackage;
            }
    
    
            #region IVsEditorFactory Member
    
            int IVsEditorFactory.Close()
            {
                return VSConstants.S_OK;
            }
    
            int IVsEditorFactory.CreateEditorInstance(uint grfCreateDoc, string pszMkDocument, string pszPhysicalView, IVsHierarchy pvHier, uint itemid, System.IntPtr punkDocDataExisting, out System.IntPtr ppunkDocView, out System.IntPtr ppunkDocData, out string pbstrEditorCaption, out System.Guid pguidCmdUI, out int pgrfCDW)
            {
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering {0} CreateEditorInstance()", this));
    
                // Initialize to null
                ppunkDocView = IntPtr.Zero;
                ppunkDocData = IntPtr.Zero;
                pguidCmdUI = GuidList.guidColorTableFactory;
                pgrfCDW = 0;
    
    
                pbstrEditorCaption = null;
    
                // Validate inputs
                if ((grfCreateDoc & (VSConstants.CEF_OPENFILE | VSConstants.CEF_SILENT)) == 0)
                {
                    return VSConstants.E_INVALIDARG;
                }
                if (punkDocDataExisting != IntPtr.Zero)
                {
                    return VSConstants.VS_E_INCOMPATIBLEDOCDATA;
                }
    
                // Create the Document (editor)
                ColorTableEditorPane newEditor = new ColorTableEditorPane();
    
                ppunkDocView = Marshal.GetIUnknownForObject(newEditor);
                ppunkDocData = Marshal.GetIUnknownForObject(newEditor);
                pbstrEditorCaption = "";
    
                return VSConstants.S_OK;
            }
    
            int IVsEditorFactory.MapLogicalView(ref System.Guid rguidLogicalView, out string pbstrPhysicalView)
            {
                int retval = VSConstants.E_NOTIMPL;
                pbstrPhysicalView = null;   // We support only one view.
                if (rguidLogicalView.Equals(VSConstants.LOGVIEWID_Designer) ||
                rguidLogicalView.Equals(VSConstants.LOGVIEWID_Primary))
                {
                    retval = VSConstants.S_OK;
                }
                return retval;
            }
    
            int IVsEditorFactory.SetSite(IOleServiceProvider psp)
            {
                this.serviceProvider = psp;
                return VSConstants.S_OK;
            }
    
            #endregion
        }

    In debugger I see that the constructor and the set site are called on VS startup.

    When I use a file with no XML content, MapLogicalView and CreateEditorInstance are called and everythings works fine.

    If file has XML content both routines are not called and default editor opens

    furthermore there is a another file ... maybe I'm missing something here ... 

        internal static class FileAndContentTypeDefinitions
        {
            [Export]
            [Name("isql")]
            [BaseDefinition("text")]
            internal static ContentTypeDefinition isqlContentTypeDefinition;
    
            [Export]
            [FileExtension(".isql")]
            [ContentType("isql")]
            internal static FileExtensionToContentTypeDefinition isqlFileExtensionDefinition;
    
    
            [Export]
            [Name("gcs")]
            [BaseDefinition("text")]
            internal static ContentTypeDefinition gcsContentTypeDefinition;
    
            [Export]
            [FileExtension(".gcs")]
            [ContentType("gcs")]
            internal static FileExtensionToContentTypeDefinition gcsFileExtensionDefinition;
    
        }


    best regards Stephan Hartmann ML-Software GmbH



    • Edited by S. Hartmann Monday, July 22, 2013 2:49 AM added another code file
    Monday, July 22, 2013 2:28 AM
  • We're doing research on this issue. It might take some time before we get back to you.Thanks for your patience.


    Sophia<br/> MSDN Community Support | <a href="mailto:msdnmg@microsoft.com">Feedback to us</a><br/> <a href="http://blogs.msdn.com/b/win8devsupport/"><font color="red">Develop and promote your apps in Windows Store</font></a><br/> Please remember to mark the replies as answers if they help and unmark them if they provide no help.<br/>

    Monday, July 22, 2013 3:09 AM
    Moderator
  • Ok,  found solution.

    The ProvideEditorExtension Attribute has a Priority value.
    The value in the example was 32 and it is to low. I changed it to 65535 ans it works now.

    it is documented here http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.provideeditorextensionattribute.provideeditorextensionattribute.aspx


    best regards Stephan Hartmann ML-Software GmbH

    Monday, July 22, 2013 3:23 AM
  • Thank you for sharing your solutions & experience here. It will be very beneficial for other community members who have similar questions.


    Sophia<br/> MSDN Community Support | <a href="mailto:msdnmg@microsoft.com">Feedback to us</a><br/> <a href="http://blogs.msdn.com/b/win8devsupport/"><font color="red">Develop and promote your apps in Windows Store</font></a><br/> Please remember to mark the replies as answers if they help and unmark them if they provide no help.<br/>

    Monday, July 22, 2013 5:44 AM
    Moderator
  • Please remember to mark the replies as answers if your case has been resolved.

    And it would be convenient for other community members who have similar questions to search your cases and solution.Thanks.


    Sophia Gou
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 23, 2013 1:24 AM
    Moderator
  • Sorry,

    I didn't notice the difference between "proposed" and "marked as answer" ...


    best regards Stephan Hartmann ML-Software GmbH

    Tuesday, July 23, 2013 1:29 AM
  • Thank you for your active participation in the MSDN community!

    Sophia Gou
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 23, 2013 1:38 AM
    Moderator