Merge remote-tracking branch 'origin/GP-1_bug_fixes_related_to_toggle_variables_feature' into Ghidra_12.0

This commit is contained in:
Ryan Kurtz 2025-09-17 12:08:21 -04:00
commit 1942e0e95e
6 changed files with 62 additions and 28 deletions

View file

@ -481,22 +481,23 @@ public class CodeViewerProvider extends NavigatableComponentProviderAdapter
action = new GotoNextFunctionAction(tool, plugin.getName()); action = new GotoNextFunctionAction(tool, plugin.getName());
tool.addAction(action); tool.addAction(action);
toggleVariablesAction = new ToggleActionBuilder("Show Function Variables", plugin.getName()) toggleVariablesAction =
.popupMenuPath("Show/Hide All Variables") new ToggleActionBuilder("Show All Function Variables", plugin.getName())
.popupMenuGroup("Variables") .popupMenuPath("Function", "Show/Hide All Variables")
.helpLocation(new HelpLocation("CodeBrowserPlugin", "Show_All_Variables")) .popupMenuGroup("Variables")
.selected(true) .helpLocation(new HelpLocation("CodeBrowserPlugin", "Show_All_Variables"))
.withContext(ProgramLocationActionContext.class) .selected(true)
.enabledWhen(this::isInFunctionArea) .withContext(ProgramLocationActionContext.class)
.onAction(c -> showVariablesForAllFunctions(toggleVariablesAction.isSelected())) .onAction(c -> showVariablesForAllFunctions(toggleVariablesAction.isSelected()))
.buildAndInstallLocal(this); .buildAndInstallLocal(this);
new ActionBuilder("Toggle Show Function Variables", plugin.getName()) new ActionBuilder("Toggle Show Function Variables", plugin.getName())
.popupMenuPath("Show/Hide Variables") .popupMenuPath("Function", "Show/Hide Variables")
.popupMenuGroup("Variables") .popupMenuGroup("Variables")
.helpLocation(new HelpLocation("CodeBrowserPlugin", "Show_Variables")) .helpLocation(new HelpLocation("CodeBrowserPlugin", "Show_Variables"))
.keyBinding("SPACE") .keyBinding("SPACE")
.withContext(ProgramLocationActionContext.class) .withContext(ProgramLocationActionContext.class)
.validWhen(this::isInFunctionArea)
.enabledWhen(this::isInFunctionArea) .enabledWhen(this::isInFunctionArea)
.onAction(c -> toggleShowVariables(c.getAddress())) .onAction(c -> toggleShowVariables(c.getAddress()))
.buildAndInstallLocal(this); .buildAndInstallLocal(this);

View file

@ -42,7 +42,8 @@ public class CollapseAllDataAction extends ProgramLocationContextAction {
super("Collapse All Data", provider.getOwner()); super("Collapse All Data", provider.getOwner());
this.provider = provider; this.provider = provider;
setPopupMenuData(new MenuData(new String[] { "Collapse All Data" }, null, "Structure")); setPopupMenuData(
new MenuData(new String[] { "Data", "Collapse All Data" }, null, "BasicData2"));
setHelpLocation(new HelpLocation("CodeBrowserPlugin", "ExpandCollapseActions")); setHelpLocation(new HelpLocation("CodeBrowserPlugin", "ExpandCollapseActions"));

View file

@ -39,7 +39,8 @@ public class ExpandAllDataAction extends ProgramLocationContextAction {
super("Expand All Data", provider.getOwner()); super("Expand All Data", provider.getOwner());
this.provider = provider; this.provider = provider;
setPopupMenuData(new MenuData(new String[] { "Expand All Data" }, null, "Structure")); setPopupMenuData(
new MenuData(new String[] { "Data", "Expand All Data" }, null, "BasicData2"));
setDescription("Open all data recursively from the current location downward."); setDescription("Open all data recursively from the current location downward.");
setHelpLocation(new HelpLocation("CodeBrowserPlugin", "ExpandCollapseActions")); setHelpLocation(new HelpLocation("CodeBrowserPlugin", "ExpandCollapseActions"));
@ -83,11 +84,11 @@ public class ExpandAllDataAction extends ProgramLocationContextAction {
private void updatePopupMenuName(boolean hasSelection) { private void updatePopupMenuName(boolean hasSelection) {
if (hasSelection) { if (hasSelection) {
getPopupMenuData().setMenuPath(new String[] { "Expand All Data In Selection" }); getPopupMenuData().setMenuPath(new String[] { "Data", "Expand All Data In Selection" });
setDescription("Open all data recursively in the current selection."); setDescription("Open all data recursively in the current selection.");
} }
else { else {
getPopupMenuData().setMenuPath(new String[] { "Expand All Data" }); getPopupMenuData().setMenuPath(new String[] { "Data", "Expand All Data" });
setDescription("Open all data recursively from the current location downward."); setDescription("Open all data recursively from the current location downward.");
} }
} }

View file

@ -42,7 +42,8 @@ public class ToggleExpandCollapseDataAction extends ProgramLocationContextAction
this.provider = provider; this.provider = provider;
setPopupMenuData( setPopupMenuData(
new MenuData(new String[] { "Toggle Expand/Collapse Data" }, null, "Structure")); new MenuData(new String[] { "Data", "Toggle Expand/Collapse Data" }, null,
"BasicData2"));
setKeyBindingData(new KeyBindingData(' ', 0)); setKeyBindingData(new KeyBindingData(' ', 0));
setHelpLocation(new HelpLocation("CodeBrowserPlugin", "ExpandCollapseActions")); setHelpLocation(new HelpLocation("CodeBrowserPlugin", "ExpandCollapseActions"));

View file

@ -83,7 +83,7 @@ public class FieldFormatModel {
} }
/** /**
* Returns the formatMgr that is managing this model. * {@return the FormatManager managing this format.}
*/ */
public FormatManager getFormatManager() { public FormatManager getFormatManager() {
return formatMgr; return formatMgr;
@ -109,6 +109,7 @@ public class FieldFormatModel {
/** /**
* Adds new empty row at the given position. The position must be in the * Adds new empty row at the given position. The position must be in the
* interval [0,numRows]. * interval [0,numRows].
* @param index the index to add a new row
* @exception IllegalArgumentException thrown if the position is outside the * @exception IllegalArgumentException thrown if the position is outside the
* interval [0,numRows]. * interval [0,numRows].
*/ */
@ -186,21 +187,23 @@ public class FieldFormatModel {
} }
/** /**
* Returns the number of rows in the model. * {@return the number of rows in this format}
*/ */
public int getNumRows() { public int getNumRows() {
return rows.size(); return rows.size();
} }
/** /**
* Returns the name of this format model. * {@return the name of this format model.}
*/ */
public String getName() { public String getName() {
return name; return name;
} }
/** /**
* Returns the number of FieldFactorys on any given row. * Returns the number of factories on the given row.
* @param row the row to get the number of factories for
* @return the number of factories on the given row
*/ */
public int getNumFactorys(int row) { public int getNumFactorys(int row) {
if ((row < 0) || (row >= rows.size())) { if ((row < 0) || (row >= rows.size())) {
@ -210,14 +213,16 @@ public class FieldFormatModel {
} }
/** /**
* Returns the FieldFactorys on a given row. * Returns the factories on the given row.
* @param row the row to factories for
* @return the FieldFactorys for a given row
*/ */
public FieldFactory[] getFactorys(int row) { public FieldFactory[] getFactorys(int row) {
return (rows.get(row)).getFactorys(); return (rows.get(row)).getFactorys();
} }
/** /**
* Returns the list factories valid for this format. * {@return the list of factories used in this format.}
*/ */
public FieldFactory[] getFactorys() { public FieldFactory[] getFactorys() {
return factories.clone(); return factories.clone();
@ -251,7 +256,7 @@ public class FieldFormatModel {
} }
/** /**
* Returns the width of this model * {@return the width of this format.}
*/ */
public int getWidth() { public int getWidth() {
return width; return width;
@ -280,6 +285,7 @@ public class FieldFormatModel {
/** /**
* Saves this format to XML. * Saves this format to XML.
* @return the XML element for the saved format
*/ */
public Element saveToXml() { public Element saveToXml() {
Element root = new Element("FORMAT"); Element root = new Element("FORMAT");

View file

@ -959,6 +959,9 @@ public class FormatManager implements OptionsChangeListener {
for (int i = 0; i < NUM_MODELS; i++) { for (int i = 0; i < NUM_MODELS; i++) {
if (saveState.hasValue(models[i].getName())) { if (saveState.hasValue(models[i].getName())) {
models[i].restoreFromXml(saveState.getXmlElement(models[i].getName())); models[i].restoreFromXml(saveState.getXmlElement(models[i].getName()));
// hack to make sure the new open/close variables field is present
// If missing, we are just going to reset it to the default format
checkForMissingOpenCloseField(models[i]);
} }
else { else {
models[i].restoreFromXml(getDefaultModel(i)); models[i].restoreFromXml(getDefaultModel(i));
@ -968,6 +971,27 @@ public class FormatManager implements OptionsChangeListener {
modelChanged(null); modelChanged(null);
} }
// This is a hack to make sure the new variables open/close field is present.
// This was added in version 12.0 and can probably be removed in a few releases.
private void checkForMissingOpenCloseField(FieldFormatModel model) {
if (!model.getName().equals("Variable")) {
return;
}
if (!hasField(model, "+")) {
model.restoreFromXml(getDefaultVariableFormat());
}
}
private boolean hasField(FieldFormatModel model, String fieldName) {
FieldFactory[] unusedFactories = model.getUnusedFactories();
for (FieldFactory fieldFactory : unusedFactories) {
if (fieldFactory.getFieldName().equals("+")) {
return false;
}
}
return true;
}
public ServiceProvider getServiceProvider() { public ServiceProvider getServiceProvider() {
return serviceProvider; return serviceProvider;
} }