diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java index 11a35c849500..93314a27178b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java @@ -152,9 +152,11 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement ((CompletionPhase.BgCalculation)phase).focusLookupWhenDone = true; } } else { + /* myLookup.setAdvertisementText("Press " + CompletionContributor.getActionShortcut(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_REPLACE) + " to choose the first suggestion"); + */ } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupActionHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupActionHandler.java index b00d961853ef..976b624c5d29 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupActionHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupActionHandler.java @@ -16,12 +16,16 @@ package com.intellij.codeInsight.lookup.impl; +import com.intellij.codeInsight.lookup.Lookup; import com.intellij.codeInsight.lookup.LookupManager; import com.intellij.ide.ui.UISettings; +import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.actionSystem.EditorActionHandler; +import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.ui.ListScrollingUtil; @@ -73,6 +77,10 @@ public abstract class LookupActionHandler extends EditorActionHandler { } protected void executeInLookup(final LookupImpl lookup, DataContext context) { + executeDown(lookup); + } + + static void executeDown(LookupImpl lookup) { if (!lookup.isFocused()) { lookup.setFocused(true); lookup.getList().setSelectedIndex(0); @@ -83,16 +91,55 @@ public abstract class LookupActionHandler extends EditorActionHandler { } } + public static class UpAction extends DumbAwareAction { + + @Override + public void actionPerformed(AnActionEvent e) { + LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(PlatformDataKeys.EDITOR.getData(e.getDataContext())); + lookup.setHintMode(false); + lookup.refreshUi(); + UpHandler.executeUp(lookup); + } + + @Override + public void update(AnActionEvent e) { + Lookup lookup = LookupManager.getActiveLookup(PlatformDataKeys.EDITOR.getData(e.getDataContext())); + e.getPresentation().setEnabled(lookup != null); + } + } + + public static class DownAction extends DumbAwareAction { + + @Override + public void actionPerformed(AnActionEvent e) { + LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(PlatformDataKeys.EDITOR.getData(e.getDataContext())); + lookup.setHintMode(false); + lookup.refreshUi(); + DownHandler.executeDown(lookup); + } + + @Override + public void update(AnActionEvent e) { + Lookup lookup = LookupManager.getActiveLookup(PlatformDataKeys.EDITOR.getData(e.getDataContext())); + e.getPresentation().setEnabled(lookup != null); + } + } + public static class UpHandler extends LookupActionHandler { public UpHandler(EditorActionHandler originalHandler){ super(originalHandler, false); } protected void executeInLookup(final LookupImpl lookup, DataContext context) { + if (!executeUp(lookup)) { + myOriginalHandler.execute(lookup.getEditor(), context); + } + } + + static boolean executeUp(final LookupImpl lookup) { if (!lookup.isFocused()) { if (!UISettings.getInstance().CYCLE_SCROLLING) { - myOriginalHandler.execute(lookup.getEditor(), context); - return; + return false; } lookup.setFocused(true); @@ -100,6 +147,7 @@ public abstract class LookupActionHandler extends EditorActionHandler { lookup.refreshUi(); } ListScrollingUtil.moveUp(lookup.getList(), 0); + return true; } } 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 0794fad95ef5..57d85ca2b345 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 @@ -126,7 +126,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { private JLabel mySortingLabel; private final JScrollPane myScrollPane; private boolean myHintMode; - private LightweightHint myAutopopupHint; + private MyLightweightHint myAutopopupHint; public LookupImpl(Project project, Editor editor, @NotNull LookupArranger arranger){ super(new JPanel(new BorderLayout())); @@ -484,6 +484,11 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { public void setHintMode(final boolean hintMode) { if (!hintMode) { hideAutopopupHint(); + markSelectionTouched(); + setFocused(true); + if (!myShown) { + show(); + } } myHintMode = hintMode; } @@ -1151,7 +1156,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { } } else if (myHintMode) { - final int itemTextPadding = 5; + final int itemTextPadding = 2; final JPanel hintComponent = createAutopopupHintComponent(itemTextPadding); Point bestPoint = calculatePosition(hintComponent); @@ -1168,13 +1173,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { if (myAutopopupHint == null) { final JPanel panel = new JPanel(new BorderLayout()); panel.add(hintComponent); - myAutopopupHint = new LightweightHint(panel) { - @Override - public void hide() { - hideLookup(true); - super.hide(); - } - }; + myAutopopupHint = new MyLightweightHint(panel); myAutopopupHint.setForceShowAsPopup(true); hintManager.showEditorHint(myAutopopupHint, editor, new Point(bestPoint), HintManagerImpl.HIDE_BY_ESCAPE | HintManagerImpl.UPDATE_BY_SCROLLING, 0, false, hintHint); @@ -1193,16 +1192,22 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { pane.setBackground(HintUtil.INFORMATION_COLOR); final Font editorFont = EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN); - final String ctrlSpace = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION)); + final String ctrlSpace = KeymapUtil.getFirstKeyboardShortcutText( + ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION)); + final String ctrlDown = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction("EditorLookupDown")); + final String tab = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_REPLACE)); + final String enter = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM)); final List items = getItems(); GridBag gb = new GridBag().setDefaultFill(GridBagConstraints.HORIZONTAL).setDefaultWeightX(1); for (int i = 0; i < Math.min(maxAutopopupItems, items.size()); i++) { + /* if (i == 1) { - JLabel more = normalizedLabel("Other suggestions (" + ctrlSpace + " for a complete list):", editorFont); + JLabel more = normalizedLabel("Other suggestions (" + KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction("EditorLookupDown")) + " to choose):", editorFont); more.setBorder(BorderFactory.createCompoundBorder(new MatteBorder(1, 0, 0, 0, Color.lightGray), new EmptyBorder(5, 2, 5, 7))); pane.add(more, gb.nextLine()); } + */ final LookupElement element = items.get(i); final LookupElementPresentation presentation = new LookupElementPresentation(); @@ -1225,7 +1230,12 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { final JLabel tailLabel = normalizedLabel(presentation.getTailText(), editorFont); tailLabel.setForeground(LookupCellRenderer.getTailTextColor(false, presentation, tailLabel.getForeground())); - row.add(tailLabel, rgb.next().weightx(1).fillCellHorizontally()); + row.add(tailLabel, rgb.next()); + + String keys = i == 0 ? " [" + tab + (isFocused() ? ", " + enter : "") + "]" : i == 1 ? " [" + ctrlDown + "]" : ""; + JLabel adLabel = new JLabel(keys); + adLabel.setFont(adLabel.getFont().deriveFont(Font.BOLD, editorFont.getSize())); + row.add(adLabel, rgb.next().weightx(1).fillCellHorizontally()); row.add(normalizedLabel(" " + StringUtil.notNullize(presentation.getTypeText()) + " ", editorFont), rgb.next()); @@ -1256,14 +1266,12 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { if (items.size() > maxAutopopupItems) { if (StringUtil.isNotEmpty(ctrlSpace)) { //ad.add(normalizedLabel(ctrlSpace + " for more ", editorFont), BorderLayout.WEST); + //ad.add(normalizedLabel("Other suggestions (" + KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction("EditorLookupDown")) + " to choose):", editorFont), BorderLayout.WEST); } } - final String tab = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_REPLACE)); - if (StringUtil.isNotEmpty(tab)) { - final String enter = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM)); - String message = " " + tab + (isFocused() ? ", " + enter : "") + " for the first item"; - ad.add(normalizedLabel(message, editorFont), BorderLayout.EAST); + if (StringUtil.isNotEmpty(ctrlSpace)) { + ad.add(normalizedLabel("Press " + ctrlSpace + " for the complete list", editorFont), BorderLayout.EAST); } pane.add(ad, gb.nextLine().padx(5).pady(2).coverColumn()); } @@ -1279,7 +1287,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { private void hideAutopopupHint() { if (myAutopopupHint != null) { - myAutopopupHint.hide(); + myAutopopupHint.justHide(); myPositionedAbove = null; } } @@ -1382,4 +1390,24 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { return myModel.getRelevanceStrings(); } + private class MyLightweightHint extends LightweightHint { + private boolean myHidden; + + public MyLightweightHint(JPanel panel) { + super(panel); + } + + @Override + public void hide() { + if (myHidden) return; + + hideLookup(true); + justHide(); + } + + private void justHide() { + myHidden = true; + super.hide(); + } + } } diff --git a/platform/platform-resources/src/idea/Keymap_Default.xml b/platform/platform-resources/src/idea/Keymap_Default.xml index b075de2d9e48..f6652638141a 100644 --- a/platform/platform-resources/src/idea/Keymap_Default.xml +++ b/platform/platform-resources/src/idea/Keymap_Default.xml @@ -79,6 +79,8 @@ + + diff --git a/platform/platform-resources/src/idea/Keymap_Mac.xml b/platform/platform-resources/src/idea/Keymap_Mac.xml index d50286d232b3..f1f615b3ce42 100644 --- a/platform/platform-resources/src/idea/Keymap_Mac.xml +++ b/platform/platform-resources/src/idea/Keymap_Mac.xml @@ -309,6 +309,9 @@ + + + diff --git a/platform/platform-resources/src/idea/Keymap_MacClassic.xml b/platform/platform-resources/src/idea/Keymap_MacClassic.xml index 47a55edc08ed..91b192d9cf14 100644 --- a/platform/platform-resources/src/idea/Keymap_MacClassic.xml +++ b/platform/platform-resources/src/idea/Keymap_MacClassic.xml @@ -77,6 +77,9 @@ + + + diff --git a/platform/platform-resources/src/idea/PlatformLangActionManager.xml b/platform/platform-resources/src/idea/PlatformLangActionManager.xml index 82957fb05947..d4b4ee7a2c82 100644 --- a/platform/platform-resources/src/idea/PlatformLangActionManager.xml +++ b/platform/platform-resources/src/idea/PlatformLangActionManager.xml @@ -15,6 +15,9 @@ + + + diff --git a/resources/src/idea/IdeaActions.xml b/resources/src/idea/IdeaActions.xml index ab01fb606c8a..57c46ff3a576 100644 --- a/resources/src/idea/IdeaActions.xml +++ b/resources/src/idea/IdeaActions.xml @@ -14,6 +14,9 @@ + + +