How to open file in one of standard editor?
Hello,
subj.
for example, i have virtual file with fileType A. It have assotiated file editor. But i want to open it with different editor.
For instance. I want to open XML file in Text editor and edit it as simple text.
Thanks!
Please sign in to leave a comment.
If i correctly understand your question, what you need is to create a FileEditorProvider to associate a FileEditor with some file type.
You can search the forum for "FileEditorProvider" if you need more info on how to do this.
No, it too simple :)
I want to open file not in assotiated editor, but as Simple Text for example. Imagine, you have, XML file, and want to open it as Text.
Ok.
So what you want is to replace the default editor for a given file. Again, you can do this by implementing FileEditorProvider like this:
+public class MyEditorProvider implements ApplicationComponent, FileEditorProvider
{
.....
public boolean accept(Project project, VirtualFile file)
{
// check if the default editor should be replaced
}
public FileEditor createEditor(Project project, VirtualFile file)
{
// return the new editor
}
public FileEditorPolicy getPolicy()
{
return FileEditorPolicy.HIDE_DEFAULT_EDITOR;
}
......
}+
If you really want the TextEditor, i'm not sure how you can use the TextEditorImpl class that is provided because it has a package protected contructor, i guess you would have to figure out a way to get hold of an instance of the editor. I haven't looked for a way to do that though.
This i good for replacing standard editor by custom one, but how to replace one standard editor by another one standard editor?
You can always do this:
FileTypeManager.getInstance().registerFileType(StdFileTypes.PLAIN_TEXT, new String[]{"xml"});
The main trouble of 4.5 version is here :)
Many peoples not used Property Editor inlined in IDEA, cos FileType 'Text files' have extension '.properties' assigned. Here you try to do the same.
I not need to assign extension to wrong file type. I just want something like:
StdFileTypes.PLAINT_TEXT.getMyPrefferedEditor() : FileEditor
I don't think there's such an API like what you describe.
Still, you could use:
+String[] fileExtensions = FileTypeManager.getInstance().getAssociatedExtensions(StdFileTypes.]]>);
FileTypeManager.getInstance().registerFileType(StdFileTypes.PLAIN_TEXT, fileExtensions);+
I think this a little more like what you describe.
If this doesn't do it for you then i've run out of ideas. Sorry.
I have same purposes to open file in the Intellij default editor, then I found these two ways to call a default FileEditor or Editor. :