From d3e23bbb387fea9080cb86c4f74056e078b235b2 Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Mon, 11 Mar 2019 10:49:30 +0700 Subject: [PATCH] AbstractPopup: intercept other show() methods. ChooserInterceptor: use UIUtil.findComponentOfType --- .../src/com/intellij/ui/popup/AbstractPopup.java | 2 ++ .../src/com/intellij/ui/ChooserInterceptor.java | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) 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 41b9be75db89..6b337e6394fd 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java @@ -406,6 +406,7 @@ public class AbstractPopup implements JBPopup { @Override public void showCenteredInCurrentWindow(@NotNull Project project) { + if (UiInterceptors.tryIntercept(this)) return; Window window = null; Component focusedComponent = getWndManager().getFocusedComponent(project); @@ -760,6 +761,7 @@ public class AbstractPopup implements JBPopup { } public void show(Component owner, int aScreenX, int aScreenY, final boolean considerForcedXY) { + if (UiInterceptors.tryIntercept(this)) return; if (ApplicationManagerEx.getApplicationEx() != null && ApplicationManager.getApplication().isHeadlessEnvironment()) return; if (isDisposed()) { throw new IllegalStateException("Popup was already disposed. Recreate a new instance to show again"); diff --git a/platform/testFramework/src/com/intellij/ui/ChooserInterceptor.java b/platform/testFramework/src/com/intellij/ui/ChooserInterceptor.java index f8bc69a3a53b..3690646a865f 100644 --- a/platform/testFramework/src/com/intellij/ui/ChooserInterceptor.java +++ b/platform/testFramework/src/com/intellij/ui/ChooserInterceptor.java @@ -3,6 +3,7 @@ package com.intellij.ui; import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.ui.components.JBList; +import com.intellij.util.ui.UIUtil; import one.util.streamex.IntStreamEx; import one.util.streamex.StreamEx; import org.intellij.lang.annotations.RegExp; @@ -10,7 +11,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.awt.*; import java.util.List; import java.util.regex.Pattern; @@ -39,10 +39,9 @@ public class ChooserInterceptor extends UiInterceptors.UiInterceptor { @Override protected void doIntercept(JBPopup popup) { JComponent component = popup.getContent(); - JBList content = StreamEx.ofTree((Component)component, Container.class, c -> StreamEx.of(c.getComponents())) - .select(JBList.class).findFirst().orElse(null); + JBList content = UIUtil.findComponentOfType(component, JBList.class); if (content == null) { - fail("Expected chooser; got: " + component); + fail("JBList not found under " + component); } ListModel model = content.getModel(); List actualOptions = IntStreamEx.range(model.getSize()).mapToObj(model::getElementAt).map(Object::toString).toList();