diff --git a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/export/ExportAttributedGraphDisplay.java b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/export/ExportAttributedGraphDisplay.java index 68ca10a558..23c3b9ca23 100644 --- a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/export/ExportAttributedGraphDisplay.java +++ b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/export/ExportAttributedGraphDisplay.java @@ -111,6 +111,11 @@ class ExportAttributedGraphDisplay implements GraphDisplay { // do nothing, actions are not supported by this display } + @Override + public Collection getActions() { + return Collections.emptyList(); + } + @Override public AttributedVertex getFocusedVertex() { return null; diff --git a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplay.java b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplay.java index c8a8657a3f..3d8786cafe 100644 --- a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplay.java +++ b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplay.java @@ -601,7 +601,7 @@ public class DefaultGraphDisplay implements GraphDisplay { display.setGraph(createSubGraph(), graphRenderer.getGraphDisplayOptions(), title + " - Sub-graph", false, TaskMonitor.DUMMY); display.setGraphDisplayListener(listener.cloneWith(display)); - copyActionsToNewGraph((DefaultGraphDisplay) display); + copyActionsToNewGraph(display); } catch (CancelledException e) { // using Dummy, so can't happen @@ -1277,10 +1277,11 @@ public class DefaultGraphDisplay implements GraphDisplay { return vv; } - private void copyActionsToNewGraph(DefaultGraphDisplay display) { + private void copyActionsToNewGraph(GraphDisplay display) { + Collection defaultActions = display.getActions(); for (DockingActionIf action : addedActions) { - if (display.containsAction(action)) { + if (defaultActions.contains(action)) { // ignore actions added by the graph itself and any actions that the end user may // accidentally add more than once continue; @@ -1288,7 +1289,6 @@ public class DefaultGraphDisplay implements GraphDisplay { display.addAction(new DockingActionProxy(action)); } - } private boolean containsAction(DockingActionIf action) { @@ -1314,6 +1314,11 @@ public class DefaultGraphDisplay implements GraphDisplay { componentProvider.addLocalAction(action); } + @Override + public Collection getActions() { + return new ArrayList<>(addedActions); + } + @Override public AttributedVertex getFocusedVertex() { return focusedVertex; diff --git a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplayWrapper.java b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplayWrapper.java index 9584442d5c..47a1d9d710 100644 --- a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplayWrapper.java +++ b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplayWrapper.java @@ -15,6 +15,7 @@ */ package ghidra.graph.visualization; +import java.util.Collection; import java.util.Set; import docking.action.DockingActionIf; @@ -108,6 +109,11 @@ public class DefaultGraphDisplayWrapper Swing.runNow(() -> delegate.addAction(action)); } + @Override + public Collection getActions() { + return Swing.runNow(() -> delegate.getActions()); + } + @Override public int compareTo(DefaultGraphDisplayWrapper other) { // note: no need for call to Swing, assuming ID is immutable diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/service/graph/GraphDisplay.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/service/graph/GraphDisplay.java index 8ec8389db4..a654c1a10a 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/service/graph/GraphDisplay.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/service/graph/GraphDisplay.java @@ -15,6 +15,7 @@ */ package ghidra.service.graph; +import java.util.Collection; import java.util.Set; import docking.action.DockingActionIf; @@ -147,4 +148,11 @@ public interface GraphDisplay { * @param action the action to add */ public void addAction(DockingActionIf action); + + /** + * Gets all actions that have been added to this graph display. If this display does not + * support actions, then an empty collection will be returned. + * @return the actions + */ + public Collection getActions(); } diff --git a/Ghidra/Test/IntegrationTest/src/test/java/ghidra/graph/TestGraphDisplay.java b/Ghidra/Test/IntegrationTest/src/test/java/ghidra/graph/TestGraphDisplay.java index 0535f15e05..0add0a67b4 100644 --- a/Ghidra/Test/IntegrationTest/src/test/java/ghidra/graph/TestGraphDisplay.java +++ b/Ghidra/Test/IntegrationTest/src/test/java/ghidra/graph/TestGraphDisplay.java @@ -15,8 +15,7 @@ */ package ghidra.graph; -import java.util.Map; -import java.util.Set; +import java.util.*; import docking.action.DockingActionIf; import docking.widgets.EventTrigger; @@ -62,8 +61,7 @@ public class TestGraphDisplay implements GraphDisplay { } @Override - public void setGraph(AttributedGraph graph, String title, boolean append, - TaskMonitor monitor) + public void setGraph(AttributedGraph graph, String title, boolean append, TaskMonitor monitor) throws CancelledException { if (append) { this.graph = mergeGraphs(graph, this.graph); @@ -113,6 +111,11 @@ public class TestGraphDisplay implements GraphDisplay { // do nothing, actions are not supported by this display } + @Override + public Collection getActions() { + return Collections.emptyList(); + } + private AttributedGraph mergeGraphs(AttributedGraph newGraph, AttributedGraph oldGraph) { for (AttributedVertex vertex : oldGraph.vertexSet()) { newGraph.addVertex(vertex);