mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
list with filter revalidates popup on filtering text changes
This commit is contained in:
@@ -182,4 +182,6 @@ public interface JBPopup extends Disposable, LightweightWindow {
|
||||
void moveToFitScreen();
|
||||
|
||||
Point getLocationOnScreen();
|
||||
|
||||
void pack(boolean with, boolean height);
|
||||
}
|
||||
|
||||
@@ -219,7 +219,6 @@ public class PopupChooserBuilder {
|
||||
}
|
||||
|
||||
scrollPane.getViewport().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
((JComponent)scrollPane.getViewport().getView()).setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||
|
||||
if (myChooserComponent instanceof ListWithFilter) {
|
||||
contentPane.add(myChooserComponent, BorderLayout.CENTER);
|
||||
|
||||
@@ -50,6 +50,19 @@ public class PopupUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static JBPopup getPopupContainerFor(@Nullable Component c) {
|
||||
if (c == null) return null;
|
||||
|
||||
final Window wnd = SwingUtilities.getWindowAncestor(c);
|
||||
if (wnd instanceof JWindow) {
|
||||
final JRootPane root = ((JWindow)wnd).getRootPane();
|
||||
return (JBPopup)root.getClientProperty(JBPopup.KEY);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static void setPopupType(@NotNull final PopupFactory factory, final int type) {
|
||||
try {
|
||||
final Method method = PopupFactory.class.getDeclaredMethod("setPopupType", int.class);
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
*/
|
||||
package com.intellij.ui.speedSearch;
|
||||
|
||||
import com.intellij.openapi.ui.popup.JBPopup;
|
||||
import com.intellij.openapi.ui.popup.util.PopupUtil;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.LightColors;
|
||||
@@ -101,6 +103,14 @@ public class ListWithFilter<T> extends JPanel {
|
||||
revalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private void revalidate() {
|
||||
JBPopup popup = PopupUtil.getPopupContainerFor(mySpeedSearchPatternField);
|
||||
if (popup != null) {
|
||||
popup.pack(false, true);
|
||||
}
|
||||
ListWithFilter.this.revalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onSpeedSearchPatternChanged() {
|
||||
|
||||
@@ -692,6 +692,7 @@ public class AbstractPopup implements JBPopup {
|
||||
}
|
||||
|
||||
myPopup.setRequestFocus(myRequestFocus);
|
||||
pack(true, true);
|
||||
myPopup.show();
|
||||
|
||||
final Window window = SwingUtilities.getWindowAncestor(myContent);
|
||||
@@ -939,6 +940,28 @@ public class AbstractPopup implements JBPopup {
|
||||
wnd.setLocation(p.getScreenPoint());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pack(boolean width, boolean height) {
|
||||
if (!isVisible() || (!width && !height)) return;
|
||||
|
||||
Dimension size = getSize();
|
||||
Dimension prefSize = myContent.computePreferredSize();
|
||||
|
||||
|
||||
if (width) {
|
||||
size.width = prefSize.width;
|
||||
}
|
||||
|
||||
if (height) {
|
||||
size.height = prefSize.height;
|
||||
}
|
||||
|
||||
size = computeWindowSize(size);
|
||||
|
||||
final Window window = SwingUtilities.getWindowAncestor(myContent);
|
||||
window.setSize(size);
|
||||
}
|
||||
|
||||
public void pack() {
|
||||
final Window window = SwingUtilities.getWindowAncestor(myContent);
|
||||
|
||||
@@ -1046,6 +1069,18 @@ public class AbstractPopup implements JBPopup {
|
||||
this);
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension computePreferredSize() {
|
||||
if (isPreferredSizeSet()) {
|
||||
Dimension setSize;
|
||||
setSize = getPreferredSize();
|
||||
setPreferredSize(null);
|
||||
Dimension result = getPreferredSize();
|
||||
setPreferredSize(setSize);
|
||||
return result;
|
||||
}
|
||||
return getPreferredSize();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCancelOnClickOutside() {
|
||||
@@ -1122,19 +1157,27 @@ public class AbstractPopup implements JBPopup {
|
||||
}
|
||||
|
||||
private void setSize(Dimension size, boolean adjustByContent) {
|
||||
Dimension toSet = size;
|
||||
if (myPopup == null) {
|
||||
myForcedSize = size;
|
||||
myForcedSize = toSet;
|
||||
}
|
||||
else {
|
||||
if (adjustByContent) {
|
||||
if (myAdCmp != null) {
|
||||
size.height += myAdCmp.getPreferredSize().height;
|
||||
}
|
||||
toSet = computeWindowSize(toSet);
|
||||
}
|
||||
updateMaskAndAlpha(setSize(myContent, size));
|
||||
updateMaskAndAlpha(setSize(myContent, toSet));
|
||||
}
|
||||
}
|
||||
|
||||
private Dimension computeWindowSize(Dimension size) {
|
||||
Dimension result = new Dimension(size);
|
||||
if (myAdCmp != null && myAdCmp.isVisible()) {
|
||||
result.height += myAdCmp.getPreferredSize().height;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getSize() {
|
||||
if (myPopup != null) {
|
||||
|
||||
Reference in New Issue
Block a user