GT-2858 - fixed pointer data action keybinding

This commit is contained in:
dragonmacher 2019-05-14 12:19:42 -04:00
parent 8ed646450c
commit 92e72e71ed
4 changed files with 76 additions and 60 deletions

View file

@ -15,20 +15,19 @@
*/
package ghidra.app.plugin.core.data;
import javax.swing.KeyStroke;
import docking.action.*;
import docking.tool.util.DockingToolConstants;
import ghidra.app.context.ListingActionContext;
import ghidra.app.context.ListingContextAction;
import ghidra.framework.options.*;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.util.ToolConstants;
import ghidra.program.model.data.*;
import ghidra.util.HelpLocation;
import javax.swing.KeyStroke;
import docking.action.*;
/**
* Base class for comment actions to edit and delete comments.
* Base class for actions to create data types
*/
class DataAction extends ListingContextAction implements OptionsChangeListener {
@ -41,13 +40,6 @@ class DataAction extends ListingContextAction implements OptionsChangeListener {
this("Define " + dataType.getDisplayName(), "Data", dataType, plugin);
}
/**
* Constructor
*
* @param name action name
* @param isKeyBindingManagee
* @param owner owner of this action (the plugin name)
*/
public DataAction(String name, String group, DataType dataType, DataPlugin plugin) {
super(name, plugin.getName(), false);
this.actionName = name;
@ -56,12 +48,16 @@ class DataAction extends ListingContextAction implements OptionsChangeListener {
setPopupMenuData(new MenuData(new String[] { "Data", dataType.getDisplayName() }, group));
assignHelpID(dataType);
setEnabled(true);
initializeKeybinding();
}
private void initializeKeybinding() {
PluginTool tool = plugin.getTool();
dummyKeybindingsAction = new DummyKeyBindingsOptionsAction(name, getDefaultKeyStroke());
dummyKeybindingsAction =
new DummyKeyBindingsOptionsAction(actionName, getDefaultKeyStroke());
tool.addAction(dummyKeybindingsAction);
ToolOptions options = tool.getOptions(ToolConstants.KEY_BINDINGS);
ToolOptions options = tool.getOptions(DockingToolConstants.KEY_BINDINGS);
options.addOptionsChangeListener(this);
KeyStroke keyStroke =
options.getKeyStroke(dummyKeybindingsAction.getFullName(), getDefaultKeyStroke());
@ -85,10 +81,6 @@ class DataAction extends ListingContextAction implements OptionsChangeListener {
return dummyKeybindingsAction;
}
DataType getDataType() {
return dataType;
}
@Override
public void dispose() {
dataType = null;
@ -102,9 +94,25 @@ class DataAction extends ListingContextAction implements OptionsChangeListener {
return;
}
/**
* set the help ID according to what the data type is.
*/
@Override
public boolean isEnabledForContext(ListingActionContext context) {
return plugin.isCreateDataAllowed(context);
}
@Override
public void optionsChanged(ToolOptions options, String optionName, Object oldValue,
Object newValue) {
KeyStroke keyStroke = (KeyStroke) newValue;
if (optionName.startsWith(actionName)) {
setUnvalidatedKeyBindingData(new KeyBindingData(keyStroke));
}
}
DataType getDataType() {
return dataType;
}
// Set the help ID according to the data type
private void assignHelpID(DataType dt) {
String helpID = "Favorites";
@ -123,20 +131,4 @@ class DataAction extends ListingContextAction implements OptionsChangeListener {
setHelpLocation(new HelpLocation(plugin.getName(), helpID));
}
/*
* @see docking.DockableAction#isValidContext(java.lang.Object)
*/
@Override
public boolean isEnabledForContext(ListingActionContext context) {
return plugin.isCreateDataAllowed(context);
}
@Override
public void optionsChanged(ToolOptions options, String optionName, Object oldValue, Object newValue) {
KeyStroke keyStroke = (KeyStroke) newValue;
if (optionName.startsWith(actionName)) {
setUnvalidatedKeyBindingData(new KeyBindingData(keyStroke));
}
}
}

View file

@ -15,11 +15,8 @@
*/
package ghidra.app.plugin.core.data;
import java.awt.event.KeyEvent;
import java.util.*;
import javax.swing.KeyStroke;
import docking.ActionContext;
import docking.action.DockingAction;
import docking.action.MenuData;
@ -69,10 +66,7 @@ import ghidra.util.task.SwingUpdateManager;
public class DataPlugin extends Plugin implements DataService {
final static int BACKGROUND_SELECTION_THRESHOLD = 2048;
private final static KeyStroke POINTER_KEY_BINDING = KeyStroke.getKeyStroke(KeyEvent.VK_P, 0);
private final static DataType POINTER_DATA_TYPE = new PointerDataType();
final static DataType POINTER_DATA_TYPE = new PointerDataType();
private static final String BASIC_DATA_GROUP = "BasicData";
private static final String DATA_MENU_POPUP_PATH = "Data";
@ -137,7 +131,7 @@ public class DataPlugin extends Plugin implements DataService {
renameDataFieldAction = new RenameDataFieldAction(this);
tool.addAction(renameDataFieldAction);
pointerAction = new DataAction(POINTER_DATA_TYPE, this);
pointerAction = new PointerDataAction(this);
tool.addAction(pointerAction);
settingsAction = new DockingAction("Data Settings", getName()) {
@ -312,13 +306,9 @@ public class DataPlugin extends Plugin implements DataService {
return doCreateData(context, dt);
}
/**
/*
* This version uses the ProgramActionContext and does not depend on any
* plugin's currentProgram
*
* @param context
* @param dt
* @return
*/
boolean doCreateData(ListingActionContext context, DataType dt) {
ProgramSelection selection = context.getSelection();

View file

@ -0,0 +1,34 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.app.plugin.core.data;
import java.awt.event.KeyEvent;
import javax.swing.KeyStroke;
public class PointerDataAction extends DataAction {
private final static KeyStroke POINTER_KEY_BINDING = KeyStroke.getKeyStroke(KeyEvent.VK_P, 0);
public PointerDataAction(DataPlugin plugin) {
super(DataPlugin.POINTER_DATA_TYPE, plugin);
}
@Override
protected KeyStroke getDefaultKeyStroke() {
return POINTER_KEY_BINDING;
}
}

View file

@ -18,18 +18,18 @@ package ghidra.app.plugin.core.function;
import javax.swing.KeyStroke;
import docking.action.*;
import docking.tool.util.DockingToolConstants;
import ghidra.app.context.ListingActionContext;
import ghidra.app.context.ListingContextAction;
import ghidra.framework.options.*;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.util.ToolConstants;
import ghidra.program.model.data.DataType;
import ghidra.program.util.ProgramLocation;
import ghidra.program.util.VariableLocation;
import ghidra.util.HelpLocation;
/**
* Base class for comment actions to edit and delete comments.
* Base class for actions to create data types
*/
class DataAction extends ListingContextAction implements OptionsChangeListener {
@ -61,7 +61,7 @@ class DataAction extends ListingContextAction implements OptionsChangeListener {
dummyKeybindingsAction =
new DummyKeyBindingsOptionsAction(actionName, getDefaultKeyStroke());
tool.addAction(dummyKeybindingsAction);
ToolOptions options = tool.getOptions(ToolConstants.KEY_BINDINGS);
ToolOptions options = tool.getOptions(DockingToolConstants.KEY_BINDINGS);
options.addOptionsChangeListener(this);
KeyStroke keyStroke =
options.getKeyStroke(dummyKeybindingsAction.getFullName(), getDefaultKeyStroke());
@ -98,6 +98,11 @@ class DataAction extends ListingContextAction implements OptionsChangeListener {
super.dispose();
}
@Override
public void actionPerformed(ListingActionContext context) {
plugin.createData(dataType, context, true);
}
@Override
protected boolean isEnabledForContext(ListingActionContext context) {
if (context.hasSelection() || context.getAddress() == null) {
@ -115,11 +120,6 @@ class DataAction extends ListingContextAction implements OptionsChangeListener {
return false;
}
@Override
public void actionPerformed(ListingActionContext context) {
plugin.createData(dataType, context, true);
}
@Override
public void optionsChanged(ToolOptions options, String optionName, Object oldValue,
Object newValue) {