Ghidra is a software reverse engineering (SRE) framework
GP-1553 - Enum Editor - updated enum editor to scroll while using the arrow keys when in edit mode
dragonmacher82eb8944c916
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/editor/EnumEditorPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/editor/EnumEditorPanel.javaindex f5a6be5794..31d7e120b4 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/editor/EnumEditorPanel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/editor/EnumEditorPanel.java@@ -37,26 +37,17 @@ import docking.widgets.textfield.GValidatedTextField.ValidationMessageListener;import ghidra.program.model.data.*;import ghidra.program.model.listing.DataTypeArchive;import ghidra.program.model.listing.Program;-import ghidra.util.InvalidNameException;-import ghidra.util.Msg;+import ghidra.util.*;import ghidra.util.table.GhidraTable;-/**- * Panel for editing enumeration data types.- *- *- */class EnumEditorPanel extends JPanel {- // Normal color for selecting components in the table.- //private static final Color SELECTION_COLOR = Color.YELLOW.brighter().brighter();-private JTable table;private JTextField nameField;private JTextField descField;private JLabel descLabel;private JTextField categoryField;- private GhidraComboBox sizeComboBox;+ private GhidraComboBox<?> sizeComboBox;private EnumTableModel tableModel;private EnumEditorProvider provider;@@ -89,10 +80,6 @@ class EnumEditorPanel extends JPanel {return table;}- /**- * Get the selected row numbers in the model.- * @return- */int[] getSelectedRows() {return table.getSelectedRows();}@@ -111,9 +98,8 @@ class EnumEditorPanel extends JPanel {tableModel.fireTableDataChanged();}- // invoke later because the key press on the table causes the selection- // to change- SwingUtilities.invokeLater(() -> {+ // invoke later because the key press on the table causes the selection to change+ Swing.runLater(() -> {try {if (table.isEditing()) {return; // don't change the selection if a new edit is in progress@@ -142,6 +128,7 @@ class EnumEditorPanel extends JPanel {if (objectDataTypeManager != providerDataTypeManager) {return; // The editor isn't associated with the restored domain object.}+String objectType = "domain object";if (domainObject instanceof Program) {objectType = "program";@@ -149,6 +136,7 @@ class EnumEditorPanel extends JPanel {else if (domainObject instanceof DataTypeArchive) {objectType = "data type archive";}+if (tableModel.hasChanges()) {if (OptionDialog.showYesNoDialogWithNoAsDefaultButton(this, "Reload Enum Editor?","The " + objectType + " \"" + objectDataTypeManager.getName() +@@ -156,12 +144,13 @@ class EnumEditorPanel extends JPanel {"\" may have changed outside this editor.\n" +"Do you want to discard edits and reload the Enum?") == OptionDialog.OPTION_TWO) {- // no+ // 'No'; do not discardcategoryField.setText(provider.getCategoryText());- return; // Don't reload.+ return; // don't reload}}- // Reloading the enum.++ // reload the enumsetFieldInfo(editedEnumDT);tableModel.setEnum(editedEnumDT, false);}@@ -218,6 +207,7 @@ class EnumEditorPanel extends JPanel {else if (otherDesc != null && !otherDesc.equals(descr)) {doUpdate = true;}+if (doUpdate) {editedEnumDT.setDescription(otherDesc);descField.getDocument().removeDocumentListener(docListener);@@ -248,18 +238,16 @@ class EnumEditorPanel extends JPanel {}}- /**- * Add new entry for the enum.- */void addEntry() {stopCellEditing();- final int newRow = tableModel.addEntry(table.getSelectedRow());+ int newRow = tableModel.addEntry(table.getSelectedRow());if (newRow < 0) {Msg.showError(this, this, "Enum is full","All possible Enum values have already been used");return;}- SwingUtilities.invokeLater(() -> {++ Swing.runLater(() -> {table.setRowSelectionInterval(newRow, newRow);table.editCellAt(newRow, EnumTableModel.NAME_COL);Rectangle r = table.getCellRect(newRow, 0, true);@@ -307,14 +295,13 @@ class EnumEditorPanel extends JPanel {table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);add(sp, BorderLayout.CENTER);- EnumCellRenderer cellRenderer = new EnumCellRenderer();table.setRowHeight(table.getRowHeight() + 4);table.setDefaultEditor(String.class, new EnumStringCellEditor());table.getColumnModel().getColumn(EnumTableModel.VALUE_COL).setCellEditor(new EnumLongCellEditor());- table.setDefaultRenderer(String.class, cellRenderer);+ table.setDefaultRenderer(String.class, new GTableCellRenderer());add(createInfoPanel(), BorderLayout.SOUTH);}@@ -416,7 +403,7 @@ class EnumEditorPanel extends JPanel {categoryField.setEditable(false);categoryField.setName("Category");- sizeComboBox = new GhidraComboBox(new Integer[] { 1, 2, 4, 8 });+ sizeComboBox = new GhidraComboBox<>(new Integer[] { 1, 2, 4, 8 });sizeComboBox.setName("Size");sizeComboBox.addItemListener(e -> {Integer length = (Integer) sizeComboBox.getSelectedItem();@@ -462,10 +449,10 @@ class EnumEditorPanel extends JPanel {}private void vetoSizeChange(final int newLength, final int currentLength, final long badValue) {- SwingUtilities.invokeLater(() -> {+ Swing.runLater(() -> {setStatusMessage("Enum size of " + newLength + " cannot contain the value " + "0x" +Long.toHexString(badValue));- sizeComboBox.setSelectedItem(new Integer(currentLength));+ sizeComboBox.setSelectedItem(Integer.valueOf(currentLength));});}@@ -488,8 +475,8 @@ class EnumEditorPanel extends JPanel {categoryField.setText(provider.getCategoryText());}- private void focus(final JTextField field) {- SwingUtilities.invokeLater(() -> {+ private void focus(JTextField field) {+ Swing.runLater(() -> {field.requestFocusInWindow();field.selectAll();});@@ -497,7 +484,7 @@ class EnumEditorPanel extends JPanel {//==================================================================================================// Inner Classes-//==================================================================================================+//==================================================================================================private class EnumTable extends GhidraTable {EnumTable(TableModel model) {@@ -551,7 +538,6 @@ class EnumEditorPanel extends JPanel {private KeyListener editingKeyListener = new KeyAdapter() {@Overridepublic void keyPressed(KeyEvent e) {- int keycode = e.getKeyCode();if (!table.isEditing()) {return;@@ -559,10 +545,9 @@ class EnumEditorPanel extends JPanel {int row = table.getEditingRow();int col = table.getEditingColumn();-int rowCount = table.getRowCount();int columnCount = table.getColumnCount();-+ int keycode = e.getKeyCode();switch (keycode) {case KeyEvent.VK_TAB:if (e.isShiftDown()) {@@ -600,10 +585,20 @@ class EnumEditorPanel extends JPanel {e.consume();+ scrollToCell(row, col);table.setRowSelectionInterval(row, row);table.editCellAt(row, col);}};++ private void scrollToCell(int row, int col) {+ if (table.getAutoscrolls()) {+ Rectangle cellRect = table.getCellRect(row, col, false);+ if (cellRect != null) {+ table.scrollRectToVisible(cellRect);+ }+ }+ }}private class EnumStringCellEditor extends EnumCellEditor {@@ -620,8 +615,4 @@ class EnumEditorPanel extends JPanel {f.addValidationMessageListener(new StatusBarValidationMessageListener());}}-- private class EnumCellRenderer extends GTableCellRenderer {- // Might just be kruft, now...- }}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/editor/EnumTableModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/editor/EnumTableModel.javaindex 3fc52763c6..b2fb89bcd0 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/editor/EnumTableModel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/editor/EnumTableModel.java@@ -237,10 +237,6 @@ class EnumTableModel extends AbstractSortedTableModel<EnumEntry> {initialize();}- /**- * Add a new enum entry that has default values.- * @return the new value- */int addEntry(int afterRow) {Long value = findNextValue(afterRow);String name = getUniqueName();