IDEA-156284 Force Touch: Keymap, Add/Find Mouse Shortcut panel: after Button 1 is clicked and set in shortcut preview, Force Touch is ignored

This commit is contained in:
Denis Fokin
2016-07-25 20:04:41 +03:00
parent 7ea87fc63e
commit c8bf17b6bc
3 changed files with 97 additions and 10 deletions
@@ -43,6 +43,11 @@ public class MouseShortcut extends Shortcut {
return event.getButton();
}
/**
* @param button Mouse buttons MouseEvent.BUTTON_LEFT, MouseEvent.BUTTON2, etc...
* @param modifiers modifiersEx masks like InputEvent.ALT_DOWN_MASK and so on...
* @param clickCount click count from the MouseEvent that caused the MouseShortcut creation
*/
public MouseShortcut(int button, @JdkConstants.InputEventMask int modifiers, int clickCount) {
myButton = button;
// TODO[vova] check modifiers?
@@ -67,12 +72,14 @@ public class MouseShortcut extends Shortcut {
}
public boolean equals(Object obj) {
if (!(obj instanceof MouseShortcut)) {
return false;
}
MouseShortcut shortcut = (MouseShortcut)obj;
return myButton == shortcut.myButton && myModifiers == shortcut.myModifiers && myClickCount ==
shortcut.myClickCount;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
MouseShortcut other = (MouseShortcut) obj;
return myButton == other.myButton
&& myModifiers == other.myModifiers
&& myClickCount == other.myClickCount;
}
public int hashCode() {
@@ -21,11 +21,11 @@ import java.awt.event.MouseEvent;
public class PressureShortcut extends MouseShortcut {
private double stage;
private double myStage;
public PressureShortcut(double stage) {
super(MouseEvent.BUTTON1, 0, 1);
this.stage = stage;
this.myStage = stage;
}
public int getButton() {
@@ -42,11 +42,16 @@ public class PressureShortcut extends MouseShortcut {
}
public boolean equals(Object obj) {
return obj instanceof PressureShortcut;
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
PressureShortcut other = (PressureShortcut) obj;
return myStage == other.myStage;
}
public int hashCode() {
return super.hashCode() + (int)stage;
return super.hashCode() + (int)myStage;
}
@Override
@@ -0,0 +1,75 @@
/*
* Copyright 2000-2016 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.openapi.keymap.impl;
import com.intellij.openapi.actionSystem.MouseShortcut;
import com.intellij.openapi.actionSystem.PressureShortcut;
import com.intellij.testFramework.LightPlatformTestCase;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
public class MouseShortcutEqualityTest extends LightPlatformTestCase {
public void testTheSameMouseShortcutIsEqual () {
MouseShortcut mouseShortcut = new MouseShortcut(MouseEvent.BUTTON1, 0, 1);
assertEquals("The same MouseShortcut should be equals to itself", mouseShortcut, mouseShortcut);
mouseShortcut = new MouseShortcut(MouseEvent.BUTTON2, 0, 1);
assertEquals("The same MouseShortcut should be equals to itself", mouseShortcut, mouseShortcut);
mouseShortcut = new MouseShortcut(MouseEvent.BUTTON1, InputEvent.ALT_DOWN_MASK, 1);
assertEquals("The same MouseShortcut should be equals to itself", mouseShortcut, mouseShortcut);
mouseShortcut = new MouseShortcut(MouseEvent.BUTTON1, InputEvent.CTRL_DOWN_MASK, 2);
assertEquals("The same MouseShortcut should be equals to itself", mouseShortcut, mouseShortcut);
}
public void testEqualMouseShortcutsAreEqual () {
assertEquals("Mouse shortcuts with equal data are equal",
new MouseShortcut(MouseEvent.BUTTON1, 0, 1),
new MouseShortcut(MouseEvent.BUTTON1, 0, 1));
assertEquals("Mouse shortcuts with equal data are equal",
new MouseShortcut(MouseEvent.BUTTON2, InputEvent.ALT_DOWN_MASK, 2),
new MouseShortcut(MouseEvent.BUTTON2, InputEvent.ALT_DOWN_MASK, 2));
}
public void testSubclassesOfMouseEventsAreNotEqualToMouseEvents () {
MouseShortcut mouseShortcut = new MouseShortcut(MouseEvent.BUTTON2, InputEvent.ALT_DOWN_MASK, 2);
PressureShortcut pressureShortcut = new PressureShortcut(1);
assertFalse("MouseShortcut is not equal to PressureShortcut", mouseShortcut.equals(pressureShortcut));
assertFalse("MouseShortcut is not equal to PressureShortcut", pressureShortcut.equals(mouseShortcut));
}
public void testPressureShortcutsWithTheSameDataAreEqual () {
PressureShortcut pressureShortcut = new PressureShortcut(1);
PressureShortcut anotherPressureShortcut = new PressureShortcut(1);
assertEquals("Pressure shortcuts with the same data are equal", pressureShortcut, anotherPressureShortcut);
}
public void testUnequalPressureShortcuts () {
PressureShortcut pressureShortcut = new PressureShortcut(1);
PressureShortcut anotherPressureShortcut = new PressureShortcut(2);
assertFalse("Pressure shortcuts with different data are not equal", pressureShortcut.equals(anotherPressureShortcut));
assertFalse("Pressure shortcuts with different data are not equal", anotherPressureShortcut.equals(pressureShortcut));
}
}