GP-5711 - Updated the Structure Editor's 'Find Uses of' action to work on unnamed fields

This commit is contained in:
dragonmacher 2025-05-22 13:10:48 -04:00
parent 30b0e80733
commit e830dbabfa

View file

@ -18,6 +18,7 @@ package ghidra.app.plugin.core.compositeeditor;
import docking.ActionContext; import docking.ActionContext;
import docking.action.MenuData; import docking.action.MenuData;
import ghidra.app.plugin.core.navigation.FindAppliedDataTypesService; import ghidra.app.plugin.core.navigation.FindAppliedDataTypesService;
import ghidra.app.services.FieldMatcher;
import ghidra.app.util.HelpTopics; import ghidra.app.util.HelpTopics;
import ghidra.program.model.data.Composite; import ghidra.program.model.data.Composite;
import ghidra.program.model.data.DataTypeComponent; import ghidra.program.model.data.DataTypeComponent;
@ -39,9 +40,6 @@ public class FindReferencesToStructureFieldAction extends CompositeEditorTableAc
@Override @Override
public void actionPerformed(ActionContext context) { public void actionPerformed(ActionContext context) {
if (!isEnabledForContext(context)) {
return;
}
FindAppliedDataTypesService service = tool.getService(FindAppliedDataTypesService.class); FindAppliedDataTypesService service = tool.getService(FindAppliedDataTypesService.class);
if (service == null) { if (service == null) {
Msg.showError(this, null, "Missing Plugin", Msg.showError(this, null, "Missing Plugin",
@ -50,26 +48,33 @@ public class FindReferencesToStructureFieldAction extends CompositeEditorTableAc
return; return;
} }
String fieldName = getFieldName(); FieldMatcher fieldMatcher = getFieldMatcher();
Composite composite = model.getOriginalComposite(); Composite composite = model.getOriginalComposite();
Swing.runLater(() -> service.findAndDisplayAppliedDataTypeAddresses(composite, fieldName)); Swing.runLater(
() -> service.findAndDisplayAppliedDataTypeAddresses(composite, fieldMatcher));
} }
private String getFieldName() { private FieldMatcher getFieldMatcher() {
int[] rows = model.getSelectedComponentRows(); int[] rows = model.getSelectedComponentRows();
if (rows.length == 0) { if (rows.length == 0) {
return null; return null;
} }
int row = rows[0]; int row = rows[0];
DataTypeComponent dtComponet = model.getComponent(row); DataTypeComponent dtComponent = model.getComponent(row);
String fieldName = dtComponet.getFieldName(); String fieldName = dtComponent.getFieldName();
return fieldName; Composite composite = model.getOriginalComposite();
if (fieldName != null) {
return new FieldMatcher(composite, fieldName);
}
int offset = dtComponent.getOffset();
return new FieldMatcher(composite, offset);
} }
@Override @Override
public boolean isEnabledForContext(ActionContext context) { public boolean isEnabledForContext(ActionContext context) {
setEnabled(false);
if (hasIncompleteFieldEntry()) { if (hasIncompleteFieldEntry()) {
return false; return false;
} }
@ -82,12 +87,12 @@ public class FindReferencesToStructureFieldAction extends CompositeEditorTableAc
return false; // not sure if this can happen return false; // not sure if this can happen
} }
String fieldName = getFieldName(); FieldMatcher fieldMatcher = getFieldMatcher();
if (fieldName == null) { if (fieldMatcher == null) {
return false; return false;
} }
updateMenuName(fieldName); updateMenuName(fieldMatcher.getFieldName());
return true; return true;
} }