Skip to content

Ghidra is a software reverse engineering (SRE) framework

Test fixes; Revert of mouse listener fix for 11.4

dragonmacher68bc9c810984
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/FunctionTagProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/FunctionTagProvider.java
index 97c8505c05..7ea44ac393 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/FunctionTagProvider.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/FunctionTagProvider.java
@@ -126,8 +126,6 @@ public class FunctionTagProvider extends ComponentProviderAdapter implements Dom
createActions();
}
-
-
@Override
public void componentShown() {
updateView();
@@ -445,7 +443,7 @@ public class FunctionTagProvider extends ComponentProviderAdapter implements Dom
dropped.add(name);
}
else {
- Command cmd = new CreateFunctionTagCmd(name);
+ Command<Program> cmd = new CreateFunctionTagCmd(name);
tool.execute(cmd, program);
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/SourceTagsPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/SourceTagsPanel.java
index 00c9a7f44b..2834f8ae06 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/SourceTagsPanel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/SourceTagsPanel.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,8 +21,7 @@ import ghidra.app.cmd.function.AddFunctionTagCmd;
import ghidra.app.cmd.function.CreateFunctionTagCmd;
import ghidra.framework.cmd.Command;
import ghidra.framework.plugintool.PluginTool;
-import ghidra.program.model.listing.Function;
-import ghidra.program.model.listing.FunctionTag;
+import ghidra.program.model.listing.*;
/**
* List for displaying all tags in the programs
@@ -59,11 +58,11 @@ public class SourceTagsPanel extends TagListPanel {
// If the tag is one that has not yet been created (a temp tag), first create it,
// then add it to the function.
if (tag instanceof InMemoryFunctionTag) {
- Command cmd = new CreateFunctionTagCmd(tag.getName(), tag.getComment());
+ Command<Program> cmd = new CreateFunctionTagCmd(tag.getName(), tag.getComment());
tool.execute(cmd, program);
}
- Command cmd = new AddFunctionTagCmd(tag.getName(), function.getEntryPoint());
+ Command<Program> cmd = new AddFunctionTagCmd(tag.getName(), function.getEntryPoint());
tool.execute(cmd, program);
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/TagListPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/TagListPanel.java
index 7a133ff33c..ba415e366b 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/TagListPanel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/function/tags/TagListPanel.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -86,15 +86,13 @@ public abstract class TagListPanel extends JPanel {
table.setAccessibleNamePrefix(name);
filterPanel.setAccessibleNamePrefix(name);
- table.addMouseListener(new MouseAdapter() {
-
- @Override
- public void mousePressed(MouseEvent e) {
- // Click events aren't reliably captured for some reason,
- // but presses are, so this is the best way to ensure that
- // user selections are handled
+ table.getSelectionModel().addListSelectionListener(e -> {
+ if (!e.getValueIsAdjusting()) {
provider.selectionChanged(TagListPanel.this);
}
+ });
+
+ table.addMouseListener(new MouseAdapter() {
// Handles the double-click event on table rows, which will bring up
// a dialog for editing the tag name and/or comment.
@@ -173,14 +171,14 @@ public abstract class TagListPanel extends JPanel {
// Only process the name edit if the name actually changed.
if (!newName.equals(tagName)) {
- Command cmd =
+ Command<Program> cmd =
new ChangeFunctionTagCmd(tagName, newName, ChangeFunctionTagCmd.TAG_NAME_CHANGED);
tool.execute(cmd, program);
}
// Only process the comment edit if the comment actually changed.
if (!newComment.equals(comment)) {
- Command cmd = new ChangeFunctionTagCmd(tagName, newComment,
+ Command<Program> cmd = new ChangeFunctionTagCmd(tagName, newComment,
ChangeFunctionTagCmd.TAG_COMMENT_CHANGED);
tool.execute(cmd, program);
}
@@ -259,7 +257,7 @@ public abstract class TagListPanel extends JPanel {
if (option == OptionDialog.OPTION_ONE) {
for (FunctionTag tag : selectedTags) {
- Command cmd = new DeleteFunctionTagCmd(tag.getName());
+ Command<Program> cmd = new DeleteFunctionTagCmd(tag.getName());
tool.execute(cmd, program);
}
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/tags/FunctionTagPluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/tags/FunctionTagPluginTest.java
index f23d03240f..37814dff44 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/tags/FunctionTagPluginTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/function/tags/FunctionTagPluginTest.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -401,15 +401,15 @@ public class FunctionTagPluginTest extends AbstractGhidraHeadedIntegrationTest {
goTo(tool, program, addr("00000000"));
FunctionTagTable table = getSourceTable();
selectTagInTable(tagName1, table);
- int index = table.getSelectedRow();
- table.addRowSelectionInterval(index, index + 1);
- clickTableRange(table, index, 2);
+ int row = table.getSelectedRow();
+ table.addRowSelectionInterval(row, row + 1);
+ clickTableRange(table, row, 2);
waitForTableModel(functionsPanel.getTableModel());
// Verify that all 3 functions are in the function panel
functions = functionsPanel.getFunctions();
- assertTrue(functions.size() == 3);
+ assertEquals(3, functions.size());
Function f1 = functions.get(0);
Function f2 = functions.get(1);
Function f3 = functions.get(2);
diff --git a/Ghidra/Features/GnuDemangler/src/main/java/ghidra/app/util/demangler/gnu/GnuDemanglerParser.java b/Ghidra/Features/GnuDemangler/src/main/java/ghidra/app/util/demangler/gnu/GnuDemanglerParser.java
index e304bc85c2..63798aef8a 100644
--- a/Ghidra/Features/GnuDemangler/src/main/java/ghidra/app/util/demangler/gnu/GnuDemanglerParser.java
+++ b/Ghidra/Features/GnuDemangler/src/main/java/ghidra/app/util/demangler/gnu/GnuDemanglerParser.java
@@ -1778,8 +1778,8 @@ public class GnuDemanglerParser {
Matcher arrayMatcher = ARRAY_DATA_PATTERN.matcher(type);
if (arrayMatcher.matches()) {
// keep only the type information, dropping the array definition
- type = arrayMatcher.group(1);
- arrayType = arrayMatcher.group(2).trim();
+ this.type = arrayMatcher.group(1);
+ this.arrayType = arrayMatcher.group(2).trim();
}
}
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/DockableComponent.java b/Ghidra/Framework/Docking/src/main/java/docking/DockableComponent.java
index 5638d3790f..826f4456d5 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/DockableComponent.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/DockableComponent.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,7 +18,6 @@ package docking;
import java.awt.*;
import java.awt.dnd.*;
import java.awt.event.*;
-import java.util.List;
import javax.swing.*;
@@ -26,7 +25,6 @@ import docking.action.DockingActionIf;
import ghidra.util.CascadedDropTarget;
import ghidra.util.HelpLocation;
import help.HelpService;
-import util.CollectionUtils;
/**
* Wrapper class for user components. Adds the title, local toolbar and provides the drag target
@@ -152,10 +150,6 @@ public class DockableComponent extends JPanel implements ContainerListener {
return;
}
- if (!e.isPopupTrigger()) {
- return;
- }
-
Component component = e.getComponent();
if (component == null) {
return; // not sure this can happen
@@ -168,13 +162,11 @@ public class DockableComponent extends JPanel implements ContainerListener {
}
Point point = e.getPoint();
- if (!bounds.contains(point)) {
- return;
+ boolean withinBounds = bounds.contains(point);
+ if (e.isPopupTrigger() && withinBounds) {
+ PopupMenuContext popupContext = new PopupMenuContext(e);
+ actionMgr.showPopupMenu(placeholder, popupContext);
}
-
- e.consume();
- PopupMenuContext popupContext = new PopupMenuContext(e);
- actionMgr.showPopupMenu(placeholder, popupContext);
}
@Override
@@ -336,46 +328,11 @@ public class DockableComponent extends JPanel implements ContainerListener {
}
if (comp.isFocusable()) {
- installPopupListener(comp);
+ comp.removeMouseListener(popupListener);
+ comp.addMouseListener(popupListener);
}
}
- /**
- * Remove, reorder and re-add all mouse listeners so Java listeners go last. This allows our
- * popup listener to consume the event, preventing Java UI listeners from changing the table
- * selection when the user is performing a Ctrl-Mouse click on the Mac.
- *
- * @param comp the component
- */
- private void installPopupListener(Component comp) {
-
- // remove and add the listeners according to the sorted order so that will be installed as
- // they are ordered in the list
- List<MouseListener> listeners = createOrderedListeners(comp);
- for (MouseListener l : listeners) {
- comp.removeMouseListener(l);
- comp.addMouseListener(l);
- }
- }
-
- private List<MouseListener> createOrderedListeners(Component comp) {
-
- // Get the current listeners, add the popup mouse listener for this class, then move any
- // Java listeners to the back of the list by removing them and re-adding them.
- MouseListener[] listeners = comp.getMouseListeners();
- List<MouseListener> orderedListeners = CollectionUtils.asList(listeners);
- orderedListeners.add(popupListener);
- for (MouseListener l : listeners) {
- String name = l.getClass().getName();
- if (name.startsWith("javax.") || name.startsWith("sun.")) {
- orderedListeners.remove(l);
- orderedListeners.add(l);
- }
- }
-
- return orderedListeners;
- }
-
private void deinitializeComponents(Component comp) {
if (comp instanceof CellRendererPane) {
return;