Plugin - Add gap between editor tabs

Answered

Hello IDEA Community,

I am trying to write a plugin which sorts the editor tabs based on the file extension.
For example, all Java Files are next to each other and if there is another file extension, there is a gap between those files.

After some research, I only found a solution by achieving this when I rewrite the whole tab bar.
This includes basicly the whole file handling, opening files, closing files and to hide the current editor bar, so only my custom one gets displayed.

Is there a clean solution to do this, without rewriting the whole editor tab bar?

 

 

8 comments
Avatar
Vassiliy Kudryashov
Comment actions Permalink

Hello! Try to override JBEditorTabs.createSingleRowLayout() in your Tabs implementation. There are three implementations now: SingleRowLayout, CompressibleSingleRowLayout and ScrollableSingleRowLayout. You're welcome to add new one, say GroupingSingleRowLayout.

0
Comment actions Permalink

Hello Vassiliy,

thanks for your answer, this seems like the right way to do it.
I followed your suggestion and made a new class for my grouping style.

public class GroupingSingleRowLayout extends SingleRowLayout {

public GroupingSingleRowLayout(JBTabsImpl tabs) {
super( tabs );
System.out.println("GroupingSingleRowLayout called");
}

}

 

Also I made a custom JBEditorTabs, to let him call my new style in the constructor. 

public class JBEditorCustomTabs extends JBEditorTabs {

public JBEditorCustomTabs(@Nullable Project project, @NotNull ActionManager actionManager, IdeFocusManager focusManager, @NotNull Disposable parent) {
super(project, actionManager, focusManager, parent);
}

@Override
protected SingleRowLayout createSingleRowLayout() {
return new GroupingSingleRowLayout( this );
}

}

 

Is this right so far?
Where can I call my JBEditorCUstomTabs instead of JBEditorTabs, so the new "GroupingSingleRowLayout" gets called?

0
Avatar
Vassiliy Kudryashov
Comment actions Permalink

Spent some time chasing for solution and... Sorry, unfortunately JBEditorTabs as well as its SingleRowLayout are not designed to be replaced with custom implementation.

0
Comment actions Permalink

Hello Vassiliy Kudryashov,

thanks for your time searching for a solution.
Well, if there is no way doing it this way, than I have to hide the EditorTabs and add custom JComponent's

fileEditorManager.addTopComponent(editor, component);

 

Is there a possibility to do this at the position of the EditorTab bar, I couldnt find a documentation or image where every single component is mentioned, so I couldn't try it myself.
At the moment I just know about the FileEditorManager, but If I do it this way, I need to do this for every single tab, and haven't got something like a "global" component where those components are stored. This means if I open or close a new tab, I have to iterate over each editor and add or delete a component.

0
Avatar
Vassiliy Kudryashov
Comment actions Permalink

If you setup tabs placement like this 

UISettings.getInstance().setEditorTabPlacement(UISettings.TABS_NONE)

your top component would replace tabs completely.

Yes, you have to handle it for every editor with FileEditorManagerListener.

0
Comment actions Permalink

Hello Vassiliy Kudryashov,

thanks for your answer.
Thats what I wanted to avoid, listening for multiple Events and handle the TopComponent separatly for each editor doesn't make sense.

JetBrains editors are really powerfull and nice to use, but if you are working with multiple files it is impossible to get a clean sorted navigation.
Sorting by filetype or user dependent attributes would be really nice.

Nevertheless, thanks for your time, patience and all your effort you put into this!

 

0
Comment actions Permalink

Hello Vassiliy Kudryashov,

I played arround a little bit and at the moment it looks like this.


I use JButtons at the moment embedded inside an JPanel.
Is there any way to use the same "build" function for those tabs like IntelliJ itself?
I had a quick look inside those methods and there is a lot of logic for theme separation (Dracula, etc.) so the correct tab color gets returned.
If I write my own tab component, than I have to implement the theme and color management myself.

Is there a method which I can call with a VirtualFile and it returns a EditorTab component?

0
Avatar
Vassiliy Kudryashov
Comment actions Permalink

Actually 'tabs' are not components, it's just a model for JBTabsImpl. So you have to borrow a lot of logic from JBEditorTabs etc. to use proper names, icons and colors, but it's still possible.

0

Please sign in to leave a comment.