mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fast expand/collapse with mouse is being recognized as double-click and trigger some selection-based actions wrongly.
This commit is contained in:
@@ -19,13 +19,40 @@
|
||||
*/
|
||||
package com.intellij.ui;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.basic.BasicTreeUI;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public abstract class DoubleClickListener extends ClickListener {
|
||||
@Override
|
||||
public final boolean onClick(MouseEvent event, int clickCount) {
|
||||
if (clickCount == 2 && event.getButton() == MouseEvent.BUTTON1) {
|
||||
return onDoubleClick(event);
|
||||
return isExpandIconClick(event) ? false : onDoubleClick(event);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isExpandIconClick(MouseEvent event) {
|
||||
if (event.getComponent() instanceof JTree) {
|
||||
JTree tree = (JTree)event.getComponent();
|
||||
TreePath treePath = tree.getClosestPathForLocation(event.getX(), event.getY());
|
||||
if (treePath == null || !(tree.getUI() instanceof BasicTreeUI)) return false;
|
||||
BasicTreeUI ui = (BasicTreeUI)tree.getUI();
|
||||
try {
|
||||
Method method = BasicTreeUI.class.getDeclaredMethod("isLocationInExpandControl", TreePath.class, Integer.TYPE, Integer.TYPE);
|
||||
method.setAccessible(true);
|
||||
Object result = method.invoke(ui, treePath, event.getX(), event.getY());
|
||||
if (result instanceof Boolean && result.equals(Boolean.TRUE)) return true;
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user