Retrieving and setting split window settings

I am currently working on a plugin called "Tab Session" which is quite useful if you want to save and load certain sets of open tabs. It works well, but an important feature is still missing: Splitted Tabs are ignored and are lost when reloading a session.

I want to do two things:

  1. Retrieve information about all splitted or unsplitted windows that are containers for editor tabs. I need their position and split direction (horizontal or vertical).
  2. When this information is saved and a tab session needs to be loaded, i need to reconstruct the splitted panes and their tabs exactly as they were before.


Due to the lack of documentation i browsed through the source code and found this promising piece of code:

private EditorsSplitters getSplittersFromFocus() {
  return FileEditorManagerEx.getInstanceEx(myProject).getSplitters();
}


It allows me to iterate through the set of splitted windows by using

EditorWindow[] windows = getSplittersFromFocus.getOrderedWindows()
. They contain the editor tabs and information about their width and height. But i did not found any information about the split direction and how to reconstruct the splitted windows as they were before. I also looked at FileEditorManagerImpl but didn't find anything useful.

I also asked at Stackoverflow, but got no attention:
http://stackoverflow.com/questions/19728469/retrieving-and-setting-split-window-settings-for-intellij-idea-plugin-developmen

Maybe someone can help me with this. I find it quite diffictult to find the right methods without a documentation.
0
7 comments

The state of a split window is stored by the EditorsSplitters.writeExternal() method. You can see how it's implemented and implement similar logic in your own code.

To restore the split state, you can use the EditorWindow.split() method.

0

Thank you.

The writeExternal() method is not very interesting afaik:

  public void writeExternal(final Element element) {     if (getComponentCount() != 0) {       final Component comp = getComponent(0);       LOG.assertTrue(comp instanceof JPanel);       final JPanel panel = (JPanel)comp;       if (panel.getComponentCount() != 0) {         final Element res = writePanel(panel);         element.addContent(res);       }     }   }


Did you mean the writePanel() method?

  private Element writePanel(final JPanel panel) {     final Component comp = panel.getComponent(0);     if (comp instanceof Splitter) {       final Splitter splitter = (Splitter)comp;       final Element res = new Element("splitter");       res.setAttribute("split-orientation", splitter.getOrientation() ? "vertical" : "horizontal");       res.setAttribute("split-proportion", Float.toString(splitter.getProportion()));       final Element first = new Element("split-first");       first.addContent(writePanel((JPanel)splitter.getFirstComponent()));       final Element second = new Element("split-second");       second.addContent(writePanel((JPanel)splitter.getSecondComponent()));       res.addContent(first);       res.addContent(second);       return res;     }


That could be interesting, but i didn't find any way to find the Element "splitter".

Also, there is no split() method in EditorWindow.

0

Thank you! I looked at the wrong EditorWindow class.

0

I reviewed the EditorWindow class, and indeed there are some very useful bits in there. There is a huge problem though: no getter for the panel or splitter components.

In the class the protected field myPanel holds the panel, and myPanel.getParent() is the Splitter container which i need to get information about orientation, size and position of the splitted window (see https://github.com/JetBrains/intellij-community/blob/master/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorWindow.java#L826).

Is there any other way to get to the splitter instance of a window?

0

Maybe this thread was forgotten. Can anyone provide me with new input? I am quite stuck here.

This is my current progess of things:

        final FileEditorManagerImpl fileEditorManager = (FileEditorManagerImpl)FileEditorManager.getInstance(project);
        EditorsSplitters splitters = fileEditorManager.getSplitters();
        EditorWindow[] orderedWindows = splitters.getOrderedWindows();

        for (EditorWindow window : orderedWindows) {

             // TODO here I need a method to determine if the splitters are horizontally or vertically splitted

            for(EditorWithProviderComposite editor : window.getEditors()) {
                VirtualFile vf = editor.getFile();
                // editor file can be saved here
            }
        }

0

That method is package private and getParent is not pssible to call either. what a shit 

0

Please sign in to leave a comment.