Quantcast
Channel: SharpDevelop Community
Viewing all articles
Browse latest Browse all 1764

Adding File Extensions to the XML Editor

$
0
0

Hi all,

In my quest to extend SharpDevelop to support a non-.NET language (you probably heard me rumble enough already :D ), I also wanted to make the great built-in XML editor open my file type, which has a unique extension (.dscanvas).

(The question is at the end of the post, this is some background. ;-)  ) 

I tried searching for the method to do this, but it seemed too hard-coded into the editor, so what I eventually did was create a primary display binding for my filetype and use the XmlView to display the file.
I supplied the XmlView with my custom schema for code-completion using some hacking:

//Get schema from embedded resource.
Stream schemaResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetType(), "dscanvas.xsd");
//Setup an XML reader for the schema document and pass that to the editor.
XmlTextReader xmlReader = new XmlTextReader(schemaResourceStream);
canvasSchema = new XmlSchemaCompletionData(xmlReader);
canvasSchemas = new XmlSchemaCompletionDataCollection(new XmlSchemaCompletionData[] { canvasSchema });
//Add the schema to the collection and make it the default.
xmlEditor.SchemaCompletionDataItems = canvasSchemas;
xmlEditor.DefaultSchemaCompletionData = canvasSchema;

I ran into two problems:

  1. Code completion would not work after save. I found out this is because the Save method sets the FileName property which resets the DefaultSchemaCompletionData property. To solve this I hooked an event handler for XmlView.Saved that set the default schema to my schema again.
  2. There is no syntax highlighting. I've tried:
    xmlEditor.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy(XmlView.Language);
    But it doesn't help. Any ideas, Matt or anyone?

Thanks in advance,

    GoMa
 

 

 


Viewing all articles
Browse latest Browse all 1764

Trending Articles