mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-178503 change shortcuts to switch method overloads
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.editorActions;
|
||||
|
||||
import com.intellij.openapi.editor.actionSystem.EditorAction;
|
||||
|
||||
public class JavaMethodOverloadSwitchDownAction extends EditorAction {
|
||||
public JavaMethodOverloadSwitchDownAction() {
|
||||
super(new JavaMethodOverloadSwitchHandler(false));
|
||||
}
|
||||
}
|
||||
+5
-83
@@ -22,13 +22,11 @@ import com.intellij.codeInsight.hint.ParameterInfoController;
|
||||
import com.intellij.codeInsight.hints.ParameterHintsPass;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.EditorModificationUtil;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Key;
|
||||
@@ -43,23 +41,18 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
abstract class JavaMethodOverloadSwitchHandler extends EditorActionHandler {
|
||||
private static final Key<Boolean> SWITCH_DISABLED = Key.create("switch.disabled");
|
||||
class JavaMethodOverloadSwitchHandler extends EditorActionHandler {
|
||||
private static final Key<Map<String, String>> ENTERED_PARAMETERS = Key.create("entered.parameters");
|
||||
private final EditorActionHandler myOriginalHandler;
|
||||
private final boolean mySwitchUp;
|
||||
|
||||
private JavaMethodOverloadSwitchHandler(EditorActionHandler originalHandler, boolean up) {
|
||||
myOriginalHandler = originalHandler;
|
||||
JavaMethodOverloadSwitchHandler(boolean up) {
|
||||
mySwitchUp = up;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEnabledForCaret(@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) {
|
||||
if (myOriginalHandler.isEnabled(editor, caret, dataContext)) return true;
|
||||
|
||||
if (editor.getUserData(SWITCH_DISABLED) != null ||
|
||||
!CodeInsightSettings.getInstance().SHOW_PARAMETER_NAME_HINTS_ON_COMPLETION || !ParameterInfoController.existsForEditor(editor)) return false;
|
||||
if (!CodeInsightSettings.getInstance().SHOW_PARAMETER_NAME_HINTS_ON_COMPLETION ||
|
||||
!ParameterInfoController.existsForEditor(editor)) return false;
|
||||
|
||||
Project project = CommonDataKeys.PROJECT.getData(dataContext);
|
||||
if (project == null) return false;
|
||||
@@ -82,14 +75,10 @@ abstract class JavaMethodOverloadSwitchHandler extends EditorActionHandler {
|
||||
@Override
|
||||
protected void doExecute(@NotNull Editor editor, @Nullable Caret caret, DataContext dataContext) {
|
||||
Project project = CommonDataKeys.PROJECT.getData(dataContext);
|
||||
if (project != null && editor.getUserData(SWITCH_DISABLED) == null &&
|
||||
CodeInsightSettings.getInstance().SHOW_PARAMETER_NAME_HINTS_ON_COMPLETION &&
|
||||
if (project != null && CodeInsightSettings.getInstance().SHOW_PARAMETER_NAME_HINTS_ON_COMPLETION &&
|
||||
ParameterInfoController.existsWithVisibleHintForEditor(editor, false)) {
|
||||
doSwitch(editor, caret == null ? editor.getCaretModel().getPrimaryCaret() : caret, project);
|
||||
}
|
||||
else {
|
||||
myOriginalHandler.execute(editor, caret, dataContext);
|
||||
}
|
||||
}
|
||||
|
||||
private void doSwitch(@NotNull final Editor editor, @NotNull Caret caret, @NotNull Project project) {
|
||||
@@ -172,71 +161,4 @@ abstract class JavaMethodOverloadSwitchHandler extends EditorActionHandler {
|
||||
PsiParameter parameter = method.getParameterList().getParameters()[parameterIndex];
|
||||
return parameter.getName() + ":" + parameter.getType().getCanonicalText();
|
||||
}
|
||||
|
||||
public static class Up extends JavaMethodOverloadSwitchHandler {
|
||||
public Up(EditorActionHandler originalHandler) {
|
||||
super(originalHandler, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Down extends JavaMethodOverloadSwitchHandler {
|
||||
public Down(EditorActionHandler originalHandler) {
|
||||
super(originalHandler, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static class UpInEditor extends UpDownInEditor {
|
||||
public UpInEditor(EditorActionHandler originalHandler) {
|
||||
super(originalHandler, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DownInEditor extends UpDownInEditor {
|
||||
public DownInEditor(EditorActionHandler originalHandler) {
|
||||
super(originalHandler, false);
|
||||
}
|
||||
}
|
||||
|
||||
private static abstract class UpDownInEditor extends EditorActionHandler {
|
||||
private final EditorActionHandler myOriginalHandler;
|
||||
private final boolean myUp;
|
||||
|
||||
private UpDownInEditor(EditorActionHandler originalHandler, boolean up) {
|
||||
myOriginalHandler = originalHandler;
|
||||
myUp = up;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEnabledForCaret(@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) {
|
||||
return myOriginalHandler.isEnabled(editor, caret, dataContext) ||
|
||||
isEnabled(editor);
|
||||
}
|
||||
|
||||
private static boolean isEnabled(@NotNull Editor editor) {
|
||||
return CodeInsightSettings.getInstance().SHOW_PARAMETER_NAME_HINTS_ON_COMPLETION &&
|
||||
ParameterInfoController.existsWithVisibleHintForEditor(editor, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(@NotNull Editor editor, @Nullable Caret caret, DataContext dataContext) {
|
||||
if (isEnabled(editor)) {
|
||||
ParameterInfoController.hideAllHints(editor);
|
||||
}
|
||||
// hints can be hidden asynchronously (with animation), so we disable switching explicitly here
|
||||
editor.putUserData(SWITCH_DISABLED, Boolean.TRUE);
|
||||
try {
|
||||
if (myOriginalHandler.isEnabled(editor, caret, dataContext)) {
|
||||
myOriginalHandler.execute(editor, caret, dataContext);
|
||||
}
|
||||
else {
|
||||
EditorActionManager.getInstance().getActionHandler(myUp ? IdeActions.ACTION_EDITOR_MOVE_CARET_UP
|
||||
: IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN)
|
||||
.execute(editor, caret, dataContext);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
editor.putUserData(SWITCH_DISABLED, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.editorActions;
|
||||
|
||||
import com.intellij.openapi.editor.actionSystem.EditorAction;
|
||||
|
||||
public class JavaMethodOverloadSwitchUpAction extends EditorAction {
|
||||
public JavaMethodOverloadSwitchUpAction() {
|
||||
super(new JavaMethodOverloadSwitchHandler(true));
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -155,7 +155,7 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
|
||||
complete("toChars(int codePoint)");
|
||||
checkResultWithInlays("class C { void m() { Character.toChars(<HINT text=\"codePoint:\"/><caret>) } }");
|
||||
showParameterInfo();
|
||||
down();
|
||||
methodOverloadDown();
|
||||
checkResultWithInlays(
|
||||
"class C { void m() { Character.toChars(<HINT text=\"codePoint:\"/><caret>, <hint text=\"dst:\"/>, <hint text=\"dstIndex:\"/>) } }");
|
||||
}
|
||||
@@ -166,7 +166,7 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
|
||||
type("123");
|
||||
checkResultWithInlays("class C { void m() { Character.toChars(<HINT text=\"codePoint:\"/>123<caret>) } }");
|
||||
showParameterInfo();
|
||||
down();
|
||||
methodOverloadDown();
|
||||
checkResultWithInlays("class C { void m() { Character.toChars(<hint text=\"codePoint:\"/>123, <HINT text=\"dst:\"/><caret>, <hint text=\"dstIndex:\"/>) } }");
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
|
||||
" void m() { some(<HINT text=\"from:\"/><caret>, <hint text=\"to:\"/>, <hint text=\"other:\"/>) }\n" +
|
||||
"}");
|
||||
showParameterInfo();
|
||||
down();
|
||||
methodOverloadDown();
|
||||
waitForAllAsyncStuff();
|
||||
checkResultWithInlays("class C {\n" +
|
||||
" int some(int from, int to) { return 0; }\n" +
|
||||
@@ -589,7 +589,7 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
|
||||
waitForAllAsyncStuff();
|
||||
checkHintContents("<html><b>@NotNull String key</b></html>\n" +
|
||||
"<html><b>@NotNull String key</b>, String def</html>");
|
||||
myFixture.performEditorAction(IdeActions.ACTION_LOOKUP_UP);
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP);
|
||||
waitForAllAsyncStuff();
|
||||
checkResultWithInlays("<caret>class C { void m() { System.getProperty(<hint text=\"key:\"/>, <hint text=\"def:\"/>) } }");
|
||||
checkHintContents(null);
|
||||
@@ -604,7 +604,7 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
|
||||
waitForAllAsyncStuff();
|
||||
checkHintContents("<html><b>@NotNull String key</b></html>\n" +
|
||||
"<html><b>@NotNull String key</b>, String def</html>");
|
||||
myFixture.performEditorAction(IdeActions.ACTION_LOOKUP_DOWN);
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN);
|
||||
waitForAllAsyncStuff();
|
||||
checkResultWithInlays("class C { void m() { System.getProperty(<hint text=\"key:\"/>, <hint text=\"def:\"/>) } }<caret>");
|
||||
checkHintContents(null);
|
||||
@@ -650,8 +650,8 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT);
|
||||
}
|
||||
|
||||
private void down() {
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN);
|
||||
private void methodOverloadDown() {
|
||||
myFixture.performEditorAction(IdeActions.ACTION_METHOD_OVERLOAD_SWITCH_DOWN);
|
||||
}
|
||||
|
||||
private void home() {
|
||||
|
||||
@@ -20,8 +20,10 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.lang.parameterInfo.ParameterInfoHandler;
|
||||
import com.intellij.lang.parameterInfo.ParameterInfoUIContextEx;
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.keymap.KeymapUtil;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -127,13 +129,22 @@ public class ParameterInfoComponent extends JPanel {
|
||||
pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
add(pane, BorderLayout.CENTER);
|
||||
|
||||
myShortcutLabel = new JLabel(CodeInsightBundle.message("parameter.info.switch.overload.shortcuts"));
|
||||
myShortcutLabel.setForeground(new JBColor(0x787878, 0x787878));
|
||||
Font labelFont = UIUtil.getLabelFont();
|
||||
myShortcutLabel.setFont(labelFont.deriveFont(labelFont.getSize2D() - (SystemInfo.isWindows ? 1 : 2)));
|
||||
myShortcutLabel.setBorder(new JBEmptyBorder(3, 0, 0, 0));
|
||||
add(myShortcutLabel, BorderLayout.SOUTH);
|
||||
|
||||
String upShortcut = KeymapUtil.getFirstKeyboardShortcutText(IdeActions.ACTION_METHOD_OVERLOAD_SWITCH_UP);
|
||||
String downShortcut = KeymapUtil.getFirstKeyboardShortcutText(IdeActions.ACTION_METHOD_OVERLOAD_SWITCH_DOWN);
|
||||
if (upShortcut.isEmpty() && downShortcut.isEmpty()) {
|
||||
myShortcutLabel = null;
|
||||
}
|
||||
else {
|
||||
myShortcutLabel = new JLabel(
|
||||
upShortcut.isEmpty() || downShortcut.isEmpty()
|
||||
? CodeInsightBundle.message("parameter.info.switch.overload.shortcuts.single", upShortcut.isEmpty() ? downShortcut : upShortcut)
|
||||
: CodeInsightBundle.message("parameter.info.switch.overload.shortcuts", upShortcut, downShortcut));
|
||||
myShortcutLabel.setForeground(new JBColor(0x787878, 0x787878));
|
||||
Font labelFont = UIUtil.getLabelFont();
|
||||
myShortcutLabel.setFont(labelFont.deriveFont(labelFont.getSize2D() - (SystemInfo.isWindows ? 1 : 2)));
|
||||
myShortcutLabel.setBorder(new JBEmptyBorder(3, 0, 0, 0));
|
||||
add(myShortcutLabel, BorderLayout.SOUTH);
|
||||
}
|
||||
myCurrentParameterIndex = -1;
|
||||
}
|
||||
|
||||
@@ -266,7 +277,9 @@ public class ParameterInfoComponent extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
myShortcutLabel.setVisible(!singleParameterInfo && myObjects.length > 1 && myHandler.supportsOverloadSwitching());
|
||||
if (myShortcutLabel != null) {
|
||||
myShortcutLabel.setVisible(!singleParameterInfo && myObjects.length > 1 && myHandler.supportsOverloadSwitching());
|
||||
}
|
||||
|
||||
invalidate();
|
||||
validate();
|
||||
|
||||
@@ -131,12 +131,6 @@ public class ParameterInfoController implements Disposable {
|
||||
return getAllControllers(editor).stream().anyMatch(c -> c.isHintShown(anyHintType));
|
||||
}
|
||||
|
||||
public static void hideAllHints(@NotNull Editor editor) {
|
||||
getAllControllers(editor).forEach(c -> {
|
||||
if (c.myHint.isVisible()) c.myHint.hide();
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isHintShown(boolean anyType) {
|
||||
return myHint.isVisible() && (!mySingleParameterInfo || anyType);
|
||||
}
|
||||
|
||||
@@ -337,4 +337,7 @@ public interface IdeActions {
|
||||
String ACTION_SWITCHER = "Switcher";
|
||||
|
||||
@NonNls String INSPECTION_TOOL_WINDOW_TREE_POPUP = "InspectionToolWindow.TreePopup";
|
||||
|
||||
@NonNls String ACTION_METHOD_OVERLOAD_SWITCH_UP = "MethodOverloadSwitchUp";
|
||||
@NonNls String ACTION_METHOD_OVERLOAD_SWITCH_DOWN = "MethodOverloadSwitchDown";
|
||||
}
|
||||
|
||||
@@ -1613,3 +1613,6 @@ action.TogglePresentationMode.exit=Exit Presentation Mode
|
||||
action.TogglePresentationMode.enter=Enter Presentation Mode
|
||||
|
||||
action.EmojiAndSymbols.description=Input special characters using macOS system palette
|
||||
|
||||
action.MethodOverloadSwitchUp.text=Previous Method Overload
|
||||
action.MethodOverloadSwitchDown.text=Next Method Overload
|
||||
@@ -559,4 +559,5 @@ block.comment.nested.comment=Selected region contained block {0, choice, 1#comme
|
||||
|
||||
intention.unroll.loop.family=Unroll loop
|
||||
|
||||
parameter.info.switch.overload.shortcuts=Switch with \u2191 or \u2193
|
||||
parameter.info.switch.overload.shortcuts=Switch with {0} or {1}
|
||||
parameter.info.switch.overload.shortcuts.single=Switch with {0}
|
||||
@@ -77,6 +77,9 @@
|
||||
<action id="EditorLookupUp"><keyboard-shortcut first-keystroke="control UP"/></action>
|
||||
<action id="EditorLookupDown"><keyboard-shortcut first-keystroke="control DOWN"/></action>
|
||||
|
||||
<action id="MethodOverloadSwitchUp"><keyboard-shortcut first-keystroke="alt P"/></action>
|
||||
<action id="MethodOverloadSwitchDown"><keyboard-shortcut first-keystroke="alt N"/></action>
|
||||
|
||||
<action id="ReformatCode">
|
||||
<keyboard-shortcut first-keystroke="control alt L"/>
|
||||
</action>
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
<keyboard-shortcut first-keystroke="control alt E"/>
|
||||
</action>
|
||||
<action id="$Paste">
|
||||
<keyboard-shortcut first-keystroke="alt P"/>
|
||||
<keyboard-shortcut first-keystroke="shift INSERT"/>
|
||||
<keyboard-shortcut first-keystroke="control Y"/>
|
||||
</action>
|
||||
|
||||
@@ -594,4 +594,11 @@
|
||||
<action id="EmojiAndSymbols">
|
||||
<keyboard-shortcut first-keystroke="control meta SPACE"/>
|
||||
</action>
|
||||
|
||||
<action id="MethodOverloadSwitchUp">
|
||||
<keyboard-shortcut first-keystroke="control P"/>
|
||||
</action>
|
||||
<action id="MethodOverloadSwitchDown">
|
||||
<keyboard-shortcut first-keystroke="control N"/>
|
||||
</action>
|
||||
</keymap>
|
||||
@@ -389,4 +389,11 @@
|
||||
<action id="EmojiAndSymbols">
|
||||
<keyboard-shortcut first-keystroke="control meta SPACE"/>
|
||||
</action>
|
||||
|
||||
<action id="MethodOverloadSwitchUp">
|
||||
<keyboard-shortcut first-keystroke="control P"/>
|
||||
</action>
|
||||
<action id="MethodOverloadSwitchDown">
|
||||
<keyboard-shortcut first-keystroke="control N"/>
|
||||
</action>
|
||||
</keymap>
|
||||
|
||||
@@ -1437,10 +1437,6 @@
|
||||
<editorActionHandler action="EditorLineStart" implementationClass="com.intellij.codeInsight.editorActions.JavadocLineStartHandler"/>
|
||||
<editorActionHandler action="NextParameter" implementationClass="com.intellij.codeInsight.editorActions.JavaVarArgNextParameterHandler"/>
|
||||
<editorActionHandler action="PrevParameter" implementationClass="com.intellij.codeInsight.editorActions.JavaVarArgPrevParameterHandler"/>
|
||||
<editorActionHandler action="EditorUp" implementationClass="com.intellij.codeInsight.editorActions.JavaMethodOverloadSwitchHandler$Up"/>
|
||||
<editorActionHandler action="EditorDown" implementationClass="com.intellij.codeInsight.editorActions.JavaMethodOverloadSwitchHandler$Down"/>
|
||||
<editorActionHandler action="EditorLookupUp" implementationClass="com.intellij.codeInsight.editorActions.JavaMethodOverloadSwitchHandler$UpInEditor"/>
|
||||
<editorActionHandler action="EditorLookupDown" implementationClass="com.intellij.codeInsight.editorActions.JavaMethodOverloadSwitchHandler$DownInEditor"/>
|
||||
|
||||
<editorSmartKeysConfigurable instance="com.intellij.application.options.JavadocOptionsProvider"
|
||||
id="editor.preferences.javadocOptions"
|
||||
@@ -2077,6 +2073,9 @@
|
||||
text="JShell Console..." description="Launch JShell Console">
|
||||
<add-to-group group-id="ToolsMenu" anchor="last"/>
|
||||
</action>
|
||||
|
||||
<action id="MethodOverloadSwitchUp" class="com.intellij.codeInsight.editorActions.JavaMethodOverloadSwitchUpAction"/>
|
||||
<action id="MethodOverloadSwitchDown" class="com.intellij.codeInsight.editorActions.JavaMethodOverloadSwitchDownAction" />
|
||||
</actions>
|
||||
|
||||
</idea-plugin>
|
||||
|
||||
Reference in New Issue
Block a user