GP-66 - updated goto action to be disabled when there is no program

This commit is contained in:
dragonmacher 2021-02-25 11:15:48 -05:00 committed by ghidra1
parent 7b8e6b4471
commit c17448d2f2

View file

@ -17,6 +17,7 @@ package ghidra.app.plugin.core.navigation;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import docking.ActionContext;
import docking.action.*; import docking.action.*;
import docking.tool.ToolConstants; import docking.tool.ToolConstants;
import ghidra.GhidraOptions; import ghidra.GhidraOptions;
@ -29,7 +30,7 @@ import ghidra.app.util.HelpTopics;
import ghidra.app.util.navigation.GoToAddressLabelDialog; import ghidra.app.util.navigation.GoToAddressLabelDialog;
import ghidra.framework.options.*; import ghidra.framework.options.*;
import ghidra.framework.plugintool.*; import ghidra.framework.plugintool.*;
import ghidra.framework.plugintool.util.*; import ghidra.framework.plugintool.util.PluginStatus;
import ghidra.util.HelpLocation; import ghidra.util.HelpLocation;
import ghidra.util.bean.opteditor.OptionsVetoException; import ghidra.util.bean.opteditor.OptionsVetoException;
@ -91,10 +92,20 @@ public class GoToAddressLabelPlugin extends Plugin implements OptionsChangeListe
public void actionPerformed(NavigatableActionContext context) { public void actionPerformed(NavigatableActionContext context) {
goToDialog.show(context.getNavigatable(), context.getAddress(), tool); goToDialog.show(context.getNavigatable(), context.getAddress(), tool);
} }
@Override
protected boolean isEnabledForContext(NavigatableActionContext context) {
return context.getProgram() != null;
}
@Override
public boolean isAddToPopup(ActionContext context) {
return true;
}
}; };
action.setHelpLocation(new HelpLocation(HelpTopics.NAVIGATION, action.getName())); action.setHelpLocation(new HelpLocation(HelpTopics.NAVIGATION, action.getName()));
action.setMenuBarData(new MenuData( action.setMenuBarData(
new String[] { ToolConstants.MENU_NAVIGATION, "Go To..." }, null, "GoTo", new MenuData(new String[] { ToolConstants.MENU_NAVIGATION, "Go To..." }, null, "GoTo",
MenuData.NO_MNEMONIC, "2")); // second item in the menu MenuData.NO_MNEMONIC, "2")); // second item in the menu
action.setKeyBindingData(new KeyBindingData(KeyEvent.VK_G, 0)); action.setKeyBindingData(new KeyBindingData(KeyEvent.VK_G, 0));
@ -144,7 +155,8 @@ public class GoToAddressLabelPlugin extends Plugin implements OptionsChangeListe
* @param newValue new value of the option * @param newValue new value of the option
*/ */
@Override @Override
public void optionsChanged(ToolOptions options, String opName, Object oldValue, Object newValue) { public void optionsChanged(ToolOptions options, String opName, Object oldValue,
Object newValue) {
if (opName.equals(GhidraOptions.OPTION_MAX_GO_TO_ENTRIES)) { if (opName.equals(GhidraOptions.OPTION_MAX_GO_TO_ENTRIES)) {
maximumGotoEntries = maximumGotoEntries =
options.getInt(GhidraOptions.OPTION_MAX_GO_TO_ENTRIES, DEFAULT_MAX_GOTO_ENTRIES); options.getInt(GhidraOptions.OPTION_MAX_GO_TO_ENTRIES, DEFAULT_MAX_GOTO_ENTRIES);
@ -182,16 +194,16 @@ public class GoToAddressLabelPlugin extends Plugin implements OptionsChangeListe
ToolOptions opt = tool.getOptions(ToolConstants.TOOL_OPTIONS); ToolOptions opt = tool.getOptions(ToolConstants.TOOL_OPTIONS);
// descriptions // descriptions
opt.registerOption(GhidraOptions.OPTION_NUMERIC_FORMATTING, DEFAULT_C_STYLE, null, opt.registerOption(GhidraOptions.OPTION_NUMERIC_FORMATTING, DEFAULT_C_STYLE, null,
"Interpret value entered in the Go To dialog as either hex, " "Interpret value entered in the Go To dialog as either hex, " +
+ "octal, or binary number."); "octal, or binary number.");
opt.registerOption(GhidraOptions.OPTION_MAX_GO_TO_ENTRIES, DEFAULT_MAX_GOTO_ENTRIES, null, opt.registerOption(GhidraOptions.OPTION_MAX_GO_TO_ENTRIES, DEFAULT_MAX_GOTO_ENTRIES, null,
"Max number of entries remembered in the go to list."); "Max number of entries remembered in the go to list.");
opt.registerOption(GO_TO_MEMORY, DEFAULT_MEMORY, null, opt.registerOption(GO_TO_MEMORY, DEFAULT_MEMORY, null,
"Remember the last successful go to input in the " "Remember the last successful go to input in the " +
+ "Go To dialog. If this option is enabled, then the " "Go To dialog. If this option is enabled, then the " +
+ "Go To dialog will leave the last " "Go To dialog will leave the last " +
+ "successful go to input in the combo box of the Go " "successful go to input in the combo box of the Go " +
+ "To dialog and will select the " + "value for easy paste replacement."); "To dialog and will select the " + "value for easy paste replacement.");
// options // options
maximumGotoEntries = maximumGotoEntries =