From c7b4c6972064bdab400165f2ce0d9fb8cf8f086b Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Wed, 15 Mar 2023 15:58:57 -0400 Subject: [PATCH] Fixed the structure editor sometimes losing focus when editing data types --- .../compositeeditor/CompositeEditorPanel.java | 3 +- .../CompositeEditorTableAction.java | 7 +++++ .../java/docking/widgets/table/GTable.java | 28 +++++++++++-------- 3 files changed, 25 insertions(+), 13 deletions(-) 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.java index 0ea7fb1603..6a9cbc09f3 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 @@ -186,6 +186,7 @@ public abstract class CompositeEditorPanel extends JPanel if (editingRow < 0) { return; } + int modelColumn = table.convertColumnIndexToModel(table.getEditingColumn()); if (!launchBitFieldEditor(modelColumn, editingRow)) { model.beginEditingField(editingRow, modelColumn); @@ -1332,7 +1333,7 @@ public abstract class CompositeEditorPanel extends JPanel @Override public void focusEditor() { - boolean didFocus = textField.requestFocusInWindow(); + textField.requestFocusInWindow(); } @Override diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorTableAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorTableAction.java index 3d8ee05b99..764cdfb255 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorTableAction.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorTableAction.java @@ -20,6 +20,7 @@ import java.awt.event.ActionListener; import javax.swing.*; import docking.action.*; +import docking.widgets.table.GTable; import ghidra.framework.plugintool.Plugin; import ghidra.framework.plugintool.PluginTool; import ghidra.util.HelpLocation; @@ -79,7 +80,13 @@ abstract public class CompositeEditorTableAction extends DockingAction implement if (provider == null) { return; // must have been disposed } + JTable table = ((CompositeEditorPanel) provider.getComponent()).getTable(); + if (table instanceof GTable gTable) { + gTable.requestTableFocus(); + return; + } + if (table.isEditing()) { table.getEditorComponent().requestFocus(); } diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/GTable.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/GTable.java index f882c42701..6d9e05640c 100644 --- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/GTable.java +++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/GTable.java @@ -940,22 +940,26 @@ public class GTable extends JTable { public boolean editCellAt(int row, int column, EventObject e) { boolean editAtCell = super.editCellAt(row, column, e); if (editAtCell) { - TableCellEditor currentEditor = getCellEditor(); - Component editorComponent = getEditorComponent(); - if (currentEditor instanceof FocusableEditor focusable) { - focusable.focusEditor(); - } - else { - editorComponent.requestFocusInWindow(); - } - - if (editorComponent instanceof JTextComponent textComponent) { - textComponent.selectAll(); - } + requestTableFocus(); } return editAtCell; } + public void requestTableFocus() { + TableCellEditor currentEditor = getCellEditor(); + Component editorComponent = getEditorComponent(); + if (currentEditor instanceof FocusableEditor focusable) { + focusable.focusEditor(); + } + else { + editorComponent.requestFocusInWindow(); + } + + if (editorComponent instanceof JTextComponent textComponent) { + textComponent.selectAll(); + } + } + public void scrollToSelectedRow() { int[] selectedRows = getSelectedRows(); if (selectedRows == null || selectedRows.length == 0) {