mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-24 13:21:22 +08:00
GT-2383 - tree focus, code review tweaks
This commit is contained in:
+11
-2
@@ -1,6 +1,5 @@
|
||||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,7 +25,7 @@ import javax.swing.tree.TreeSelectionModel;
|
||||
|
||||
public class JTreeMouseListenerDelegate extends MouseAdapter {
|
||||
|
||||
private final Set<MouseListener> listeners = new CopyOnWriteArraySet<MouseListener>();
|
||||
private final Set<MouseListener> listeners = new CopyOnWriteArraySet<>();
|
||||
private final JTree tree;
|
||||
|
||||
private boolean consumedPressed;
|
||||
@@ -87,6 +86,10 @@ public class JTreeMouseListenerDelegate extends MouseAdapter {
|
||||
if (isPotentialDragSelection(e)) {
|
||||
e.consume();
|
||||
consumedPressed = true;
|
||||
|
||||
// ensure the tree has focus in this case, since we consumed the event, which can
|
||||
// prevent the normal focus updating done by Swing
|
||||
fixFocus();
|
||||
}
|
||||
else {
|
||||
consumedPressed = false;
|
||||
@@ -94,6 +97,12 @@ public class JTreeMouseListenerDelegate extends MouseAdapter {
|
||||
fireMousePressed(e);
|
||||
}
|
||||
|
||||
private void fixFocus() {
|
||||
if (!tree.hasFocus()) {
|
||||
tree.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
handlePopupTrigger(e);
|
||||
|
||||
@@ -1324,10 +1324,6 @@ public class GTree extends JPanel implements BusyListener {
|
||||
protected void setSelectedPathNow(TreePath path) {
|
||||
GTreeSelectionModel selectionModel = (GTreeSelectionModel) gTree.getSelectionModel();
|
||||
selectionModel.setSelectionPaths(new TreePath[] { path }, USER_GENERATED);
|
||||
|
||||
// If the user clicked on the same node as was already selected, no events are generated
|
||||
// and the tree might be left unfocused. Force the focus to the tree.
|
||||
gTree.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user