From baa940b8c1f7d7013111593f2fbb3bde3bf56f11 Mon Sep 17 00:00:00 2001 From: "Vassiliy.Kudryashov" Date: Tue, 26 Dec 2017 00:15:02 +0300 Subject: [PATCH] IDEA-149061 Tool Window docking issue --- .../wm/impl/ToolWindowManagerImpl.java | 9 +++-- .../openapi/wm/impl/ToolWindowsPane.java | 36 +++++++++++++++---- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java index d099812ad9a2..1409e191117e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java @@ -1609,13 +1609,18 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements myLayout.setSplitMode(id, isSplit); boolean wasActive = info.isActive(); - if (wasActive) { - deactivateToolWindowImpl(id, true, commandList); + boolean wasVisible = info.isVisible(); + // We should hide the window and show it in a 'new place' to automatically hide possible window that is already located in a 'new place' + if (wasActive || wasVisible) { + hideToolWindow(id, false); } final WindowInfoImpl[] infos = myLayout.getInfos(); for (WindowInfoImpl info1 : infos) { appendApplyWindowInfoCmd(info1, commandList); } + if (wasVisible || wasActive) { + showToolWindowImpl(id, true, commandList); + } if (wasActive) { activateToolWindowImpl(id, commandList, true, true); } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowsPane.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowsPane.java index a1c32f8b7cb1..3d135a5ac6ce 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowsPane.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowsPane.java @@ -45,6 +45,7 @@ import java.awt.image.BufferedImage; import java.lang.ref.Reference; import java.util.ArrayList; import java.util.Comparator; +import java.util.Iterator; import java.util.List; /** @@ -328,7 +329,7 @@ public final class ToolWindowsPane extends JBLayeredPane implements UISettingsLi return myId2Button.get(id); } - private Component getDecoratorById(final String id) { + private InternalDecorator getDecoratorById(final String id) { return myId2Decorator.get(id); } @@ -827,22 +828,43 @@ public final class ToolWindowsPane extends JBLayeredPane implements UISettingsLi }); } JComponent c = getComponentAt(anchor); + //If all components are hidden for anchor we should find the second component to put in a splitter + //Otherwise we add empty splitter + if (c == null) { + List ids = ToolWindowsPane.this.myManager.getIdsOn(anchor); + ids.remove(myInfo.getId()); + for (Iterator iterator = ids.iterator(); iterator.hasNext(); ) { + String id = iterator.next(); + ToolWindow window = myManager.getToolWindow(id); + if (window == null || window.isSplitMode() == myInfo.isSplit() || !window.isVisible()) iterator.remove(); + } + if (!ids.isEmpty()) { + InternalDecorator anotherDecorator = getDecoratorById(ids.get(0)); + if (anotherDecorator!= null) { + c = anotherDecorator; + } + } + if (c == null) { + LOG.error("Empty splitter @ " + anchor + " during AddAndSplitDockedComponentCmd for " + myInfo.getId()); + } + } float newWeight; if (c instanceof InternalDecorator) { InternalDecorator oldComponent = (InternalDecorator)c; + WindowInfoImpl oldInfo = oldComponent.getWindowInfo(); if (myInfo.isSplit()) { splitter.setFirstComponent(oldComponent); splitter.setSecondComponent(myNewComponent); - float proportion = getPreferredSplitProportion(oldComponent.getWindowInfo().getId(), - normalizeWeigh(oldComponent.getWindowInfo().getSideWeight() / - (oldComponent.getWindowInfo().getSideWeight() + + float proportion = getPreferredSplitProportion(oldInfo.getId(), + normalizeWeigh(oldInfo.getSideWeight() / + (oldInfo.getSideWeight() + myInfo.getSideWeight()))); splitter.setProportion(proportion); if (!anchor.isHorizontal() && !anchor.isSplitVertically()) { - newWeight = normalizeWeigh(oldComponent.getWindowInfo().getWeight() + myInfo.getWeight()); + newWeight = normalizeWeigh(oldInfo.getWeight() + myInfo.getWeight()); } else { - newWeight = normalizeWeigh(oldComponent.getWindowInfo().getWeight()); + newWeight = normalizeWeigh(oldInfo.getWeight()); } } else { @@ -850,7 +872,7 @@ public final class ToolWindowsPane extends JBLayeredPane implements UISettingsLi splitter.setSecondComponent(oldComponent); splitter.setProportion(normalizeWeigh(myInfo.getSideWeight())); if (!anchor.isHorizontal() && !anchor.isSplitVertically()) { - newWeight = normalizeWeigh(oldComponent.getWindowInfo().getWeight() + myInfo.getWeight()); + newWeight = normalizeWeigh(oldInfo.getWeight() + myInfo.getWeight()); } else { newWeight = normalizeWeigh(myInfo.getWeight());