From 5303dbb329ef2ea38b65d9ac45dac01f70806426 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 16 Sep 2011 17:32:28 +0200 Subject: [PATCH] remember the resized lookup size --- .../lookup/RealLookupElementPresentation.java | 2 +- .../lookup/impl/LookupCellRenderer.java | 7 ++----- .../codeInsight/lookup/impl/LookupImpl.java | 16 ++++++++++++---- .../src/com/intellij/ide/ui/UISettings.java | 2 ++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/platform/lang-api/src/com/intellij/codeInsight/lookup/RealLookupElementPresentation.java b/platform/lang-api/src/com/intellij/codeInsight/lookup/RealLookupElementPresentation.java index 99e82716a660..4cd78b143e19 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/lookup/RealLookupElementPresentation.java +++ b/platform/lang-api/src/com/intellij/codeInsight/lookup/RealLookupElementPresentation.java @@ -35,7 +35,7 @@ public class RealLookupElementPresentation extends LookupElementPresentation { result += getStringWidth(presentation.getTailText(), normalMetrics); final String typeText = presentation.getTypeText(); if (StringUtil.isNotEmpty(typeText)) { - result += getStringWidth("XXX", normalMetrics); //3 spaces for nice tail-type separation + result += getStringWidth("W", normalMetrics); // nice tail-type separation result += getStringWidth(typeText, normalMetrics); } result += getStringWidth("W", boldMetrics); //for unforeseen Swing size adjustments diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java index 3e33cfccc8c8..1e57f45a5ebe 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java @@ -45,7 +45,6 @@ public class LookupCellRenderer implements ListCellRenderer { private final Font myBoldFont; private final FontMetrics myNormalMetrics; private final FontMetrics myBoldMetrics; - private final int myMaxWidth; public static final Color BACKGROUND_COLOR = new Color(235, 244, 254); static final Color FOREGROUND_COLOR = Color.black; @@ -98,7 +97,6 @@ public class LookupCellRenderer implements ListCellRenderer { myNormalMetrics = myLookup.getEditor().getComponent().getFontMetrics(myNormalFont); myBoldMetrics = myLookup.getEditor().getComponent().getFontMetrics(myBoldFont); - myMaxWidth = myNormalMetrics.stringWidth(StringUtil.repeatSymbol('W', MAX_LENGTH)); UIUtil.removeQuaquaVisualMarginsIn(myPanel); } @@ -266,7 +264,7 @@ public class LookupCellRenderer implements ListCellRenderer { int allowedWidth, boolean selected) { final String givenText = presentation.getTypeText(); - final String labelText = trimLabelText(StringUtil.isEmpty(givenText) ? "" : " " + givenText, allowedWidth, myNormalMetrics); + final String labelText = trimLabelText(StringUtil.isEmpty(givenText) ? "" : " " + givenText, allowedWidth, myNormalMetrics); int used = RealLookupElementPresentation.getStringWidth(labelText, myNormalMetrics); @@ -320,8 +318,7 @@ public class LookupCellRenderer implements ListCellRenderer { myEmptyIcon = new EmptyIcon(Math.max(icon.getIconWidth(), myEmptyIcon.getIconWidth()), Math.max(icon.getIconHeight(), myEmptyIcon.getIconHeight())); } - int maxWidth = Math.min(RealLookupElementPresentation.calculateWidth(p, myNormalMetrics, myBoldMetrics), myMaxWidth); - return maxWidth + getCommonGapsWidth(); + return RealLookupElementPresentation.calculateWidth(p, myNormalMetrics, myBoldMetrics) + getCommonGapsWidth(); } private int getCommonGapsWidth() { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index bdcfa9446cbe..8317065aa58b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -90,7 +90,6 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable private static final int MAX_PREFERRED_COUNT = 5; private static final LookupItem EMPTY_LOOKUP_ITEM = LookupItem.fromString("preselect"); - private static final int LOOKUP_HEIGHT = Integer.getInteger("idea.lookup.height", 11).intValue(); private static final Icon relevanceSortIcon = IconLoader.getIcon("/ide/lookupRelevance.png"); private static final Icon lexiSortIcon = IconLoader.getIcon("/ide/lookupAlphanumeric.png"); @@ -442,7 +441,8 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable updateListHeight(listModel); if (!model.isEmpty()) { - myList.setFixedCellWidth(Math.max(myLookupTextWidth + myCellRenderer.getIconIndent(), myAdComponent.getAdComponent().getPreferredSize().width)); + int listWidth = Math.min(myLookupTextWidth + myCellRenderer.getIconIndent(), UISettings.getInstance().MAX_LOOKUP_LIST_WIDTH); + myList.setFixedCellWidth(Math.max(listWidth, myAdComponent.getAdComponent().getPreferredSize().width)); LookupElement first = model.iterator().next(); if (isFocused() && (!(isExactPrefixItem(first, true) || isExactPrefixItem(first, false)) || mySelectionTouched)) { @@ -528,7 +528,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable private void updateListHeight(ListModel model) { myList.setFixedCellHeight(myCellRenderer.getListCellRendererComponent(myList, model.getElementAt(0), 0, false, false).getPreferredSize().height); - myList.setVisibleRowCount(Math.min(model.getSize(), LOOKUP_HEIGHT)); + myList.setVisibleRowCount(Math.min(model.getSize(), UISettings.getInstance().MAX_LOOKUP_ITEM_COUNT)); } private void addEmptyItem(DefaultListModel model) { @@ -1356,8 +1356,16 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable @Override public void componentResized(ComponentEvent e) { - mainPanel.setSize(getSize()); + Dimension size = getSize(); + mainPanel.setSize(size); mainPanel.validate(); + + UISettings.getInstance().MAX_LOOKUP_LIST_WIDTH = Math.max(300, myScrollPane.getViewport().getWidth()); + int visibleRowCount = myList.getLastVisibleIndex() - myList.getFirstVisibleIndex() + 1; + if (visibleRowCount != myList.getModel().getSize()) { + UISettings.getInstance().MAX_LOOKUP_ITEM_COUNT = Math.max(5, visibleRowCount); + } + layoutStatusIcons(); layoutHint(); diff --git a/platform/platform-api/src/com/intellij/ide/ui/UISettings.java b/platform/platform-api/src/com/intellij/ide/ui/UISettings.java index c18932aa0c63..2b052360f5ea 100644 --- a/platform/platform-api/src/com/intellij/ide/ui/UISettings.java +++ b/platform/platform-api/src/com/intellij/ide/ui/UISettings.java @@ -87,6 +87,8 @@ public class UISettings implements PersistentStateComponent, Exporta public boolean SHOW_ICONS_IN_MENUS = true; public boolean DISABLE_MNEMONICS = SystemInfo.isMac; // IDEADEV-33409, should be disabled by default on MacOS public boolean SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = false; + public int MAX_LOOKUP_LIST_WIDTH = 500; + public int MAX_LOOKUP_ITEM_COUNT = 11; /** * Defines whether asterisk is shown on modified editor tab or not