Merge remote-tracking branch 'origin/GP-0-dragonmacher-test-fixes-10-12-24'

This commit is contained in:
Ryan Kurtz 2024-10-15 07:24:29 -04:00
commit ddf1efd486
6 changed files with 46 additions and 37 deletions

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -30,6 +30,7 @@ import javax.swing.tree.TreePath;
import org.junit.*; import org.junit.*;
import docking.KeyEntryPanel;
import docking.action.DockingActionIf; import docking.action.DockingActionIf;
import docking.actions.KeyBindingUtils; import docking.actions.KeyBindingUtils;
import docking.options.editor.OptionsDialog; import docking.options.editor.OptionsDialog;
@ -429,7 +430,11 @@ public class KeyBindingUtilsTest extends AbstractGhidraHeadedIntegrationTest {
panel = (KeyBindingsPanel) getEditorPanel(keyBindingsNode, optionsDialog); panel = (KeyBindingsPanel) getEditorPanel(keyBindingsNode, optionsDialog);
table = findComponent(panel, JTable.class); table = findComponent(panel, JTable.class);
Object actionBindingPanel = getInstanceField("actionBindingPanel", panel); Object actionBindingPanel = getInstanceField("actionBindingPanel", panel);
keyField = (JTextField) getInstanceField("keyEntryField", actionBindingPanel);
KeyEntryPanel keyEntryPanel =
(KeyEntryPanel) getInstanceField("keyEntryPanel", actionBindingPanel);
keyField = keyEntryPanel.getTextField();
model = table.getModel(); model = table.getModel();
debug("ff"); debug("ff");

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -94,8 +94,7 @@ public class KeyBindingsTest extends AbstractGhidraHeadedIntegrationTest {
// look for the info panel // look for the info panel
MultiLineLabel label = findComponent(panel, MultiLineLabel.class); MultiLineLabel label = findComponent(panel, MultiLineLabel.class);
String str = "To add or change a key binding, select an action\n" + String str = "To add or change a key binding, select an action\n" +
"and type any key combination\n" + " \n" + "and type any key combination.";
"To remove a key binding, select an action and\n" + "press <Enter> or <Backspace>";
assertEquals(str, label.getLabel()); assertEquals(str, label.getLabel());
@ -239,18 +238,7 @@ public class KeyBindingsTest extends AbstractGhidraHeadedIntegrationTest {
selectRowForAction(action1); selectRowForAction(action1);
typeKeyStroke(KeyEvent.VK_ENTER); pressButtonByName(panel, "Clear Key Binding");
assertNoKeyStrokeText();
apply();
assertNull(getKeyStroke(action1));
}
@Test
public void testClearKeyBinding2() throws Exception {
selectRowForAction(action1);
typeBackspace();
assertNoKeyStrokeText(); assertNoKeyStrokeText();
apply(); apply();
@ -290,7 +278,6 @@ public class KeyBindingsTest extends AbstractGhidraHeadedIntegrationTest {
selectRowForAction(action1); selectRowForAction(action1);
typeKeyStroke(reservedKeystroke); typeKeyStroke(reservedKeystroke);
assertNoKeyStrokeText(); assertNoKeyStrokeText();
assertMessage("F4 in use by System action 'Set KeyBinding'"); assertMessage("F4 in use by System action 'Set KeyBinding'");
@ -313,7 +300,7 @@ public class KeyBindingsTest extends AbstractGhidraHeadedIntegrationTest {
selectRowForAction(action1); selectRowForAction(action1);
assertEquals(validKeyStroke, getKeyStroke(action1)); assertEquals(validKeyStroke, getKeyStroke(action1));
typeKeyStroke(reservedKeystroke.getKeyCode()); typeKeyStroke(reservedKeystroke);
assertNoKeyStrokeText(); assertNoKeyStrokeText();
assertMessage("F4 in use by System action 'Set KeyBinding'"); assertMessage("F4 in use by System action 'Set KeyBinding'");
@ -384,7 +371,7 @@ public class KeyBindingsTest extends AbstractGhidraHeadedIntegrationTest {
assertMessage(systemKsText + " in use by System action 'Show Context Menu'"); assertMessage(systemKsText + " in use by System action 'Show Context Menu'");
selectRowForAction(systemAction); selectRowForAction(systemAction);
typeBackspace(); pressButtonByName(panel, "Clear Key Binding");
apply(); apply();
assertEquals(null, getKeyStroke(systemAction)); assertEquals(null, getKeyStroke(systemAction));
@ -422,11 +409,6 @@ public class KeyBindingsTest extends AbstractGhidraHeadedIntegrationTest {
assertMessage(""); assertMessage("");
} }
private void typeBackspace() {
triggerBackspaceKey(keyField);
waitForSwing();
}
private void typeKeyStroke(KeyStroke ks) { private void typeKeyStroke(KeyStroke ks) {
triggerKey(keyField, ks); triggerKey(keyField, ks);
waitForSwing(); waitForSwing();

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -36,6 +36,7 @@ import org.apache.commons.lang3.StringUtils;
import org.junit.*; import org.junit.*;
import docking.DialogComponentProvider; import docking.DialogComponentProvider;
import docking.KeyEntryPanel;
import docking.action.DockingActionIf; import docking.action.DockingActionIf;
import docking.actions.KeyBindingUtils; import docking.actions.KeyBindingUtils;
import docking.options.editor.*; import docking.options.editor.*;
@ -1010,7 +1011,9 @@ public class OptionsDialogTest extends AbstractGhidraHeadedIntegrationTest {
setToggleButtonSelected(panel, "Enter Mouse Binding", false); setToggleButtonSelected(panel, "Enter Mouse Binding", false);
JPanel actionBindingPanel = (JPanel) getInstanceField("actionBindingPanel", panel); JPanel actionBindingPanel = (JPanel) getInstanceField("actionBindingPanel", panel);
JTextField textField = (JTextField) getInstanceField("keyEntryField", actionBindingPanel); KeyEntryPanel keyEntryPanel =
(KeyEntryPanel) getInstanceField("keyEntryPanel", actionBindingPanel);
JTextField textField = keyEntryPanel.getTextField();
triggerKey(textField, modifiers, keyCode, keyChar); triggerKey(textField, modifiers, keyCode, keyChar);
waitForSwing(); waitForSwing();
@ -1030,10 +1033,7 @@ public class OptionsDialogTest extends AbstractGhidraHeadedIntegrationTest {
setToggleButtonSelected(panel, "Enter Mouse Binding", false); setToggleButtonSelected(panel, "Enter Mouse Binding", false);
JPanel actionBindingPanel = (JPanel) getInstanceField("actionBindingPanel", panel); pressButtonByName(panel, "Clear Key Binding");
JTextField textField = (JTextField) getInstanceField("keyEntryField", actionBindingPanel);
triggerBackspaceKey(textField);
waitForSwing(); waitForSwing();
KeyStroke currentBinding = getKeyBindingFromTable(actionName, actionOwner); KeyStroke currentBinding = getKeyBindingFromTable(actionName, actionOwner);

View File

@ -42,14 +42,22 @@ public class KeyEntryPanel extends JPanel {
keyEntryField = new KeyEntryTextField(columns, listener); keyEntryField = new KeyEntryTextField(columns, listener);
clearButton = new EmptyBorderButton(Icons.DELETE_ICON); clearButton = new EmptyBorderButton(Icons.DELETE_ICON);
clearButton.setToolTipText("Clear the current key binding"); clearButton.setName("Clear Key Binding");
clearButton.addActionListener(e -> keyEntryField.clearField()); clearButton.addActionListener(e -> keyEntryField.clearKeyStroke());
add(keyEntryField); add(keyEntryField);
add(Box.createHorizontalStrut(2)); add(Box.createHorizontalStrut(2));
add(clearButton); add(clearButton);
} }
/**
* Returns the text field used by this class
* @return the text field
*/
public JTextField getTextField() {
return keyEntryField;
}
/** /**
* Sets the key stroke on this panel * Sets the key stroke on this panel
* @param ks the key stroke * @param ks the key stroke

View File

@ -81,7 +81,21 @@ public class KeyEntryTextField extends HintTextField {
setText(KeyBindingUtils.parseKeyStroke(ks)); setText(KeyBindingUtils.parseKeyStroke(ks));
} }
/**
* Clears the state of this class, but does not notify listeners. This allows clients to
* control the state of the field without having a callback change the client state.
*/
public void clearField() { public void clearField() {
ksName = null;
setText("");
currentKeyStroke = null;
}
/**
* Clears the state of this class and notifies this client. This effectively allows for the
* programmatic setting of the keystroke in use to be null, or in the 'no keystroke set' state.
*/
public void clearKeyStroke() {
if (currentKeyStroke == null) { if (currentKeyStroke == null) {
return; return;
} }

View File

@ -455,8 +455,8 @@ public class KeyBindingsPanel extends JPanel {
ToolActions toolActions = (ToolActions) tool.getToolActions(); ToolActions toolActions = (ToolActions) tool.getToolActions();
String errorMessage = toolActions.validateActionKeyBinding(action, ks); String errorMessage = toolActions.validateActionKeyBinding(action, ks);
if (errorMessage != null) { if (errorMessage != null) {
statusLabel.setText(errorMessage);
actionBindingPanel.clearKeyStroke(); actionBindingPanel.clearKeyStroke();
statusLabel.setText(errorMessage);
return; return;
} }