From 4fc494cb650c7ce5317e70c03012d28cd7fbe749 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 15 Feb 2012 12:00:14 +0100 Subject: [PATCH] IDEA-81189 (fix double clicking in Nimbus/GTK+ trees) --- .../com/intellij/ui/treeStructure/Tree.java | 24 ++++++++++--------- .../util/EditSourceOnDoubleClickHandler.java | 22 ++++++++--------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java b/platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java index a3466fb0a54e..e4cc48f5e191 100644 --- a/platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java +++ b/platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -292,33 +292,35 @@ public class Tree extends JTree implements ComponentWithEmptyText, ComponentWith * See faulty code at BasicTreeUI.selectPathForEvent():2245 * * Another hack to match selection UI (wide) and selection behavior (narrow) in Nimbus/GTK+. - * - * @param e */ - protected void processMouseEvent(MouseEvent e) { + protected void processMouseEvent(final MouseEvent e) { + MouseEvent e2 = e; + if (SystemInfo.isMac) { if (SwingUtilities.isLeftMouseButton(e) && e.isControlDown() && e.getID() == MouseEvent.MOUSE_PRESSED) { int modifiers = e.getModifiers() & ~(InputEvent.CTRL_MASK | InputEvent.BUTTON1_MASK) | InputEvent.BUTTON3_MASK; - e = new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), modifiers, e.getX(), e.getY(), e.getClickCount(), true, - MouseEvent.BUTTON3); + e2 = new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), modifiers, e.getX(), e.getY(), e.getClickCount(), + true, MouseEvent.BUTTON3); } } else if (UIUtil.isUnderNimbusLookAndFeel() || UIUtil.isUnderGTKLookAndFeel()) { - if (SwingUtilities.isLeftMouseButton(e) && e.getID() == MouseEvent.MOUSE_PRESSED) { + if (SwingUtilities.isLeftMouseButton(e) && (e.getID() == MouseEvent.MOUSE_PRESSED || e.getID() == MouseEvent.MOUSE_CLICKED)) { final TreePath path = getClosestPathForLocation(e.getX(), e.getY()); if (path != null) { final Rectangle bounds = getPathBounds(path); - if ((e.getY() > bounds.y && e.getY() < bounds.y + bounds.height) && + if (bounds != null && + (e.getY() > bounds.y && e.getY() < bounds.y + bounds.height) && (e.getX() >= bounds.x + bounds.width || e.getX() < bounds.x && !isLocationInExpandControl(path, e.getX(), e.getY()))) { int newX = bounds.x + bounds.width - 2; - e = new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), e.getModifiers(), newX, e.getY(), e.getClickCount(), - e.isPopupTrigger(), e.getButton()); + e2 = new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), e.getModifiers(), newX, e.getY(), e.getClickCount(), + e.isPopupTrigger(), e.getButton()); } } } } - super.processMouseEvent(e); + + super.processMouseEvent(e2); } private boolean isLocationInExpandControl(final TreePath path, final int x, final int y) { diff --git a/platform/platform-api/src/com/intellij/util/EditSourceOnDoubleClickHandler.java b/platform/platform-api/src/com/intellij/util/EditSourceOnDoubleClickHandler.java index b853b780daca..3ce064b0d84a 100644 --- a/platform/platform-api/src/com/intellij/util/EditSourceOnDoubleClickHandler.java +++ b/platform/platform-api/src/com/intellij/util/EditSourceOnDoubleClickHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -22,7 +22,6 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.Project; import com.intellij.ui.treeStructure.treetable.TreeTable; -import com.intellij.util.ui.Table; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.Nullable; @@ -35,8 +34,7 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class EditSourceOnDoubleClickHandler { - private EditSourceOnDoubleClickHandler() { - } + private EditSourceOnDoubleClickHandler() { } public static void install(final JTree tree, @Nullable final Runnable whenPerformed) { tree.addMouseListener(new TreeMouseListener(tree, whenPerformed)); @@ -60,7 +58,7 @@ public class EditSourceOnDoubleClickHandler { }); } - public static void install(final Table table) { + public static void install(final JTable table) { table.addMouseListener(new MouseAdapter(){ public void mouseClicked(MouseEvent e) { if (e.getClickCount() != 2) return; @@ -75,8 +73,7 @@ public class EditSourceOnDoubleClickHandler { }); } - public static void install(final JList list, - final Runnable whenPerformed) { + public static void install(final JList list, final Runnable whenPerformed) { list.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() != 2) return; @@ -107,12 +104,12 @@ public class EditSourceOnDoubleClickHandler { public void mouseClicked(MouseEvent e) { if (MouseEvent.BUTTON1 != e.getButton() || e.getClickCount() != 2) return; - if (myTree.getUI() instanceof UIUtil.MacTreeUI) { - if (myTree.getClosestPathForLocation(e.getX(), e.getY()) == null) return; - } else if (myTree.getPathForLocation(e.getX(), e.getY()) == null) return; + final TreePath path = myTree.getUI() instanceof UIUtil.MacTreeUI ? myTree.getClosestPathForLocation(e.getX(), e.getY()) + : myTree.getPathForLocation(e.getX(), e.getY()); + if (path == null) return; - DataContext dataContext = DataManager.getInstance().getDataContext(myTree); - Project project = PlatformDataKeys.PROJECT.getData(dataContext); + final DataContext dataContext = DataManager.getInstance().getDataContext(myTree); + final Project project = PlatformDataKeys.PROJECT.getData(dataContext); if (project == null) return; final TreePath selectionPath = myTree.getSelectionPath(); @@ -124,6 +121,7 @@ public class EditSourceOnDoubleClickHandler { } } + @SuppressWarnings("UnusedParameters") protected void processDoubleClick(final MouseEvent e, final DataContext dataContext, final TreeNode lastPathComponent) { OpenSourceUtil.openSourcesFrom(dataContext, true); if (myWhenPerformed != null) myWhenPerformed.run();