Merge remote-tracking branch 'origin/GP-1-dragonmacher-lable-dialog-exception'

This commit is contained in:
ghidra1
2023-12-01 16:55:15 -05:00
4 changed files with 34 additions and 19 deletions
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +15,10 @@
*/
package ghidra.app.plugin.core.function;
import java.awt.event.KeyEvent;
import docking.action.KeyBindingData;
import docking.action.MenuData;
import ghidra.app.context.ListingActionContext;
import ghidra.app.context.ListingContextAction;
import ghidra.app.util.AddEditDialog;
@@ -25,11 +28,6 @@ import ghidra.program.util.OperandFieldLocation;
import ghidra.program.util.ProgramLocation;
import ghidra.util.Msg;
import java.awt.event.KeyEvent;
import docking.action.KeyBindingData;
import docking.action.MenuData;
/**
* <CODE>EditNameAction</CODE> allows the user to rename a function.
* Action in FunctionPlugin.
@@ -26,7 +26,6 @@ import ghidra.app.context.ListingActionContext;
import ghidra.app.events.ProgramActivatedPluginEvent;
import ghidra.app.plugin.PluginCategoryNames;
import ghidra.app.services.*;
import ghidra.app.util.AddEditDialog;
import ghidra.framework.cmd.BackgroundCommand;
import ghidra.framework.cmd.Command;
import ghidra.framework.plugintool.*;
@@ -118,8 +117,6 @@ public class FunctionPlugin extends Plugin implements DataService {
private List<DataAction> favoriteActions = new ArrayList<>();
private List<CycleGroupAction> cgActions = new ArrayList<>();
private AddEditDialog functionNameDialog;
private AddEditDialog variableNameDialog;
private VariableCommentDialog variableCommentDialog;
private DataTypeManagerChangeListenerAdapter adapter;
private EditFunctionAction editFunctionAction;
@@ -148,14 +145,7 @@ public class FunctionPlugin extends Plugin implements DataService {
dtmService.removeDataTypeManagerChangeListener(adapter);
}
super.dispose();
if (functionNameDialog != null) {
functionNameDialog.close();
functionNameDialog = null;
}
if (variableNameDialog != null) {
variableNameDialog.close();
variableNameDialog = null;
}
if (variableCommentDialog != null) {
variableCommentDialog.close();
variableCommentDialog = null;
@@ -62,6 +62,7 @@ public class LabelMgrPlugin extends Plugin {
setupActions();
addEditDialog = new AddEditDialog("", tool);
addEditDialog.setReusable(true);
}
private void setupActions() {
@@ -25,7 +25,7 @@ import javax.swing.border.*;
import org.apache.commons.lang3.StringUtils;
import docking.ComponentProvider;
import docking.DialogComponentProvider;
import docking.ReusableDialogComponentProvider;
import docking.widgets.OptionDialog;
import docking.widgets.checkbox.GCheckBox;
import docking.widgets.combobox.GhidraComboBox;
@@ -44,7 +44,7 @@ import ghidra.util.layout.VerticalLayout;
/**
* Dialog used to a label or to edit an existing label.
*/
public class AddEditDialog extends DialogComponentProvider {
public class AddEditDialog extends ReusableDialogComponentProvider {
private static final int MAX_RETENTION = 10;
private PluginTool tool;
private TitledBorder nameBorder;
@@ -59,6 +59,8 @@ public class AddEditDialog extends DialogComponentProvider {
private Address addr;
private JCheckBox pinnedCheckBox;
private boolean isReusable = false; // most clients are not reusable
public AddEditDialog(String title, PluginTool tool) {
super(title, true, true, true, false);
this.tool = tool;
@@ -74,6 +76,30 @@ public class AddEditDialog extends DialogComponentProvider {
setDefaultButton(okButton);
}
/**
* Signals that the client wishes to reuse the dialog instead of creating a new instance each
* time the dialog is shown.
* <p>
* When not reusable, closing this dialog will call {@link #dispose()}.
*
* @param isReusable true when being reused
*/
public void setReusable(boolean isReusable) {
this.isReusable = isReusable;
}
@Override
public void close() {
if (isReusable) {
// call the default parent close, which does *not* call dispose
super.close();
}
else {
closeDialog();
dispose();
}
}
/**
* Invokes the dialog to add a new label in the given program at the given address
* @param address the address at which to add a new label