mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-108023 Add "mouse wheel up" and "mouse wheel down" to mouse shortcuts
This commit is contained in:
@@ -18,16 +18,30 @@ package com.intellij.openapi.actionSystem;
|
||||
import org.intellij.lang.annotations.JdkConstants;
|
||||
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
|
||||
/**
|
||||
* A mouse shortcut, which can consist of a specific mouse button, click count and modifier keys
|
||||
* (Shift, Ctrl or Alt).
|
||||
*/
|
||||
public final class MouseShortcut extends Shortcut {
|
||||
public static final int BUTTON_WHEEL_UP = 143;
|
||||
public static final int BUTTON_WHEEL_DOWN = 142;
|
||||
private final int myButton;
|
||||
@JdkConstants.InputEventMask private final int myModifiers;
|
||||
private final int myClickCount;
|
||||
|
||||
public static int getButton(MouseEvent event) {
|
||||
if (event instanceof MouseWheelEvent) {
|
||||
MouseWheelEvent wheel = (MouseWheelEvent)event;
|
||||
return 0 < wheel.getWheelRotation()
|
||||
? BUTTON_WHEEL_DOWN
|
||||
: BUTTON_WHEEL_UP;
|
||||
}
|
||||
return event.getButton();
|
||||
}
|
||||
|
||||
public MouseShortcut(int button, @JdkConstants.InputEventMask int modifiers, int clickCount) {
|
||||
myButton = button;
|
||||
// TODO[vova] check modifiers?
|
||||
|
||||
@@ -110,11 +110,22 @@ public class KeymapUtil {
|
||||
* @return string representation of passed mouse shortcut.
|
||||
*/
|
||||
public static String getMouseShortcutText(int button, @JdkConstants.InputEventMask int modifiers, int clickCount) {
|
||||
if (clickCount < 3) {
|
||||
return KeyMapBundle.message("mouse." + (clickCount == 1? "" : "double.") + "click.shortcut.text", getModifiersText(mapNewModifiers(modifiers)), button);
|
||||
String resource;
|
||||
if (button == MouseShortcut.BUTTON_WHEEL_UP) {
|
||||
resource = "mouse.wheel.rotate.up.shortcut.text";
|
||||
}
|
||||
else if (button == MouseShortcut.BUTTON_WHEEL_DOWN) {
|
||||
resource = "mouse.wheel.rotate.down.shortcut.text";
|
||||
}
|
||||
else if (clickCount < 2) {
|
||||
resource = "mouse.click.shortcut.text";
|
||||
}
|
||||
else if (clickCount < 3) {
|
||||
resource = "mouse.double.click.shortcut.text";
|
||||
} else {
|
||||
throw new IllegalStateException("unknown clickCount: " + clickCount);
|
||||
}
|
||||
return KeyMapBundle.message(resource, getModifiersText(mapNewModifiers(modifiers)), button);
|
||||
}
|
||||
|
||||
@JdkConstants.InputEventMask
|
||||
@@ -401,7 +412,7 @@ public class KeymapUtil {
|
||||
if (keymap == null) {
|
||||
return false;
|
||||
}
|
||||
int button = e.getButton();
|
||||
int button = MouseShortcut.getButton(e);
|
||||
int modifiers = e.getModifiersEx();
|
||||
if (button == MouseEvent.NOBUTTON && e.getID() == MouseEvent.MOUSE_DRAGGED) {
|
||||
// mouse drag events don't have button field set due to some reason
|
||||
|
||||
+11
-4
@@ -146,17 +146,24 @@ public final class IdeMouseEventDispatcher {
|
||||
boolean ignore = false;
|
||||
if (!(e.getID() == MouseEvent.MOUSE_PRESSED ||
|
||||
e.getID() == MouseEvent.MOUSE_RELEASED ||
|
||||
e.getID() == MOUSE_WHEEL ||
|
||||
e.getID() == MOUSE_CLICKED)) {
|
||||
ignore = true;
|
||||
}
|
||||
|
||||
patchClickCount(e);
|
||||
|
||||
int clickCount = e.getClickCount();
|
||||
int button = MouseShortcut.getButton(e);
|
||||
if (button == MouseShortcut.BUTTON_WHEEL_UP || button == MouseShortcut.BUTTON_WHEEL_DOWN) {
|
||||
clickCount = 1;
|
||||
}
|
||||
|
||||
if (e.isConsumed()
|
||||
|| e.isPopupTrigger()
|
||||
|| (e.getButton() > 3 ? e.getID() != MOUSE_PRESSED : e.getID() != MOUSE_RELEASED)
|
||||
|| e.getClickCount() < 1
|
||||
|| e.getButton() == MouseEvent.NOBUTTON) { // See #16995. It did happen
|
||||
|| (button > 3 ? e.getID() != MOUSE_PRESSED && e.getID() != MOUSE_WHEEL : e.getID() != MOUSE_RELEASED)
|
||||
|| clickCount < 1
|
||||
|| button == NOBUTTON) { // See #16995. It did happen
|
||||
ignore = true;
|
||||
}
|
||||
|
||||
@@ -218,7 +225,7 @@ public final class IdeMouseEventDispatcher {
|
||||
return false;
|
||||
}
|
||||
|
||||
final MouseShortcut shortcut = new MouseShortcut(e.getButton(), modifiersEx, e.getClickCount());
|
||||
final MouseShortcut shortcut = new MouseShortcut(button, modifiersEx, clickCount);
|
||||
fillActionsList(c, shortcut, IdeKeyEventDispatcher.isModalContext(c));
|
||||
ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
|
||||
if (actionManager != null) {
|
||||
|
||||
+7
-4
@@ -113,7 +113,7 @@ class MouseShortcutDialog extends DialogWrapper{
|
||||
* @return created/edited shortcut. Returns <code>null</code> if shortcut is invalid.
|
||||
*/
|
||||
public MouseShortcut getMouseShortcut(){
|
||||
if (myButton > 3 && getClickCount() == 2) {
|
||||
if (myButton > 3 && myButton != MouseShortcut.BUTTON_WHEEL_UP && myButton != MouseShortcut.BUTTON_WHEEL_DOWN && getClickCount() == 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -289,17 +289,20 @@ class MouseShortcutDialog extends DialogWrapper{
|
||||
// Alt+Button2 event.
|
||||
// See bug ID 4109826 on Sun's bug parade.
|
||||
//cast is needed in order to compile with mustang
|
||||
MouseShortcutDialog.this.addMouseListener((MouseListener)new MouseAdapter(){
|
||||
MouseAdapter adapter = new MouseAdapter() {
|
||||
public void mouseReleased(MouseEvent e){
|
||||
Component component= SwingUtilities.getDeepestComponentAt(e.getComponent(),e.getX(),e.getY());
|
||||
if(component== MyClickPad.this){
|
||||
e.consume();
|
||||
myButton=e.getButton();
|
||||
myButton = MouseShortcut.getButton(e);
|
||||
myModifiers=e.getModifiersEx();
|
||||
updatePreviewAndConflicts();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
Window window = MouseShortcutDialog.this.getPeer().getWindow();
|
||||
window.addMouseListener(adapter);
|
||||
window.addMouseWheelListener(adapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +91,8 @@ no.actions=No actions
|
||||
#0 - modifiers (with + for windows or empty str), 1 - button num (1 - left, 2 - center, 3 - right etc.)
|
||||
mouse.click.shortcut.text={0}Button{1} Click
|
||||
mouse.double.click.shortcut.text={0}Button{1} Double-Click
|
||||
mouse.wheel.rotate.up.shortcut.text={0}Wheel up
|
||||
mouse.wheel.rotate.down.shortcut.text={0}Wheel down
|
||||
configuration.all.keymaps.should.have.non.empty.names.error.message=All keymaps should have non empty names
|
||||
configuration.all.keymaps.should.have.unique.names.error.message=All keymaps should have unique names
|
||||
|
||||
|
||||
Reference in New Issue
Block a user