Merge remote-tracking branch 'origin/GP-5740-dragonmacher-dtm-chooser-dialog-fix'

This commit is contained in:
Ryan Kurtz 2025-06-06 13:52:47 -04:00
commit 1b8faba952
7 changed files with 23 additions and 54 deletions

View file

@ -306,8 +306,6 @@ public class BitFieldEditorPanel extends JPanel {
} }
}); });
dtChoiceEditor.getBrowseButton().setFocusable(false);
JComponent editorComponent = dtChoiceEditor.getEditorComponent(); JComponent editorComponent = dtChoiceEditor.getEditorComponent();
Dimension preferredSize = editorComponent.getPreferredSize(); Dimension preferredSize = editorComponent.getPreferredSize();
editorComponent.setPreferredSize(new Dimension(200, preferredSize.height)); editorComponent.setPreferredSize(new Dimension(200, preferredSize.height));

View file

@ -43,7 +43,6 @@ import docking.widgets.label.GLabel;
import docking.widgets.table.*; import docking.widgets.table.*;
import docking.widgets.textfield.GValidatedTextField; import docking.widgets.textfield.GValidatedTextField;
import generic.theme.GColor; import generic.theme.GColor;
import ghidra.app.services.DataTypeManagerService;
import ghidra.app.util.datatype.DataTypeSelectionEditor; import ghidra.app.util.datatype.DataTypeSelectionEditor;
import ghidra.app.util.datatype.NavigationDirection; import ghidra.app.util.datatype.NavigationDirection;
import ghidra.framework.plugintool.Plugin; 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() { textField.addFocusListener(new FocusAdapter() {
@Override @Override
public void focusGained(FocusEvent e) { public 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();
}
}
@Override @Override
public void focusEditor() { public void focusEditor() {
textField.requestFocusInWindow(); textField.requestFocusInWindow();

View file

@ -586,7 +586,6 @@ public class DataTypeManagerPlugin extends ProgramPlugin
@Override @Override
public DataType getDataType(TreePath selectedPath) { public DataType getDataType(TreePath selectedPath) {
DataTypeChooserDialog dialog = new DataTypeChooserDialog(this); DataTypeChooserDialog dialog = new DataTypeChooserDialog(this);
if (selectedPath != null) { if (selectedPath != null) {
dialog.setSelectedPath(selectedPath); dialog.setSelectedPath(selectedPath);
} }

View file

@ -19,7 +19,8 @@ import java.awt.Component;
import java.awt.event.*; import java.awt.event.*;
import java.util.EventObject; import java.util.EventObject;
import javax.swing.*; import javax.swing.AbstractCellEditor;
import javax.swing.JTable;
import javax.swing.event.CellEditorListener; import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.table.TableCellEditor; 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.DataType;
import ghidra.program.model.data.DataTypeManager; import ghidra.program.model.data.DataTypeManager;
import ghidra.util.MessageType; import ghidra.util.MessageType;
import ghidra.util.Swing;
import ghidra.util.data.DataTypeParser; import ghidra.util.data.DataTypeParser;
class ParameterDataTypeCellEditor extends AbstractCellEditor 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() { textField.addFocusListener(new FocusAdapter() {
@Override @Override
public void focusGained(FocusEvent e) { public void focusGained(FocusEvent e) {
@ -116,14 +104,6 @@ class ParameterDataTypeCellEditor extends AbstractCellEditor
return textField; return 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();
}
@Override @Override
public Object getCellEditorValue() { public Object getCellEditorValue() {
return dt; return dt;

View file

@ -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); variableData.getFormalDataType(), false, 0, 0);
final DropDownSelectionTextField<DataType> textField = dataTypeEditor.getTextField(); 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());
textField.addFocusListener(new FocusListener() { textField.addFocusListener(new FocusListener() {
@Override @Override

View file

@ -400,7 +400,23 @@ public class KeyBindingOverrideKeyEventDispatcher implements KeyEventDispatcher
JComponent jComponent = (JComponent) focusOwner; JComponent jComponent = (JComponent) focusOwner;
Action action = getJavaActionForComponent(jComponent, keyStroke); 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) { private Action getJavaActionForComponent(JComponent jComponent, KeyStroke keyStroke) {

View file

@ -149,6 +149,8 @@ public class DropDownTextField<T> extends JTextField implements GComponent {
setPreviewPaneAttributes(); setPreviewPaneAttributes();
initDataList(); initDataList();
getAccessibleContext().setAccessibleName("Data Type Editor");
} }
protected ListSelectionModel createListSelectionModel() { protected ListSelectionModel createListSelectionModel() {