GP-1259 Fixing search action enablement when in restricted view componennts (FunctionGraph, Decompiler)

This commit is contained in:
ghidravore
2021-10-04 12:25:26 -04:00
parent 7e2cd85eac
commit d536512dd6
6 changed files with 57 additions and 33 deletions
@@ -20,15 +20,46 @@ import docking.action.DockingAction;
import docking.action.KeyBindingType; import docking.action.KeyBindingType;
public abstract class NavigatableContextAction extends DockingAction { public abstract class NavigatableContextAction extends DockingAction {
// means this action is applicable on navigable providers that restrict the program view such
// as the FunctionGraph or the Decompiler views.
private final boolean supportsRestrictedAddressSetContext;
/**
* Constructor for actions that can work on any Navigatable
*
* @param name the action's name
* @param owner the action's owner
*/
public NavigatableContextAction(String name, String owner) { public NavigatableContextAction(String name, String owner) {
super(name, owner); this(name, owner, true);
setSupportsDefaultToolContext(true);
} }
/**
* Constructor for specifying if that the context works on {@link RestrictedAddressSetContext}
*
* @param name the action's name
* @param owner the action's owner
* @param supportsRestrictedAddressSetContext true if this action can work on
* {@link RestrictedAddressSetContext}
*/
public NavigatableContextAction(String name, String owner,
boolean supportsRestrictedAddressSetContext) {
super(name, owner);
setSupportsDefaultToolContext(true);
this.supportsRestrictedAddressSetContext = supportsRestrictedAddressSetContext;
}
/**
* Constructor when using a non-standard {@link KeyBindingType}
*
* @param name the action's name
* @param owner the action's owner
* @param type the KeybindingType
*/
public NavigatableContextAction(String name, String owner, KeyBindingType type) { public NavigatableContextAction(String name, String owner, KeyBindingType type) {
super(name, owner, type); super(name, owner, type);
setSupportsDefaultToolContext(true); setSupportsDefaultToolContext(true);
this.supportsRestrictedAddressSetContext = true;
} }
@Override @Override
@@ -48,6 +79,12 @@ public abstract class NavigatableContextAction extends DockingAction {
@Override @Override
public final boolean isValidContext(ActionContext context) { public final boolean isValidContext(ActionContext context) {
// If this method returns false, then when the user is in a restricted view, the action
// will be passed the global context instead of the current local context
if (!supportsRestrictedAddressSetContext &&
context instanceof RestrictedAddressSetContext) {
return false;
}
return context instanceof NavigatableActionContext; return context instanceof NavigatableActionContext;
} }
@@ -1,6 +1,5 @@
/* ### /* ###
* IP: GHIDRA * IP: GHIDRA
* REVIEWED: YES
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,6 +15,12 @@
*/ */
package ghidra.app.context; package ghidra.app.context;
import ghidra.app.nav.Navigatable;
/**
* Marker interface for {@link Navigatable} contexts that don't support navigating to the entire
* program. Typically, these are used by providers that show only one function at a time such
* as the Decompiler.
*/
public interface RestrictedAddressSetContext { public interface RestrictedAddressSetContext {
} }
@@ -23,7 +23,8 @@ import docking.action.DockingAction;
import docking.action.MenuData; import docking.action.MenuData;
import docking.tool.ToolConstants; import docking.tool.ToolConstants;
import ghidra.app.CorePluginPackage; import ghidra.app.CorePluginPackage;
import ghidra.app.context.*; import ghidra.app.context.NavigatableActionContext;
import ghidra.app.context.NavigatableContextAction;
import ghidra.app.plugin.PluginCategoryNames; import ghidra.app.plugin.PluginCategoryNames;
import ghidra.app.plugin.ProgramPlugin; import ghidra.app.plugin.ProgramPlugin;
import ghidra.app.plugin.core.instructionsearch.ui.InstructionSearchDialog; import ghidra.app.plugin.core.instructionsearch.ui.InstructionSearchDialog;
@@ -238,17 +239,11 @@ public class InstructionSearchPlugin extends ProgramPlugin {
} }
private void createActions() { private void createActions() {
searchAction = new NavigatableContextAction(SEARCH_ACTION_NAME, getName()) { searchAction = new NavigatableContextAction(SEARCH_ACTION_NAME, getName(), false) {
@Override @Override
public void actionPerformed(NavigatableActionContext context) { public void actionPerformed(NavigatableActionContext context) {
showSearchDialog(context); showSearchDialog(context);
} }
@Override
protected boolean isEnabledForContext(NavigatableActionContext context) {
return !(context instanceof RestrictedAddressSetContext);
}
}; };
searchAction.addToWindowWhen(NavigatableActionContext.class); searchAction.addToWindowWhen(NavigatableActionContext.class);
searchAction.setHelpLocation(new HelpLocation("Search", "Instruction_Pattern_Search")); searchAction.setHelpLocation(new HelpLocation("Search", "Instruction_Pattern_Search"));
@@ -21,7 +21,8 @@ import docking.action.DockingAction;
import docking.action.MenuData; import docking.action.MenuData;
import docking.tool.ToolConstants; import docking.tool.ToolConstants;
import ghidra.app.CorePluginPackage; import ghidra.app.CorePluginPackage;
import ghidra.app.context.*; import ghidra.app.context.NavigatableActionContext;
import ghidra.app.context.NavigatableContextAction;
import ghidra.app.events.ViewChangedPluginEvent; import ghidra.app.events.ViewChangedPluginEvent;
import ghidra.app.plugin.PluginCategoryNames; import ghidra.app.plugin.PluginCategoryNames;
import ghidra.app.plugin.ProgramPlugin; import ghidra.app.plugin.ProgramPlugin;
@@ -138,16 +139,11 @@ public class ScalarSearchPlugin extends ProgramPlugin implements DomainObjectLis
private void createActions() { private void createActions() {
searchAction = new NavigatableContextAction(SEARCH_ACTION_NAME, getName()) { searchAction = new NavigatableContextAction(SEARCH_ACTION_NAME, getName(), false) {
@Override @Override
public void actionPerformed(NavigatableActionContext context) { public void actionPerformed(NavigatableActionContext context) {
openSearchDialog(); openSearchDialog();
} }
@Override
protected boolean isEnabledForContext(NavigatableActionContext context) {
return !(context instanceof RestrictedAddressSetContext);
}
}; };
searchAction.setHelpLocation(new HelpLocation(this.getName(), "Scalar_Search")); searchAction.setHelpLocation(new HelpLocation(this.getName(), "Scalar_Search"));
@@ -30,7 +30,8 @@ import docking.widgets.fieldpanel.support.Highlight;
import docking.widgets.table.threaded.*; import docking.widgets.table.threaded.*;
import ghidra.GhidraOptions; import ghidra.GhidraOptions;
import ghidra.app.CorePluginPackage; import ghidra.app.CorePluginPackage;
import ghidra.app.context.*; import ghidra.app.context.NavigatableActionContext;
import ghidra.app.context.NavigatableContextAction;
import ghidra.app.events.ProgramSelectionPluginEvent; import ghidra.app.events.ProgramSelectionPluginEvent;
import ghidra.app.nav.Navigatable; import ghidra.app.nav.Navigatable;
import ghidra.app.nav.NavigatableRemovalListener; import ghidra.app.nav.NavigatableRemovalListener;
@@ -342,17 +343,12 @@ public class MemSearchPlugin extends Plugin implements OptionsChangeListener,
} }
private void createActions() { private void createActions() {
searchAction = new NavigatableContextAction("Search Memory", getName()) { searchAction = new NavigatableContextAction("Search Memory", getName(), false) {
@Override @Override
public void actionPerformed(NavigatableActionContext context) { public void actionPerformed(NavigatableActionContext context) {
setNavigatable(context.getNavigatable()); setNavigatable(context.getNavigatable());
invokeSearchDialog(context); invokeSearchDialog(context);
} }
@Override
protected boolean isEnabledForContext(NavigatableActionContext context) {
return !(context instanceof RestrictedAddressSetContext);
}
}; };
searchAction.setHelpLocation(new HelpLocation(HelpTopics.SEARCH, searchAction.getName())); searchAction.setHelpLocation(new HelpLocation(HelpTopics.SEARCH, searchAction.getName()));
String[] menuPath = new String[] { "&Search", "&Memory..." }; String[] menuPath = new String[] { "&Search", "&Memory..." };
@@ -362,17 +358,12 @@ public class MemSearchPlugin extends Plugin implements OptionsChangeListener,
searchAction.addToWindowWhen(NavigatableActionContext.class); searchAction.addToWindowWhen(NavigatableActionContext.class);
tool.addAction(searchAction); tool.addAction(searchAction);
searchAgainAction = new NavigatableContextAction("Repeat Memory Search", getName()) { searchAgainAction = new NavigatableContextAction("Repeat Memory Search", getName(), false) {
@Override @Override
public void actionPerformed(NavigatableActionContext context) { public void actionPerformed(NavigatableActionContext context) {
setNavigatable(context.getNavigatable()); setNavigatable(context.getNavigatable());
performSearch(searchInfo); performSearch(searchInfo);
} }
@Override
protected boolean isEnabledForContext(NavigatableActionContext context) {
return !(context instanceof RestrictedAddressSetContext) && searchInfo != null;
}
}; };
searchAgainAction searchAgainAction
.setHelpLocation(new HelpLocation(HelpTopics.SEARCH, searchAgainAction.getName())); .setHelpLocation(new HelpLocation(HelpTopics.SEARCH, searchAgainAction.getName()));
@@ -30,8 +30,7 @@ import docking.widgets.fieldpanel.support.Highlight;
import docking.widgets.table.threaded.*; import docking.widgets.table.threaded.*;
import ghidra.GhidraOptions; import ghidra.GhidraOptions;
import ghidra.app.CorePluginPackage; import ghidra.app.CorePluginPackage;
import ghidra.app.context.ListingActionContext; import ghidra.app.context.*;
import ghidra.app.context.NavigatableActionContext;
import ghidra.app.nav.Navigatable; import ghidra.app.nav.Navigatable;
import ghidra.app.nav.NavigatableRemovalListener; import ghidra.app.nav.NavigatableRemovalListener;
import ghidra.app.plugin.PluginCategoryNames; import ghidra.app.plugin.PluginCategoryNames;
@@ -380,6 +379,7 @@ public class SearchTextPlugin extends ProgramPlugin implements OptionsChangeList
.description(DESCRIPTION) .description(DESCRIPTION)
.helpLocation(new HelpLocation(HelpTopics.SEARCH, "Search Text")) .helpLocation(new HelpLocation(HelpTopics.SEARCH, "Search Text"))
.withContext(NavigatableActionContext.class) .withContext(NavigatableActionContext.class)
.validContextWhen(c -> !(c instanceof RestrictedAddressSetContext))
.inWindow(ActionBuilder.When.CONTEXT_MATCHES) .inWindow(ActionBuilder.When.CONTEXT_MATCHES)
.supportsDefaultToolContext(true) .supportsDefaultToolContext(true)
.onAction(c -> { .onAction(c -> {