Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-1617 shift-click for Next/Prev Bookmark toolbar button

dev7473684a4aea7d64a2
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Navigation/Navigation.htm b/Ghidra/Features/Base/src/main/help/help/topics/Navigation/Navigation.htm
index feea3618cb..474889177a 100644
--- a/Ghidra/Features/Base/src/main/help/help/topics/Navigation/Navigation.htm
+++ b/Ghidra/Features/Base/src/main/help/help/topics/Navigation/Navigation.htm
@@ -2,12 +2,8 @@
<HTML>
<HEAD>
- <META name="generator" content=
- "HTML Tidy for Java (vers. 2009-12-01), see jtidy.sourceforge.net">
-
<TITLE>Navigation</TITLE>
<LINK rel="stylesheet" type="text/css" href="../../shared/Frontpage.css">
- <META name="generator" content="Microsoft FrontPage 4.0">
</HEAD>
<BODY>
@@ -416,6 +412,8 @@
"up_arrow" border="0"> icon indicates the search will be performed in the backward
(previous) direction. To change the direction of the code unit search, toggle the arrow
icon on the toolbar.</P>
+ <P>Alternatively, holding the <b>SHIFT</b> key when clicking a navigation button will
+ temporarily invert the direction of the search.</P>
</BLOCKQUOTE>
<H3><A name="Next_Instruction"></A>Navigate to Instruction</H3>
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/AbstractNextPreviousAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/AbstractNextPreviousAction.java
index a5c2e8e94f..ab491610ec 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/AbstractNextPreviousAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/AbstractNextPreviousAction.java
@@ -17,7 +17,8 @@ package ghidra.app.plugin.core.navigation;
import java.awt.event.ActionEvent;
-import javax.swing.*;
+import javax.swing.Icon;
+import javax.swing.KeyStroke;
import docking.action.KeyBindingData;
import docking.action.ToolBarData;
@@ -32,6 +33,7 @@ import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Program;
import ghidra.program.util.AddressFieldLocation;
import ghidra.util.HelpLocation;
+import ghidra.util.Swing;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.*;
@@ -74,21 +76,15 @@ public abstract class AbstractNextPreviousAction extends NavigatableContextActio
try {
boolean direction = isForward;
- if ((context.getEventClickModifiers() & ActionEvent.SHIFT_MASK) != 0) {
+ if (context.hasAnyEventClickModifiers(ActionEvent.SHIFT_MASK)) {
direction = !direction;
}
- Address address =
- direction ? getNextAddress(monitor, context.getProgram(), context.getAddress())
- : getPreviousAddress(monitor, context.getProgram(), context.getAddress());
-
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- gotoAddress(context, address);
- }
- });
+ Address address = direction
+ ? getNextAddress(monitor, context.getProgram(), context.getAddress())
+ : getPreviousAddress(monitor, context.getProgram(), context.getAddress());
+ Swing.runLater(() -> gotoAddress(context, address));
}
catch (CancelledException e) {
// cancelled
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousBookmarkAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousBookmarkAction.java
index e3ead7cc26..871443b3e3 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousBookmarkAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/NextPreviousBookmarkAction.java
@@ -15,11 +15,12 @@
*/
package ghidra.app.plugin.core.navigation;
-import java.awt.event.InputEvent;
-import java.awt.event.KeyEvent;
import java.util.Iterator;
-import javax.swing.*;
+import java.awt.event.*;
+
+import javax.swing.ImageIcon;
+import javax.swing.KeyStroke;
import docking.ActionContext;
import docking.action.*;
@@ -37,6 +38,7 @@ import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.*;
import ghidra.util.HelpLocation;
+import ghidra.util.Swing;
import resources.ResourceManager;
public class NextPreviousBookmarkAction extends MultiStateDockingAction<String> {
@@ -197,16 +199,16 @@ public class NextPreviousBookmarkAction extends MultiStateDockingAction<String>
//==================================================================================================
private void gotoNextPrevious(final NavigatableActionContext context,
final String bookmarkType) {
- final Address address =
- isForward ? getNextAddress(context.getProgram(), context.getAddress(), bookmarkType)
- : getPreviousAddress(context.getProgram(), context.getAddress(), bookmarkType);
-
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- gotoAddress(context, address);
- }
- });
+ boolean direction = isForward;
+ if (context.hasAnyEventClickModifiers(ActionEvent.SHIFT_MASK)) {
+ direction = !direction;
+ }
+
+ Address address = direction
+ ? getNextAddress(context.getProgram(), context.getAddress(), bookmarkType)
+ : getPreviousAddress(context.getProgram(), context.getAddress(), bookmarkType);
+
+ Swing.runLater(() -> gotoAddress(context, address));
}
private void gotoAddress(NavigatableActionContext listingActionContext, Address address) {
@@ -234,6 +236,7 @@ public class NextPreviousBookmarkAction extends MultiStateDockingAction<String>
public String getToolTipText() {
String description = "Go To " + (isForward ? "Next" : "Previous");
description += " Bookmark: " + getCurrentState().getName();
+ description += " (shift-click inverts direction)";
return description;
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/NextPrevCodeUnitPluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/NextPrevCodeUnitPluginTest.java
index 112aca644b..8c36150c3a 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/NextPrevCodeUnitPluginTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/navigation/NextPrevCodeUnitPluginTest.java
@@ -15,7 +15,8 @@
*/
package ghidra.app.plugin.core.navigation;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.awt.Color;
@@ -118,54 +119,41 @@ public class NextPrevCodeUnitPluginTest extends AbstractGhidraHeadedIntegrationT
Icon downIcon = ResourceManager.loadImage("images/down.png");
assertEquals(downIcon, direction.getToolBarData().getIcon());
- assertEquals("Go To Next Instruction (shift-click inverts direction)",
- nextInst.getDescription());
- assertEquals("Go To Next Data (shift-click inverts direction)", nextData.getDescription());
- assertEquals("Go To Next Undefined (shift-click inverts direction)",
- nextUndef.getDescription());
- assertEquals("Go To Next Label (shift-click inverts direction)",
- nextLabel.getDescription());
- assertEquals("Go To Next Function (shift-click inverts direction)",
- nextFunc.getDescription());
- assertEquals("Go To Next Instruction Not In a Function (shift-click inverts direction)",
- nextNonFunc.getDescription());
- assertEquals("Go To Next Bookmark: All Types",
- nextBookmark.getDescription());
+ assertStartsWith("Go To Next Instruction", nextInst.getDescription());
+ assertStartsWith("Go To Next Data", nextData.getDescription());
+ assertStartsWith("Go To Next Undefined", nextUndef.getDescription());
+ assertStartsWith("Go To Next Label", nextLabel.getDescription());
+ assertStartsWith("Go To Next Function", nextFunc.getDescription());
+ assertStartsWith("Go To Next Instruction Not In a Function", nextNonFunc.getDescription());
+ assertStartsWith("Go To Next Bookmark: All Types", nextBookmark.getDescription());
performAction(direction, cb.getProvider(), true);
assertEquals(upIcon, direction.getToolBarData().getIcon());
- assertEquals("Go To Previous Instruction (shift-click inverts direction)",
- nextInst.getDescription());
- assertEquals("Go To Previous Data (shift-click inverts direction)",
- nextData.getDescription());
- assertEquals("Go To Previous Undefined (shift-click inverts direction)",
- nextUndef.getDescription());
- assertEquals("Go To Previous Label (shift-click inverts direction)",
- nextLabel.getDescription());
- assertEquals("Go To Previous Function (shift-click inverts direction)",
- nextFunc.getDescription());
- assertEquals("Go To Previous Instruction Not In a Function (shift-click inverts direction)",
+ assertStartsWith("Go To Previous Instruction", nextInst.getDescription());
+ assertStartsWith("Go To Previous Data", nextData.getDescription());
+ assertStartsWith("Go To Previous Undefined", nextUndef.getDescription());
+ assertStartsWith("Go To Previous Label", nextLabel.getDescription());
+ assertStartsWith("Go To Previous Function", nextFunc.getDescription());
+ assertStartsWith("Go To Previous Instruction Not In a Function",
nextNonFunc.getDescription());
- assertEquals("Go To Previous Bookmark: All Types",
- nextBookmark.getDescription());
+ assertStartsWith("Go To Previous Bookmark: All Types", nextBookmark.getDescription());
performAction(direction, cb.getProvider(), true);
assertEquals(downIcon, direction.getToolBarData().getIcon());
- assertEquals("Go To Next Instruction (shift-click inverts direction)",
- nextInst.getDescription());
- assertEquals("Go To Next Data (shift-click inverts direction)", nextData.getDescription());
- assertEquals("Go To Next Undefined (shift-click inverts direction)",
- nextUndef.getDescription());
- assertEquals("Go To Next Label (shift-click inverts direction)",
- nextLabel.getDescription());
- assertEquals("Go To Next Function (shift-click inverts direction)",
- nextFunc.getDescription());
- assertEquals("Go To Next Instruction Not In a Function (shift-click inverts direction)",
- nextNonFunc.getDescription());
- assertEquals("Go To Next Bookmark: All Types",
- nextBookmark.getDescription());
+ assertStartsWith("Go To Next Instruction", nextInst.getDescription());
+ assertStartsWith("Go To Next Data", nextData.getDescription());
+ assertStartsWith("Go To Next Undefined", nextUndef.getDescription());
+ assertStartsWith("Go To Next Label", nextLabel.getDescription());
+ assertStartsWith("Go To Next Function", nextFunc.getDescription());
+ assertStartsWith("Go To Next Instruction Not In a Function", nextNonFunc.getDescription());
+ assertStartsWith("Go To Next Bookmark: All Types", nextBookmark.getDescription());
+ }
+
+ private static void assertStartsWith(String expected, String actual) {
+ assertTrue("startsWith expected: \"" + expected + "\", got: \"" + actual + "\"",
+ actual.startsWith(expected));
}
@Test
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/ActionContext.java b/Ghidra/Framework/Docking/src/main/java/docking/ActionContext.java
index bef6edff42..11acd73193 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/ActionContext.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/ActionContext.java
@@ -206,6 +206,17 @@ public class ActionContext {
return eventClickModifiers;
}
+ /**
+ * Tests the click modifiers for this event to see if they contain any bit from the
+ * specified modifiersMask parameter.
+ *
+ * @param modifiersMask bitmask to test
+ * @return boolean true if any bit in the eventClickModifiers matches the mask
+ */
+ public boolean hasAnyEventClickModifiers(int modifiersMask) {
+ return (eventClickModifiers & modifiersMask) != 0;
+ }
+
/**
* Sets the sourceObject for this ActionContext. This method is used internally by the
* DockingWindowManager. ComponentProvider and action developers should only use this