Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-2894 - Key Bindings - fixed bug in Structure Editor that prevented toolbar action keybinding from working; updated all keybindings to work with focus in text components when the binding is modified, as long as the component does itself not have an action registered for that binding

dragonmacher28c5218f188c
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/ApplyAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/ApplyAction.java
index 8c8f119da0..9738b2fe4d 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/ApplyAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/ApplyAction.java
@@ -25,16 +25,12 @@ import resources.ResourceManager;
/**
* ApplyAction is an action for applying editor changes.
*/
-public class ApplyAction extends CompositeEditorAction {
+public class ApplyAction extends CompositeEditorTableAction {
private final static String GROUP_NAME = BASIC_ACTION_GROUP;
private final static ImageIcon APPLY_ICON = ResourceManager.loadImage("images/disk.png");
private final static String[] popupPath = new String[] { "Apply Edits" };
- /**
- * Constructor
- * @param owner the plugin that owns this action
- */
public ApplyAction(CompositeEditorProvider provider) {
super(provider, EDIT_ACTION_PREFIX + "Apply Editor Changes", GROUP_NAME, popupPath, null,
APPLY_ICON);
@@ -43,9 +39,6 @@ public class ApplyAction extends CompositeEditorAction {
adjustEnablement();
}
- /* (non-Javadoc)
- * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
- */
@Override
public void actionPerformed(ActionContext context) {
if (!model.isValidName()) {
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/KeyBindingOverrideKeyEventDispatcher.java b/Ghidra/Framework/Docking/src/main/java/docking/KeyBindingOverrideKeyEventDispatcher.java
index fab24f5eb5..249e7ed900 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/KeyBindingOverrideKeyEventDispatcher.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/KeyBindingOverrideKeyEventDispatcher.java
@@ -202,7 +202,7 @@ class KeyBindingOverrideKeyEventDispatcher implements KeyEventDispatcher {
// note: this call has no effect if 'action' is null
SwingUtilities.notifyAction(action, keyStroke, event, event.getSource(),
- event.getModifiers());
+ event.getModifiersEx());
}
return wasInProgress;
@@ -254,8 +254,30 @@ class KeyBindingOverrideKeyEventDispatcher implements KeyEventDispatcher {
// }
// We've made the executive decision to allow all keys to go through to the text component
- // unless they are modified with the 'Alt' key
- return !event.isAltDown();
+ // unless they are modified with the 'Alt'/'Ctrl'/etc keys, unless they directly used
+ // by the text component
+ if (!isNonTextModifierOn(event)) {
+ return true; // unmodified keys will be given to the text component
+ }
+
+ // the key is modified; let it through if the component has a mapping for the key
+ return hasComponentKeyToActionMapping((JTextComponent) destination, event);
+ }
+
+ /**
+ * A test to see if the given event is modified in such a way as a text component would not
+ * handle the event
+ * @param e the event
+ * @return true if modified
+ */
+ private boolean isNonTextModifierOn(KeyEvent e) {
+ return e.isAltDown() || e.isAltGraphDown() || e.isMetaDown() || e.isControlDown();
+ }
+
+ private boolean hasComponentKeyToActionMapping(JComponent c, KeyEvent event) {
+ KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(event);
+ Action action = getJavaActionForComponent(c, keyStroke);
+ return action != null;
}
/**
@@ -371,7 +393,7 @@ class KeyBindingOverrideKeyEventDispatcher implements KeyEventDispatcher {
Action action = getJavaActionForComponent(jComponent, keyStroke);
if (action != null) {
return SwingUtilities.notifyAction(action, keyStroke, keyEvent, keyEvent.getSource(),
- keyEvent.getModifiers());
+ keyEvent.getModifiersEx());
}
return false;
}