initial size for toolwindow couldn't make it work?

Answered

I have a TOP anchored toolwindow and trying to give an initial height? So far tried stretchHeight, resize, even tried using loadstate and setstate in toolwindowManager, but couldn't make it work. Any ideas how to do that?

6 comments
Comment actions Permalink

I think you need to post some code instead of error describe.

0
Comment actions Permalink

so the toolwindow class I use is below a simple toolwindow with implements createToolWindowContent method.

and in plugin.xml  I give the anchor top. what I want to do is to limit the initial size of the toolwindow to a height I give. In order to do that I clean my build and reinstall plugin from scratch and by default the height is some value big which I couldnt find a way to override. The code below initially occupies a a big vertical space. Is it possible to limit that toolwindow height somehow?

<toolWindow factoryClass="io.undo.intellij.ui.UndoBookmarksToolWindowFactory" secondary="false" anchor="top" id="Application Timeline"/>
...
public class UndoBookmarksToolWindowFactory implements ToolWindowFactory, DumbAware {

private static final boolean isHideTimeline = Boolean.getBoolean("hide.timeline");

@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
TimelineToolWindow undoBookmarksToolWindow = new TimelineToolWindow(toolWindow);
ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
Content content =
contentFactory.createContent(undoBookmarksToolWindow.getContent(), "", false);
toolWindow.getContentManager().addContent(content);
ToolWindowEx ex = (ToolWindowEx) toolWindow;
// toolWindow.getComponent().setSize(toolWindow.getComponent().getWidth(),100);
ex.stretchHeight(100);
}

@Override
public boolean shouldBeAvailable(@NotNull Project project) {
return !isHideTimeline;
}
}
0
Comment actions Permalink

I also tried with a blank implementation nothing at all just to limit the vertical height with the blank code below, you can see how big that blank toolwindow is. 

public class UndoBookmarksToolWindowFactory implements ToolWindowFactory, DumbAware {

private static final boolean isHideTimeline = Boolean.getBoolean("hide.timeline");

@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
ToolWindowEx ex = (ToolWindowEx) toolWindow;
// toolWindow.getComponent().setSize(toolWindow.getComponent().getWidth(),100);
ex.stretchHeight(100);
}

@Override
public boolean shouldBeAvailable(@NotNull Project project) {
return !isHideTimeline;
}
}

0
Comment actions Permalink

with my current resolution  I tested couple of times, and finally got a perfect result when I specify -150 value to stretchHeight. But should it be negative value like that? 

0
Comment actions Permalink

I just debugged the intellij source code and found the solution. Just posting here just in case anyone might need that:

TOOL_WINDOW_HEIGHT is the size you want it to be. 

ToolWindowEx ex = (ToolWindowEx) toolWindow;
ex.stretchHeight(TOOL_WINDOW_HEIGHT - ex.getDecorator().getHeight());
3
Comment actions Permalink

It is not work for my idea version (2021.2). 
Guess toolWindow size is overriding after calling my factory method.
So, I set the size in startUpActivity, after all toolWindows are initializated

0

Please sign in to leave a comment.