Ghidra is a software reverse engineering (SRE) framework
GP-2405 - Small tweaks to the 'Replace Date Type' action to clarify its functionality
dragonmacher555d63683eaf
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/data_type_manager_description.htm b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/data_type_manager_description.htmindex c5e9417a0c..291f25f32e 100644--- a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/data_type_manager_description.htm+++ b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/data_type_manager_description.htm@@ -1026,7 +1026,10 @@<P>A data type can be replaced by another data type. This means that every occurrence ofthe original data type in a program is replaced by the new data type and the originaldata type is deleted. To replace a data type, right-click on the type to be replaced- and select the <B><I>Replace Data Type...</I></B> action.</P>+ and select the <B><I>Replace Data Type...</I></B> action. This will show a+ <A HREF="help/topics/DataTypeEditors/DataTypeSelectionDialog.htm">dialog</A> that allows+ you to choose the replacement data type.+ </P></BLOCKQUOTE>diff --git a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/data_type_manager_window.html b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/data_type_manager_window.htmlindex 393a2cd1a0..d277751c06 100644--- a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/data_type_manager_window.html+++ b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/data_type_manager_window.html@@ -513,14 +513,6 @@</TABLE></BLOCKQUOTE>- <H2>Popup Menu Actions</H2>-- <BLOCKQUOTE>- <P>The set of actions on the right-mouse popup menu change depending on what nodes are- selected. These actions will be described in the appropriate sections below.</P>- </BLOCKQUOTE>--<H2>Miscellaneous Actions</H2><BLOCKQUOTE>@@ -591,19 +583,15 @@</BLOCKQUOTE>- <H3><A name="Replace_Data_Type"></A>Replace Data Type...</H3>+ <H3><A name="Replace"></A>Replace Data Type...</H3><BLOCKQUOTE>- <P>The <I><B>Replace Data Type...</B></I> action is used to+ <P>The <I><B>Replace...</B></I> action is used to<A href="data_type_manager_description.htm#ReplaceDataType">replace</A> aselected data type and all occurrences in the program.</P></BLOCKQUOTE>- </BLOCKQUOTE>--- <BLOCKQUOTE><H3><A name="Collapse_All"></A>Collapse All</H3>@@ -614,7 +602,6 @@</BLOCKQUOTE><H3><A name="Expand_All"></A>Expand All</H3>- </BLOCKQUOTE><BLOCKQUOTE><BLOCKQUOTE>@@ -795,6 +782,7 @@for each enclosed structure or pointed to type</P></BLOCKQUOTE></BLOCKQUOTE>+ </BLOCKQUOTE>diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/ReplaceDataTypeAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/ReplaceDataTypeAction.javaindex fbb4e47625..05af5d2e1e 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/ReplaceDataTypeAction.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/ReplaceDataTypeAction.java@@ -15,11 +15,13 @@*/package ghidra.app.plugin.core.datamgr.actions;+import javax.swing.*;import javax.swing.tree.TreePath;import docking.ActionContext;import docking.action.DockingAction;import docking.action.MenuData;+import docking.widgets.label.GHtmlLabel;import docking.widgets.tree.GTree;import docking.widgets.tree.GTreeNode;import ghidra.app.plugin.core.datamgr.DataTypeManagerPlugin;@@ -28,10 +30,12 @@ import ghidra.app.plugin.core.datamgr.archive.Archive;import ghidra.app.plugin.core.datamgr.archive.DataTypeManagerHandler;import ghidra.app.plugin.core.datamgr.tree.*;import ghidra.app.util.datatype.DataTypeSelectionDialog;+import ghidra.app.util.datatype.DataTypeSelectionEditor;import ghidra.framework.plugintool.PluginTool;import ghidra.program.model.data.*;import ghidra.util.Msg;import ghidra.util.data.DataTypeParser.AllowedDataTypes;+import ghidra.util.layout.VerticalLayout;/*** Replace the selected data type with the chosen data type@@ -41,10 +45,10 @@ public class ReplaceDataTypeAction extends DockingAction {private DataTypeManagerPlugin plugin;public ReplaceDataTypeAction(DataTypeManagerPlugin plugin) {- super("Replace Data Type", plugin.getName());+ super("Replace", plugin.getName());this.plugin = plugin;- setPopupMenuData(new MenuData(new String[] { "Replace Data Type..." }, "Edit"));+ setPopupMenuData(new MenuData(new String[] { "Replace..." }, "Edit"));}@Override@@ -91,24 +95,47 @@ public class ReplaceDataTypeAction extends DockingAction {@Overridepublic void actionPerformed(ActionContext context) {+ DataTypeTreeNode node = getSelectedDataTypeTreeNode(context);+ String name = node.getName();+PluginTool tool = plugin.getTool();int noSizeRestriction = -1;DataTypeSelectionDialog selectionDialog = new DataTypeSelectionDialog(tool,- plugin.getProgram().getDataTypeManager(), noSizeRestriction, AllowedDataTypes.ALL);+ plugin.getProgram().getDataTypeManager(), noSizeRestriction, AllowedDataTypes.ALL) {++ @Override+ protected JComponent createEditorPanel(DataTypeSelectionEditor dtEditor) {++ setTitle("Replace '" + name + "'");++ JPanel updatedPanel = new JPanel();+ updatedPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 10, 0));+ updatedPanel.setLayout(new VerticalLayout(5));++ GHtmlLabel label = new GHtmlLabel("<html>Choose the relacment data type: ");+ label.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));+ updatedPanel.add(label);++ updatedPanel.add(dtEditor.getEditorComponent());++ return updatedPanel;+ }++ };+ selectionDialog.setHelpLocation(getHelpLocation());tool.showDialog(selectionDialog);DataType newDt = selectionDialog.getUserChosenDataType();if (newDt == null) {return; // cancelled}- DataTypeTreeNode node = getSelectedDataTypeTreeNode(context);-DataTypeManagerHandler dtmHandler = plugin.getDataTypeManagerHandler();- DataTypeManager dtm = newDt.getDataTypeManager();- Archive sourceArchive = dtmHandler.getArchive(dtm);+ DataTypeManager newDtm = newDt.getDataTypeManager();+ Archive sourceArchive = dtmHandler.getArchive(newDtm);Archive destinationArchive = findArchive(node);DataType oldDt = ((DataTypeNode) node).getDataType();+ DataTypeManager dtm = oldDt.getDataTypeManager();if (sourceArchive != destinationArchive) {oldDt = oldDt.clone(oldDt.getDataTypeManager());}diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/DialogRememberOption.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/DialogRememberOption.javaindex 3a277696d4..8b94f285b7 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/DialogRememberOption.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/DialogRememberOption.java@@ -46,8 +46,7 @@ public class DialogRememberOption {}/**- * Returns the result from a previous call to an OptionDialog that had this SavedDialogChoice- * installed.+ * Returns the result from a previous call to an OptionDialog that had this class installed.* @return the saved results from a previous call to an OptionDialog.*/public int getRememberedResult() {@@ -66,10 +65,9 @@ public class DialogRememberOption {/*** Sets the results from the dialog only if choice is true.* <P>- * In other words, if the user selects the checkBox, then- * the result will be saved. The, whenever the dialog is- * "shown", if there is a saved result, it will be returned- * instead of actually showing the dialog.+ * In other words, if the user selects the checkBox, then the result will be saved. Then,+ * whenever the dialog is shown, if there is a saved result, it will be returned instead of+ * actually showing the dialog.** @param choice the user's choice from the OptionDialog*/diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/OptionDialogBuilder.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/OptionDialogBuilder.javaindex 1a0580f9ee..a0ec07b2f0 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/OptionDialogBuilder.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/OptionDialogBuilder.java@@ -60,7 +60,7 @@ import ghidra.util.Swing;* The checkBox text will be either "Apply to all", "Remember my decision",* or "Don't show again" depending on whether {@link #addApplyToAllOption()},* {@link #addDontShowAgainOption()}, or {@link #addRememberMyDecisionOption()} method is- * called.+ * called. Each of these methods called will overwrite the previously called method.** <P>If the user selects the checkBox, then the dialog result will be remembered.* In future calls to display that dialog (or any dialog sharing