Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3427 - GTree - Updated key binding code to allow for F2 ke to be used

dragonmacher1b557ee45fde
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/actions/KeyBindingUtils.java b/Ghidra/Framework/Docking/src/main/java/docking/actions/KeyBindingUtils.java
index 2fb2ccabaf..e095aa8165 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/actions/KeyBindingUtils.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/actions/KeyBindingUtils.java
@@ -401,6 +401,36 @@ public class KeyBindingUtils {
}
}
+ /**
+ * Clears the currently assigned Java key binding for the action by the given name. This
+ * method will find the currently assigned key binding, if any, and then remove it.
+ *
+ * @param component the component for which to clear the key binding
+ * @param actionName the name of the action that should not have a key binding
+ * @see LookAndFeel
+ */
+ public static void clearKeyBinding(JComponent component, String actionName) {
+
+ InputMap inputMap = component.getInputMap(JComponent.WHEN_FOCUSED);
+ if (inputMap == null) {
+ return;
+ }
+
+ KeyStroke keyStroke = null;
+ KeyStroke[] keys = inputMap.allKeys();
+ for (KeyStroke ks : keys) {
+ Object object = inputMap.get(ks);
+ if (actionName.equals(object)) {
+ keyStroke = ks;
+ break;
+ }
+ }
+
+ if (keyStroke != null) {
+ clearKeyBinding(component, keyStroke);
+ }
+ }
+
/**
* Returns the registered action for the given keystroke, or null of no
* action is bound to that keystroke.
@@ -906,5 +936,4 @@ public class KeyBindingUtils {
return selectedFile;
}
-
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/GTree.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/GTree.java
index 18303c8b30..b5a12ce124 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/GTree.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/GTree.java
@@ -36,6 +36,7 @@ import javax.swing.tree.*;
import org.apache.commons.lang3.StringUtils;
import docking.DockingWindowManager;
+import docking.actions.KeyBindingUtils;
import docking.widgets.JTreeMouseListenerDelegate;
import docking.widgets.filter.FilterTextField;
import docking.widgets.table.AutoscrollAdapter;
@@ -228,10 +229,6 @@ public class GTree extends JPanel implements BusyListener {
});
tree = new AutoScrollTree(model);
- tree.setRowHeight(-1);// variable size rows
- tree.setSelectionModel(new GTreeSelectionModel());
- tree.setInvokesStopCellEditing(true);// clicking outside the cell editor will trigger a save, not a cancel
- ToolTipManager.sharedInstance().registerComponent(tree);
setLayout(new BorderLayout());
@@ -1233,6 +1230,22 @@ public class GTree extends JPanel implements BusyListener {
public AutoScrollTree(TreeModel model) {
super(model);
scroller = new AutoscrollAdapter(this, 5);
+
+ setRowHeight(-1);// variable size rows
+ setSelectionModel(new GTreeSelectionModel());
+ setInvokesStopCellEditing(true);// clicking outside the cell editor will trigger a save, not a cancel
+
+ updateDefaultKeyBindings();
+
+ ToolTipManager.sharedInstance().registerComponent(this);
+ }
+
+ private void updateDefaultKeyBindings() {
+
+ // Remove the edit keybinding, as the GTree triggers editing via a task, since it
+ // is multi-threaded. Doing this allows users to assign their own key bindings to
+ // the edit task.
+ KeyBindingUtils.clearKeyBinding(this, "startEditing");
}
@Override