From 54142b6c5efd57c066536bf81f67655bbff504cd Mon Sep 17 00:00:00 2001 From: graann Date: Tue, 17 Dec 2019 19:42:38 +0300 Subject: [PATCH] Fixe for IDEA-229234 Window header is displayed in "Find in Path" dialog GitOrigin-RevId: e48211b86996679b9229755314359bc1ea73c328 --- .../com/intellij/openapi/ui/FrameWrapper.java | 2 +- .../ui/impl/DialogWrapperPeerImpl.java | 7 +++- .../header/CustomFrameDialogContent.kt | 42 ++++++------------- .../impl/welcomeScreen/FlatWelcomeFrame.java | 8 ++-- 4 files changed, 24 insertions(+), 35 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.java b/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.java index b3889097269c..6502c3de3e96 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/FrameWrapper.java @@ -154,7 +154,7 @@ public class FrameWrapper implements Disposable, DataProvider { if (myCloseOnEsc) addCloseOnEsc((RootPaneContainer)frame); if (IdeFrameDecorator.isCustomDecorationActive()) { - myComponent = CustomFrameDialogContent.getContent(frame, myComponent); + myComponent = CustomFrameDialogContent.getCustomContentHolder(frame, myComponent); } ((RootPaneContainer)frame).getContentPane().add(myComponent, BorderLayout.CENTER); 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 806daed99dda..b0ae8b92e867 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 @@ -387,6 +387,11 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer { UIUtil.setCustomTitleBar(window, rootPane, runnable -> Disposer.register(myWrapper.getDisposable(), () -> runnable.run())); } + Container contentPane = getContentPane(); + if(contentPane instanceof CustomFrameDialogContent) { + ((CustomFrameDialogContent)contentPane).updateLayout(); + } + anCancelAction.registerCustomShortcutSet(CommonShortcuts.ESCAPE, rootPane); myDisposeActions.add(() -> anCancelAction.unregisterCustomShortcutSet(rootPane)); @@ -987,7 +992,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer { public void setContentPane(JComponent content) { JComponent wrappedContent = IdeFrameDecorator.isCustomDecorationActive() && !isHeadlessEnv() - ? CustomFrameDialogContent.getContent(getWindow(), content) + ? CustomFrameDialogContent.getCustomContentHolder(getWindow(), content) : content; myDialog.setContentPane(wrappedContent); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/customFrameDecorations/header/CustomFrameDialogContent.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/customFrameDecorations/header/CustomFrameDialogContent.kt index 59fb3def996e..1d0222097415 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/customFrameDecorations/header/CustomFrameDialogContent.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/customFrameDecorations/header/CustomFrameDialogContent.kt @@ -7,21 +7,16 @@ import java.awt.Container import java.awt.Window import javax.swing.* -class CustomFrameDialogContent private constructor(window: Window, content: Container, titleBackgroundColor: Color? = null): CustomFrameViewHolder { +class CustomFrameDialogContent private constructor(val window: Window, content: Container, titleBackgroundColor: Color? = null): JPanel() { companion object { @JvmStatic - fun getContent(window: Window, content: JComponent) = getContent(window, content, null) + fun getCustomContentHolder(window: Window, content: JComponent) = getCustomContentHolder(window, content, null) @JvmStatic - fun getContent(window: Window, content: JComponent, titleBackgroundColor: Color? = null): JComponent { - return getCustomContentHolder(window, content, titleBackgroundColor).content - } + fun getCustomContentHolder(window: Window, content: JComponent, titleBackgroundColor: Color? = null): JComponent { + if (content is CustomFrameDialogContent) return content - @JvmStatic - fun getCustomContentHolder(window: Window, content: JComponent, titleBackgroundColor: Color? = null): CustomFrameViewHolder { - if(content is CustomFrameViewHolder) return content - - val rootPane: JRootPane? = when (window) { + when (window) { is JWindow -> window.rootPane is JDialog -> { if (window.isUndecorated) null @@ -29,39 +24,28 @@ class CustomFrameDialogContent private constructor(window: Window, content: Cont } is JFrame -> window.rootPane else -> null - } - - rootPane ?: return object : CustomFrameViewHolder { - override val content: JComponent - get() = content - override val headerHeight: Int - get() = 0 - } + } ?: return content return CustomFrameDialogContent(window, content, titleBackgroundColor) - } } - private val panel = JPanel(MigLayout("novisualpadding, ins 0, gap 0, fill, flowy", "", "[min!][]")) private val header: CustomHeader = CustomHeader.create(window) init { + layout = MigLayout("novisualpadding, ins 0, gap 0, fill, flowy, hidemode 2", "", "[min!][]") titleBackgroundColor?.let { header.background = it } - panel.add(header, "growx, wmin 100") - panel.add(content, "grow") + add(header, "growx, wmin 100") + add(content, "grow") } - override val content: JComponent - get() = panel - override val headerHeight: Int - get() = header.preferredSize.height -} + fun updateLayout() { + if(window is JDialog && window.isUndecorated) header.isVisible = false + } -interface CustomFrameViewHolder { - val content: JComponent val headerHeight: Int + get() = if(header.isVisible) header.preferredSize.height else 0 } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/FlatWelcomeFrame.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/FlatWelcomeFrame.java index b8a3f49c07cb..dbf55c1a2cb0 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/FlatWelcomeFrame.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/FlatWelcomeFrame.java @@ -37,7 +37,6 @@ import com.intellij.openapi.wm.impl.IdeFrameDecorator; import com.intellij.openapi.wm.impl.IdeGlassPaneImpl; import com.intellij.openapi.wm.impl.ProjectFrameHelper; import com.intellij.openapi.wm.impl.customFrameDecorations.header.CustomFrameDialogContent; -import com.intellij.openapi.wm.impl.customFrameDecorations.header.CustomFrameViewHolder; import com.intellij.ui.*; import com.intellij.ui.border.CustomLineBorder; import com.intellij.ui.components.JBList; @@ -109,11 +108,12 @@ public class FlatWelcomeFrame extends JFrame implements IdeFrame, Disposable, Ac int defaultHeight = DEFAULT_HEIGHT; if (IdeFrameDecorator.isCustomDecorationActive()) { - CustomFrameViewHolder holder = + JComponent holder = CustomFrameDialogContent.getCustomContentHolder(this, myScreen.getWelcomePanel(), UIManager.getColor("WelcomeScreen.background")); - setContentPane(holder.getContent()); + setContentPane(holder); - defaultHeight+=holder.getHeaderHeight(); + if(holder instanceof CustomFrameDialogContent) + defaultHeight+= ((CustomFrameDialogContent)holder).getHeaderHeight(); } else { setContentPane(myScreen.getWelcomePanel());