diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/data/AbstractSettingsDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/data/AbstractSettingsDialog.java index 37af5e8650..ef45d300a3 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/data/AbstractSettingsDialog.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/data/AbstractSettingsDialog.java @@ -24,7 +24,6 @@ import java.util.List; import javax.swing.*; import javax.swing.border.EmptyBorder; -import javax.swing.event.ChangeEvent; import javax.swing.table.TableCellEditor; import docking.DialogComponentProvider; @@ -146,21 +145,6 @@ public abstract class AbstractSettingsDialog extends DialogComponentProvider { addButton(newApplyButton); addCancelButton(); - - MouseAdapter listener = new MouseAdapter() { - - @Override - public void mousePressed(MouseEvent e) { - - if (settingsTable.isEditing()) { - settingsTable.editingStopped(new ChangeEvent(this)); - } - } - }; - - okButton.addMouseListener(listener); - newApplyButton.addMouseListener(listener); - cancelButton.addMouseListener(listener); } private String getHexModePropertyName(SettingsDefinition settingsDef) { @@ -280,12 +264,17 @@ public abstract class AbstractSettingsDialog extends DialogComponentProvider { } @Override - protected void okCallback() { + protected void okCallback(boolean isMouseClick) { - // prevent users from closing the dialog when pressing Enter to confirm an edit + // When the OK button is pressed we want to finish any open edits. However, if this call is + // from the user pressing Enter, then do not close the dialog after finishing the edit. This + // allows users to press Enter to close the combo box edit without closing the dialog. if (settingsTable.isEditing()) { settingsTable.editingStopped(null); - return; + + if (!isMouseClick) { + return; + } } apply(); @@ -313,7 +302,7 @@ public abstract class AbstractSettingsDialog extends DialogComponentProvider { protected abstract String[] getSuggestedValues(StringSettingsDefinition settingsDefinition); /** - * Apply changes to settings. This method must be ov + * Apply changes to settings. * @throws CancelledException thrown if apply operation cancelled */ protected abstract void applySettings() throws CancelledException; @@ -360,7 +349,7 @@ public abstract class AbstractSettingsDialog extends DialogComponentProvider { StringChoices choices = (StringChoices) value; int selectedChoice = choices.getSelectedValueIndex(); if (defaultSettings == null) { - if (selectedChoice == 0) { // blank choosen + if (selectedChoice == 0) { // blank chosen settings.clearSetting(def.getName()); return; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/data/DataSettingsDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/data/DataSettingsDialog.java index f07ef4e1a6..113a0bb237 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/data/DataSettingsDialog.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/data/DataSettingsDialog.java @@ -75,7 +75,7 @@ public class DataSettingsDialog extends AbstractSettingsDialog { } private static String constructTitle(Data data) { - StringBuffer buffy = new StringBuffer( + StringBuilder buffy = new StringBuilder( DataTypeSettingsDialog.constructTitle(null, data.getDataType(), false)); buffy.append(" at "); buffy.append(data.getMinAddress().toString()); @@ -203,7 +203,8 @@ public class DataSettingsDialog extends AbstractSettingsDialog { private static SettingsDefinition[] getCommonSettings(Program program, ProgramSelection selection) throws CancelledException { - CommonSettingsAccumulatorTask myTask = new CommonSettingsAccumulatorTask(program, selection); + CommonSettingsAccumulatorTask myTask = + new CommonSettingsAccumulatorTask(program, selection); new TaskLauncher(myTask, null); if (myTask.isCancelled()) { throw new CancelledException(); @@ -237,7 +238,8 @@ public class DataSettingsDialog extends AbstractSettingsDialog { Program program; ProgramSelection selection; - ApplyCommonSettingsTask(DataSettingsDialog dlg, Program program, ProgramSelection selection) { + ApplyCommonSettingsTask(DataSettingsDialog dlg, Program program, + ProgramSelection selection) { super("Applying Settings", true, false, true); this.dlg = dlg; this.program = program; diff --git a/Ghidra/Framework/Docking/src/main/java/docking/DialogComponentProvider.java b/Ghidra/Framework/Docking/src/main/java/docking/DialogComponentProvider.java index 61134bad20..5a6539f5e1 100644 --- a/Ghidra/Framework/Docking/src/main/java/docking/DialogComponentProvider.java +++ b/Ghidra/Framework/Docking/src/main/java/docking/DialogComponentProvider.java @@ -488,7 +488,14 @@ public class DialogComponentProvider okButton.setMnemonic('K'); okButton.setName("OK"); okButton.getAccessibleContext().setAccessibleName("OK"); - okButton.addActionListener(e -> okCallback()); + okButton.addActionListener(e -> { + + int mods = e.getModifiers(); + // Note: action event does not use extended modifiers; use the deprecated values + @SuppressWarnings("deprecation") + boolean isMouseClick = (mods & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK; + okCallback(isMouseClick); + }); addButton(okButton); } @@ -923,6 +930,15 @@ public class DialogComponentProvider Msg.debug(this, "Ok button pressed"); } + /** + * A version of the OK callback that allows clients to know if the action is a result of a + * mouse click or the Enter key. + * @param mouseClick true if the mouse clicked the OK button + */ + protected void okCallback(boolean mouseClick) { + okCallback(); + } + /** * The callback method for when the "Cancel" button is pressed. The * default behavior is to call setVisible(false) and dispose() on the