Ghidra is a software reverse engineering (SRE) framework
GP-5740 - Data Types - Fixed composite editor showing 2 data type chooser dialogs; fixed Escape not working in the chooser dialog
dragonmacher08b990412e4f
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/BitFieldEditorPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/BitFieldEditorPanel.javaindex 69c014d2ee..160e72f102 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/BitFieldEditorPanel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/BitFieldEditorPanel.java@@ -306,8 +306,6 @@ public class BitFieldEditorPanel extends JPanel {}});- dtChoiceEditor.getBrowseButton().setFocusable(false);-JComponent editorComponent = dtChoiceEditor.getEditorComponent();Dimension preferredSize = editorComponent.getPreferredSize();editorComponent.setPreferredSize(new Dimension(200, preferredSize.height));diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.javaindex 2abce33b4a..51d5920b1c 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java@@ -43,7 +43,6 @@ import docking.widgets.label.GLabel;import docking.widgets.table.*;import docking.widgets.textfield.GValidatedTextField;import generic.theme.GColor;-import ghidra.app.services.DataTypeManagerService;import ghidra.app.util.datatype.DataTypeSelectionEditor;import ghidra.app.util.datatype.NavigationDirection;import ghidra.framework.plugintool.Plugin;@@ -1204,9 +1203,6 @@ public abstract class CompositeEditorPanel<T extends Composite, M extends Compos}});- JButton browseButton = editor.getBrowseButton();- browseButton.addActionListener(e -> Swing.runLater(() -> stopEdit(tool)));-textField.addFocusListener(new FocusAdapter() {@Overridepublic void focusGained(FocusEvent e) {@@ -1217,18 +1213,6 @@ public abstract class CompositeEditorPanel<T extends Composite, M extends Compos}- private void stopEdit(PluginTool tool) {- DataTypeManagerService service = tool.getService(DataTypeManagerService.class);- DataType dataType = service.getDataType((String) null);- if (dataType != null) {- editor.setCellEditorValue(dataType);- editor.stopCellEditing();- }- else {- editor.cancelCellEditing();- }- }-@Overridepublic void focusEditor() {textField.requestFocusInWindow();diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/DataTypeManagerPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/DataTypeManagerPlugin.javaindex 4d25970811..2a3b3ba952 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/DataTypeManagerPlugin.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/DataTypeManagerPlugin.java@@ -586,7 +586,6 @@ public class DataTypeManagerPlugin extends ProgramPlugin@Overridepublic DataType getDataType(TreePath selectedPath) {DataTypeChooserDialog dialog = new DataTypeChooserDialog(this);-if (selectedPath != null) {dialog.setSelectedPath(selectedPath);}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/editor/ParameterDataTypeCellEditor.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/editor/ParameterDataTypeCellEditor.javaindex 96c5581574..87946f10c9 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/editor/ParameterDataTypeCellEditor.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/editor/ParameterDataTypeCellEditor.java@@ -19,7 +19,8 @@ import java.awt.Component;import java.awt.event.*;import java.util.EventObject;-import javax.swing.*;+import javax.swing.AbstractCellEditor;+import javax.swing.JTable;import javax.swing.event.CellEditorListener;import javax.swing.event.ChangeEvent;import javax.swing.table.TableCellEditor;@@ -32,7 +33,6 @@ import ghidra.app.util.datatype.DataTypeSelectionEditor;import ghidra.program.model.data.DataType;import ghidra.program.model.data.DataTypeManager;import ghidra.util.MessageType;-import ghidra.util.Swing;import ghidra.util.data.DataTypeParser;class ParameterDataTypeCellEditor extends AbstractCellEditor@@ -82,18 +82,6 @@ class ParameterDataTypeCellEditor extends AbstractCellEditor}});- JButton browseButton = editor.getBrowseButton();- browseButton.addActionListener(e -> Swing.runLater(() -> {- DataType dataType = service.getDataType((String) null);- if (dataType != null) {- editor.setCellEditorValue(dataType);- editor.stopCellEditing();- }- else {- editor.cancelCellEditing();- }- }));-textField.addFocusListener(new FocusAdapter() {@Overridepublic void focusGained(FocusEvent e) {@@ -116,14 +104,6 @@ class ParameterDataTypeCellEditor extends AbstractCellEditorreturn textField;}- /**- * @return chooser button '...' associated with the generated component. Null will- * be returned if getTableCellEditorComponent method has not yet been invoked.- */- public JButton getChooserButton() {- return editor.getBrowseButton();- }-@Overridepublic Object getCellEditorValue() {return dt;diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/editor/StorageAddressEditorDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/editor/StorageAddressEditorDialog.javaindex 53a6fbe898..dcc3ce251f 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/editor/StorageAddressEditorDialog.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/editor/StorageAddressEditorDialog.java@@ -192,20 +192,10 @@ public class StorageAddressEditorDialog extends DialogComponentProvider}});- final Component dataTypeEditComponent = dataTypeEditor.getTableCellEditorComponent(null,+ Component dataTypeEditComponent = dataTypeEditor.getTableCellEditorComponent(null,variableData.getFormalDataType(), false, 0, 0);- final DropDownSelectionTextField<DataType> textField = dataTypeEditor.getTextField();- textField.setBorder((new JTextField()).getBorder()); // restore default border- textField.getAccessibleContext().setAccessibleName("Data Type Editor");-- JButton chooserButton = dataTypeEditor.getChooserButton();- chooserButton.getAccessibleContext().setAccessibleName("Choose");- JButton defaultButton = new JButton(); // restore default border/background- defaultButton.getAccessibleContext().setAccessibleName("Default");- chooserButton.setBorder(defaultButton.getBorder());- chooserButton.setBackground(defaultButton.getBackground());-+ DropDownSelectionTextField<DataType> textField = dataTypeEditor.getTextField();textField.addFocusListener(new FocusListener() {@Overridediff --git a/Ghidra/Framework/Docking/src/main/java/docking/KeyBindingOverrideKeyEventDispatcher.java b/Ghidra/Framework/Docking/src/main/java/docking/KeyBindingOverrideKeyEventDispatcher.javaindex bcd2819614..83c4f2d614 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/KeyBindingOverrideKeyEventDispatcher.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/KeyBindingOverrideKeyEventDispatcher.java@@ -400,7 +400,23 @@ public class KeyBindingOverrideKeyEventDispatcher implements KeyEventDispatcherJComponent jComponent = (JComponent) focusOwner;Action action = getJavaActionForComponent(jComponent, keyStroke);- return action != null && action.isEnabled();+ if (action == null) {+ return false;+ }++ /*+ Some Java actions use the accept() method for more fine-grained enablement checking. An+ example of this is the JTree 'cancel' action, bound to Escape, which will cancel any+ current edits. The tree UI is smart enough to say the action is only enabled if there+ is an active edit. The accept() method may return false when isEnabled() will return+ true. So, check the accept() method first, since it may be more specific.+ */+ boolean isEnabled = action.accept(focusOwner);+ if (!isEnabled) {+ return false;+ }++ return action.isEnabled();}private Action getJavaActionForComponent(JComponent jComponent, KeyStroke keyStroke) {diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/DropDownTextField.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/DropDownTextField.javaindex 3f9e98234b..af22255b89 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/DropDownTextField.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/DropDownTextField.java@@ -149,6 +149,8 @@ public class DropDownTextField<T> extends JTextField implements GComponent {setPreviewPaneAttributes();initDataList();++ getAccessibleContext().setAccessibleName("Data Type Editor");}protected ListSelectionModel createListSelectionModel() {