|
32 | 32 | import docking.ActionContext;
|
33 | 33 | import docking.action.DockingAction;
|
34 | 34 | import docking.action.MenuData;
|
| 35 | +import docking.action.builder.ActionBuilder; |
35 | 36 | import docking.tool.ToolConstants;
|
36 | 37 | import docking.widgets.fieldpanel.*;
|
37 | 38 | import docking.widgets.fieldpanel.field.Field;
|
38 | 39 | import docking.widgets.fieldpanel.support.*;
|
39 | 40 | import ghidra.GhidraOptions;
|
40 | 41 | import ghidra.app.CorePluginPackage;
|
| 42 | +import ghidra.app.context.ListingActionContext; |
41 | 43 | import ghidra.app.events.*;
|
42 | 44 | import ghidra.app.nav.Navigatable;
|
43 | 45 | import ghidra.app.plugin.PluginCategoryNames;
|
|
60 | 62 | import ghidra.framework.plugintool.util.PluginStatus;
|
61 | 63 | import ghidra.program.model.address.*;
|
62 | 64 | import ghidra.program.model.listing.*;
|
| 65 | +import ghidra.program.model.symbol.Reference; |
63 | 66 | import ghidra.program.util.ProgramLocation;
|
64 | 67 | import ghidra.program.util.ProgramSelection;
|
65 | 68 | import ghidra.util.*;
|
@@ -121,6 +124,8 @@ public class CodeBrowserPlugin extends Plugin
|
121 | 124 | private FocusingMouseListener focusingMouseListener = new FocusingMouseListener();
|
122 | 125 |
|
123 | 126 | private DockingAction tableFromSelectionAction;
|
| 127 | + private DockingAction showXrefsAction; |
| 128 | + |
124 | 129 | private Color cursorHighlightColor;
|
125 | 130 | private boolean isHighlightCursorLine;
|
126 | 131 | private ProgramDropProvider dndProvider;
|
@@ -440,6 +445,7 @@ void removeProvider(CodeViewerProvider provider) {
|
440 | 445 | public void serviceAdded(Class<?> interfaceClass, Object service) {
|
441 | 446 | if (interfaceClass == TableService.class) {
|
442 | 447 | tool.addAction(tableFromSelectionAction);
|
| 448 | + tool.addAction(showXrefsAction); |
443 | 449 | }
|
444 | 450 | if (interfaceClass == ViewManagerService.class && viewManager == null) {
|
445 | 451 | viewManager = (ViewManagerService) service;
|
@@ -471,6 +477,7 @@ public void serviceRemoved(Class<?> interfaceClass, Object service) {
|
471 | 477 | if (interfaceClass == TableService.class) {
|
472 | 478 | if (tool != null) {
|
473 | 479 | tool.removeAction(tableFromSelectionAction);
|
| 480 | + tool.removeAction(showXrefsAction); |
474 | 481 | }
|
475 | 482 | }
|
476 | 483 | if ((service == viewManager) && (currentProgram != null)) {
|
@@ -902,6 +909,9 @@ private void initMiscellaneousOptions() {
|
902 | 909 | }
|
903 | 910 |
|
904 | 911 | public void initActions() {
|
| 912 | + |
| 913 | + // note: these actions gets added later when the TableService is added |
| 914 | + |
905 | 915 | tableFromSelectionAction = new DockingAction("Create Table From Selection", getName()) {
|
906 | 916 | ImageIcon markerIcon = ResourceManager.loadImage("images/searchm_obj.gif");
|
907 | 917 |
|
@@ -932,13 +942,35 @@ public boolean isEnabledForContext(ActionContext context) {
|
932 | 942 | }
|
933 | 943 | };
|
934 | 944 |
|
935 |
| - // note: this action gets added later when the TableService is added |
936 | 945 | tableFromSelectionAction.setEnabled(false);
|
937 | 946 | tableFromSelectionAction.setMenuBarData(new MenuData(
|
938 | 947 | new String[] { ToolConstants.MENU_SELECTION, "Create Table From Selection" }, null,
|
939 | 948 | "SelectUtils"));
|
940 | 949 | tableFromSelectionAction
|
941 | 950 | .setHelpLocation(new HelpLocation("CodeBrowserPlugin", "Selection_Table"));
|
| 951 | + |
| 952 | + showXrefsAction = new ActionBuilder("Show Xrefs", getName()) |
| 953 | + .description("Show the Xrefs to the code unit containing the cursor") |
| 954 | + .validContextWhen(context -> context instanceof ListingActionContext) |
| 955 | + .onAction(context -> showXrefs(context)) |
| 956 | + .build(); |
| 957 | + } |
| 958 | + |
| 959 | + private void showXrefs(ActionContext context) { |
| 960 | + |
| 961 | + TableService service = tool.getService(TableService.class); |
| 962 | + if (service == null) { |
| 963 | + return; |
| 964 | + } |
| 965 | + |
| 966 | + ListingActionContext lac = (ListingActionContext) context; |
| 967 | + ProgramLocation location = lac.getLocation(); |
| 968 | + if (location == null) { |
| 969 | + return; // not sure if this can happen |
| 970 | + } |
| 971 | + |
| 972 | + Set<Reference> refs = XReferenceUtil.getAllXrefs(location); |
| 973 | + XReferenceUtil.showAllXrefs(connectedProvider, tool, service, location, refs); |
942 | 974 | }
|
943 | 975 |
|
944 | 976 | private GhidraProgramTableModel<Address> createTableModel(CodeUnitIterator iterator,
|
|
0 commit comments