I have a file with extension .xyz .i want to open an editor when it is double clicked How to go about doing it.I have a treeviewer that lists only my files that i need ,in those i have a .xyz file.I have added an editor in the extension point and in the extensions textfield i hav e added .xyz also.I dont want to add a doubleclicklistener to the viewer.Is there a way to add or tell eclipse that if this is the extension of the file then by default it should open.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Well if you have your own viewer implementation you will need to define the complete behavior in that viewer, even the opening of files. Since you have registered an editor against that extension so whenever that file is opened in Eclipse, either by your viewer or some other viewer (Project Explorer, Navigator) Eclipse will automatically open the file in the assigned editor.
In your double click listener you can use org.eclipse.ui.actions.OpenFileAction
or something like it to ensure that the file is opened by Eclipse according to Workbench rules. Btw why do you want to avoid adding a double click listener?
回答2:
You need to add an org.eclipse.ui.editors extension point.
<extension point="org.eclipse.ui.editors">
<editor
name="MyEditor Name"
extensions="my_file_extension"
icon="icons/sample.gif"
class="com.me.MyEditor"
id="com.me.MyEditorID">
</editor>