mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 12:00:04 +02:00
Merge remote-tracking branch
'origin/GP-2843-dragonmacher-options-veto--SQUASHED'
This commit is contained in:
commit
ed5c44335e
6 changed files with 80 additions and 42 deletions
|
@ -116,19 +116,17 @@ public class EditorState implements PropertyChangeListener {
|
|||
if (Objects.equals(currentValue, originalValue)) {
|
||||
return;
|
||||
}
|
||||
boolean success = false;
|
||||
try {
|
||||
options.putObject(name, currentValue);
|
||||
Object newValue = options.getObject(name, null);
|
||||
|
||||
options.putObject(name, currentValue);
|
||||
Object newValue = options.getObject(name, null);
|
||||
boolean success = Objects.equals(currentValue, newValue);
|
||||
if (success) {
|
||||
originalValue = newValue;
|
||||
currentValue = newValue;
|
||||
success = true;
|
||||
}
|
||||
finally {
|
||||
if (!success) {
|
||||
editor.setValue(originalValue);
|
||||
currentValue = originalValue;
|
||||
}
|
||||
else {
|
||||
editor.setValue(originalValue);
|
||||
currentValue = originalValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,8 +143,8 @@ public class EditorState implements PropertyChangeListener {
|
|||
public Component getEditorComponent() {
|
||||
if (editor == null) {
|
||||
// can occur if support has been dropped for custom state/option
|
||||
editor = new ErrorPropertyEditor(
|
||||
"Ghidra does not know how to render state: " + name, null);
|
||||
editor =
|
||||
new ErrorPropertyEditor("Ghidra does not know how to render state: " + name, null);
|
||||
return editor.getCustomEditor();
|
||||
}
|
||||
if (editor.supportsCustomEditor()) {
|
||||
|
@ -165,16 +163,14 @@ public class EditorState implements PropertyChangeListener {
|
|||
Class<? extends PropertyEditor> clazz = editor.getClass();
|
||||
String clazzName = clazz.getSimpleName();
|
||||
if (clazzName.startsWith("String")) {
|
||||
// Most likely some kind of string editor with a null value. Just use a string
|
||||
// Most likely some kind of string editor with a null value. Just use a string
|
||||
// property and let the value be empty.
|
||||
return new PropertyText(editor);
|
||||
}
|
||||
|
||||
editor.removePropertyChangeListener(this);
|
||||
editor = new ErrorPropertyEditor(
|
||||
Application.getName() + " does not know how to use PropertyEditor: " +
|
||||
editor.getClass().getName(),
|
||||
null);
|
||||
editor = new ErrorPropertyEditor(Application.getName() +
|
||||
" does not know how to use PropertyEditor: " + editor.getClass().getName(), null);
|
||||
return editor.getCustomEditor();
|
||||
}
|
||||
|
||||
|
|
|
@ -32,16 +32,16 @@ import ghidra.util.exception.AssertException;
|
|||
|
||||
/**
|
||||
* Class to manage a set of option name/value pairs for a category.
|
||||
*
|
||||
*
|
||||
* <p>The values may be primitives or {@link WrappedOption}s that are containers for primitive
|
||||
* components.
|
||||
*
|
||||
*
|
||||
* <p>The name/value pair has an owner so that the option name can be removed from the Options
|
||||
* object when it is no longer being used.
|
||||
*
|
||||
*
|
||||
* <p>Note: Property Names can have {@link Options#DELIMITER} characters to create a hierarchy.
|
||||
* So too can sub-options accessed via {@link #getOptions(String)}.
|
||||
*
|
||||
*
|
||||
* <p>The Options Dialog shows the delimited hierarchy in tree format.
|
||||
*/
|
||||
public class ToolOptions extends AbstractOptions {
|
||||
|
@ -148,7 +148,7 @@ public class ToolOptions extends AbstractOptions {
|
|||
* Return an XML element for the option names and values.
|
||||
* Note: only those options which have been explicitly set
|
||||
* will be included.
|
||||
*
|
||||
*
|
||||
* @param includeDefaultBindings true to include default key binding values in the xml
|
||||
* @return the xml root element
|
||||
*/
|
||||
|
@ -421,14 +421,20 @@ public class ToolOptions extends AbstractOptions {
|
|||
NotifyListenersRunnable runnable =
|
||||
new NotifyListenersRunnable(optionName, oldValue, newValue);
|
||||
Swing.runNow(runnable);
|
||||
return !runnable.wasVetoed();
|
||||
|
||||
OptionsVetoException veto = runnable.getVetoException();
|
||||
if (veto != null) {
|
||||
throw veto;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private class NotifyListenersRunnable implements Runnable {
|
||||
private String optionName;
|
||||
private Object oldValue;
|
||||
private Object newValue;
|
||||
private boolean vetoed;
|
||||
private OptionsVetoException veto;
|
||||
|
||||
NotifyListenersRunnable(String optionName, Object oldValue, Object newValue) {
|
||||
this.optionName = optionName;
|
||||
|
@ -446,7 +452,7 @@ public class ToolOptions extends AbstractOptions {
|
|||
}
|
||||
}
|
||||
catch (OptionsVetoException e) {
|
||||
vetoed = true;
|
||||
veto = e;
|
||||
for (OptionsChangeListener notifiedListener : notifiedListeners) {
|
||||
notifiedListener.optionsChanged(ToolOptions.this, optionName, newValue,
|
||||
oldValue);
|
||||
|
@ -454,8 +460,8 @@ public class ToolOptions extends AbstractOptions {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean wasVetoed() {
|
||||
return vetoed;
|
||||
OptionsVetoException getVetoException() {
|
||||
return veto;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue