Skip to content

Commit 62c0e44

Browse files
committed
Merge remote-tracking branch
'origin/GP-2405-dragonmacher-dt-action-tweak--SQUASHED' (Closes NationalSecurityAgency#4463)
2 parents 03bd4b4 + 555d636 commit 62c0e44

File tree

5 files changed

+46
-30
lines changed

5 files changed

+46
-30
lines changed

Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/data_type_manager_description.htm

+4-1
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,10 @@ <H3><A name="ReplaceDataType"></A>Replacing a Data Type</H3>
10261026
<P>A data type can be replaced by another data type. This means that every occurrence of
10271027
the original data type in a program is replaced by the new data type and the original
10281028
data type is deleted. To replace a data type, right-click on the type to be replaced
1029-
and select the <B><I>Replace Data Type...</I></B> action.</P>
1029+
and select the <B><I>Replace Data Type...</I></B> action. This will show a
1030+
<A HREF="help/topics/DataTypeEditors/DataTypeSelectionDialog.htm">dialog</A> that allows
1031+
you to choose the replacement data type.
1032+
</P>
10301033

10311034
</BLOCKQUOTE>
10321035

Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/data_type_manager_window.html

+3-15
Original file line numberDiff line numberDiff line change
@@ -513,14 +513,6 @@ <H2>Local Menu Actions</H2>
513513
</TABLE>
514514
</BLOCKQUOTE>
515515

516-
<H2>Popup Menu Actions</H2>
517-
518-
<BLOCKQUOTE>
519-
<P>The set of actions on the right-mouse popup menu change depending on what nodes are
520-
selected. These actions will be described in the appropriate sections below.</P>
521-
</BLOCKQUOTE>
522-
523-
524516
<H2>Miscellaneous Actions</H2>
525517

526518
<BLOCKQUOTE>
@@ -591,19 +583,15 @@ <H3><A name="Rename"></A>Rename</H3>
591583
</BLOCKQUOTE>
592584

593585

594-
<H3><A name="Replace_Data_Type"></A>Replace Data Type...</H3>
586+
<H3><A name="Replace"></A>Replace Data Type...</H3>
595587

596588
<BLOCKQUOTE>
597-
<P>The <I><B>Replace Data Type...</B></I> action is used to
589+
<P>The <I><B>Replace...</B></I> action is used to
598590
<A href="data_type_manager_description.htm#ReplaceDataType">replace</A> a
599591
selected data type and all occurrences in the program.</P>
600592
</BLOCKQUOTE>
601593

602594

603-
</BLOCKQUOTE>
604-
605-
606-
<BLOCKQUOTE>
607595

608596
<H3><A name="Collapse_All"></A>Collapse All</H3>
609597

@@ -614,7 +602,6 @@ <H3><A name="Collapse_All"></A>Collapse All</H3>
614602
</BLOCKQUOTE>
615603

616604
<H3><A name="Expand_All"></A>Expand All</H3>
617-
</BLOCKQUOTE>
618605

619606
<BLOCKQUOTE>
620607
<BLOCKQUOTE>
@@ -795,6 +782,7 @@ <H3><A name="Type_Graph">Display Data Type as Graph</A></H3>
795782
for each enclosed structure or pointed to type</P>
796783
</BLOCKQUOTE>
797784
</BLOCKQUOTE>
785+
</BLOCKQUOTE>
798786

799787

800788

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/ReplaceDataTypeAction.java

+34-7
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
*/
1616
package ghidra.app.plugin.core.datamgr.actions;
1717

18+
import javax.swing.*;
1819
import javax.swing.tree.TreePath;
1920

2021
import docking.ActionContext;
2122
import docking.action.DockingAction;
2223
import docking.action.MenuData;
24+
import docking.widgets.label.GHtmlLabel;
2325
import docking.widgets.tree.GTree;
2426
import docking.widgets.tree.GTreeNode;
2527
import ghidra.app.plugin.core.datamgr.DataTypeManagerPlugin;
@@ -28,10 +30,12 @@
2830
import ghidra.app.plugin.core.datamgr.archive.DataTypeManagerHandler;
2931
import ghidra.app.plugin.core.datamgr.tree.*;
3032
import ghidra.app.util.datatype.DataTypeSelectionDialog;
33+
import ghidra.app.util.datatype.DataTypeSelectionEditor;
3134
import ghidra.framework.plugintool.PluginTool;
3235
import ghidra.program.model.data.*;
3336
import ghidra.util.Msg;
3437
import ghidra.util.data.DataTypeParser.AllowedDataTypes;
38+
import ghidra.util.layout.VerticalLayout;
3539

3640
/**
3741
* Replace the selected data type with the chosen data type
@@ -41,10 +45,10 @@ public class ReplaceDataTypeAction extends DockingAction {
4145
private DataTypeManagerPlugin plugin;
4246

4347
public ReplaceDataTypeAction(DataTypeManagerPlugin plugin) {
44-
super("Replace Data Type", plugin.getName());
48+
super("Replace", plugin.getName());
4549

4650
this.plugin = plugin;
47-
setPopupMenuData(new MenuData(new String[] { "Replace Data Type..." }, "Edit"));
51+
setPopupMenuData(new MenuData(new String[] { "Replace..." }, "Edit"));
4852
}
4953

5054
@Override
@@ -91,24 +95,47 @@ private DataTypeTreeNode getSelectedDataTypeTreeNode(ActionContext context) {
9195
@Override
9296
public void actionPerformed(ActionContext context) {
9397

98+
DataTypeTreeNode node = getSelectedDataTypeTreeNode(context);
99+
String name = node.getName();
100+
94101
PluginTool tool = plugin.getTool();
95102
int noSizeRestriction = -1;
96103
DataTypeSelectionDialog selectionDialog = new DataTypeSelectionDialog(tool,
97-
plugin.getProgram().getDataTypeManager(), noSizeRestriction, AllowedDataTypes.ALL);
104+
plugin.getProgram().getDataTypeManager(), noSizeRestriction, AllowedDataTypes.ALL) {
105+
106+
@Override
107+
protected JComponent createEditorPanel(DataTypeSelectionEditor dtEditor) {
108+
109+
setTitle("Replace '" + name + "'");
110+
111+
JPanel updatedPanel = new JPanel();
112+
updatedPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 10, 0));
113+
updatedPanel.setLayout(new VerticalLayout(5));
114+
115+
GHtmlLabel label = new GHtmlLabel("<html>Choose the relacment data type: ");
116+
label.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
117+
updatedPanel.add(label);
118+
119+
updatedPanel.add(dtEditor.getEditorComponent());
120+
121+
return updatedPanel;
122+
}
123+
124+
};
125+
selectionDialog.setHelpLocation(getHelpLocation());
98126
tool.showDialog(selectionDialog);
99127
DataType newDt = selectionDialog.getUserChosenDataType();
100128
if (newDt == null) {
101129
return; // cancelled
102130
}
103131

104-
DataTypeTreeNode node = getSelectedDataTypeTreeNode(context);
105-
106132
DataTypeManagerHandler dtmHandler = plugin.getDataTypeManagerHandler();
107-
DataTypeManager dtm = newDt.getDataTypeManager();
108-
Archive sourceArchive = dtmHandler.getArchive(dtm);
133+
DataTypeManager newDtm = newDt.getDataTypeManager();
134+
Archive sourceArchive = dtmHandler.getArchive(newDtm);
109135
Archive destinationArchive = findArchive(node);
110136

111137
DataType oldDt = ((DataTypeNode) node).getDataType();
138+
DataTypeManager dtm = oldDt.getDataTypeManager();
112139
if (sourceArchive != destinationArchive) {
113140
oldDt = oldDt.clone(oldDt.getDataTypeManager());
114141
}

Ghidra/Framework/Docking/src/main/java/docking/widgets/DialogRememberOption.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ public String getDescription() {
4646
}
4747

4848
/**
49-
* Returns the result from a previous call to an OptionDialog that had this SavedDialogChoice
50-
* installed.
49+
* Returns the result from a previous call to an OptionDialog that had this class installed.
5150
* @return the saved results from a previous call to an OptionDialog.
5251
*/
5352
public int getRememberedResult() {
@@ -66,10 +65,9 @@ public boolean hasRememberedResult() {
6665
/**
6766
* Sets the results from the dialog only if choice is true.
6867
* <P>
69-
* In other words, if the user selects the checkBox, then
70-
* the result will be saved. The, whenever the dialog is
71-
* "shown", if there is a saved result, it will be returned
72-
* instead of actually showing the dialog.
68+
* In other words, if the user selects the checkBox, then the result will be saved. Then,
69+
* whenever the dialog is shown, if there is a saved result, it will be returned instead of
70+
* actually showing the dialog.
7371
*
7472
* @param choice the user's choice from the OptionDialog
7573
*/

Ghidra/Framework/Docking/src/main/java/docking/widgets/OptionDialogBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
* The checkBox text will be either "Apply to all", "Remember my decision",
6161
* or "Don't show again" depending on whether {@link #addApplyToAllOption()},
6262
* {@link #addDontShowAgainOption()}, or {@link #addRememberMyDecisionOption()} method is
63-
* called.
63+
* called. Each of these methods called will overwrite the previously called method.
6464
*
6565
* <P>If the user selects the checkBox, then the dialog result will be remembered.
6666
* In future calls to display that dialog (or any dialog sharing

0 commit comments

Comments
 (0)