From f5af4de06b361be0955cf2957cdcbb6e70ad9f7b Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Mon, 15 Jul 2019 19:31:19 +0300 Subject: [PATCH] store window bounds in project-based WindowStateService GitOrigin-RevId: dbb569bf7b1dc567d4db4bfce5e2dea3a826e827 --- .../ui/impl/DialogWrapperPeerImpl.java | 14 ++++++- .../com/intellij/ui/popup/AbstractPopup.java | 42 ++++++++++++------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/impl/DialogWrapperPeerImpl.java b/platform/platform-impl/src/com/intellij/openapi/ui/impl/DialogWrapperPeerImpl.java index 3129a1f26bbe..0da9659d2807 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/impl/DialogWrapperPeerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/impl/DialogWrapperPeerImpl.java @@ -26,6 +26,7 @@ import com.intellij.openapi.util.ActionCallback; import com.intellij.openapi.util.DimensionService; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.WindowStateService; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.openapi.wm.IdeFrame; @@ -663,8 +664,10 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer { if (myDimensionServiceKey != null) { final Project projectGuess = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(this)); - location = DimensionService.getInstance().getLocation(myDimensionServiceKey, projectGuess); - Dimension size = DimensionService.getInstance().getSize(myDimensionServiceKey, projectGuess); + location = getWindowStateService(projectGuess).getLocation(myDimensionServiceKey); + if (location == null) location = DimensionService.getInstance().getLocation(myDimensionServiceKey, projectGuess); + Dimension size = getWindowStateService(projectGuess).getSize(myDimensionServiceKey); + if (size == null) size = DimensionService.getInstance().getSize(myDimensionServiceKey, projectGuess); if (size != null) { myInitialSize = new Dimension(size); _setSizeForLocation(myInitialSize.width, myInitialSize.height, location); @@ -808,10 +811,12 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer { // Save location Point location = getLocation(); + getWindowStateService(projectGuess).putLocation(myDimensionServiceKey, location); DimensionService.getInstance().setLocation(myDimensionServiceKey, location, projectGuess); // Save size Dimension size = getSize(); if (!myInitialSize.equals(size)) { + getWindowStateService(projectGuess).putSize(myDimensionServiceKey, size); DimensionService.getInstance().setSize(myDimensionServiceKey, size, projectGuess); } myOpened = false; @@ -966,6 +971,11 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer { return wrapper != null && PlatformDataKeys.UI_DISPOSABLE.is(dataId) ? wrapper.getDisposable() : null; } } + + @NotNull + private static WindowStateService getWindowStateService(@Nullable Project project) { + return project == null ? WindowStateService.getInstance() : WindowStateService.getInstance(project); + } } private static void setupSelectionOnPreferredComponent(final JComponent component) { diff --git a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java index 96b993cd45ea..bec966f70f39 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java @@ -527,8 +527,8 @@ public class AbstractPopup implements JBPopup, ScreenAreaConsumer { private Dimension getSizeForPositioning() { Dimension size = getSize(); - if (size == null && myDimensionServiceKey != null) { - size = DimensionService.getInstance().getSize(myDimensionServiceKey, myProject); + if (size == null) { + size = getStoredSize(); } if (size == null) { size = myContent.getPreferredSize(); @@ -654,10 +654,8 @@ public class AbstractPopup implements JBPopup, ScreenAreaConsumer { if (myForcedSize != null) { return myForcedSize; } - if (myDimensionServiceKey != null) { - final Dimension dimension = DimensionService.getInstance().getSize(myDimensionServiceKey, myProject); - if (dimension != null) return dimension; - } + Dimension size = getStoredSize(); + if (size != null) return size; return myComponent.getPreferredSize(); } @@ -785,12 +783,7 @@ public class AbstractPopup implements JBPopup, ScreenAreaConsumer { prepareToShow(); installWindowHook(this); - Dimension sizeToSet = null; - - if (myDimensionServiceKey != null) { - sizeToSet = DimensionService.getInstance().getSize(myDimensionServiceKey, myProject); - } - + Dimension sizeToSet = getStoredSize(); if (myForcedSize != null) { sizeToSet = myForcedSize; } @@ -829,8 +822,8 @@ public class AbstractPopup implements JBPopup, ScreenAreaConsumer { Point xy = new Point(aScreenX, aScreenY); boolean adjustXY = true; - if (myUseDimServiceForXYLocation && myDimensionServiceKey != null) { - final Point storedLocation = DimensionService.getInstance().getLocation(myDimensionServiceKey, myProject); + if (myUseDimServiceForXYLocation) { + Point storedLocation = getStoredLocation(); if (storedLocation != null) { xy = storedLocation; adjustXY = false; @@ -1475,12 +1468,14 @@ public class AbstractPopup implements JBPopup, ScreenAreaConsumer { if (myDimensionServiceKey != null) { Dimension size = myContent.getSize(); JBInsets.removeFrom(size, myContent.getInsets()); + getWindowStateService(myProject).putSize(myDimensionServiceKey, size); DimensionService.getInstance().setSize(myDimensionServiceKey, size, myProject); } } private void storeLocation(final Point xy) { if (myDimensionServiceKey != null) { + getWindowStateService(myProject).putLocation(myDimensionServiceKey, xy); DimensionService.getInstance().setLocation(myDimensionServiceKey, xy, myProject); } } @@ -2003,4 +1998,23 @@ public class AbstractPopup implements JBPopup, ScreenAreaConsumer { Window focused = event.getWindow(); return focused != window && (focused == null || window != focused.getOwner()); } + + @Nullable + private Point getStoredLocation() { + if (myDimensionServiceKey == null) return null; + Point location = getWindowStateService(myProject).getLocation(myDimensionServiceKey); + return location != null ? location : DimensionService.getInstance().getLocation(myDimensionServiceKey, myProject); + } + + @Nullable + private Dimension getStoredSize() { + if (myDimensionServiceKey == null) return null; + Dimension size = getWindowStateService(myProject).getSize(myDimensionServiceKey); + return size != null ? size : DimensionService.getInstance().getSize(myDimensionServiceKey, myProject); + } + + @NotNull + private static WindowStateService getWindowStateService(@Nullable Project project) { + return project == null ? WindowStateService.getInstance() : WindowStateService.getInstance(project); + } }