A few questions about fileEditorProvider implementations

I've reviewed the other threads here on fileEditorProvider as well as the internal documentation for the related classes, but I'm still left with a few questions.

My plugin supports a concept of "bundles" of content where each bundle contains a markup file, a few optional JS files, an optional CSS file, etc. When the user opens any file from these bundles, I want to show a tabbed editor with a tab for each existing bundle content file, always in the same order.

I've registered fileEditorProvider implementations in my plugin.xml, one for each type of bundle content file, using id and order to specify the order of evaluation assuming that will correspond to left-to-right layout in the resulting tabbed editor. Each of these implementations returns a wrapper around TextEditorImpl that delegates all methods except for getName() which returns a proper name for the underlying file. That all works quite well for the most part, so now I'll get to my questions...

First, I'd like to remove/replace the editor for the original file since my registered file editor providers are authoritative on the editors that should be presented. However, if I specify a FileEditorPolicy of anything but HIDE_DEFAULT_EDITOR, the original file's tab is still displayed with a tab of "Text". I thought perhaps I could specify HIDE_DEFAULT_EDITOR for the file editor provider that should be displayed first/left-most and PLACE_AFTER_DEFAULT_EDITOR for the others, but that didn't work either...no editor window is ever opened. How can I either have my file editor providers replace the default editor, or if that's not possible, how I can set the tab title for the original file's tab?

Next question...it's possible to add more content files to an existing bundle which basically means adding another child of the same shared parent directory. My plugin already supports this well. However, when I do this I'd like to have a new tab for the new file added to any existing open tabbed editor. Is this possible? Would I need to look for the open editor and quickly close/reopen it, or can I tell the editor to "refresh" itself and add a new tab?

Thanks in advance for any insights!

0
3 comments

Ah, I believe the behavior of the first one is due to the following in FileEditorProviderManagerImpl.getProviders():

// Throw out default editors provider if necessary
if (doNotShowTextEditor) {
ContainerUtil.retainAll(sharedProviders, provider -> !(provider instanceof TextEditorProvider));
}

and all of my file editor providers are implementations of TextEditorProvider. So assuming I have to retain the original file's tab, I guess the real questions are:

  1. How I can have more control over the order of the tabs?
  2. How can I change the original file's tab name from "Text"?

Thanks again!

0

What if you just don't extend TextEditorProvider? You can delegate to existing instance, if you want, provider doesn't keep any state internally.

Then the order of tabs should match the order in which your providers are registered.

 

2

Good thought, Dmitry. That did the trick! I still need to work through adding tabs as bundle content files are added (and similar on delete), but worst case scenario it looks like I can just close/reopen the editor itself and it'll make things right. Thanks!

0

Please sign in to leave a comment.