Fixed the structure editor sometimes losing focus when editing data

types
This commit is contained in:
dragonmacher 2023-03-15 15:58:57 -04:00
parent 179f093aca
commit c7b4c69720
3 changed files with 25 additions and 13 deletions

View file

@ -186,6 +186,7 @@ public abstract class CompositeEditorPanel extends JPanel
if (editingRow < 0) { if (editingRow < 0) {
return; return;
} }
int modelColumn = table.convertColumnIndexToModel(table.getEditingColumn()); int modelColumn = table.convertColumnIndexToModel(table.getEditingColumn());
if (!launchBitFieldEditor(modelColumn, editingRow)) { if (!launchBitFieldEditor(modelColumn, editingRow)) {
model.beginEditingField(editingRow, modelColumn); model.beginEditingField(editingRow, modelColumn);
@ -1332,7 +1333,7 @@ public abstract class CompositeEditorPanel extends JPanel
@Override @Override
public void focusEditor() { public void focusEditor() {
boolean didFocus = textField.requestFocusInWindow(); textField.requestFocusInWindow();
} }
@Override @Override

View file

@ -20,6 +20,7 @@ import java.awt.event.ActionListener;
import javax.swing.*; import javax.swing.*;
import docking.action.*; import docking.action.*;
import docking.widgets.table.GTable;
import ghidra.framework.plugintool.Plugin; import ghidra.framework.plugintool.Plugin;
import ghidra.framework.plugintool.PluginTool; import ghidra.framework.plugintool.PluginTool;
import ghidra.util.HelpLocation; import ghidra.util.HelpLocation;
@ -79,7 +80,13 @@ abstract public class CompositeEditorTableAction extends DockingAction implement
if (provider == null) { if (provider == null) {
return; // must have been disposed return; // must have been disposed
} }
JTable table = ((CompositeEditorPanel) provider.getComponent()).getTable(); JTable table = ((CompositeEditorPanel) provider.getComponent()).getTable();
if (table instanceof GTable gTable) {
gTable.requestTableFocus();
return;
}
if (table.isEditing()) { if (table.isEditing()) {
table.getEditorComponent().requestFocus(); table.getEditorComponent().requestFocus();
} }

View file

@ -940,6 +940,12 @@ public class GTable extends JTable {
public boolean editCellAt(int row, int column, EventObject e) { public boolean editCellAt(int row, int column, EventObject e) {
boolean editAtCell = super.editCellAt(row, column, e); boolean editAtCell = super.editCellAt(row, column, e);
if (editAtCell) { if (editAtCell) {
requestTableFocus();
}
return editAtCell;
}
public void requestTableFocus() {
TableCellEditor currentEditor = getCellEditor(); TableCellEditor currentEditor = getCellEditor();
Component editorComponent = getEditorComponent(); Component editorComponent = getEditorComponent();
if (currentEditor instanceof FocusableEditor focusable) { if (currentEditor instanceof FocusableEditor focusable) {
@ -953,8 +959,6 @@ public class GTable extends JTable {
textComponent.selectAll(); textComponent.selectAll();
} }
} }
return editAtCell;
}
public void scrollToSelectedRow() { public void scrollToSelectedRow() {
int[] selectedRows = getSelectedRows(); int[] selectedRows = getSelectedRows();