Ghidra is a software reverse engineering (SRE) framework
GT-3222 - review fixes
dragonmacher0db920564525
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/NextPreviousDataTypeAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/NextPreviousDataTypeAction.javaindex 1ea3dd6d4d..16947fe771 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/NextPreviousDataTypeAction.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/NextPreviousDataTypeAction.java@@ -66,22 +66,17 @@ class NextPreviousDataTypeAction extends MultiActionDockingAction {@Overridepublic void actionPerformed(ActionContext context) {- if (isNext) {- history.goForward();- }- else {- history.goBack();- }+ // rely on the individual actions to navigate, as they know them item that is being+ // navigated to, allowing them to skip through the list+ List<DockingActionIf> actions = getActionList(context);+ DockingActionIf action = actions.get(0);+ action.actionPerformed(context);provider.contextChanged();}@Overridepublic boolean isEnabledForContext(ActionContext context) {-- if (isNext) {- return history.hasNext();- }- return history.hasPrevious();+ return !getActionList(context).isEmpty();}@Override@@ -111,7 +106,7 @@ class NextPreviousDataTypeAction extends MultiActionDockingAction {results.add(createHorizontalRule(lastDtm, dtm));}- results.add(new NavigationAction(dt.getDisplayName()));+ results.add(new NavigationAction(url, dt));lastDtm = dtm;}@@ -129,21 +124,28 @@ class NextPreviousDataTypeAction extends MultiActionDockingAction {private class NavigationAction extends DockingAction {- private NavigationAction(String dtDisplayName) {+ private DataTypeUrl url;++ private NavigationAction(DataTypeUrl url, DataType dt) {super("DataTypeNavigationAction_" + ++navigationActionIdCount, owner);+ this.url = url;- setMenuBarData(new MenuData(new String[] { dtDisplayName }));+ setMenuBarData(new MenuData(new String[] { dt.getDisplayName() }));setEnabled(true);setHelpLocation(new HelpLocation("DataTypeManagerPlugin", "Navigation_Actions"));}@Overridepublic void actionPerformed(ActionContext context) {++ // note: we use 'goBackTo()' and 'goForwardTo()' since items in the history list+ // may not have been added to the multi-action; we have to tell the list+ // to skip those items.if (isNext) {- history.goForward();+ history.goForwardTo(url);}else {- history.goBack();+ history.goBackTo(url);}provider.contextChanged();}diff --git a/Ghidra/Framework/Generic/src/main/java/util/HistoryList.java b/Ghidra/Framework/Generic/src/main/java/util/HistoryList.javaindex e8488e8627..428efd385a 100644--- a/Ghidra/Framework/Generic/src/main/java/util/HistoryList.java+++ b/Ghidra/Framework/Generic/src/main/java/util/HistoryList.java@@ -175,6 +175,18 @@ public class HistoryList<T> {broadcast(t);}+ /**+ * Performs a {@link #goBack()} until the given item becomes the current item. This is+ * useful if you wish to go backward to a specific item in the list.+ *+ * @param t the item+ */+ public void goBackTo(T t) {+ while (!getCurrentHistoryItem().equals(t) && hasPrevious()) {+ goBack();+ }+ }+/*** Moves this history list's current item pointer forward one and then calls the user-provided* callback to signal the newly selected item.@@ -190,6 +202,18 @@ public class HistoryList<T> {broadcast(t);}+ /**+ * Performs a {@link #goForward()} until the given item becomes the current item. This is+ * useful if you wish to go forward to a specific item in the list.+ *+ * @param t the item+ */+ public void goForwardTo(T t) {+ while (!getCurrentHistoryItem().equals(t) && hasNext()) {+ goForward();+ }+ }+/*** Returns the item currently pointed to within the list of items. When an item is* added, this will be that item. Otherwise, it will be the last item navigated.diff --git a/Ghidra/Framework/Generic/src/test/java/util/HistoryListTest.java b/Ghidra/Framework/Generic/src/test/java/util/HistoryListTest.javaindex 05b6b51609..97fb3900b3 100644--- a/Ghidra/Framework/Generic/src/test/java/util/HistoryListTest.java+++ b/Ghidra/Framework/Generic/src/test/java/util/HistoryListTest.java@@ -15,7 +15,7 @@*/package util;-import static org.hamcrest.CoreMatchers.is;+import static org.hamcrest.CoreMatchers.*;import static org.junit.Assert.*;import java.util.LinkedList;@@ -425,6 +425,32 @@ public class HistoryListTest {assertNextItems();}+ @Test+ public void testBackToItem() {++ addHistory(A);+ addHistory(B);+ addHistory(C);++ historyList.goBackTo(A);+ assertCurrentItem(A);+ }++ @Test+ public void testForwardToItem() {++ addHistory(A);+ addHistory(B);+ addHistory(C);+ goBack();+ goBack();+ goBack();+ assertCurrentItem(A);++ historyList.goForwardTo(C);+ assertCurrentItem(C);+ }+//==================================================================================================// Private Methods//==================================================================================================