Is it possible to specify default editor?

Hello. I use `OpenFileDescriptor(project, file).navigate(true);` to open my file in editor. If file extension is unknown then IDEA ask which editor to use. Is it possible to specify default editor (to skip popup window)?

0
6 comments

Try to use OpenFileDescriptor.navigateInEditor(...) method.

0

It doesn't work - just nothing happens. I need to open plain text editor for unknown file extension.

0

I read sources and found following solution. Is it correct? Is it possible to improve it?

OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file);
        if (!descriptor.navigateInEditor(project, true)) {
            FileTypeManagerImpl.cacheFileType(file, PlainTextFileType.INSTANCE);
            new OpenFileDescriptor(project, file).navigate(true);
        }
            

0

This should work.You can also just check whether file.getFileType() is FileTypes.UNKNOWN, and if it is, do the manual type override as you do.

0

Is `FileTypeManagerImpl.cacheFileType(file, PlainTextFileType.INSTANCE);` correct way to override file type? It doesn't look like public API and I think it may change in future versions of IDEA

0

There's no other way to do it, unless there's a filename pattern that identifies your files (or any other criteria on a VirtualFile).

0

Please sign in to leave a comment.