Ghidra is a software reverse engineering (SRE) framework
Tests - fixed bug in GTable auto-lookup feature
dragonmacher8d6b857a5fc7
diff --git a/Ghidra/Features/Base/src/test.slow/java/docking/widgets/table/GTableTest.java b/Ghidra/Features/Base/src/test.slow/java/docking/widgets/table/GTableTest.javaindex 79e4213510..b8112d6644 100644--- a/Ghidra/Features/Base/src/test.slow/java/docking/widgets/table/GTableTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/docking/widgets/table/GTableTest.java@@ -15,7 +15,7 @@*/package docking.widgets.table;-import static org.junit.Assert.assertEquals;+import static org.junit.Assert.*;import java.awt.BorderLayout;@@ -36,7 +36,6 @@ public class GTableTest extends AbstractGhidraHeadedIntegrationTest {public void setUp() throws Exception {model = new TestDataModel();table = new GhidraTable(model);- table.setAutoLookupColumn(4);frame = new JFrame("Ghidra Table Test");frame.getContentPane().setLayout(new BorderLayout());@@ -52,6 +51,9 @@ public class GTableTest extends AbstractGhidraHeadedIntegrationTest {@Testpublic void testAutoLookup() throws Exception {++ table.setAutoLookupColumn(4);+setSelectedRow(table, 0);triggerText(table, "a");@@ -72,6 +74,44 @@ public class GTableTest extends AbstractGhidraHeadedIntegrationTest {assertEquals(11, table.getSelectedRow());}+ @Test+ public void testSetActionsEnabled() throws Exception {++ table.setAutoLookupColumn(4);+ assertFalse(table.areActionsEnabled());+ setSelectedRow(table, 0);++ triggerText(table, "a");+ assertEquals("Auto-lookup failed to change the table row", 11, table.getSelectedRow());++ // this will disable 'auto lookup'+ table.setActionsEnabled(true);+ setSelectedRow(table, 0);++ triggerText(table, "a");+ assertEquals("Auto-lookup should be disabled when actions are enabled", 0,+ table.getSelectedRow());++ table.setActionsEnabled(false);+ setSelectedRow(table, 0);++ triggerText(table, "a");+ assertEquals("Auto-lookup failed to change the table row", 11, table.getSelectedRow());++ table.setActionsEnabled(true);+ setSelectedRow(table, 0);++ triggerText(table, "a");+ assertEquals("Auto-lookup should be disabled when actions are enabled", 0,+ table.getSelectedRow());++ table.setAutoLookupColumn(4);+ setSelectedRow(table, 0);++ triggerText(table, "a");+ assertEquals("Auto-lookup failed to change the table row", 11, table.getSelectedRow());+ }+private void timeout() throws InterruptedException {Thread.sleep(GTable.KEY_TIMEOUT * 2);}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.javaindex a1b37ef984..174e65c954 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@@ -84,7 +84,7 @@ public class GTable extends JTable {private int userDefinedRowHeight;private boolean isInitialized;- private boolean allowActions;+ private boolean enableActionKeyBindings;private KeyListener autoLookupListener;private long lastLookupTime;private String lookupString;@@ -386,6 +386,11 @@ public class GTable extends JTable {/*** Sets the column in which auto-lookup will be enabled.+ *+ * <p>Note: calling this method with a valid column index will disable key binding support+ * of actions. See {@link #setActionsEnabled(boolean)}. Passing an invalid column index+ * will disable the auto-lookup feature.+ ** @param lookupColumn the column in which auto-lookup will be enabled*/public void setAutoLookupColumn(int lookupColumn) {@@ -395,7 +400,8 @@ public class GTable extends JTable {autoLookupListener = new KeyAdapter() {@Overridepublic void keyPressed(KeyEvent e) {- if (!allowActions) {+ if (enableActionKeyBindings) {+ // actions will consume key bindings, so don't process themreturn;}@@ -428,6 +434,7 @@ public class GTable extends JTable {if (lookupColumn >= 0 && lookupColumn < getModel().getColumnCount()) {addKeyListener(autoLookupListener);+ enableActionKeyBindings = false;}else {removeKeyListener(autoLookupListener);@@ -471,7 +478,22 @@ public class GTable extends JTable {* @param b true allows keyboard actions to pass up the component hierarchy.*/public void setActionsEnabled(boolean b) {- allowActions = b;+ enableActionKeyBindings = b;+ }++ /**+ * Returns true if key strokes are used to trigger actions.+ *+ * <p>This method has a relationship with {@link #setAutoLookupColumn(int)}. If this method+ * returns <code>true</code>, then the auto-lookup feature is disabled. If this method+ * returns <code>false</code>, then the auto-lookup may or may not be enabled.+ *+ * @return true if key strokes are used to trigger actions+ * @see #setActionsEnabled(boolean)+ * @see #setAutoLookupColumn(int)+ */+ public boolean areActionsEnabled() {+ return enableActionKeyBindings;}/**