mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
filtering popup fixes
This commit is contained in:
@@ -24,9 +24,11 @@ import com.intellij.ui.InplaceButton;
|
||||
import com.intellij.ui.ListScrollingUtil;
|
||||
import com.intellij.ui.ScrollPaneFactory;
|
||||
import com.intellij.ui.components.JBScrollPane;
|
||||
import com.intellij.ui.components.JBViewport;
|
||||
import com.intellij.ui.speedSearch.ListWithFilter;
|
||||
import com.intellij.ui.treeStructure.treetable.TreeTable;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.ui.ComponentWithEmptyText;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.util.ui.tree.TreeUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
@@ -36,6 +38,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.ArrayList;
|
||||
@@ -219,6 +222,7 @@ 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);
|
||||
@@ -399,7 +403,26 @@ public class PopupChooserBuilder {
|
||||
private final JList myList;
|
||||
|
||||
private MyListWrapper(final JList list) {
|
||||
super(list);
|
||||
JBViewport viewport = new JBViewport() {
|
||||
@Override
|
||||
protected LayoutManager createLayoutManager() {
|
||||
return new ViewportLayout() {
|
||||
@Override
|
||||
public Dimension preferredLayoutSize(Container parent) {
|
||||
int size = list.getModel().getSize();
|
||||
if (size >= 0 && size <= 20) {
|
||||
return list.getPreferredSize();
|
||||
} else {
|
||||
return super.preferredLayoutSize(parent);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
setViewport(viewport);
|
||||
setViewportView(list);
|
||||
|
||||
|
||||
if (myAutoselectOnMouseMove) {
|
||||
list.addMouseMotionListener(new MouseMotionAdapter() {
|
||||
boolean myIsEngaged = false;
|
||||
@@ -418,19 +441,10 @@ public class PopupChooserBuilder {
|
||||
|
||||
ListScrollingUtil.installActions(list);
|
||||
|
||||
int modelSize = list.getModel().getSize();
|
||||
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
||||
if (modelSize > 0 && modelSize <= 20) {
|
||||
list.setVisibleRowCount(0);
|
||||
getViewport().setPreferredSize(list.getPreferredSize());
|
||||
}
|
||||
else {
|
||||
list.setVisibleRowCount(20);
|
||||
}
|
||||
myList = list;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public Object getData(@NonNls String dataId) {
|
||||
if (PlatformDataKeys.SELECTED_ITEM.is(dataId)){
|
||||
|
||||
@@ -71,6 +71,21 @@ public class JBList extends JList implements ComponentWithEmptyText, ComponentWi
|
||||
myEmptyText.paint(this, g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
if (getModel().getSize() == 0) {
|
||||
Dimension s = getEmptyText().getPreferredSize();
|
||||
Insets insets = getInsets();
|
||||
if (insets != null) {
|
||||
s.width += (insets.left + insets.right);
|
||||
s.height += (insets.top + insets.bottom);
|
||||
}
|
||||
return s;
|
||||
} else {
|
||||
return super.getPreferredSize();
|
||||
}
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setSelectionBackground(UIUtil.getListSelectionBackground());
|
||||
setSelectionForeground(UIUtil.getListSelectionForeground());
|
||||
|
||||
@@ -25,7 +25,9 @@ import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.LightColors;
|
||||
import com.intellij.ui.ScrollPaneFactory;
|
||||
import com.intellij.ui.UIBundle;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.ui.ComponentWithEmptyText;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -50,6 +52,10 @@ public class ListWithFilter<T> extends JPanel {
|
||||
private ListWithFilter(JList list, JScrollPane scroller, Function<T, String> namer) {
|
||||
super(new BorderLayout());
|
||||
|
||||
if (list instanceof ComponentWithEmptyText) {
|
||||
((ComponentWithEmptyText)list).getEmptyText().setText(UIBundle.message("message.noMatchesFound"));
|
||||
}
|
||||
|
||||
myList = list;
|
||||
myScroller = scroller;
|
||||
|
||||
@@ -95,13 +101,13 @@ public class ListWithFilter<T> extends JPanel {
|
||||
if (isHoldingFilter() && !searchFieldShown) {
|
||||
mySpeedSearchPatternField.setVisible(true);
|
||||
searchFieldShown = true;
|
||||
revalidate();
|
||||
}
|
||||
else if (!isHoldingFilter() && searchFieldShown) {
|
||||
mySpeedSearchPatternField.setVisible(false);
|
||||
searchFieldShown = false;
|
||||
revalidate();
|
||||
}
|
||||
|
||||
revalidate();
|
||||
}
|
||||
|
||||
private void revalidate() {
|
||||
@@ -127,6 +133,7 @@ public class ListWithFilter<T> extends JPanel {
|
||||
}
|
||||
else {
|
||||
mySpeedSearchPatternField.setBackground(LightColors.RED);
|
||||
revalidate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.intellij.util.ui;
|
||||
|
||||
import com.intellij.ui.ScreenUtil;
|
||||
import com.intellij.ui.SimpleColoredComponent;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.ui.UIBundle;
|
||||
@@ -108,11 +109,11 @@ public abstract class StatusText {
|
||||
}
|
||||
|
||||
private Rectangle getTextComponentBound() {
|
||||
Rectangle bounds = myOwner == null ? new Rectangle(0, 0, 0, 0) : myOwner.getBounds();
|
||||
Rectangle ownerRec = myOwner == null ? new Rectangle(0, 0, 0, 0) : myOwner.getBounds();
|
||||
|
||||
Dimension size = myComponent.getPreferredSize();
|
||||
int x = (bounds.width - size.width) / 2;
|
||||
int y = bounds.height / 3;
|
||||
int x = (ownerRec.width - size.width) / 2;
|
||||
int y = (ownerRec.height - size.height) / 2;
|
||||
return new Rectangle(x, y, size.width, size.height);
|
||||
}
|
||||
|
||||
@@ -167,4 +168,8 @@ public abstract class StatusText {
|
||||
myComponent.paint(g2);
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return myComponent.getPreferredSize();
|
||||
}
|
||||
}
|
||||
@@ -692,7 +692,6 @@ public class AbstractPopup implements JBPopup {
|
||||
}
|
||||
|
||||
myPopup.setRequestFocus(myRequestFocus);
|
||||
pack(true, true);
|
||||
myPopup.show();
|
||||
|
||||
final Window window = SwingUtilities.getWindowAncestor(myContent);
|
||||
@@ -947,7 +946,6 @@ public class AbstractPopup implements JBPopup {
|
||||
Dimension size = getSize();
|
||||
Dimension prefSize = myContent.computePreferredSize();
|
||||
|
||||
|
||||
if (width) {
|
||||
size.width = prefSize.width;
|
||||
}
|
||||
|
||||
@@ -167,4 +167,5 @@ move.down.action.name=Move Down
|
||||
file.chooser.save.dialog.file.name=File name:
|
||||
tool.window.name.documentation=Documentation
|
||||
|
||||
message.nothingToShow=Nothing to show
|
||||
message.nothingToShow=Nothing to show
|
||||
message.noMatchesFound=No matches found
|
||||
Reference in New Issue
Block a user