navigation in the hint autopopup

This commit is contained in:
peter
2011-03-01 17:09:37 +01:00
parent 18bff6ea9b
commit 402d0a7565
8 changed files with 112 additions and 20 deletions
@@ -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");
*/
}
}
@@ -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;
}
}
@@ -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<LookupElement> 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();
}
}
}
@@ -79,6 +79,8 @@
<action id="DumpLookupElementWeights">
<keyboard-shortcut first-keystroke="control alt shift W"/>
</action>
<action id="EditorLookupUp"><keyboard-shortcut first-keystroke="control UP"/></action>
<action id="EditorLookupDown"><keyboard-shortcut first-keystroke="control DOWN"/></action>
<action id="ReformatCode">
<keyboard-shortcut first-keystroke="control alt L"/>
@@ -309,6 +309,9 @@
<keyboard-shortcut first-keystroke="alt DOWN"/>
</action>
<action id="EditorLookupUp"> <keyboard-shortcut first-keystroke="alt UP"/> </action>
<action id="EditorLookupDown"> <keyboard-shortcut first-keystroke="alt DOWN"/> </action>
<action id="EditorDeleteToWordStart">
<keyboard-shortcut first-keystroke="alt BACK_SPACE"/>
</action>
@@ -77,6 +77,9 @@
<action id="RunGc"/>
<action id="RunClass"/>
<action id="EditorLookupUp"> <keyboard-shortcut first-keystroke="alt UP"/> </action>
<action id="EditorLookupDown"> <keyboard-shortcut first-keystroke="alt DOWN"/> </action>
<action id="GotoBookmark0">
<keyboard-shortcut first-keystroke="control 0"/>
</action>
@@ -15,6 +15,9 @@
<action id="EditorIndentSelection" class="com.intellij.openapi.editor.actions.LangIndentSelectionAction"/>
<action id="EditorLookupUp" class="com.intellij.codeInsight.lookup.impl.LookupActionHandler$UpAction"/>
<action id="EditorLookupDown" class="com.intellij.codeInsight.lookup.impl.LookupActionHandler$DownAction"/>
</actions>
<xi:include href="/idea/PlatformActions.xml" xpointer="xpointer(/component/*)"/>
+3
View File
@@ -14,6 +14,9 @@
</group>
<action id="EditorIndentSelection" class="com.intellij.openapi.editor.actions.LangIndentSelectionAction"/>
<action id="EditorLookupUp" class="com.intellij.codeInsight.lookup.impl.LookupActionHandler$UpAction"/>
<action id="EditorLookupDown" class="com.intellij.codeInsight.lookup.impl.LookupActionHandler$DownAction"/>
</actions>
<xi:include href="/idea/PlatformActions.xml" xpointer="xpointer(/component/*)"/>