Merge remote-tracking branch 'origin/GP-5914-dragonmacher-symbol-tree-nav-fix'

This commit is contained in:
Ryan Kurtz 2025-08-18 12:47:50 -04:00
commit 16a2e78806

View file

@ -19,6 +19,7 @@ import static ghidra.framework.model.DomainObjectEvent.*;
import static ghidra.program.util.ProgramEvent.*; import static ghidra.program.util.ProgramEvent.*;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Point;
import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner; import java.awt.datatransfer.ClipboardOwner;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
@ -167,7 +168,8 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
return; return;
} }
maybeGoToSymbol(); SymbolNode symbolNode = getSelectedSymbolNode();
maybeGoToSymbol(symbolNode);
contextChanged(); contextChanged();
}); });
@ -176,13 +178,23 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
// This code serves to perform navigation in the case that the selection handler // This code serves to perform navigation in the case that the selection handler
// above does not, as is the case when the node is already selected. This code // above does not, as is the case when the clicked node is already selected. This
// will get called on the mouse release, whereas the selection handler gets called // code will get called on the mouse clicked, whereas the selection handler gets
// on the mouse pressed. // called on the mouse pressed.
// For now, just attempt to perform the goto. It may get called twice, but this // For now, just attempt to perform the goto. It may get called twice, but this
// should have no real impact on performance. // should have no real impact on performance.
Point p = e.getPoint();
GTreeNode clickedNode = newTree.getNodeForLocation(p.x, p.y);
if (clickedNode == null) {
return;
}
maybeGoToSymbol(); SymbolNode symbolNode = getSelectedSymbolNode();
if (!clickedNode.equals(symbolNode)) {
return;
}
maybeGoToSymbol(symbolNode);
} }
}); });
@ -211,19 +223,24 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
} }
} }
private void maybeGoToSymbol() { private SymbolNode getSelectedSymbolNode() {
TreePath[] paths = tree.getSelectionPaths(); TreePath[] paths = tree.getSelectionPaths();
if (paths == null || paths.length != 1) { if (paths == null || paths.length != 1) {
return; return null;
} }
Object object = paths[0].getLastPathComponent(); Object object = paths[0].getLastPathComponent();
if (!(object instanceof SymbolNode)) { if (object instanceof SymbolNode symbolNode) {
return; return symbolNode;
} }
SymbolNode node = (SymbolNode) object; return null;
}
private void maybeGoToSymbol(SymbolNode node) {
if (node == null) {
return;
}
Symbol symbol = node.getSymbol(); Symbol symbol = node.getSymbol();
SymbolType type = symbol.getSymbolType(); SymbolType type = symbol.getSymbolType();
if (!type.isNamespace() || type == SymbolType.FUNCTION) { if (!type.isNamespace() || type == SymbolType.FUNCTION) {