GP-5528 fix toggle data open/closed to not use task thread

Causes unnecessary progress dialog.  Also improve where the cursor is
left when collapsing something when the cursor is on a child field.
This commit is contained in:
dev747368 2025-03-25 20:07:38 +00:00
parent 1bed582491
commit 21aadafacf

View file

@ -26,7 +26,6 @@ import ghidra.program.model.data.DataUtilities;
import ghidra.program.model.listing.Data;
import ghidra.program.util.ProgramLocation;
import ghidra.util.HelpLocation;
import ghidra.util.task.*;
/**
* Action for toggling the expanded/collapsed state of an single expandable data element. This
@ -56,12 +55,9 @@ public class ToggleExpandCollapseDataAction extends ProgramLocationContextAction
@Override
protected boolean isEnabledForContext(ProgramLocationActionContext context) {
Data data = getClosestComponentDataUnit(context.getLocation());
if (data == null) {
return false;
}
return true;
Data cursorData = DataUtilities.getDataAtLocation(context.getLocation());
return cursorData != null &&
(cursorData.getNumComponents() > 0 || cursorData.getParent() != null);
}
@Override
@ -70,46 +66,15 @@ public class ToggleExpandCollapseDataAction extends ProgramLocationContextAction
ListingModel layoutModel = listingPanel.getListingModel();
ProgramLocation location = context.getLocation();
Data data = getClosestComponentDataUnit(location);
new TaskLauncher(new OpenCloseDataTask(data, layoutModel), listingPanel);
Data cursorData = DataUtilities.getDataAtLocation(location);
Data actionData = cursorData.getNumComponents() > 0 ? cursorData : cursorData.getParent();
boolean collapsing = layoutModel.isOpen(actionData);
if (collapsing && cursorData != actionData) {
ProgramLocation newLoc = new ProgramLocation(context.getProgram(),
actionData.getAddress(), actionData.getComponentPath(), null, 0, 0, 0);
listingPanel.goTo(newLoc);
}
layoutModel.toggleOpen(actionData);
}
private Data getClosestComponentDataUnit(ProgramLocation location) {
if (location == null) {
return null;
}
Data data = DataUtilities.getDataAtLocation(location);
if (data == null) {
return null;
}
if (data.getNumComponents() > 0) {
return data;
}
return data.getParent();
}
private static class OpenCloseDataTask extends Task {
private ListingModel model;
private Data data;
public OpenCloseDataTask(Data data, ListingModel model) {
super("Open/Close Data In Selection", true, true, true, true);
this.data = data;
this.model = model;
}
@Override
public void run(TaskMonitor monitor) {
if (!model.isOpen(data)) {
model.openData(data);
}
else {
model.closeData(data);
}
}
}
}