Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Editor type based on document location
Editor type based on document location [message #906534] Sat, 01 September 2012 19:48 Go to next message
Daniel Mising name is currently offline Daniel Mising nameFriend
Messages: 9
Registered: April 2011
Junior Member
I am trying to provide a custom editor for XML files in certain folders of a project. They have the extension ".xml" so I cannot register my editor for that or it will affect all XML files.

I thought perhaps I had to provide an IEditorMatchingStrategy but as far as I can tell that is only for already open editors. When no editors are open the matching strategy does not fire. That doesn't help in this case.

Please help, I do not know how to proceed nor what I should be looking for.
Re: Editor type based on document location [message #908063 is a reply to message #906534] Tue, 04 September 2012 16:21 Go to previous messageGo to next message
Curtis Windatt is currently offline Curtis WindattFriend
Messages: 166
Registered: July 2009
Senior Member
PDE has multiple editors for xml files. To distinguish them, in org.eclipse.pde.core we create a org.eclipse.core.contenttype.contentTypes extension. As part of that extension we add an XMLRootElementContentDescriber so that we distinguish different xml files based on their root element. There are other options available on the extension.

Then when defining the editor in org.eclipse.pde.ui we add a contentTypeBinding, using the same id as defined in pde.core.


<content-type 
id="org.eclipse.pde.schema" 
name="%schemaFile" 
base-type="org.eclipse.core.runtime.xml"
priority="high"				
file-extensions="exsd">
<describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber">
<parameter name="element" value="schema"/>
</describer>
</content-type>

<editor
default="true"
name="%editors.schema.name"
icon="$nl$/icons/obj16/schema_obj.gif"
class="org.eclipse.pde.internal.ui.editor.schema.SchemaEditor"      contributorClass="org.eclipse.pde.internal.ui.editor.schema.SchemaEditorContributor"
            id="org.eclipse.pde.ui.schemaEditor">
<contentTypeBinding contentTypeId="org.eclipse.pde.schema"/>
</editor>

Re: Editor type based on document location [message #908168 is a reply to message #908063] Tue, 04 September 2012 21:32 Go to previous message
Daniel Mising name is currently offline Daniel Mising nameFriend
Messages: 9
Registered: April 2011
Junior Member
Thank you for this.

Using the debugger I found that between a resource being detected as a file and the last segment of the file name being extracted for the content type, there are no hooks nor extension points. Short of editing the core and distributing my own version I see no way to test the file's path, so this cannot be done with a plugin.

I had not considered examining the file's contents directly (which seems wasteful since content describers are used by label decorators too). There is a chance of false positives but it's the best suggestion so far, I will have to make the most of it.
Previous Topic:Reading resources from a Eclipse plugin ?
Next Topic:Plugin Activation
Goto Forum:
  


Current Time: Thu Apr 25 01:25:32 GMT 2024

Powered by FUDForum. Page generated in 0.02970 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top