Merge branch 'master' of

https://github.com/NationalSecurityAgency/ghidra into spell
This commit is contained in:
Benjamin Levy 2020-01-27 16:15:47 -05:00 committed by dragonmacher
commit 74fae2f644
142 changed files with 1242 additions and 1568 deletions

View file

@ -377,7 +377,6 @@ src/main/help/help/topics/FunctionComparison/images/ListingCodeComparisonOptions
src/main/help/help/topics/FunctionComparison/images/MultiFunctionComparisonWindow.png||GHIDRA||||END| src/main/help/help/topics/FunctionComparison/images/MultiFunctionComparisonWindow.png||GHIDRA||||END|
src/main/help/help/topics/FunctionComparison/images/NavNextIcon.png||GHIDRA||||END| src/main/help/help/topics/FunctionComparison/images/NavNextIcon.png||GHIDRA||||END|
src/main/help/help/topics/FunctionComparison/images/NavPreviousIcon.png||GHIDRA||||END| src/main/help/help/topics/FunctionComparison/images/NavPreviousIcon.png||GHIDRA||||END|
src/main/help/help/topics/FunctionComparison/images/NavSelectedIcon.png||GHIDRA||||END|
src/main/help/help/topics/FunctionComparison/images/RemoveFromComparisonIcon.png||GHIDRA||||END| src/main/help/help/topics/FunctionComparison/images/RemoveFromComparisonIcon.png||GHIDRA||||END|
src/main/help/help/topics/FunctionComparison/images/binaryData.gif||GHIDRA||||END| src/main/help/help/topics/FunctionComparison/images/binaryData.gif||GHIDRA||||END|
src/main/help/help/topics/FunctionComparison/images/class.png||GHIDRA||||END| src/main/help/help/topics/FunctionComparison/images/class.png||GHIDRA||||END|
@ -725,7 +724,7 @@ src/main/help/help/topics/ShowInstructionInfoPlugin/images/ProcessorManualOption
src/main/help/help/topics/ShowInstructionInfoPlugin/images/RawInstructionDisplay.png||GHIDRA||||END| src/main/help/help/topics/ShowInstructionInfoPlugin/images/RawInstructionDisplay.png||GHIDRA||||END|
src/main/help/help/topics/ShowInstructionInfoPlugin/images/ShowInstructionInfo.png||GHIDRA||||END| src/main/help/help/topics/ShowInstructionInfoPlugin/images/ShowInstructionInfo.png||GHIDRA||||END|
src/main/help/help/topics/ShowInstructionInfoPlugin/images/UnableToLaunch.png||GHIDRA||||END| src/main/help/help/topics/ShowInstructionInfoPlugin/images/UnableToLaunch.png||GHIDRA||||END|
src/main/help/help/topics/Snapshots/Snapshots.html||GHIDRA||reviewed||END| src/main/help/help/topics/Snapshots/Snapshots.html||GHIDRA||||END|
src/main/help/help/topics/Snapshots/images/camera-photo.png||Tango Icons - Public Domain|||tango|END| src/main/help/help/topics/Snapshots/images/camera-photo.png||Tango Icons - Public Domain|||tango|END|
src/main/help/help/topics/StackEditor/StackEditor.html||GHIDRA||||END| src/main/help/help/topics/StackEditor/StackEditor.html||GHIDRA||||END|
src/main/help/help/topics/StackEditor/images/Array.png||GHIDRA||||END| src/main/help/help/topics/StackEditor/images/Array.png||GHIDRA||||END|

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -17,9 +17,11 @@ package ghidra.app.context;
import java.util.Set; import java.util.Set;
import docking.ActionContext; import docking.*;
import docking.action.DockingAction; import docking.action.DockingAction;
import docking.action.KeyBindingType; import docking.action.KeyBindingType;
import ghidra.app.nav.Navigatable;
import ghidra.app.services.GoToService;
public abstract class NavigatableContextAction extends DockingAction { public abstract class NavigatableContextAction extends DockingAction {
@ -33,23 +35,61 @@ public abstract class NavigatableContextAction extends DockingAction {
@Override @Override
public boolean isEnabledForContext(ActionContext context) { public boolean isEnabledForContext(ActionContext context) {
if (!(context instanceof NavigatableActionContext)) { NavigatableActionContext appropriateContext = getAppropriateContext(context);
if (appropriateContext == null) {
return false; return false;
} }
return isEnabledForContext((NavigatableActionContext) context); return isEnabledForContext(appropriateContext);
} }
@Override @Override
public void actionPerformed(ActionContext context) { public void actionPerformed(ActionContext context) {
actionPerformed((NavigatableActionContext) context); actionPerformed(getAppropriateContext(context));
}
private NavigatableActionContext getAppropriateContext(ActionContext context) {
if (context instanceof NavigatableActionContext &&
isValidNavigationContext((NavigatableActionContext) context)) {
return (NavigatableActionContext) context;
}
return getGlobalNavigationContext(context);
} }
@Override @Override
public boolean isValidContext(ActionContext context) { public final boolean isValidContext(ActionContext context) {
if (!(context instanceof NavigatableActionContext)) { return true;
return false;
} }
return isValidContext((NavigatableActionContext) context);
protected boolean isValidNavigationContext(NavigatableActionContext context) {
return true;
}
private NavigatableActionContext getGlobalNavigationContext(ActionContext context) {
Tool tool = getTool(context.getComponentProvider());
if (tool == null) {
return null;
}
GoToService service = tool.getService(GoToService.class);
if (service == null) {
return null;
}
Navigatable defaultNavigatable = service.getDefaultNavigatable();
if (defaultNavigatable.getProgram() == null) {
return null;
}
return new NavigatableActionContext(null, defaultNavigatable);
}
private Tool getTool(ComponentProvider provider) {
if (provider != null) {
return provider.getTool();
}
DockingWindowManager manager = DockingWindowManager.getActiveInstance();
if (manager != null) {
return manager.getTool();
}
return null;
} }
@Override @Override
@ -60,10 +100,6 @@ public abstract class NavigatableContextAction extends DockingAction {
return isAddToPopup((NavigatableActionContext) context); return isAddToPopup((NavigatableActionContext) context);
} }
protected boolean isValidContext(NavigatableActionContext context) {
return true;
}
protected boolean isEnabledForContext(NavigatableActionContext context) { protected boolean isEnabledForContext(NavigatableActionContext context) {
return true; return true;
} }

View file

@ -55,7 +55,7 @@ public class ListingMergePanelProvider extends ComponentProviderAdapter
} }
@Override @Override
public List<DockingActionIf> getPopupActions(DockingTool dt, ActionContext context) { public List<DockingActionIf> getPopupActions(Tool dt, ActionContext context) {
ListingPanel resultPanel = mergePanel.getResultPanel(); ListingPanel resultPanel = mergePanel.getResultPanel();
if (resultPanel != null) { if (resultPanel != null) {
return resultPanel.getHeaderActions(getName()); return resultPanel.getHeaderActions(getName());

View file

@ -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,16 +15,16 @@
*/ */
package ghidra.app.nav; package ghidra.app.nav;
import ghidra.framework.model.Tool;
import java.util.*; import java.util.*;
import ghidra.framework.plugintool.PluginTool;
public class NavigatableRegistry { public class NavigatableRegistry {
private static Map<Long, Navigatable> navigatableMap = new HashMap<Long, Navigatable>(); private static Map<Long, Navigatable> navigatableMap = new HashMap<Long, Navigatable>();
private static Map<Tool, List<Navigatable>> toolMap = new HashMap<Tool, List<Navigatable>>(); private static Map<PluginTool, List<Navigatable>> toolMap =
new HashMap<PluginTool, List<Navigatable>>();
public static void registerNavigatable(PluginTool tool, Navigatable navigatable) {
public static void registerNavigatable(Tool tool, Navigatable navigatable) {
navigatableMap.put(navigatable.getInstanceID(), navigatable); navigatableMap.put(navigatable.getInstanceID(), navigatable);
List<Navigatable> list = toolMap.get(tool); List<Navigatable> list = toolMap.get(tool);
if (list == null) { if (list == null) {
@ -35,7 +34,7 @@ public class NavigatableRegistry {
list.add(navigatable); list.add(navigatable);
} }
public static void unregisterNavigatable(Tool tool, Navigatable navigatable) { public static void unregisterNavigatable(PluginTool tool, Navigatable navigatable) {
navigatableMap.remove(navigatable.getInstanceID()); navigatableMap.remove(navigatable.getInstanceID());
List<Navigatable> list = toolMap.get(tool); List<Navigatable> list = toolMap.get(tool);
if (list == null) { if (list == null) {
@ -46,13 +45,15 @@ public class NavigatableRegistry {
toolMap.remove(tool); toolMap.remove(tool);
} }
} }
public static List<Navigatable> getRegisteredNavigatables(Tool tool) {
public static List<Navigatable> getRegisteredNavigatables(PluginTool tool) {
List<Navigatable> list = toolMap.get(tool); List<Navigatable> list = toolMap.get(tool);
if (list == null) { if (list == null) {
list = new ArrayList<Navigatable>(navigatableMap.values()); list = new ArrayList<Navigatable>(navigatableMap.values());
} }
return list; return list;
} }
public static Navigatable getNavigatable(long navigationID) { public static Navigatable getNavigatable(long navigationID) {
return navigatableMap.get(navigationID); return navigatableMap.get(navigationID);
} }

View file

@ -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,8 @@
*/ */
package ghidra.app.nav; package ghidra.app.nav;
import java.util.Set;
import ghidra.app.context.*; import ghidra.app.context.*;
import ghidra.app.plugin.core.navigation.NavigationOptions; import ghidra.app.plugin.core.navigation.NavigationOptions;
import ghidra.app.services.GoToService; import ghidra.app.services.GoToService;
@ -24,8 +25,6 @@ import ghidra.program.model.address.*;
import ghidra.program.model.listing.CodeUnit; import ghidra.program.model.listing.CodeUnit;
import ghidra.program.util.ProgramSelection; import ghidra.program.util.ProgramSelection;
import java.util.Set;
public abstract class NextRangeAction extends NavigatableContextAction { public abstract class NextRangeAction extends NavigatableContextAction {
private PluginTool tool; private PluginTool tool;
@ -39,7 +38,7 @@ public abstract class NextRangeAction extends NavigatableContextAction {
} }
@Override @Override
protected boolean isValidContext(NavigatableActionContext context) { protected boolean isValidNavigationContext(NavigatableActionContext context) {
// //
// We want the nav actions to work in the current view that supports this, which right // We want the nav actions to work in the current view that supports this, which right
// now is the ListingActionContext. If the current context does not support that, then // now is the ListingActionContext. If the current context does not support that, then
@ -51,13 +50,12 @@ public abstract class NextRangeAction extends NavigatableContextAction {
@Override @Override
public boolean isEnabledForContext(NavigatableActionContext context) { public boolean isEnabledForContext(NavigatableActionContext context) {
Address currentAddress = context.getAddress(); Address currentAddress = context.getAddress();
ListingActionContext listingContext = (ListingActionContext) context; ProgramSelection selection = getSelection(context);
ProgramSelection selection = getSelection(listingContext);
if (selection == null || selection.isEmpty() || currentAddress == null) { if (selection == null || selection.isEmpty() || currentAddress == null) {
return false; return false;
} }
CodeUnit cu = listingContext.getProgram().getListing().getCodeUnitAt(currentAddress); CodeUnit cu = context.getProgram().getListing().getCodeUnitAt(currentAddress);
if (cu != null) { if (cu != null) {
currentAddress = cu.getMaxAddress(); currentAddress = cu.getMaxAddress();
} }
@ -71,13 +69,10 @@ public abstract class NextRangeAction extends NavigatableContextAction {
@Override @Override
public void actionPerformed(NavigatableActionContext context) { public void actionPerformed(NavigatableActionContext context) {
// Note: we verified above that the context we are grabbing here is the correct type Address goToAddress = getGoToAddress(context);
ListingActionContext listingContext = (ListingActionContext) context;
Address goToAddress = getGoToAddress(listingContext);
GoToService service = tool.getService(GoToService.class); GoToService service = tool.getService(GoToService.class);
if (service != null) { if (service != null) {
service.goTo(listingContext.getNavigatable(), goToAddress); service.goTo(context.getNavigatable(), goToAddress);
} }
} }

View file

@ -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,8 @@
*/ */
package ghidra.app.nav; package ghidra.app.nav;
import java.util.Set;
import ghidra.app.context.*; import ghidra.app.context.*;
import ghidra.app.plugin.core.navigation.NavigationOptions; import ghidra.app.plugin.core.navigation.NavigationOptions;
import ghidra.app.services.GoToService; import ghidra.app.services.GoToService;
@ -23,8 +24,6 @@ import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.address.*; import ghidra.program.model.address.*;
import ghidra.program.util.ProgramSelection; import ghidra.program.util.ProgramSelection;
import java.util.Set;
public abstract class PreviousRangeAction extends NavigatableContextAction { public abstract class PreviousRangeAction extends NavigatableContextAction {
private PluginTool tool; private PluginTool tool;
@ -39,7 +38,7 @@ public abstract class PreviousRangeAction extends NavigatableContextAction {
} }
@Override @Override
protected boolean isValidContext(NavigatableActionContext context) { protected boolean isValidNavigationContext(NavigatableActionContext context) {
// //
// We want the nav actions to work in the current view that supports this, which right // We want the nav actions to work in the current view that supports this, which right
// now is the ListingActionContext. If the current context does not support that, then // now is the ListingActionContext. If the current context does not support that, then
@ -58,9 +57,8 @@ public abstract class PreviousRangeAction extends NavigatableContextAction {
} }
private Address getGoToAddress(NavigatableActionContext context) { private Address getGoToAddress(NavigatableActionContext context) {
ListingActionContext listingContext = (ListingActionContext) context; ProgramSelection selection = getSelection(context);
ProgramSelection selection = getSelection(listingContext); Address currentAddress = context.getAddress();
Address currentAddress = listingContext.getAddress();
AddressRangeIterator it = selection.getAddressRanges(currentAddress, false); AddressRangeIterator it = selection.getAddressRanges(currentAddress, false);
if (!it.hasNext()) { if (!it.hasNext()) {
@ -94,8 +92,7 @@ public abstract class PreviousRangeAction extends NavigatableContextAction {
@Override @Override
public boolean isEnabledForContext(NavigatableActionContext context) { public boolean isEnabledForContext(NavigatableActionContext context) {
Address currentAddress = context.getAddress(); Address currentAddress = context.getAddress();
ListingActionContext listingContext = (ListingActionContext) context; ProgramSelection selection = getSelection(context);
ProgramSelection selection = getSelection(listingContext);
if (selection == null || selection.isEmpty() || currentAddress == null) { if (selection == null || selection.isEmpty() || currentAddress == null) {
return false; return false;
} }

View file

@ -22,7 +22,7 @@ import javax.swing.Icon;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import docking.ActionContext; import docking.ActionContext;
import docking.DockingTool; import docking.Tool;
import docking.action.*; import docking.action.*;
import docking.actions.PopupActionProvider; import docking.actions.PopupActionProvider;
import docking.widgets.table.GTable; import docking.widgets.table.GTable;
@ -362,10 +362,6 @@ public class BookmarkPlugin extends ProgramPlugin
getBookmarkNavigator(bookmarkMgr.getBookmarkType(type)); getBookmarkNavigator(bookmarkMgr.getBookmarkType(type));
} }
/**
* Bookmark has been changed.
* @param bookmark
*/
private void bookmarkChanged(Bookmark bookmark) { private void bookmarkChanged(Bookmark bookmark) {
if (bookmark == null) { if (bookmark == null) {
scheduleUpdate(null); scheduleUpdate(null);
@ -378,10 +374,6 @@ public class BookmarkPlugin extends ProgramPlugin
provider.bookmarkChanged(bookmark); provider.bookmarkChanged(bookmark);
} }
/**
* Bookmark has been added.
* @param bookmark
*/
private void bookmarkAdded(Bookmark bookmark) { private void bookmarkAdded(Bookmark bookmark) {
if (bookmark == null) { if (bookmark == null) {
scheduleUpdate(null); scheduleUpdate(null);
@ -496,7 +488,7 @@ public class BookmarkPlugin extends ProgramPlugin
} }
@Override @Override
public List<DockingActionIf> getPopupActions(DockingTool tool, ActionContext context) { public List<DockingActionIf> getPopupActions(Tool activeTool, ActionContext context) {
Object contextObject = context.getContextObject(); Object contextObject = context.getContextObject();
if (!(contextObject instanceof MarkerLocation)) { if (!(contextObject instanceof MarkerLocation)) {
return null; return null;

View file

@ -26,7 +26,7 @@ import ghidra.app.context.ListingContextAction;
import ghidra.app.plugin.PluginCategoryNames; import ghidra.app.plugin.PluginCategoryNames;
import ghidra.framework.cmd.Command; import ghidra.framework.cmd.Command;
import ghidra.framework.plugintool.*; import ghidra.framework.plugintool.*;
import ghidra.framework.plugintool.util.*; import ghidra.framework.plugintool.util.PluginStatus;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSet; import ghidra.program.model.address.AddressSet;
import ghidra.program.model.data.*; import ghidra.program.model.data.*;
@ -264,12 +264,6 @@ public class ClearPlugin extends Plugin {
} }
return false; return false;
} }
@Override
public boolean isValidGlobalContext(ActionContext context) {
// it's too dangerous to let the clear action work globally
return false;
}
}; };
int menuOrdinal = 1; int menuOrdinal = 1;

View file

@ -952,7 +952,7 @@ public class CodeViewerProvider extends NavigatableComponentProviderAdapter
} }
@Override @Override
public List<DockingActionIf> getPopupActions(DockingTool dt, ActionContext context) { public List<DockingActionIf> getPopupActions(Tool dt, ActionContext context) {
if (context.getComponentProvider() == this) { if (context.getComponentProvider() == this) {
return listingPanel.getHeaderActions(getName()); return listingPanel.getHeaderActions(getName());
} }

View file

@ -17,7 +17,6 @@ package ghidra.app.plugin.core.comments;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import docking.ActionContext;
import docking.action.*; import docking.action.*;
import ghidra.app.CorePluginPackage; import ghidra.app.CorePluginPackage;
import ghidra.app.cmd.comments.SetCommentCmd; import ghidra.app.cmd.comments.SetCommentCmd;
@ -187,11 +186,6 @@ public class CommentsPlugin extends Plugin implements OptionsChangeListener {
getPopupMenuData().setMenuPath(new String[] { "Comments", "Delete" }); getPopupMenuData().setMenuPath(new String[] { "Comments", "Delete" });
return false; return false;
} }
@Override
public boolean isValidGlobalContext(ActionContext globalContext) {
return false; // only work on active provider context.
}
}; };
deleteAction.setPopupMenuData(new MenuData(DELETE_MENUPATH, null, "comments")); deleteAction.setPopupMenuData(new MenuData(DELETE_MENUPATH, null, "comments"));
deleteAction.setKeyBindingData(new KeyBindingData(KeyEvent.VK_DELETE, 0)); deleteAction.setKeyBindingData(new KeyBindingData(KeyEvent.VK_DELETE, 0));

View file

@ -27,7 +27,7 @@ import javax.swing.SwingUtilities;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import docking.ActionContext; import docking.ActionContext;
import docking.DockingTool; import docking.Tool;
import docking.action.*; import docking.action.*;
import docking.actions.PopupActionProvider; import docking.actions.PopupActionProvider;
import docking.widgets.tree.GTreeNode; import docking.widgets.tree.GTreeNode;
@ -678,7 +678,7 @@ public class DataTypeManagerPlugin extends ProgramPlugin
} }
@Override @Override
public List<DockingActionIf> getPopupActions(DockingTool dockingTool, ActionContext context) { public List<DockingActionIf> getPopupActions(Tool dockingTool, ActionContext context) {
if (!(context instanceof DataTypesActionContext)) { if (!(context instanceof DataTypesActionContext)) {
return null; return null;
} }

View file

@ -22,8 +22,8 @@ import javax.swing.ComboBoxModel;
import javax.swing.JPanel; import javax.swing.JPanel;
import docking.ComponentProvider; import docking.ComponentProvider;
import docking.actions.DockingToolActions;
import docking.actions.SharedDockingActionPlaceholder; import docking.actions.SharedDockingActionPlaceholder;
import docking.actions.ToolActions;
import docking.widgets.checkbox.GCheckBox; import docking.widgets.checkbox.GCheckBox;
import docking.widgets.combobox.GhidraComboBox; import docking.widgets.combobox.GhidraComboBox;
import docking.widgets.label.GLabel; import docking.widgets.label.GLabel;
@ -163,7 +163,7 @@ public class DataTypeEditorManager
} }
private void registerAction(String name) { private void registerAction(String name) {
ToolActions toolActions = plugin.getTool().getToolActions(); DockingToolActions toolActions = plugin.getTool().getToolActions();
toolActions.registerSharedActionPlaceholder(new DtSharedActionPlaceholder(name)); toolActions.registerSharedActionPlaceholder(new DtSharedActionPlaceholder(name));
} }

View file

@ -19,7 +19,6 @@ import java.awt.event.KeyEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import docking.ActionContext;
import docking.action.*; import docking.action.*;
import docking.widgets.OptionDialog; import docking.widgets.OptionDialog;
import ghidra.app.CorePluginPackage; import ghidra.app.CorePluginPackage;
@ -374,8 +373,8 @@ public class EquatePlugin extends Plugin {
Program program = context.getProgram(); Program program = context.getProgram();
List<Integer> opIndices = getInstructionMatches(program, inst, equate); List<Integer> opIndices = getInstructionMatches(program, inst, equate);
Address addr = inst.getAddress(); Address addr = inst.getAddress();
for (int i = 0; i < opIndices.size(); i++) { for (Integer opIndice : opIndices) {
bgCmd.add(createRenameCmd(oldName, newName, addr, opIndices.get(i))); bgCmd.add(createRenameCmd(oldName, newName, addr, opIndice));
} }
} }
else if (cu instanceof Data) { else if (cu instanceof Data) {
@ -429,9 +428,9 @@ public class EquatePlugin extends Plugin {
Program program = context.getProgram(); Program program = context.getProgram();
List<Integer> opIndexes = getInstructionMatches(program, instr, equate); List<Integer> opIndexes = getInstructionMatches(program, instr, equate);
for (int i = 0; i < opIndexes.size(); i++) { for (Integer opIndexe : opIndexes) {
bckCmd.add( bckCmd.add(
new ClearEquateCmd(equate.getName(), instr.getAddress(), opIndexes.get(i))); new ClearEquateCmd(equate.getName(), instr.getAddress(), opIndexe));
} }
} }
else if (cu instanceof Data) { else if (cu instanceof Data) {
@ -728,12 +727,6 @@ public class EquatePlugin extends Plugin {
protected boolean isEnabledForContext(ListingActionContext context) { protected boolean isEnabledForContext(ListingActionContext context) {
return getEquate(context) != null; return getEquate(context) != null;
} }
@Override
public boolean isValidGlobalContext(ActionContext globalContext) {
return false; // only work on active provider context.
}
}; };
removeAction.setPopupMenuData(new MenuData(REMOVE_MENUPATH, null, GROUP_NAME)); removeAction.setPopupMenuData(new MenuData(REMOVE_MENUPATH, null, GROUP_NAME));
removeAction.setKeyBindingData(new KeyBindingData(KeyEvent.VK_DELETE, 0)); removeAction.setKeyBindingData(new KeyBindingData(KeyEvent.VK_DELETE, 0));

View file

@ -17,7 +17,6 @@ package ghidra.app.plugin.core.function;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import docking.ActionContext;
import docking.action.KeyBindingData; import docking.action.KeyBindingData;
import docking.action.MenuData; import docking.action.MenuData;
import ghidra.app.cmd.function.DeleteFunctionCmd; import ghidra.app.cmd.function.DeleteFunctionCmd;
@ -71,9 +70,4 @@ class DeleteFunctionAction extends ListingContextAction {
return false; return false;
} }
@Override
public boolean isValidGlobalContext(ActionContext globalContext) {
return false; // only work on active provider context.
}
} }

View file

@ -17,7 +17,6 @@ package ghidra.app.plugin.core.function;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import docking.ActionContext;
import docking.action.KeyBindingData; import docking.action.KeyBindingData;
import docking.action.MenuData; import docking.action.MenuData;
import ghidra.app.cmd.function.CallDepthChangeInfo; import ghidra.app.cmd.function.CallDepthChangeInfo;
@ -73,9 +72,4 @@ class RemoveStackDepthChangeAction extends ListingContextAction {
context.getAddress()) != null; context.getAddress()) != null;
} }
@Override
public boolean isValidGlobalContext(ActionContext globalContext) {
return false; // only work on active provider context.
}
} }

View file

@ -17,7 +17,6 @@ package ghidra.app.plugin.core.function;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import docking.ActionContext;
import docking.action.KeyBindingData; import docking.action.KeyBindingData;
import docking.action.KeyBindingType; import docking.action.KeyBindingType;
import ghidra.app.cmd.function.SetVariableCommentCmd; import ghidra.app.cmd.function.SetVariableCommentCmd;
@ -89,8 +88,4 @@ class VariableCommentDeleteAction extends ListingContextAction {
return (loc instanceof VariableCommentFieldLocation); return (loc instanceof VariableCommentFieldLocation);
} }
@Override
public boolean isValidGlobalContext(ActionContext globalContext) {
return false; // only work on active provider context.
}
} }

View file

@ -17,7 +17,6 @@ package ghidra.app.plugin.core.function;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import docking.ActionContext;
import docking.action.KeyBindingData; import docking.action.KeyBindingData;
import docking.action.MenuData; import docking.action.MenuData;
import ghidra.app.cmd.function.DeleteVariableCmd; import ghidra.app.cmd.function.DeleteVariableCmd;
@ -105,9 +104,4 @@ class VariableDeleteAction extends ListingContextAction {
} }
return null; return null;
} }
@Override
public boolean isValidGlobalContext(ActionContext globalContext) {
return false; // only work on active provider context.
}
} }

View file

@ -19,7 +19,7 @@ import java.awt.event.MouseEvent;
import java.util.*; import java.util.*;
import docking.ActionContext; import docking.ActionContext;
import docking.DockingTool; import docking.Tool;
import docking.action.DockingAction; import docking.action.DockingAction;
import docking.action.DockingActionIf; import docking.action.DockingActionIf;
import docking.actions.PopupActionProvider; import docking.actions.PopupActionProvider;
@ -130,7 +130,7 @@ public class FunctionComparisonProvider extends ComponentProviderAdapter
} }
@Override @Override
public List<DockingActionIf> getPopupActions(DockingTool tool, ActionContext context) { public List<DockingActionIf> getPopupActions(Tool tool, ActionContext context) {
if (context.getComponentProvider() == this) { if (context.getComponentProvider() == this) {
ListingCodeComparisonPanel dualListingPanel = ListingCodeComparisonPanel dualListingPanel =
functionComparisonPanel.getDualListingPanel(); functionComparisonPanel.getDualListingPanel();

View file

@ -60,7 +60,7 @@ public final class GoToServicePlugin extends ProgramPlugin {
* Creates a new instance of the <CODE>GoToServicePlugin</CODE> * Creates a new instance of the <CODE>GoToServicePlugin</CODE>
*/ */
public GoToServicePlugin(PluginTool plugintool) { public GoToServicePlugin(PluginTool plugintool) {
super(plugintool, true, false); super(plugintool, true, true);
gotoService = new GoToServiceImpl(this, new DefaultNavigatable()); gotoService = new GoToServiceImpl(this, new DefaultNavigatable());

View file

@ -245,7 +245,7 @@ public class InstructionSearchPlugin extends ProgramPlugin {
} }
@Override @Override
protected boolean isValidContext(NavigatableActionContext context) { protected boolean isValidNavigationContext(NavigatableActionContext context) {
return !(context instanceof RestrictedAddressSetContext); return !(context instanceof RestrictedAddressSetContext);
} }
}; };

View file

@ -19,7 +19,6 @@ import java.awt.event.KeyEvent;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
import docking.ActionContext;
import docking.action.*; import docking.action.*;
import ghidra.app.context.ListingActionContext; import ghidra.app.context.ListingActionContext;
import ghidra.app.context.ListingContextAction; import ghidra.app.context.ListingContextAction;
@ -66,11 +65,6 @@ class RemoveLabelAction extends ListingContextAction {
return !plugin.isOnExternalReference(context) && isOnSymbol(context); return !plugin.isOnExternalReference(context) && isOnSymbol(context);
} }
@Override
public boolean isValidGlobalContext(ActionContext globalContext) {
return false; // only work on active provider context.
}
boolean isOnSymbol(ListingActionContext context) { boolean isOnSymbol(ListingActionContext context) {
Symbol s = plugin.getSymbol(context); Symbol s = plugin.getSymbol(context);
return ((s instanceof CodeSymbol) && !s.isDynamic()) || return ((s instanceof CodeSymbol) && !s.isDynamic()) ||

View file

@ -316,16 +316,6 @@ public class NextPrevAddressPlugin extends Plugin {
setDescription(isNext ? "Go to next location" : "Go to previous location"); setDescription(isNext ? "Go to next location" : "Go to previous location");
} }
@Override
public boolean isValidContext(ActionContext context) {
return false;
}
@Override
public boolean isValidGlobalContext(ActionContext globalContext) {
return (globalContext instanceof NavigatableActionContext);
}
@Override @Override
public boolean isEnabledForContext(ActionContext context) { public boolean isEnabledForContext(ActionContext context) {
Navigatable navigatable = getNavigatable(context); Navigatable navigatable = getNavigatable(context);
@ -426,16 +416,6 @@ public class NextPrevAddressPlugin extends Plugin {
setMenuBarData(menuData); setMenuBarData(menuData);
} }
@Override
public boolean isValidContext(ActionContext context) {
return false;
}
@Override
public boolean isValidGlobalContext(ActionContext globalContext) {
return (globalContext instanceof NavigatableActionContext);
}
@Override @Override
public boolean isEnabledForContext(ActionContext context) { public boolean isEnabledForContext(ActionContext context) {
Navigatable navigatable = getNavigatable(context); Navigatable navigatable = getNavigatable(context);

View file

@ -326,7 +326,7 @@ public final class LanguageProviderPlugin extends Plugin implements FrontEndable
SwingUtilities.invokeAndWait(() -> { SwingUtilities.invokeAndWait(() -> {
ToolServices toolServices = tool.getToolServices(); ToolServices toolServices = tool.getToolServices();
String defaultToolName = toolServices.getDefaultToolTemplate(file).getName(); String defaultToolName = toolServices.getDefaultToolTemplate(file).getName();
for (Tool t : toolServices.getRunningTools()) { for (PluginTool t : toolServices.getRunningTools()) {
if (t.getName().equals(defaultToolName)) { if (t.getName().equals(defaultToolName)) {
openTool = (PluginTool) t; openTool = (PluginTool) t;
break; break;

View file

@ -17,7 +17,6 @@ package ghidra.app.plugin.core.references;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import docking.ActionContext;
import docking.action.KeyBindingData; import docking.action.KeyBindingData;
import docking.action.MenuData; import docking.action.MenuData;
import ghidra.app.cmd.refs.RemoveAllReferencesCmd; import ghidra.app.cmd.refs.RemoveAllReferencesCmd;
@ -116,10 +115,4 @@ public class DeleteReferencesAction extends ListingContextAction {
} }
return actionOK; return actionOK;
} }
@Override
public boolean isValidGlobalContext(ActionContext globalContext) {
return false; // only work on active provider context.
}
} }

View file

@ -167,11 +167,6 @@ public class RegisterPlugin extends ProgramPlugin {
} }
return false; return false;
} }
@Override
public boolean isValidGlobalContext(ActionContext globalContext) {
return false; // only work on active provider context.
}
}; };
deleteRegisterRangeAction.setKeyBindingData(new KeyBindingData(KeyEvent.VK_DELETE, 0)); deleteRegisterRangeAction.setKeyBindingData(new KeyBindingData(KeyEvent.VK_DELETE, 0));

View file

@ -145,7 +145,7 @@ public class ScalarSearchPlugin extends ProgramPlugin implements DomainObjectLis
} }
@Override @Override
protected boolean isValidContext(NavigatableActionContext context) { protected boolean isValidNavigationContext(NavigatableActionContext context) {
return !(context instanceof RestrictedAddressSetContext); return !(context instanceof RestrictedAddressSetContext);
} }
}; };

View file

@ -350,7 +350,7 @@ public class MemSearchPlugin extends Plugin implements OptionsChangeListener,
} }
@Override @Override
protected boolean isValidContext(NavigatableActionContext context) { protected boolean isValidNavigationContext(NavigatableActionContext context) {
return !(context instanceof RestrictedAddressSetContext); return !(context instanceof RestrictedAddressSetContext);
} }
}; };
@ -374,7 +374,7 @@ public class MemSearchPlugin extends Plugin implements OptionsChangeListener,
} }
@Override @Override
protected boolean isValidContext(NavigatableActionContext context) { protected boolean isValidNavigationContext(NavigatableActionContext context) {
return !(context instanceof RestrictedAddressSetContext); return !(context instanceof RestrictedAddressSetContext);
} }
}; };

View file

@ -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.

View file

@ -95,6 +95,7 @@ public class BinaryLoader extends AbstractProgramLoader {
long length = 0; long length = 0;
long fileOffset = 0; long fileOffset = 0;
long origFileLength; long origFileLength;
boolean isOverlay = false;
try { try {
origFileLength = provider.length(); origFileLength = provider.length();
} }
@ -174,6 +175,7 @@ public class BinaryLoader extends AbstractProgramLoader {
if (!Boolean.class.isAssignableFrom(option.getValueClass())) { if (!Boolean.class.isAssignableFrom(option.getValueClass())) {
return OPTION_NAME_IS_OVERLAY + " must be a boolean"; return OPTION_NAME_IS_OVERLAY + " must be a boolean";
} }
isOverlay = (boolean) option.getValue();
} }
} }
catch (Exception e) { catch (Exception e) {
@ -194,7 +196,7 @@ public class BinaryLoader extends AbstractProgramLoader {
return "Invalid length specified"; return "Invalid length specified";
} }
if (program != null) { if (program != null) {
if (program.getMemory().intersects(baseAddr, baseAddr.add(length - 1))) { if (program.getMemory().intersects(baseAddr, baseAddr.add(length - 1)) && !isOverlay) {
return "Memory Conflict: Use <Options...> to change the base address!"; return "Memory Conflict: Use <Options...> to change the base address!";
} }
} }
@ -340,7 +342,7 @@ public class BinaryLoader extends AbstractProgramLoader {
FileBytes fileBytes, long length, MessageLog log) FileBytes fileBytes, long length, MessageLog log)
throws AddressOverflowException, IOException { throws AddressOverflowException, IOException {
if (prog.getMemory().intersects(baseAddr, baseAddr.add(length - 1))) { if (prog.getMemory().intersects(baseAddr, baseAddr.add(length - 1)) && !isOverlay) {
throw new IOException("Can't load " + length + " bytes at address " + baseAddr + throw new IOException("Can't load " + length + " bytes at address " + baseAddr +
" since it conflicts with existing memory blocks!"); " since it conflicts with existing memory blocks!");
} }

View file

@ -166,7 +166,8 @@ class FunctionsXmlMgr {
String regularComment = getElementText(parser, "REGULAR_CMT"); String regularComment = getElementText(parser, "REGULAR_CMT");
func.setComment(regularComment); func.setComment(regularComment);
getElementText(parser, "REPEATABLE_CMT"); String repeatableComment = getElementText(parser, "REPEATABLE_CMT");
func.setRepeatableComment(repeatableComment);
String typeInfoComment = getElementText(parser, "TYPEINFO_CMT"); String typeInfoComment = getElementText(parser, "TYPEINFO_CMT");
List<Variable> stackParams = new ArrayList<>(); List<Variable> stackParams = new ArrayList<>();
List<Variable> stackVariables = new ArrayList<>(); List<Variable> stackVariables = new ArrayList<>();
@ -533,6 +534,7 @@ class FunctionsXmlMgr {
writeReturnType(writer, func); writeReturnType(writer, func);
writeAddressRange(writer, func); writeAddressRange(writer, func);
writeRegularComment(writer, func.getComment()); writeRegularComment(writer, func.getComment());
writeRepeatableComment(writer, func.getRepeatableComment());
if (func.getSignatureSource() != SourceType.DEFAULT) { if (func.getSignatureSource() != SourceType.DEFAULT) {
writeTypeInfoComment(writer, func); writeTypeInfoComment(writer, func);
} }
@ -602,6 +604,12 @@ class FunctionsXmlMgr {
} }
} }
private void writeRepeatableComment(XmlWriter writer, String comment) {
if (comment != null && comment.length() > 0) {
writer.writeElement("REPEATABLE_CMT", null, comment);
}
}
private void writeStackFrame(XmlWriter writer, Function func) { private void writeStackFrame(XmlWriter writer, Function func) {
StackFrame frame = func.getStackFrame(); StackFrame frame = func.getStackFrame();

View file

@ -22,7 +22,6 @@ import docking.ActionContext;
import docking.widgets.tree.GTreeNode; import docking.widgets.tree.GTreeNode;
import ghidra.app.services.ProgramManager; import ghidra.app.services.ProgramManager;
import ghidra.formats.gfilesystem.*; import ghidra.formats.gfilesystem.*;
import ghidra.framework.model.Tool;
import ghidra.framework.plugintool.PluginTool; import ghidra.framework.plugintool.PluginTool;
import ghidra.util.Msg; import ghidra.util.Msg;
@ -60,7 +59,7 @@ public class FSBUtils {
} }
public static FSBRootNode getNodesRoot(FSBNode node) { public static FSBRootNode getNodesRoot(FSBNode node) {
GTreeNode tmp = (GTreeNode) node; GTreeNode tmp = node;
while (tmp != null && !(tmp instanceof FSBRootNode)) { while (tmp != null && !(tmp instanceof FSBRootNode)) {
tmp = tmp.getParent(); tmp = tmp.getParent();
} }
@ -102,15 +101,13 @@ public class FSBUtils {
public static List<PluginTool> getRunningProgramManagerTools(PluginTool tool) { public static List<PluginTool> getRunningProgramManagerTools(PluginTool tool) {
List<PluginTool> pluginTools = new ArrayList<>(); List<PluginTool> pluginTools = new ArrayList<>();
for (Tool runningTool : tool.getToolServices().getRunningTools()) { for (PluginTool runningTool : tool.getToolServices().getRunningTools()) {
if (runningTool instanceof PluginTool) { PluginTool pt = runningTool;
PluginTool pt = (PluginTool) runningTool;
ProgramManager pmService = pt.getService(ProgramManager.class); ProgramManager pmService = pt.getService(ProgramManager.class);
if (pmService != null) { if (pmService != null) {
pluginTools.add(pt); pluginTools.add(pt);
} }
} }
}
return pluginTools; return pluginTools;
} }

View file

@ -22,6 +22,7 @@ import java.util.*;
import generic.test.AbstractGenericTest; import generic.test.AbstractGenericTest;
import ghidra.framework.model.*; import ghidra.framework.model.*;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.store.LockException; import ghidra.framework.store.LockException;
import ghidra.program.database.ProgramDB; import ghidra.program.database.ProgramDB;
import ghidra.program.model.lang.*; import ghidra.program.model.lang.*;
@ -155,18 +156,18 @@ public class ProjectTestUtils {
return dir.delete(); return dir.delete();
} }
for (int i = 0; i < files.length; i++) { for (File file : files) {
if (files[i].isDirectory()) { if (file.isDirectory()) {
// use a dummy monitor as not to ruin our progress // use a dummy monitor as not to ruin our progress
if (!deleteDir(files[i])) { if (!deleteDir(file)) {
Msg.debug(ProjectTestUtils.class, "Unable to delete directory: " + files[i]); Msg.debug(ProjectTestUtils.class, "Unable to delete directory: " + file);
return false; return false;
} }
} }
else { else {
if (!files[i].delete()) { if (!file.delete()) {
if (!ignoredDeleteNames.contains(files[i].getName())) { if (!ignoredDeleteNames.contains(file.getName())) {
Msg.debug(ProjectTestUtils.class, "Unable to delete file: " + files[i]); Msg.debug(ProjectTestUtils.class, "Unable to delete file: " + file);
return false; return false;
} }
@ -186,6 +187,10 @@ public class ProjectTestUtils {
* @param folder domain folder within the specified project which the * @param folder domain folder within the specified project which the
* user has permission to write. If null, the root data folder will be used. * user has permission to write. If null, the root data folder will be used.
* @return new domain file. * @return new domain file.
* @throws InvalidNameException if the filename is invalid
* @throws CancelledException if the opening is cancelled
* @throws LanguageNotFoundException if the language cannot be found
* @throws IOException if there is an exception creating the program or domain file
*/ */
public static DomainFile createProgramFile(Project proj, String progName, Language language, public static DomainFile createProgramFile(Project proj, String progName, Language language,
CompilerSpec compilerSpec, DomainFolder folder) throws InvalidNameException, CompilerSpec compilerSpec, DomainFolder folder) throws InvalidNameException,
@ -210,8 +215,9 @@ public class ProjectTestUtils {
* @param project the project to which the tool belongs * @param project the project to which the tool belongs
* @param toolName name of the tool to get from the active workspace. * @param toolName name of the tool to get from the active workspace.
* If null, launch a new empty tool in the active workspace. * If null, launch a new empty tool in the active workspace.
* @return the tool
*/ */
public static Tool getTool(Project project, String toolName) { public static PluginTool getTool(Project project, String toolName) {
ToolManager tm = project.getToolManager(); ToolManager tm = project.getToolManager();
@ -222,7 +228,7 @@ public class ProjectTestUtils {
// use the first one for the testing // use the first one for the testing
Workspace activeWorkspace = workspaces[0]; Workspace activeWorkspace = workspaces[0];
Tool tool = null; PluginTool tool = null;
if (toolName == null) { if (toolName == null) {
// create a new empty tool // create a new empty tool
tool = activeWorkspace.createTool(); tool = activeWorkspace.createTool();
@ -244,7 +250,7 @@ public class ProjectTestUtils {
* @param tool The tool to be saved * @param tool The tool to be saved
* @return The tool template for the given tool. * @return The tool template for the given tool.
*/ */
public static ToolTemplate saveTool(Project project, Tool tool) { public static ToolTemplate saveTool(Project project, PluginTool tool) {
// save the tool to the project tool chest // save the tool to the project tool chest
ToolChest toolChest = project.getLocalToolChest(); ToolChest toolChest = project.getLocalToolChest();
ToolTemplate toolTemplate = tool.saveToolToToolTemplate(); ToolTemplate toolTemplate = tool.saveToolToToolTemplate();
@ -254,8 +260,8 @@ public class ProjectTestUtils {
/** /**
* Remove the specified tool if it exists. * Remove the specified tool if it exists.
* @param project * @param project the project
* @param toolName * @param toolName the tool name
* @return true if it existed and was removed from the local tool chest. * @return true if it existed and was removed from the local tool chest.
*/ */
public static boolean deleteTool(Project project, String toolName) { public static boolean deleteTool(Project project, String toolName) {

View file

@ -640,7 +640,7 @@ public class TestEnv {
* NOTE: This array will not contain any of the TestTools! * NOTE: This array will not contain any of the TestTools!
* @return an array of tools spawned by the Ghidra environment * @return an array of tools spawned by the Ghidra environment
*/ */
public Tool[] getGhidraCreatedTools() { public PluginTool[] getGhidraCreatedTools() {
return gp.getProject().getToolManager().getRunningTools(); return gp.getProject().getToolManager().getRunningTools();
} }

View file

@ -20,7 +20,6 @@ import java.util.List;
import ghidra.app.plugin.core.datamgr.util.DataTypeUtils; import ghidra.app.plugin.core.datamgr.util.DataTypeUtils;
import ghidra.app.services.DataTypeQueryService; import ghidra.app.services.DataTypeQueryService;
import ghidra.app.services.DataTypeManagerService;
import ghidra.program.database.data.DataTypeUtilities; import ghidra.program.database.data.DataTypeUtilities;
import ghidra.program.database.data.ProgramDataTypeManager; import ghidra.program.database.data.ProgramDataTypeManager;
import ghidra.program.model.data.*; import ghidra.program.model.data.*;
@ -440,8 +439,21 @@ public class DataTypeParser {
private static String getBaseString(String dataTypeString) { private static String getBaseString(String dataTypeString) {
int nextIndex = 0; int nextIndex = 0;
int templateCount = 0;
while (nextIndex < dataTypeString.length()) { while (nextIndex < dataTypeString.length()) {
char c = dataTypeString.charAt(nextIndex); char c = dataTypeString.charAt(nextIndex);
if (c == '<') {
templateCount++;
}
else if (c == '>') {
templateCount--;
}
if (templateCount != 0) {
++nextIndex;
continue;
}
if (c == '*' || c == '[' || c == ':' || c == '{') { if (c == '*' || c == '[' || c == ':' || c == '{') {
return dataTypeString.substring(0, nextIndex).trim(); return dataTypeString.substring(0, nextIndex).trim();
} }

View file

@ -610,7 +610,7 @@ public class ComponentProviderActionsTest extends AbstractGhidraHeadedIntegratio
} }
private void performLaunchKeyStrokeDialogAction() { private void performLaunchKeyStrokeDialogAction() {
ToolActions toolActions = ((AbstractDockingTool) tool).getToolActions(); ToolActions toolActions = (ToolActions) ((AbstractDockingTool) tool).getToolActions();
Action action = toolActions.getAction(KeyStroke.getKeyStroke("F4")); Action action = toolActions.getAction(KeyStroke.getKeyStroke("F4"));
assertNotNull(action); assertNotNull(action);
runSwing(() -> action.actionPerformed(new ActionEvent(this, 0, "")), false); runSwing(() -> action.actionPerformed(new ActionEvent(this, 0, "")), false);
@ -624,7 +624,7 @@ public class ComponentProviderActionsTest extends AbstractGhidraHeadedIntegratio
private JComponent component = new JTextField("Hey!"); private JComponent component = new JTextField("Hey!");
TestActionsComponentProvider(DockingTool tool) { TestActionsComponentProvider(Tool tool) {
super(tool, PROVIDER_NAME, "Fooberry Plugin"); super(tool, PROVIDER_NAME, "Fooberry Plugin");
} }
@ -637,7 +637,7 @@ public class ComponentProviderActionsTest extends AbstractGhidraHeadedIntegratio
private class HasDefaultKeyBindingComponentProvider extends ComponentProvider { private class HasDefaultKeyBindingComponentProvider extends ComponentProvider {
private JComponent component = new JTextField("Hey!"); private JComponent component = new JTextField("Hey!");
HasDefaultKeyBindingComponentProvider(DockingTool tool) { HasDefaultKeyBindingComponentProvider(Tool tool) {
super(tool, HasDefaultKeyBindingComponentProvider.class.getSimpleName(), super(tool, HasDefaultKeyBindingComponentProvider.class.getSimpleName(),
"Fooberry Plugin"); "Fooberry Plugin");

View file

@ -36,7 +36,7 @@ import ghidra.test.DummyTool;
public class DockingWindowManagerTest extends AbstractDockingTest { public class DockingWindowManagerTest extends AbstractDockingTest {
private DockingTool tool = new DummyTool(); private Tool tool = new DummyTool();
@Test @Test
public void testDefaultGroupWindowPosition() { public void testDefaultGroupWindowPosition() {

View file

@ -25,8 +25,8 @@ import javax.swing.*;
import org.junit.*; import org.junit.*;
import docking.*; import docking.*;
import docking.actions.DockingToolActions;
import docking.actions.KeyEntryDialog; import docking.actions.KeyEntryDialog;
import docking.actions.ToolActions;
import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin; import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;
import ghidra.app.plugin.core.navigation.GoToAddressLabelPlugin; import ghidra.app.plugin.core.navigation.GoToAddressLabelPlugin;
import ghidra.framework.plugintool.PluginTool; import ghidra.framework.plugintool.PluginTool;
@ -197,7 +197,7 @@ public class KeyEntryDialogTest extends AbstractGhidraHeadedIntegrationTest {
public DockingAction getKeyBindingAction() { public DockingAction getKeyBindingAction() {
ToolActions toolActions = tool.getToolActions(); DockingToolActions toolActions = tool.getToolActions();
KeyBindingsManager kbm = KeyBindingsManager kbm =
(KeyBindingsManager) getInstanceField("keyBindingsManager", toolActions); (KeyBindingsManager) getInstanceField("keyBindingsManager", toolActions);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View file

@ -28,8 +28,7 @@ import org.junit.Test;
import docking.DockingUtils; import docking.DockingUtils;
import docking.action.DockingActionIf; import docking.action.DockingActionIf;
import docking.actions.KeyBindingUtils; import docking.actions.*;
import docking.actions.ToolActions;
public class GhidraScriptMgrPlugin1Test extends AbstractGhidraScriptMgrPluginTest { public class GhidraScriptMgrPlugin1Test extends AbstractGhidraScriptMgrPluginTest {
@ -147,7 +146,7 @@ public class GhidraScriptMgrPlugin1Test extends AbstractGhidraScriptMgrPluginTes
KeyStroke actionKs = toolAction.getKeyBinding(); KeyStroke actionKs = toolAction.getKeyBinding();
assertEquals(newKs, actionKs); assertEquals(newKs, actionKs);
ToolActions toolActions = plugin.getTool().getToolActions(); ToolActions toolActions = (ToolActions) plugin.getTool().getToolActions();
Action toolActionByKeyStroke = toolActions.getAction(newKs); Action toolActionByKeyStroke = toolActions.getAction(newKs);
assertNotNull(toolActionByKeyStroke); assertNotNull(toolActionByKeyStroke);
} }

View file

@ -15,11 +15,12 @@
*/ */
package ghidra.framework.project; package ghidra.framework.project;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import org.junit.*; import org.junit.*;
import ghidra.framework.model.*; import ghidra.framework.model.*;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.protocol.ghidra.GhidraURL; import ghidra.framework.protocol.ghidra.GhidraURL;
import ghidra.program.database.ProgramBuilder; import ghidra.program.database.ProgramBuilder;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
@ -73,7 +74,7 @@ public class CreateDomainObjectTest extends AbstractGhidraHeadedIntegrationTest
// test 1 create a program and add it to a project // test 1 create a program and add it to a project
Program program1 = createProgram(project, "Prog1", this); Program program1 = createProgram(project, "Prog1", this);
Tool consumer2 = new DummyTool(); PluginTool consumer2 = new DummyTool();
Program program2 = null; Program program2 = null;
try { try {
// test 2 - get the object from the project and make sure it is the // test 2 - get the object from the project and make sure it is the
@ -213,7 +214,7 @@ public class CreateDomainObjectTest extends AbstractGhidraHeadedIntegrationTest
private static void createProgramReadOnly(Project proj, String progName) throws Exception { private static void createProgramReadOnly(Project proj, String progName) throws Exception {
Tool t = new DummyTool(); PluginTool t = new DummyTool();
Program p = createDefaultProgram(progName, ProgramBuilder._TOY, t); Program p = createDefaultProgram(progName, ProgramBuilder._TOY, t);
try { try {
@ -295,7 +296,7 @@ public class CreateDomainObjectTest extends AbstractGhidraHeadedIntegrationTest
DomainFolder f3 = f.createFolder("Y"); DomainFolder f3 = f.createFolder("Y");
DomainFolder f4 = f.createFolder("Z"); DomainFolder f4 = f.createFolder("Z");
Tool t = new DummyTool("Tool1"); PluginTool t = new DummyTool("Tool1");
Program p1 = null; Program p1 = null;
Program p2 = null; Program p2 = null;
@ -344,7 +345,7 @@ public class CreateDomainObjectTest extends AbstractGhidraHeadedIntegrationTest
DomainFolder f3 = f.getFolder("Y"); DomainFolder f3 = f.getFolder("Y");
DomainFolder f4 = f.getFolder("Z"); DomainFolder f4 = f.getFolder("Z");
Tool t = new DummyTool("Tool1"); PluginTool t = new DummyTool("Tool1");
if ((f.getFile("AAA") == null) || (f.getFile("BBB") == null) || if ((f.getFile("AAA") == null) || (f.getFile("BBB") == null) ||
(f2.getFile("CCC") == null) || (f3.getFile("DDD") == null) || (f2.getFile("CCC") == null) || (f3.getFile("DDD") == null) ||

View file

@ -200,9 +200,9 @@ public abstract class AbstractToolSavingTest extends AbstractGhidraHeadedIntegra
protected List<PluginTool> findOpenTools() { protected List<PluginTool> findOpenTools() {
ToolManager tm = testEnv.getProject().getToolManager(); ToolManager tm = testEnv.getProject().getToolManager();
Workspace activeWorkspace = tm.getActiveWorkspace(); Workspace activeWorkspace = tm.getActiveWorkspace();
Tool[] tools = activeWorkspace.getTools(); PluginTool[] tools = activeWorkspace.getTools();
List<PluginTool> pluginToolList = new ArrayList<>(tools.length); List<PluginTool> pluginToolList = new ArrayList<>(tools.length);
for (Tool tool : tools) { for (PluginTool tool : tools) {
pluginToolList.add((PluginTool) tool); pluginToolList.add((PluginTool) tool);
} }
return pluginToolList; return pluginToolList;

View file

@ -17,8 +17,10 @@ package ghidra.framework.project.tool;
import org.junit.*; import org.junit.*;
import generic.test.AbstractGenericTest; import generic.test.AbstractGTest;
import ghidra.framework.model.*; import ghidra.framework.model.DomainFile;
import ghidra.framework.model.Project;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.database.ProgramBuilder; import ghidra.program.database.ProgramBuilder;
import ghidra.test.*; import ghidra.test.*;
@ -30,20 +32,12 @@ import ghidra.test.*;
*/ */
public class ChangeToolDataTest extends AbstractGhidraHeadedIntegrationTest { public class ChangeToolDataTest extends AbstractGhidraHeadedIntegrationTest {
private final static String DIRECTORY_NAME = AbstractGenericTest.getTestDirectoryPath(); private final static String DIRECTORY_NAME = AbstractGTest.getTestDirectoryPath();
private final static String DATA_NAME_1 = "TestData1"; private final static String DATA_NAME_1 = "TestData1";
private final static String DATA_NAME_2 = "TestData2"; private final static String DATA_NAME_2 = "TestData2";
private Project project; private Project project;
/**
* Constructor
* @param arg0
*/
public ChangeToolDataTest() {
super();
}
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
ProjectTestUtils.deleteProject(DIRECTORY_NAME, PROJECT_NAME); ProjectTestUtils.deleteProject(DIRECTORY_NAME, PROJECT_NAME);
@ -56,8 +50,8 @@ public class ChangeToolDataTest extends AbstractGhidraHeadedIntegrationTest {
ProjectTestUtils.deleteProject(DIRECTORY_NAME, PROJECT_NAME); ProjectTestUtils.deleteProject(DIRECTORY_NAME, PROJECT_NAME);
} }
/** /*
* This doTest() routine tests the following requirements: * Tests the following requirements:
* (1) connect two running tools by one or more specified events * (1) connect two running tools by one or more specified events
* (2) disconnect one or more specified events between two connected tools * (2) disconnect one or more specified events between two connected tools
* @param args same as args to main() * @param args same as args to main()
@ -72,7 +66,7 @@ public class ChangeToolDataTest extends AbstractGhidraHeadedIntegrationTest {
// //
// setup the running tool // setup the running tool
// //
Tool runningTool = new DummyTool(); PluginTool runningTool = new DummyTool();
// //
// TEST 1: set the data for a tool running without data // TEST 1: set the data for a tool running without data

View file

@ -53,10 +53,8 @@ public class CloseToolTest extends AbstractGhidraHeadedIntegrationTest {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
executeOnSwingWithoutBlocking(() -> env.dispose()); env.dispose();
closeAllWindows(); closeAllWindows();
} }
@Test @Test

View file

@ -17,8 +17,9 @@ package ghidra.framework.project.tool;
import org.junit.*; import org.junit.*;
import generic.test.AbstractGenericTest; import generic.test.AbstractGTest;
import ghidra.framework.model.*; import ghidra.framework.model.*;
import ghidra.framework.plugintool.PluginTool;
import ghidra.test.*; import ghidra.test.*;
/** /**
@ -30,18 +31,10 @@ import ghidra.test.*;
public class ConnectToolsTest extends AbstractGhidraHeadedIntegrationTest { public class ConnectToolsTest extends AbstractGhidraHeadedIntegrationTest {
private final static String BAD_EVENT_NAME = "TEST_CONNECT_FOR_BAD_EVENT"; private final static String BAD_EVENT_NAME = "TEST_CONNECT_FOR_BAD_EVENT";
private final static String DIRECTORY_NAME = AbstractGenericTest.getTestDirectoryPath(); private final static String DIRECTORY_NAME = AbstractGTest.getTestDirectoryPath();
private Project project; private Project project;
/**
* Constructor
* @param arg0
*/
public ConnectToolsTest() {
super();
}
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -56,16 +49,16 @@ public class ConnectToolsTest extends AbstractGhidraHeadedIntegrationTest {
} }
/** /*
* This doTest() routine tests the following requirements: * Tests the following requirements:
* (1) connect two running tools by one or more specified events * (1) connect two running tools by one or more specified events
* (2) disconnect one or more specified events between two connected tools * (2) disconnect one or more specified events between two connected tools
*/ */
@Test @Test
public void testConnectTools() throws Exception { public void testConnectTools() throws Exception {
Tool producer = new DummyTool("ProducerTool"); PluginTool producer = new DummyTool("ProducerTool");
Tool consumer = new DummyTool("ConsumerTool"); PluginTool consumer = new DummyTool("ConsumerTool");
ToolConnection tc; ToolConnection tc;
String eventName = null; String eventName = null;

View file

@ -17,8 +17,10 @@ package ghidra.framework.project.tool;
import org.junit.*; import org.junit.*;
import generic.test.AbstractGenericTest; import generic.test.AbstractGTest;
import ghidra.framework.model.*; import ghidra.framework.model.Project;
import ghidra.framework.model.ToolManager;
import ghidra.framework.plugintool.PluginTool;
import ghidra.test.AbstractGhidraHeadedIntegrationTest; import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.ProjectTestUtils; import ghidra.test.ProjectTestUtils;
@ -29,20 +31,10 @@ import ghidra.test.ProjectTestUtils;
*/ */
public class CreateToolTest extends AbstractGhidraHeadedIntegrationTest { public class CreateToolTest extends AbstractGhidraHeadedIntegrationTest {
private final static String DIRECTORY_NAME = AbstractGenericTest.getTestDirectoryPath(); private final static String DIRECTORY_NAME = AbstractGTest.getTestDirectoryPath();
private Project project; private Project project;
// private Workspace activeWorkspace; private PluginTool tool;
private Tool tool;
/**
* Constructor
* @param arg0
*/
public CreateToolTest() {
super();
}
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -56,7 +48,7 @@ public class CreateToolTest extends AbstractGhidraHeadedIntegrationTest {
ProjectTestUtils.deleteProject(DIRECTORY_NAME, PROJECT_NAME); ProjectTestUtils.deleteProject(DIRECTORY_NAME, PROJECT_NAME);
} }
private void closeTool(final Tool theTool) { private void closeTool(final PluginTool theTool) {
executeOnSwingWithoutBlocking(new Runnable() { executeOnSwingWithoutBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -65,10 +57,10 @@ public class CreateToolTest extends AbstractGhidraHeadedIntegrationTest {
}); });
// this handles the save changes dialog and potential analysis dialogs // this handles the save changes dialog and potential analysis dialogs
closeAllWindowsAndFrames(); closeAllWindows();
} }
/** /*
* Do the test. * Do the test.
* This doTest() routine tests the following requirements: * This doTest() routine tests the following requirements:
* (1) create (launch) an empty tool in the active workspace * (1) create (launch) an empty tool in the active workspace
@ -92,7 +84,7 @@ public class CreateToolTest extends AbstractGhidraHeadedIntegrationTest {
try { try {
// verify the tool is actually running before declaring success // verify the tool is actually running before declaring success
ToolManager tm = project.getToolManager(); ToolManager tm = project.getToolManager();
Tool[] runningTools = tm.getRunningTools(); PluginTool[] runningTools = tm.getRunningTools();
for (int t = 0; !verified && t < runningTools.length; t++) { for (int t = 0; !verified && t < runningTools.length; t++) {
if (runningTools[t].equals(tool)) { if (runningTools[t].equals(tool)) {
verified = true; verified = true;

View file

@ -15,7 +15,7 @@
*/ */
package ghidra.framework.project.tool; package ghidra.framework.project.tool;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import java.io.IOException; import java.io.IOException;
@ -23,6 +23,7 @@ import org.junit.*;
import generic.test.AbstractGenericTest; import generic.test.AbstractGenericTest;
import ghidra.framework.model.*; import ghidra.framework.model.*;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.store.LockException; import ghidra.framework.store.LockException;
import ghidra.test.AbstractGhidraHeadedIntegrationTest; import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.ProjectTestUtils; import ghidra.test.ProjectTestUtils;
@ -138,7 +139,7 @@ public class CreateWorkspaceTest extends AbstractGhidraHeadedIntegrationTest {
} }
}); });
Tool[] runningTools = wspaces[0].getTools(); PluginTool[] runningTools = wspaces[0].getTools();
assertEquals(1, runningTools.length); assertEquals(1, runningTools.length);
setWorkspaceActive(wspaces[1]); setWorkspaceActive(wspaces[1]);

View file

@ -17,8 +17,9 @@ package ghidra.framework.project.tool;
import org.junit.*; import org.junit.*;
import generic.test.AbstractGenericTest; import generic.test.AbstractGTest;
import ghidra.framework.model.*; import ghidra.framework.model.*;
import ghidra.framework.plugintool.PluginTool;
import ghidra.test.AbstractGhidraHeadedIntegrationTest; import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.ProjectTestUtils; import ghidra.test.ProjectTestUtils;
@ -30,20 +31,12 @@ import ghidra.test.ProjectTestUtils;
*/ */
public class DeleteToolTest extends AbstractGhidraHeadedIntegrationTest { public class DeleteToolTest extends AbstractGhidraHeadedIntegrationTest {
private final static String PROJECT_DIRECTORY = AbstractGenericTest.getTestDirectoryPath(); private final static String PROJECT_DIRECTORY = AbstractGTest.getTestDirectoryPath();
private final static String TOOL_NAME = "TestTool"; private final static String TOOL_NAME = "TestTool";
private Tool runningTool; private PluginTool runningTool;
private Project project; private Project project;
/**
* Constructor
* @param arg0
*/
public DeleteToolTest() {
super();
}
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
ProjectTestUtils.deleteProject(PROJECT_DIRECTORY, PROJECT_NAME); ProjectTestUtils.deleteProject(PROJECT_DIRECTORY, PROJECT_NAME);
@ -56,8 +49,8 @@ public class DeleteToolTest extends AbstractGhidraHeadedIntegrationTest {
ProjectTestUtils.deleteProject(PROJECT_DIRECTORY, PROJECT_NAME); ProjectTestUtils.deleteProject(PROJECT_DIRECTORY, PROJECT_NAME);
} }
/** /*
* This doTest() routine tests the following requirements: * Tsts the following requirements:
* (1) delete a non-running tool from the user's project space * (1) delete a non-running tool from the user's project space
* (2) delete a running tool from the user's project space * (2) delete a running tool from the user's project space
* *

View file

@ -15,16 +15,13 @@
*/ */
package ghidra.framework.project.tool; package ghidra.framework.project.tool;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.*;
import java.beans.PropertyVetoException;
import javax.swing.SwingUtilities;
import org.junit.*; import org.junit.*;
import generic.test.AbstractGenericTest; import generic.test.AbstractGTest;
import ghidra.framework.model.*; import ghidra.framework.model.*;
import ghidra.framework.plugintool.PluginTool;
import ghidra.test.AbstractGhidraHeadedIntegrationTest; import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.ProjectTestUtils; import ghidra.test.ProjectTestUtils;
@ -36,20 +33,12 @@ import ghidra.test.ProjectTestUtils;
*/ */
public class RunToolTest extends AbstractGhidraHeadedIntegrationTest { public class RunToolTest extends AbstractGhidraHeadedIntegrationTest {
private final static String DIRECTORY_NAME = AbstractGenericTest.getTestDirectoryPath(); private final static String DIRECTORY_NAME = AbstractGTest.getTestDirectoryPath();
private final static String TOOL_NAME = "TestTool"; private final static String TOOL_NAME = "TestTool";
private Project project; private Project project;
private Tool runningTool; private PluginTool runningTool;
private Tool tool; private PluginTool tool;
/**
* Constructor
* @param arg0
*/
public RunToolTest() {
super();
}
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -59,7 +48,7 @@ public class RunToolTest extends AbstractGhidraHeadedIntegrationTest {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
SwingUtilities.invokeAndWait(new Runnable() { runSwing(new Runnable() {
@Override @Override
public void run() { public void run() {
project.save(); project.save();
@ -69,7 +58,7 @@ public class RunToolTest extends AbstractGhidraHeadedIntegrationTest {
ProjectTestUtils.deleteProject(DIRECTORY_NAME, PROJECT_NAME); ProjectTestUtils.deleteProject(DIRECTORY_NAME, PROJECT_NAME);
} }
/** /*
* Do the test. * Do the test.
* This doTest() routine tests the following requirements: * This doTest() routine tests the following requirements:
* (1) Run Project Tool Without Data * (1) Run Project Tool Without Data
@ -84,22 +73,18 @@ public class RunToolTest extends AbstractGhidraHeadedIntegrationTest {
ProjectTestUtils.deleteTool(project, TOOL_NAME); ProjectTestUtils.deleteTool(project, TOOL_NAME);
// Create tool and save tool config // Create tool and save tool config
SwingUtilities.invokeAndWait(new Runnable() { runSwing(new Runnable() {
@Override @Override
public void run() { public void run() {
tool = ProjectTestUtils.getTool(project, null); tool = ProjectTestUtils.getTool(project, null);
try {
tool.setToolName(TOOL_NAME); tool.setToolName(TOOL_NAME);
} }
catch (PropertyVetoException e) {
}
}
}); });
try { try {
final ToolTemplate toolConfig = ProjectTestUtils.saveTool(project, tool); final ToolTemplate toolConfig = ProjectTestUtils.saveTool(project, tool);
SwingUtilities.invokeAndWait(new Runnable() { runSwing(new Runnable() {
@Override @Override
public void run() { public void run() {
tool.close(); tool.close();
@ -118,14 +103,14 @@ public class RunToolTest extends AbstractGhidraHeadedIntegrationTest {
// use the first one for the test // use the first one for the test
final Workspace activeWorkspace = workspaces[0]; final Workspace activeWorkspace = workspaces[0];
SwingUtilities.invokeAndWait(new Runnable() { runSwing(new Runnable() {
@Override @Override
public void run() { public void run() {
runningTool = activeWorkspace.runTool(toolConfig); runningTool = activeWorkspace.runTool(toolConfig);
} }
}); });
assertNotNull(runningTool); assertNotNull(runningTool);
SwingUtilities.invokeAndWait(new Runnable() { runSwing(new Runnable() {
@Override @Override
public void run() { public void run() {
runningTool.close(); runningTool.close();
@ -135,7 +120,7 @@ public class RunToolTest extends AbstractGhidraHeadedIntegrationTest {
} }
finally { finally {
// Don't leave the tool in the tool chest // Don't leave the tool in the tool chest
SwingUtilities.invokeAndWait(new Runnable() { runSwing(new Runnable() {
@Override @Override
public void run() { public void run() {
ProjectTestUtils.deleteTool(project, TOOL_NAME); ProjectTestUtils.deleteTool(project, TOOL_NAME);

View file

@ -15,12 +15,13 @@
*/ */
package ghidra.framework.project.tool; package ghidra.framework.project.tool;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.*;
import org.junit.*; import org.junit.*;
import generic.test.AbstractGenericTest; import generic.test.AbstractGTest;
import ghidra.framework.model.*; import ghidra.framework.model.*;
import ghidra.framework.plugintool.PluginTool;
import ghidra.test.AbstractGhidraHeadedIntegrationTest; import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.ProjectTestUtils; import ghidra.test.ProjectTestUtils;
@ -29,20 +30,12 @@ import ghidra.test.ProjectTestUtils;
*/ */
public class SaveToolTest extends AbstractGhidraHeadedIntegrationTest { public class SaveToolTest extends AbstractGhidraHeadedIntegrationTest {
private final static String DIRECTORY_NAME = AbstractGenericTest.getTestDirectoryPath(); private final static String DIRECTORY_NAME = AbstractGTest.getTestDirectoryPath();
private final static String TOOL_NAME = "TestTool"; private final static String TOOL_NAME = "TestTool";
private Tool runningTool; private PluginTool runningTool;
private Project project; private Project project;
/**
* Constructor
* @param name The name of the test to run.
*/
public SaveToolTest() {
super();
}
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
ProjectTestUtils.deleteProject(DIRECTORY_NAME, PROJECT_NAME); ProjectTestUtils.deleteProject(DIRECTORY_NAME, PROJECT_NAME);
@ -55,7 +48,7 @@ public class SaveToolTest extends AbstractGhidraHeadedIntegrationTest {
ProjectTestUtils.deleteProject(DIRECTORY_NAME, PROJECT_NAME); ProjectTestUtils.deleteProject(DIRECTORY_NAME, PROJECT_NAME);
} }
/** /*
* This tests the following requirements: * This tests the following requirements:
* (1) create an empty tool in the active workspace, and * (1) create an empty tool in the active workspace, and
* (2) that duplicate project names do not throw exceptions. * (2) that duplicate project names do not throw exceptions.

View file

@ -69,6 +69,45 @@ public class DataTypeParserTest extends AbstractEditorTest {
super.tearDown(); super.tearDown();
} }
@Test
public void testParse_NameWithTemplate() throws Exception {
String typeName = "templated_name<int, void*, custom_type>";
StructureDataType structure = new StructureDataType(typeName, 0);
tx(program, () -> {
programDTM.resolve(structure, null);
});
DataTypeParser parser = new DataTypeParser(dtmService, AllowedDataTypes.ALL);
DataType dt = parser.parse(typeName);
assertNotNull(dt);
assertTrue(dt.isEquivalent(structure));
}
@Test
public void testParse_PointerToNameWithTemplate() throws Exception {
//
// Attempt to resolve a pointer to an existing type when that pointer does not already
// exist.
//
String typeName = "templated_name<int, void*, custom_type>";
StructureDataType structure = new StructureDataType(typeName, 0);
PointerDataType pointer = new PointerDataType(structure);
String pointerName = pointer.getName();
tx(program, () -> {
programDTM.resolve(structure, null);
});
DataTypeParser parser = new DataTypeParser(dtmService, AllowedDataTypes.ALL);
DataType dt = parser.parse(pointerName);
assertNotNull(dt);
assertTrue(dt.isEquivalent(pointer));
}
@Test @Test
public void testValidDataTypeSyntax() { public void testValidDataTypeSyntax() {
checkValidDt("byte"); checkValidDt("byte");

View file

@ -97,7 +97,7 @@ public class FcgProvider
private ToggleDockingAction navigateIncomingToggleAction; private ToggleDockingAction navigateIncomingToggleAction;
public FcgProvider(DockingTool tool, FunctionCallGraphPlugin plugin) { public FcgProvider(Tool tool, FunctionCallGraphPlugin plugin) {
super(tool, NAME, plugin.getName()); super(tool, NAME, plugin.getName());
this.plugin = plugin; this.plugin = plugin;

View file

@ -174,7 +174,7 @@ public class VTSubToolManager implements VTControllerListener, OptionsChangeList
return newTool; return newTool;
} }
private DockingActionIf getToolAction(Tool tool, String actionName) { private DockingActionIf getToolAction(PluginTool tool, String actionName) {
Set<DockingActionIf> actions = tool.getDockingActionsByOwnerName(ToolConstants.TOOL_OWNER); Set<DockingActionIf> actions = tool.getDockingActionsByOwnerName(ToolConstants.TOOL_OWNER);
for (DockingActionIf action : actions) { for (DockingActionIf action : actions) {
if (action.getName().equals(actionName)) { if (action.getName().equals(actionName)) {

View file

@ -219,7 +219,7 @@ public class VTFunctionAssociationProvider extends ComponentProviderAdapter
} }
@Override @Override
public List<DockingActionIf> getPopupActions(DockingTool tool, ActionContext context) { public List<DockingActionIf> getPopupActions(Tool tool, ActionContext context) {
if (context.getComponentProvider() == this) { if (context.getComponentProvider() == this) {
ListingCodeComparisonPanel dualListingPanel = ListingCodeComparisonPanel dualListingPanel =
functionComparisonPanel.getDualListingPanel(); functionComparisonPanel.getDualListingPanel();

View file

@ -452,7 +452,7 @@ public class VTMarkupItemsTableProvider extends ComponentProviderAdapter
} }
@Override @Override
public List<DockingActionIf> getPopupActions(DockingTool tool, ActionContext context) { public List<DockingActionIf> getPopupActions(Tool tool, ActionContext context) {
ListingCodeComparisonPanel dualListingPanel = functionComparisonPanel.getDualListingPanel(); ListingCodeComparisonPanel dualListingPanel = functionComparisonPanel.getDualListingPanel();
if (context.getComponentProvider() == this && dualListingPanel != null) { if (context.getComponentProvider() == this && dualListingPanel != null) {
ListingPanel sourcePanel = dualListingPanel.getLeftPanel(); ListingPanel sourcePanel = dualListingPanel.getLeftPanel();

View file

@ -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.

View file

@ -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.

View file

@ -21,16 +21,15 @@ import java.util.*;
import javax.swing.JFrame; import javax.swing.JFrame;
import docking.action.DockingActionIf; import docking.action.DockingActionIf;
import docking.actions.PopupActionProvider; import docking.actions.*;
import docking.actions.ToolActions;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.util.Swing; import ghidra.util.Swing;
/** /**
* A partial implementation of {@link DockingTool} that serves as a place to share common * A partial implementation of {@link Tool} that serves as a place to share common
* functionality * functionality
*/ */
public abstract class AbstractDockingTool implements DockingTool { public abstract class AbstractDockingTool implements Tool {
protected DockingWindowManager winMgr; protected DockingWindowManager winMgr;
protected ToolActions toolActions; protected ToolActions toolActions;
@ -209,11 +208,6 @@ public abstract class AbstractDockingTool implements DockingTool {
winMgr.contextChanged(provider); winMgr.contextChanged(provider);
} }
@Override
public ActionContext getGlobalContext() {
return winMgr.getGlobalContext();
}
@Override @Override
public void addContextListener(DockingContextListener listener) { public void addContextListener(DockingContextListener listener) {
winMgr.addContextListener(listener); winMgr.addContextListener(listener);
@ -240,7 +234,7 @@ public abstract class AbstractDockingTool implements DockingTool {
} }
@Override @Override
public ToolActions getToolActions() { public DockingToolActions getToolActions() {
return toolActions; return toolActions;
} }
} }

View file

@ -85,7 +85,7 @@ public abstract class ComponentProvider implements HelpDescriptor, ActionContext
// maps for mapping old provider names and owner to new names and/or owner // maps for mapping old provider names and owner to new names and/or owner
private static Map<String, String> oldOwnerMap = new HashMap<>(); private static Map<String, String> oldOwnerMap = new HashMap<>();
private static Map<String, String> oldNameMap = new HashMap<>(); private static Map<String, String> oldNameMap = new HashMap<>();
protected DockingTool dockingTool; protected Tool dockingTool;
private String name; private String name;
private final String owner; private final String owner;
private String title; private String title;
@ -121,7 +121,7 @@ public abstract class ComponentProvider implements HelpDescriptor, ActionContext
* the same window. * the same window.
* @param owner The owner of this provider, usually a plugin name. * @param owner The owner of this provider, usually a plugin name.
*/ */
public ComponentProvider(DockingTool tool, String name, String owner) { public ComponentProvider(Tool tool, String name, String owner) {
this(tool, name, owner, null); this(tool, name, owner, null);
} }
@ -134,7 +134,7 @@ public abstract class ComponentProvider implements HelpDescriptor, ActionContext
* @param contextType the type of context supported by this provider; may be null (see * @param contextType the type of context supported by this provider; may be null (see
* {@link #getContextType()} * {@link #getContextType()}
*/ */
public ComponentProvider(DockingTool tool, String name, String owner, Class<?> contextType) { public ComponentProvider(Tool tool, String name, String owner, Class<?> contextType) {
this.dockingTool = tool; this.dockingTool = tool;
this.name = name; this.name = name;
this.owner = owner; this.owner = owner;
@ -744,7 +744,7 @@ public abstract class ComponentProvider implements HelpDescriptor, ActionContext
return this; return this;
} }
public DockingTool getTool() { public Tool getTool() {
return dockingTool; return dockingTool;
} }

View file

@ -74,7 +74,7 @@ class DockableToolBarManager {
String owner = provider.getOwner(); String owner = provider.getOwner();
ToolBarCloseAction closeAction = new ToolBarCloseAction(owner); ToolBarCloseAction closeAction = new ToolBarCloseAction(owner);
closeButtonManager = new ToolBarItemManager(closeAction, winMgr); closeButtonManager = new ToolBarItemManager(closeAction, winMgr);
DockingTool tool = winMgr.getTool(); Tool tool = winMgr.getTool();
// we need to add this action to the tool in order to use key bindings // we need to add this action to the tool in order to use key bindings
tool.addLocalAction(provider, closeAction); tool.addLocalAction(provider, closeAction);
@ -166,7 +166,7 @@ class DockableToolBarManager {
// this will be null for non-standard use cases // this will be null for non-standard use cases
if (dockableComponent != null) { if (dockableComponent != null) {
DockingWindowManager dwm = dockableComponent.getDockingWindowManager(); DockingWindowManager dwm = dockableComponent.getDockingWindowManager();
DockingTool tool = dwm.getTool(); Tool tool = dwm.getTool();
ComponentProvider provider = dockableComponent.getComponentProvider(); ComponentProvider provider = dockableComponent.getComponentProvider();
tool.removeLocalAction(provider, closeButtonManager.getAction()); tool.removeLocalAction(provider, closeButtonManager.getAction());
} }

View file

@ -117,11 +117,6 @@ public class DockingActionProxy
return dockingAction.isValidContext(context); return dockingAction.isValidContext(context);
} }
@Override
public boolean isValidGlobalContext(ActionContext context) {
return dockingAction.isValidGlobalContext(context);
}
@Override @Override
public void removePropertyChangeListener(PropertyChangeListener listener) { public void removePropertyChangeListener(PropertyChangeListener listener) {
propertyListeners.remove(listener); propertyListeners.remove(listener);

View file

@ -32,9 +32,9 @@ public abstract class DockingKeyBindingAction extends AbstractAction {
private DockingActionIf docakbleAction; private DockingActionIf docakbleAction;
protected final KeyStroke keyStroke; protected final KeyStroke keyStroke;
protected final DockingTool tool; protected final Tool tool;
public DockingKeyBindingAction(DockingTool tool, DockingActionIf action, KeyStroke keyStroke) { public DockingKeyBindingAction(Tool tool, DockingActionIf action, KeyStroke keyStroke) {
super(KeyBindingUtils.parseKeyStroke(keyStroke)); super(KeyBindingUtils.parseKeyStroke(keyStroke));
this.tool = tool; this.tool = tool;
this.docakbleAction = action; this.docakbleAction = action;

View file

@ -79,7 +79,7 @@ public class DockingWindowManager implements PropertyChangeListener, Placeholder
// we use a list to maintain order // we use a list to maintain order
private static List<DockingWindowManager> instances = new ArrayList<>(); private static List<DockingWindowManager> instances = new ArrayList<>();
private DockingTool tool; private Tool tool;
private RootNode root; private RootNode root;
private PlaceholderManager placeholderManager; private PlaceholderManager placeholderManager;
@ -116,7 +116,7 @@ public class DockingWindowManager implements PropertyChangeListener, Placeholder
* @param tool the tool * @param tool the tool
* @param images the images to use for windows in this window manager * @param images the images to use for windows in this window manager
*/ */
public DockingWindowManager(DockingTool tool, List<Image> images) { public DockingWindowManager(Tool tool, List<Image> images) {
this(tool, images, false, true, true, null); this(tool, images, false, true, true, null);
} }
@ -131,7 +131,7 @@ public class DockingWindowManager implements PropertyChangeListener, Placeholder
* @param hasStatusBar if true a status bar will be created for the main window * @param hasStatusBar if true a status bar will be created for the main window
* @param factory the drop target factory * @param factory the drop target factory
*/ */
public DockingWindowManager(DockingTool tool, List<Image> images, boolean modal, public DockingWindowManager(Tool tool, List<Image> images, boolean modal,
boolean isDocking, boolean hasStatusBar, DropTargetFactory factory) { boolean isDocking, boolean hasStatusBar, DropTargetFactory factory) {
KeyBindingOverrideKeyEventDispatcher.install(); KeyBindingOverrideKeyEventDispatcher.install();
@ -330,7 +330,7 @@ public class DockingWindowManager implements PropertyChangeListener, Placeholder
* Returns the tool that owns this manager * Returns the tool that owns this manager
* @return the tool * @return the tool
*/ */
public DockingTool getTool() { public Tool getTool() {
return tool; return tool;
} }
@ -353,23 +353,6 @@ public class DockingWindowManager implements PropertyChangeListener, Placeholder
defaultProvider = provider; defaultProvider = provider;
} }
/**
* Returns this tool's notion of the current action context, which is based upon the active
* {@link ComponentProvider}. If there is not active provider, then a generic context will
* be returned.
*
* @return the context
*/
public ActionContext getGlobalContext() {
if (defaultProvider != null) {
ActionContext actionContext = defaultProvider.getActionContext(null);
if (actionContext != null) {
return actionContext;
}
}
return new ActionContext();
}
/** /**
* Get the window which contains the specified Provider's component. * Get the window which contains the specified Provider's component.
* @param provider component provider * @param provider component provider

View file

@ -47,36 +47,20 @@ public class MenuBarMenuHandler extends MenuHandler {
DockingWindowManager.clearMouseOverHelp(); DockingWindowManager.clearMouseOverHelp();
ComponentProvider provider = windowManager.getActiveComponentProvider(); ComponentProvider provider = windowManager.getActiveComponentProvider();
ActionContext context = provider == null ? null : provider.getActionContext(null); ActionContext providerContext = provider == null ? null : provider.getActionContext(null);
ActionContext localContext = context == null ? new ActionContext() : context; ActionContext context = providerContext == null ? new ActionContext() : providerContext;
ActionContext globalContext = windowManager.getGlobalContext();
ActionContext tempContext = null; context.setSourceObject(event.getSource());
if (action.isValidContext(localContext)) {
tempContext = localContext; // we prefer the local over the global context if valid
}
else if (action.isValidGlobalContext(globalContext)) {
tempContext = globalContext;
}
else {
return; // context is not valid, nothing to do
}
tempContext.setSourceObject(event.getSource());
final ActionContext finalContext = tempContext;
// this gives the UI some time to repaint before executing the action // this gives the UI some time to repaint before executing the action
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(() -> {
@Override
public void run() {
windowManager.setStatusText(""); windowManager.setStatusText("");
if (action.isEnabledForContext(finalContext)) { if (action.isValidContext(context) && action.isEnabledForContext(context)) {
if (action instanceof ToggleDockingActionIf) { if (action instanceof ToggleDockingActionIf) {
ToggleDockingActionIf toggleAction = ((ToggleDockingActionIf) action); ToggleDockingActionIf toggleAction = ((ToggleDockingActionIf) action);
toggleAction.setSelected(!toggleAction.isSelected()); toggleAction.setSelected(!toggleAction.isSelected());
} }
action.actionPerformed(finalContext); action.actionPerformed(context);
}
} }
}); });
} }

View file

@ -24,12 +24,13 @@ import docking.action.DockingActionIf;
import docking.actions.DockingToolActions; import docking.actions.DockingToolActions;
import docking.actions.PopupActionProvider; import docking.actions.PopupActionProvider;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.ServiceProvider;
/** /**
* Generic tool interface for managing {@link ComponentProvider}s and * Generic tool interface for managing {@link ComponentProvider}s and
* {@link DockingActionIf actions} * {@link DockingActionIf actions}
*/ */
public interface DockingTool { public interface Tool extends ServiceProvider {
/** /**
* Returns a combination of the tool name and the instance name of the form * Returns a combination of the tool name and the instance name of the form
@ -247,15 +248,6 @@ public interface DockingTool {
*/ */
public void contextChanged(ComponentProvider provider); public void contextChanged(ComponentProvider provider);
/**
* Returns this tool's notion of the current action context, which is based upon the active
* {@link ComponentProvider}. If there is not active provider, then a generic context will
* be returned.
*
* @return the context
*/
public ActionContext getGlobalContext();
/** /**
* Adds the given context listener to this tool * Adds the given context listener to this tool
* @param listener the listener to add * @param listener the listener to add

View file

@ -121,7 +121,6 @@ public class WindowActionManager {
ComponentProvider provider = placeHolderForScheduledActionUpdate == null ? null ComponentProvider provider = placeHolderForScheduledActionUpdate == null ? null
: placeHolderForScheduledActionUpdate.getProvider(); : placeHolderForScheduledActionUpdate.getProvider();
ActionContext localContext = provider == null ? null : provider.getActionContext(null); ActionContext localContext = provider == null ? null : provider.getActionContext(null);
ActionContext globalContext = winMgr.getGlobalContext();
if (localContext == null) { if (localContext == null) {
localContext = new ActionContext(); localContext = new ActionContext();
} }
@ -132,9 +131,6 @@ public class WindowActionManager {
if (action.isValidContext(localContext)) { if (action.isValidContext(localContext)) {
action.setEnabled(action.isEnabledForContext(localContext)); action.setEnabled(action.isEnabledForContext(localContext));
} }
else if (action.isValidGlobalContext(globalContext)) {
action.setEnabled(action.isEnabledForContext(globalContext));
}
else { else {
action.setEnabled(false); action.setEnabled(false);
} }

View file

@ -76,7 +76,6 @@ public abstract class DockingAction implements DockingActionIf {
private Predicate<ActionContext> enabledPredicate; private Predicate<ActionContext> enabledPredicate;
private Predicate<ActionContext> popupPredicate; private Predicate<ActionContext> popupPredicate;
private Predicate<ActionContext> validContextPredicate; private Predicate<ActionContext> validContextPredicate;
private Predicate<ActionContext> validGlobalContextPredicate;
public DockingAction(String name, String owner) { public DockingAction(String name, String owner) {
this.name = name; this.name = name;
@ -184,14 +183,6 @@ public abstract class DockingAction implements DockingActionIf {
return true; return true;
} }
@Override
public boolean isValidGlobalContext(ActionContext globalContext) {
if (validGlobalContextPredicate != null) {
return validGlobalContextPredicate.test(globalContext);
}
return isValidContext(globalContext);
}
/** /**
* Default behavior is to add to main window; * Default behavior is to add to main window;
*/ */
@ -572,17 +563,6 @@ public abstract class DockingAction implements DockingActionIf {
validContextPredicate = predicate; validContextPredicate = predicate;
} }
/**
* Sets a predicate for dynamically determining if this action is valid for the current global
* {@link ActionContext}. See {@link DockingActionIf#isValidGlobalContext(ActionContext)}
*
* @param predicate the predicate that will be used to dynamically determine an action's
* validity for a given global {@link ActionContext}
*/
public void validGlobalContextWhen(Predicate<ActionContext> predicate) {
validGlobalContextPredicate = predicate;
}
//================================================================================================== //==================================================================================================
// Non-public methods // Non-public methods
//================================================================================================== //==================================================================================================

View file

@ -193,19 +193,6 @@ public interface DockingActionIf extends HelpDescriptor {
*/ */
public boolean isValidContext(ActionContext context); public boolean isValidContext(ActionContext context);
/**
* Method that actions implement to indicate if this action is valid (knows how to work with, is
* appropriate for) for the given global context. This method is just like the isValidContext
* and in fact calls that method by default. Many actions will work with either the active
* provider context or the global (the main listing) context if the local context is not valid.
* If you want a global action to only work on the global context, then override this method
* and return false.
*
* @param globalContext the global {@link ActionContext} from the active provider.
* @return true if this action is appropriate for the given context.
*/
public boolean isValidGlobalContext(ActionContext globalContext);
/** /**
* Method used to determine if this action should be enabled for the given context. * Method used to determine if this action should be enabled for the given context.
* <p> * <p>

View file

@ -17,7 +17,7 @@ package docking.action;
import java.util.List; import java.util.List;
import docking.DockingTool; import docking.Tool;
/** /**
* An interface for objects (really Components) to implement that signals they provide actions * An interface for objects (really Components) to implement that signals they provide actions
@ -29,7 +29,7 @@ import docking.DockingTool;
* actions. Further, in this example, the actions given will be inserted into the popup menu * actions. Further, in this example, the actions given will be inserted into the popup menu
* that is shown. * that is shown.
* *
* @deprecated use {@link DockingTool} * @deprecated use {@link Tool}
*/ */
// Note: this API is not likely used by forward-facing clients and can be removed in the next release // Note: this API is not likely used by forward-facing clients and can be removed in the next release
@Deprecated(since = "9.1", forRemoval = true) @Deprecated(since = "9.1", forRemoval = true)

View file

@ -38,9 +38,9 @@ public class KeyBindingsManager implements PropertyChangeListener {
// this map exists to update the MultiKeyBindingAction when the key binding changes // this map exists to update the MultiKeyBindingAction when the key binding changes
private Map<DockingActionIf, ComponentProvider> actionToProviderMap; private Map<DockingActionIf, ComponentProvider> actionToProviderMap;
private Map<KeyStroke, DockingKeyBindingAction> dockingKeyMap; private Map<KeyStroke, DockingKeyBindingAction> dockingKeyMap;
private DockingTool tool; private Tool tool;
public KeyBindingsManager(DockingTool tool) { public KeyBindingsManager(Tool tool) {
this.tool = tool; this.tool = tool;
dockingKeyMap = new HashMap<>(); dockingKeyMap = new HashMap<>();
actionToProviderMap = new HashMap<>(); actionToProviderMap = new HashMap<>();

View file

@ -40,7 +40,7 @@ public class MultipleKeyAction extends DockingKeyBindingAction {
* @param action action that will be added to the list of actions bound to a keystroke * @param action action that will be added to the list of actions bound to a keystroke
* @param keyStroke the keystroke, if any, associated with the action * @param keyStroke the keystroke, if any, associated with the action
*/ */
public MultipleKeyAction(DockingTool tool, ComponentProvider provider, DockingActionIf action, public MultipleKeyAction(Tool tool, ComponentProvider provider, DockingActionIf action,
KeyStroke keyStroke) { KeyStroke keyStroke) {
super(tool, action, keyStroke); super(tool, action, keyStroke);
addAction(provider, action); addAction(provider, action);
@ -121,8 +121,7 @@ public class MultipleKeyAction extends DockingKeyBindingAction {
ActionContext localContext = getLocalContext(localProvider); ActionContext localContext = getLocalContext(localProvider);
localContext.setSourceObject(event.getSource()); localContext.setSourceObject(event.getSource());
ActionContext globalContext = tool.getGlobalContext(); List<ExecutableKeyActionAdapter> list = getValidContextActions(localContext);
List<ExecutableKeyActionAdapter> list = getValidContextActions(localContext, globalContext);
// If menu active, disable all key bindings // If menu active, disable all key bindings
if (ignoreActionWhileMenuShowing()) { if (ignoreActionWhileMenuShowing()) {
@ -164,8 +163,7 @@ public class MultipleKeyAction extends DockingKeyBindingAction {
return menuManager.getSelectedPath().length != 0; return menuManager.getSelectedPath().length != 0;
} }
private List<ExecutableKeyActionAdapter> getValidContextActions(ActionContext localContext, private List<ExecutableKeyActionAdapter> getValidContextActions(ActionContext localContext) {
ActionContext globalContext) {
List<ExecutableKeyActionAdapter> list = new ArrayList<>(); List<ExecutableKeyActionAdapter> list = new ArrayList<>();
boolean hasLocalActionsForKeyBinding = false; boolean hasLocalActionsForKeyBinding = false;
@ -222,9 +220,6 @@ public class MultipleKeyAction extends DockingKeyBindingAction {
if (isValidAndEnabled(actionData, localContext)) { if (isValidAndEnabled(actionData, localContext)) {
list.add(new ExecutableKeyActionAdapter(actionData.action, localContext)); list.add(new ExecutableKeyActionAdapter(actionData.action, localContext));
} }
else if (isValidAndEnabledGlobally(actionData, globalContext)) {
list.add(new ExecutableKeyActionAdapter(actionData.action, globalContext));
}
} }
} }
return list; return list;
@ -235,11 +230,6 @@ public class MultipleKeyAction extends DockingKeyBindingAction {
return a.isValidContext(localContext) && a.isEnabledForContext(localContext); return a.isValidContext(localContext) && a.isEnabledForContext(localContext);
} }
private boolean isValidAndEnabledGlobally(ActionData actionData, ActionContext globalContext) {
DockingActionIf a = actionData.action;
return a.isValidGlobalContext(globalContext) && a.isEnabledForContext(globalContext);
}
@Override @Override
public boolean isReservedKeybindingPrecedence() { public boolean isReservedKeybindingPrecedence() {
return false; // MultipleKeyActions can never be reserved return false; // MultipleKeyActions can never be reserved
@ -249,9 +239,7 @@ public class MultipleKeyAction extends DockingKeyBindingAction {
public KeyBindingPrecedence getKeyBindingPrecedence() { public KeyBindingPrecedence getKeyBindingPrecedence() {
ComponentProvider localProvider = tool.getActiveComponentProvider(); ComponentProvider localProvider = tool.getActiveComponentProvider();
ActionContext localContext = getLocalContext(localProvider); ActionContext localContext = getLocalContext(localProvider);
ActionContext globalContext = tool.getGlobalContext(); List<ExecutableKeyActionAdapter> validActions = getValidContextActions(localContext);
List<ExecutableKeyActionAdapter> validActions =
getValidContextActions(localContext, globalContext);
if (validActions.isEmpty()) { if (validActions.isEmpty()) {
return null; // a signal that no actions are valid for the current context return null; // a signal that no actions are valid for the current context

View file

@ -21,7 +21,7 @@ import docking.*;
class ReservedKeyBindingAction extends DockingKeyBindingAction { class ReservedKeyBindingAction extends DockingKeyBindingAction {
ReservedKeyBindingAction(DockingTool tool, DockingActionIf action, KeyStroke keyStroke) { ReservedKeyBindingAction(Tool tool, DockingActionIf action, KeyStroke keyStroke) {
super(tool, action, keyStroke); super(tool, action, keyStroke);
} }

View file

@ -19,10 +19,12 @@ import java.util.function.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.KeyStroke;
import docking.*; import docking.*;
import docking.action.*; import docking.action.*;
import ghidra.util.HelpLocation; import ghidra.util.HelpLocation;
import ghidra.util.Msg;
import resources.ResourceManager; import resources.ResourceManager;
/** /**
@ -137,6 +139,11 @@ public abstract class AbstractActionBuilder<T extends DockingActionIf, B extends
*/ */
private String toolBarSubGroup; private String toolBarSubGroup;
/**
* The key binding to assign to the action
*/
private KeyStroke keyBinding;
/** /**
* Predicate for determining if an action is enabled for a given context * Predicate for determining if an action is enabled for a given context
*/ */
@ -152,11 +159,6 @@ public abstract class AbstractActionBuilder<T extends DockingActionIf, B extends
*/ */
private Predicate<ActionContext> validContextPredicate; private Predicate<ActionContext> validContextPredicate;
/**
* Predicate for determining if an action is applicable for a given global context
*/
private Predicate<ActionContext> validGlobalContextPredicate;
/** /**
* Builder constructor * Builder constructor
* @param name the name of the action to be built * @param name the name of the action to be built
@ -175,7 +177,7 @@ public abstract class AbstractActionBuilder<T extends DockingActionIf, B extends
/** /**
* Builds the action. To build and install the action in one step, use * Builds the action. To build and install the action in one step, use
* {@link #buildAndInstall(DockingTool)} or {@link #buildAndInstallLocal(ComponentProvider)}. * {@link #buildAndInstall(Tool)} or {@link #buildAndInstallLocal(ComponentProvider)}.
* *
* @return the newly build action * @return the newly build action
*/ */
@ -189,7 +191,7 @@ public abstract class AbstractActionBuilder<T extends DockingActionIf, B extends
* @see #build() * @see #build()
* @see #buildAndInstallLocal(ComponentProvider) * @see #buildAndInstallLocal(ComponentProvider)
*/ */
public T buildAndInstall(DockingTool tool) { public T buildAndInstall(Tool tool) {
T action = build(); T action = build();
tool.addAction(action); tool.addAction(action);
return action; return action;
@ -201,7 +203,7 @@ public abstract class AbstractActionBuilder<T extends DockingActionIf, B extends
* @param provider the provider to add the action to * @param provider the provider to add the action to
* @return the newly created action * @return the newly created action
* @see #build() * @see #build()
* @see #buildAndInstall(DockingTool) * @see #buildAndInstall(Tool)
*/ */
public T buildAndInstallLocal(ComponentProvider provider) { public T buildAndInstallLocal(ComponentProvider provider) {
T action = build(); T action = build();
@ -448,6 +450,32 @@ public abstract class AbstractActionBuilder<T extends DockingActionIf, B extends
return self(); return self();
} }
/**
* Sets the key binding for this action
*
* @param keyStroke the KeyStroke to bind to this action
* @return this builder (for chaining)
*/
public B keyBinding(KeyStroke keyStroke) {
this.keyBinding = keyStroke;
return self();
}
/**
* Sets the key binding for this action
*
* @param keyStrokeString the string to parse as a KeyStroke. See
* {@link KeyStroke#getKeyStroke(String)} for the format of the string.
* @return this builder (for chaining)
*/
public B keyBinding(String keyStrokeString) {
this.keyBinding = KeyStroke.getKeyStroke(keyStrokeString);
if (keyBinding == null && keyStrokeString != null) {
Msg.warn(this, "Can't parse KeyStroke: " + keyStrokeString);
}
return self();
}
/** /**
* Sets the primary callback to be executed when this action is invoked. This builder will * Sets the primary callback to be executed when this action is invoked. This builder will
* throw an {@link IllegalStateException} if one of the build methods is called without * throw an {@link IllegalStateException} if one of the build methods is called without
@ -517,22 +545,6 @@ public abstract class AbstractActionBuilder<T extends DockingActionIf, B extends
return self(); return self();
} }
/**
* Sets a predicate for dynamically determining if this action is valid for the current global
* {@link ActionContext}. See {@link DockingActionIf#isValidGlobalContext(ActionContext)}.
*
* <p>Note: most actions will not use this method, but rely instead on
* {@link #enabledWhen(Predicate)}.
*
* @param predicate the predicate that will be used to dynamically determine an action's
* validity for a given global {@link ActionContext}
* @return this builder (for chaining)
*/
public B validGlobalContextWhen(Predicate<ActionContext> predicate) {
validGlobalContextPredicate = predicate;
return self();
}
protected void validate() { protected void validate() {
if (actionCallback == null) { if (actionCallback == null) {
throw new IllegalStateException( throw new IllegalStateException(
@ -547,6 +559,7 @@ public abstract class AbstractActionBuilder<T extends DockingActionIf, B extends
setMenuData(action); setMenuData(action);
setToolbarData(action); setToolbarData(action);
setPopupMenuData(action); setPopupMenuData(action);
setKeyBindingData(action);
if (helpLocation != null) { if (helpLocation != null) {
action.setHelpLocation(helpLocation); action.setHelpLocation(helpLocation);
@ -558,9 +571,6 @@ public abstract class AbstractActionBuilder<T extends DockingActionIf, B extends
if (validContextPredicate != null) { if (validContextPredicate != null) {
action.validContextWhen(validContextPredicate); action.validContextWhen(validContextPredicate);
} }
if (validGlobalContextPredicate != null) {
action.validGlobalContextWhen(validGlobalContextPredicate);
}
if (popupPredicate != null) { if (popupPredicate != null) {
action.popupWhen(enabledPredicate); action.popupWhen(enabledPredicate);
} }
@ -578,6 +588,10 @@ public abstract class AbstractActionBuilder<T extends DockingActionIf, B extends
return menuPath != null; return menuPath != null;
} }
protected boolean isKeyBindingAction() {
return keyBinding != null;
}
private void setPopupMenuData(DockingAction action) { private void setPopupMenuData(DockingAction action) {
if (isPopupAction()) { if (isPopupAction()) {
action.setPopupMenuData(new MenuData(popupPath, popupIcon, popupGroup, action.setPopupMenuData(new MenuData(popupPath, popupIcon, popupGroup,
@ -598,4 +612,9 @@ public abstract class AbstractActionBuilder<T extends DockingActionIf, B extends
} }
} }
private void setKeyBindingData(DockingAction action) {
if (isKeyBindingAction()) {
action.setKeyBindingData(new KeyBindingData(keyBinding));
}
}
} }

View file

@ -91,4 +91,16 @@ public interface DockingToolActions {
* @return the actions * @return the actions
*/ */
public Set<DockingActionIf> getAllActions(); public Set<DockingActionIf> getAllActions();
/**
* Allows clients to register an action by using a placeholder. This is useful when
* an API wishes to have a central object (like a plugin) register actions for transient
* providers, that may not be loaded until needed.
*
* <p>This method may be called multiple times with the same conceptual placeholder--the
* placeholder will only be added once.
*
* @param placeholder the placeholder containing information related to the action it represents
*/
public void registerSharedActionPlaceholder(SharedDockingActionPlaceholder placeholder);
} }

View file

@ -33,7 +33,7 @@ import org.jdom.*;
import org.jdom.input.SAXBuilder; import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter; import org.jdom.output.XMLOutputter;
import docking.DockingTool; import docking.Tool;
import docking.DockingUtils; import docking.DockingUtils;
import docking.action.*; import docking.action.*;
import docking.widgets.filechooser.GhidraFileChooser; import docking.widgets.filechooser.GhidraFileChooser;
@ -465,7 +465,7 @@ public class KeyBindingUtils {
* @param tool the tool containing the actions * @param tool the tool containing the actions
* @return the actions mapped by their full name (e.g., 'Name (OwnerName)') * @return the actions mapped by their full name (e.g., 'Name (OwnerName)')
*/ */
public static Map<String, List<DockingActionIf>> getAllActionsByFullName(DockingTool tool) { public static Map<String, List<DockingActionIf>> getAllActionsByFullName(Tool tool) {
Map<String, List<DockingActionIf>> result = Map<String, List<DockingActionIf>> result =
LazyMap.lazyMap(new HashMap<>(), s -> new LinkedList<>()); LazyMap.lazyMap(new HashMap<>(), s -> new LinkedList<>());
@ -493,7 +493,7 @@ public class KeyBindingUtils {
* @param owner the action owner name * @param owner the action owner name
* @return the actions * @return the actions
*/ */
public static Set<DockingActionIf> getKeyBindingActionsForOwner(DockingTool tool, public static Set<DockingActionIf> getKeyBindingActionsForOwner(Tool tool,
String owner) { String owner) {
Map<String, DockingActionIf> deduper = new HashMap<>(); Map<String, DockingActionIf> deduper = new HashMap<>();

View file

@ -18,13 +18,13 @@ package docking.actions;
import java.util.List; import java.util.List;
import docking.ActionContext; import docking.ActionContext;
import docking.DockingTool; import docking.Tool;
import docking.action.DockingActionIf; import docking.action.DockingActionIf;
/** /**
* Provides notification when the popup action menu is displayed. This interface allows * Provides notification when the popup action menu is displayed. This interface allows
* temporary/transient actions (those not registered with the tool via * temporary/transient actions (those not registered with the tool via
* {@link DockingTool#addAction(DockingActionIf)}) to be used in the popup context menu. * {@link Tool#addAction(DockingActionIf)}) to be used in the popup context menu.
* *
* <p> * <p>
* Most clients will register actions directly with the tool. However, clients that have numerous * Most clients will register actions directly with the tool. However, clients that have numerous
@ -32,7 +32,7 @@ import docking.action.DockingActionIf;
* on demand as the popup is about to be shown, and only if their context is active. This * on demand as the popup is about to be shown, and only if their context is active. This
* mechanism can reduce the tool's action management overhead. Once you have created an * mechanism can reduce the tool's action management overhead. Once you have created an
* implementation of this class, you must register it with * implementation of this class, you must register it with
* {@link DockingTool#addPopupActionProvider(PopupActionProvider)}. * {@link Tool#addPopupActionProvider(PopupActionProvider)}.
*/ */
public interface PopupActionProvider { public interface PopupActionProvider {
@ -46,5 +46,5 @@ public interface PopupActionProvider {
* @param context the ActionContext * @param context the ActionContext
* @return list of temporary popup actions; return null if there are no popup actions * @return list of temporary popup actions; return null if there are no popup actions
*/ */
public List<DockingActionIf> getPopupActions(DockingTool tool, ActionContext context); public List<DockingActionIf> getPopupActions(Tool tool, ActionContext context);
} }

View file

@ -15,7 +15,7 @@
*/ */
package docking.actions; package docking.actions;
import docking.DockingTool; import docking.Tool;
import docking.action.DockingActionIf; import docking.action.DockingActionIf;
import docking.tool.ToolConstants; import docking.tool.ToolConstants;
import docking.widgets.table.GTable; import docking.widgets.table.GTable;
@ -33,7 +33,7 @@ public class SharedActionRegistry {
* @param tool the tool * @param tool the tool
* @param toolActions the tool action manager * @param toolActions the tool action manager
*/ */
public static void installSharedActions(DockingTool tool, ToolActions toolActions) { public static void installSharedActions(Tool tool, ToolActions toolActions) {
GTable.createSharedActions(tool, toolActions, ToolConstants.SHARED_OWNER); GTable.createSharedActions(tool, toolActions, ToolConstants.SHARED_OWNER);
} }
} }

View file

@ -55,7 +55,7 @@ public class ToolActions implements DockingToolActions, PropertyChangeListener {
private Map<String, SharedStubKeyBindingAction> sharedActionMap = new HashMap<>(); private Map<String, SharedStubKeyBindingAction> sharedActionMap = new HashMap<>();
private ToolOptions keyBindingOptions; private ToolOptions keyBindingOptions;
private DockingTool dockingTool; private Tool dockingTool;
private KeyBindingsManager keyBindingsManager; private KeyBindingsManager keyBindingsManager;
/** /**
@ -64,7 +64,7 @@ public class ToolActions implements DockingToolActions, PropertyChangeListener {
* @param tool tool using this ActionManager * @param tool tool using this ActionManager
* @param actionToGuiHelper the class that takes actions and maps them to GUI widgets * @param actionToGuiHelper the class that takes actions and maps them to GUI widgets
*/ */
public ToolActions(DockingTool tool, ActionToGuiHelper actionToGuiHelper) { public ToolActions(Tool tool, ActionToGuiHelper actionToGuiHelper) {
this.dockingTool = tool; this.dockingTool = tool;
this.actionGuiHelper = actionToGuiHelper; this.actionGuiHelper = actionToGuiHelper;
this.keyBindingsManager = new KeyBindingsManager(tool); this.keyBindingsManager = new KeyBindingsManager(tool);

View file

@ -150,8 +150,7 @@ public abstract class MultiStateDockingAction<T> extends DockingAction {
DockingWindowManager manager = DockingWindowManager.getActiveInstance(); DockingWindowManager manager = DockingWindowManager.getActiveInstance();
ComponentProvider provider = manager.getActiveComponentProvider(); ComponentProvider provider = manager.getActiveComponentProvider();
ActionContext localContext = provider == null ? null : provider.getActionContext(null); ActionContext localContext = provider == null ? null : provider.getActionContext(null);
final ActionContext actionContext = ActionContext actionContext = localContext == null ? new ActionContext() : localContext;
localContext == null ? manager.getGlobalContext() : localContext;
return actionContext; return actionContext;
} }

View file

@ -189,33 +189,23 @@ public class ToolBarItemManager implements PropertyChangeListener, ActionListene
@Override @Override
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
DockingWindowManager.clearMouseOverHelp(); DockingWindowManager.clearMouseOverHelp();
ActionContext localContext = getActionContext(); ActionContext context = getActionContext();
ActionContext globalContext = null;
if (windowManager != null) { if (!toolBarAction.isValidContext(context)) {
globalContext = windowManager.getGlobalContext(); return;
} }
ActionContext tempContext = null; context.setSourceObject(event.getSource());
if (toolBarAction.isValidContext(localContext)) {
tempContext = localContext; // we prefer the local over the global context if valid
}
else if (toolBarAction.isValidGlobalContext(globalContext)) {
tempContext = globalContext;
}
else {
return; // context is not valid, nothing to do
}
tempContext.setSourceObject(event.getSource());
final ActionContext finalContext = tempContext;
// this gives the UI some time to repaint before executing the action // this gives the UI some time to repaint before executing the action
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
if (toolBarAction.isEnabledForContext(finalContext)) { if (toolBarAction.isValidContext(context) &&
toolBarAction.isEnabledForContext(context)) {
if (toolBarAction instanceof ToggleDockingActionIf) { if (toolBarAction instanceof ToggleDockingActionIf) {
ToggleDockingActionIf toggleAction = (ToggleDockingActionIf) toolBarAction; ToggleDockingActionIf toggleAction = (ToggleDockingActionIf) toolBarAction;
toggleAction.setSelected(!toggleAction.isSelected()); toggleAction.setSelected(!toggleAction.isSelected());
} }
toolBarAction.actionPerformed(finalContext); toolBarAction.actionPerformed(context);
} }
}); });
} }

View file

@ -1098,7 +1098,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
* @param name the name to match * @param name the name to match
* @return the matching actions; empty list if no matches * @return the matching actions; empty list if no matches
*/ */
public static Set<DockingActionIf> getActionsByName(DockingTool tool, String name) { public static Set<DockingActionIf> getActionsByName(Tool tool, String name) {
Set<DockingActionIf> result = new HashSet<>(); Set<DockingActionIf> result = new HashSet<>();
@ -1119,7 +1119,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
* @param name the owner's name to match * @param name the owner's name to match
* @return the matching actions; empty list if no matches * @return the matching actions; empty list if no matches
*/ */
public static Set<DockingActionIf> getActionsByOwner(DockingTool tool, String name) { public static Set<DockingActionIf> getActionsByOwner(Tool tool, String name) {
return tool.getDockingActionsByOwnerName(name); return tool.getDockingActionsByOwnerName(name);
} }
@ -1132,7 +1132,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
* @param name the owner's name to match * @param name the owner's name to match
* @return the matching actions; empty list if no matches * @return the matching actions; empty list if no matches
*/ */
public static Set<DockingActionIf> getActionsByOwnerAndName(DockingTool tool, String owner, public static Set<DockingActionIf> getActionsByOwnerAndName(Tool tool, String owner,
String name) { String name) {
Set<DockingActionIf> ownerActions = tool.getDockingActionsByOwnerName(owner); Set<DockingActionIf> ownerActions = tool.getDockingActionsByOwnerName(owner);
return ownerActions.stream() return ownerActions.stream()
@ -1143,7 +1143,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
/** /**
* Finds the singular tool action by the given name. If more than one action exists with * Finds the singular tool action by the given name. If more than one action exists with
* that name, then an exception is thrown. If you want more than one matching action, * that name, then an exception is thrown. If you want more than one matching action,
* the call {@link #getActionsByName(DockingTool, String)} instead. * the call {@link #getActionsByName(Tool, String)} instead.
* *
* <P>Note: more specific test case subclasses provide other methods for finding actions * <P>Note: more specific test case subclasses provide other methods for finding actions
* when you have an owner name (which is usually the plugin name). * when you have an owner name (which is usually the plugin name).
@ -1152,7 +1152,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
* @param name the name to match * @param name the name to match
* @return the matching action; null if no matching action can be found * @return the matching action; null if no matching action can be found
*/ */
public static DockingActionIf getAction(DockingTool tool, String name) { public static DockingActionIf getAction(Tool tool, String name) {
Set<DockingActionIf> actions = getActionsByName(tool, name); Set<DockingActionIf> actions = getActionsByName(tool, name);
if (actions.isEmpty()) { if (actions.isEmpty()) {
@ -1169,7 +1169,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
/** /**
* Finds the action by the given owner name and action name. * Finds the action by the given owner name and action name.
* If you do not know the owner name, then use * If you do not know the owner name, then use
* the call {@link #getActionsByName(DockingTool, String)} instead (this will not include * the call {@link #getActionsByName(Tool, String)} instead (this will not include
* reserved system actions). * reserved system actions).
* *
* <P>Note: more specific test case subclasses provide other methods for finding actions * <P>Note: more specific test case subclasses provide other methods for finding actions
@ -1180,7 +1180,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
* @param name the name to match * @param name the name to match
* @return the matching action; null if no matching action can be found * @return the matching action; null if no matching action can be found
*/ */
public static DockingActionIf getAction(DockingTool tool, String owner, String name) { public static DockingActionIf getAction(Tool tool, String owner, String name) {
Set<DockingActionIf> actions = getActionsByOwnerAndName(tool, owner, name); Set<DockingActionIf> actions = getActionsByOwnerAndName(tool, owner, name);
if (actions.isEmpty()) { if (actions.isEmpty()) {
return null; return null;
@ -1203,7 +1203,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
* @return the action * @return the action
*/ */
public static DockingActionIf getLocalAction(ComponentProvider provider, String actionName) { public static DockingActionIf getLocalAction(ComponentProvider provider, String actionName) {
DockingTool tool = provider.getTool(); Tool tool = provider.getTool();
DockingToolActions toolActions = tool.getToolActions(); DockingToolActions toolActions = tool.getToolActions();
DockingActionIf action = toolActions.getLocalAction(provider, actionName); DockingActionIf action = toolActions.getLocalAction(provider, actionName);
return action; return action;
@ -1862,7 +1862,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
* @param name the name of the provider to show * @param name the name of the provider to show
* @return the newly shown provider * @return the newly shown provider
*/ */
public ComponentProvider showProvider(DockingTool tool, String name) { public ComponentProvider showProvider(Tool tool, String name) {
ComponentProvider provider = tool.getComponentProvider(name); ComponentProvider provider = tool.getComponentProvider(name);
tool.showComponentProvider(provider, true); tool.showComponentProvider(provider, true);
return provider; return provider;
@ -1870,7 +1870,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
/** /**
* Closes the given provider. You could just call * Closes the given provider. You could just call
* {@link DockingTool#removeComponentProvider(ComponentProvider)}, but some providers have extra * {@link Tool#removeComponentProvider(ComponentProvider)}, but some providers have extra
* logic that happens when {@link ComponentProvider#closeComponent()} is called. This will * logic that happens when {@link ComponentProvider#closeComponent()} is called. This will
* likely change in the future. * likely change in the future.
* *

View file

@ -15,10 +15,10 @@
*/ */
package docking.tool.util; package docking.tool.util;
import docking.DockingTool; import docking.Tool;
/** /**
* An interface to house constants used by the {@link DockingTool} * An interface to house constants used by the {@link Tool}
*/ */
public interface DockingToolConstants { public interface DockingToolConstants {

View file

@ -1203,7 +1203,7 @@ public class GTable extends JTable {
GTableToCSV.writeCSVUsingColunns(file, GTable.this, columnList); GTableToCSV.writeCSVUsingColunns(file, GTable.this, columnList);
} }
public static void createSharedActions(DockingTool tool, ToolActions toolActions, public static void createSharedActions(Tool tool, ToolActions toolActions,
String owner) { String owner) {
String actionMenuGroup = "zzzTableGroup"; String actionMenuGroup = "zzzTableGroup";

View file

@ -54,7 +54,7 @@ public class SharedKeyBindingDockingActionTest extends AbstractDockingTest {
private SpyErrorLogger spyLogger = new SpyErrorLogger(); private SpyErrorLogger spyLogger = new SpyErrorLogger();
private DockingTool tool; private Tool tool;
@Before @Before
public void setUp() { public void setUp() {

View file

@ -23,9 +23,10 @@ import javax.swing.ImageIcon;
import docking.actions.ToolActions; import docking.actions.ToolActions;
import docking.framework.ApplicationInformationDisplayFactory; import docking.framework.ApplicationInformationDisplayFactory;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.util.ServiceListener;
/** /**
* A Test Double of the {@link DockingTool} that provides minimal tool functionality, such * A Test Double of the {@link Tool} that provides minimal tool functionality, such
* as the {@link DockingWindowManager} * as the {@link DockingWindowManager}
*/ */
public class FakeDockingTool extends AbstractDockingTool { public class FakeDockingTool extends AbstractDockingTool {
@ -62,4 +63,19 @@ public class FakeDockingTool extends AbstractDockingTool {
public void close() { public void close() {
// stub // stub
} }
@Override
public <T> T getService(Class<T> serviceClass) {
return null;
}
@Override
public void addServiceListener(ServiceListener listener) {
// stub
}
@Override
public void removeServiceListener(ServiceListener listener) {
// stub
}
} }

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -59,11 +59,11 @@ public abstract class VisualGraphComponentProvider<V extends VisualVertex,
private List<VisualGraphFeaturette<V, E, G>> subFeatures = new ArrayList<>(); private List<VisualGraphFeaturette<V, E, G>> subFeatures = new ArrayList<>();
protected VisualGraphComponentProvider(DockingTool tool, String name, String owner) { protected VisualGraphComponentProvider(Tool tool, String name, String owner) {
super(tool, name, owner); super(tool, name, owner);
} }
protected VisualGraphComponentProvider(DockingTool tool, String name, String owner, protected VisualGraphComponentProvider(Tool tool, String name, String owner,
Class<?> contextType) { Class<?> contextType) {
super(tool, name, owner, contextType); super(tool, name, owner, contextType);
} }

View file

@ -60,7 +60,7 @@ public class VgSatelliteFeaturette<V extends VisualVertex,
private ToggleDockingAction toggleSatelliteAction; private ToggleDockingAction toggleSatelliteAction;
private ToggleDockingAction dockSatelliteAction; private ToggleDockingAction dockSatelliteAction;
private DockingTool tool; private Tool tool;
private VisualGraphView<?, ?, ?> view; private VisualGraphView<?, ?, ?> view;
private String owner; private String owner;
private String providerName; private String providerName;
@ -229,7 +229,7 @@ public class VgSatelliteFeaturette<V extends VisualVertex,
private JComponent satelliteComponent; private JComponent satelliteComponent;
public VgUndockedSatelliteProvider(DockingTool tool, JComponent component, String name, public VgUndockedSatelliteProvider(Tool tool, JComponent component, String name,
String owner, String windowGroup) { String owner, String windowGroup) {
super(tool, name, owner); super(tool, name, owner);

View file

@ -185,7 +185,7 @@ public class VisualGraphComponentProviderTest extends AbstractVisualGraphTest {
} }
private void setSatelliteVisible(boolean visible) { private void setSatelliteVisible(boolean visible) {
DockingTool tool = provider.getTool(); Tool tool = provider.getTool();
String name = "Display Satellite View"; String name = "Display Satellite View";
DockingActionIf action = getAction(tool, name); DockingActionIf action = getAction(tool, name);
assertNotNull(name + " not in tool", action); assertNotNull(name + " not in tool", action);
@ -195,7 +195,7 @@ public class VisualGraphComponentProviderTest extends AbstractVisualGraphTest {
} }
private void setSatelliteDocked(boolean docked) { private void setSatelliteDocked(boolean docked) {
DockingTool tool = provider.getTool(); Tool tool = provider.getTool();
String name = "Dock Satellite View"; String name = "Dock Satellite View";
DockingActionIf action = getAction(tool, name); DockingActionIf action = getAction(tool, name);
assertNotNull(name + " not in tool", action); assertNotNull(name + " not in tool", action);
@ -216,7 +216,7 @@ public class VisualGraphComponentProviderTest extends AbstractVisualGraphTest {
private JComponent component; private JComponent component;
protected TestProvider(DockingTool tool) { protected TestProvider(Tool tool) {
super(tool, "Test VG Provider", "Test Owner"); super(tool, "Test VG Provider", "Test Owner");
component = new JPanel(); component = new JPanel();

View file

@ -33,6 +33,7 @@ import ghidra.framework.client.ClientUtil;
import ghidra.framework.client.RepositoryAdapter; import ghidra.framework.client.RepositoryAdapter;
import ghidra.framework.model.*; import ghidra.framework.model.*;
import ghidra.framework.options.SaveState; import ghidra.framework.options.SaveState;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.store.LockException; import ghidra.framework.store.LockException;
import ghidra.util.*; import ghidra.util.*;
import ghidra.util.exception.NotFoundException; import ghidra.util.exception.NotFoundException;
@ -274,6 +275,8 @@ class FileActionManager {
/** /**
* Opens the given project in a task that will show a dialog to block input while opening * Opens the given project in a task that will show a dialog to block input while opening
* the project in the swing thread. * the project in the swing thread.
* @param projectLocator the project locator
* @return true if the project was opened
*/ */
final boolean openProject(ProjectLocator projectLocator) { final boolean openProject(ProjectLocator projectLocator) {
OpenTaskRunnable openRunnable = new OpenTaskRunnable(projectLocator); OpenTaskRunnable openRunnable = new OpenTaskRunnable(projectLocator);
@ -285,6 +288,8 @@ class FileActionManager {
/** /**
* Open an existing project, using a file chooser to specify where the * Open an existing project, using a file chooser to specify where the
* existing project folder is stored. * existing project folder is stored.
* @param projectLocator the project locator
* @return true if the project was opened
*/ */
final boolean doOpenProject(ProjectLocator projectLocator) { final boolean doOpenProject(ProjectLocator projectLocator) {
String status = "Opened project: " + projectLocator.getName(); String status = "Opened project: " + projectLocator.getName();
@ -346,7 +351,7 @@ class FileActionManager {
/** /**
* Obtain domain objects from files and lock. If unable to lock * Obtain domain objects from files and lock. If unable to lock
* one or more of the files, none are locked and null is returned. * one or more of the files, none are locked and null is returned.
* @param files * @param files the files
* @return locked domain objects, or null if unable to lock * @return locked domain objects, or null if unable to lock
* all domain objects. * all domain objects.
*/ */
@ -414,8 +419,6 @@ class FileActionManager {
* This method will always save the FrontEndTool and project, but not the data unless * This method will always save the FrontEndTool and project, but not the data unless
* <tt>confirmClose</tt> is called. * <tt>confirmClose</tt> is called.
* *
* @param confirmClose true if the confirmation dialog should be
* displayed
* @param isExiting true if we are closing the project because * @param isExiting true if we are closing the project because
* Ghidra is exiting * Ghidra is exiting
* @return false if user cancels the close operation * @return false if user cancels the close operation
@ -428,9 +431,9 @@ class FileActionManager {
} }
// check for any changes since last saved // check for any changes since last saved
Tool[] runningTools = activeProject.getToolManager().getRunningTools(); PluginTool[] runningTools = activeProject.getToolManager().getRunningTools();
for (int i = 0; i < runningTools.length; i++) { for (PluginTool runningTool : runningTools) {
if (!runningTools[i].canClose(isExiting)) { if (!runningTool.canClose(isExiting)) {
return false; return false;
} }
} }
@ -655,7 +658,7 @@ class FileActionManager {
/** /**
* Checks the list for read-only files; if any are found, pops up * Checks the list for read-only files; if any are found, pops up
* a dialog for whether to save now or lose changes. * a dialog for whether to save now or lose changes.
* @param files list of files which correspond to modified * @param objs list of files which correspond to modified
* domain objects. * domain objects.
* @return true if there are no read only files OR if the user * @return true if there are no read only files OR if the user
* wants to lose his changes; false if the user wants to save the * wants to lose his changes; false if the user wants to save the

View file

@ -660,9 +660,9 @@ public class FrontEndPlugin extends Plugin
private ToolTemplate getUpToDateTemplate(ToolTemplate template) { private ToolTemplate getUpToDateTemplate(ToolTemplate template) {
ToolManager toolManager = activeProject.getToolManager(); ToolManager toolManager = activeProject.getToolManager();
Tool[] runningTools = toolManager.getRunningTools(); PluginTool[] runningTools = toolManager.getRunningTools();
String templateName = template.getName(); String templateName = template.getName();
for (Tool runningTool : runningTools) { for (PluginTool runningTool : runningTools) {
if (runningTool.getName().equals(templateName)) { if (runningTool.getName().equals(templateName)) {
return runningTool.getToolTemplate(true); return runningTool.getToolTemplate(true);
} }
@ -960,8 +960,8 @@ public class FrontEndPlugin extends Plugin
private boolean isToolRunning(ToolTemplate template) { private boolean isToolRunning(ToolTemplate template) {
ToolManager toolManager = activeProject.getToolManager(); ToolManager toolManager = activeProject.getToolManager();
Tool[] runningTools = toolManager.getRunningTools(); PluginTool[] runningTools = toolManager.getRunningTools();
for (Tool runningTool : runningTools) { for (PluginTool runningTool : runningTools) {
if (runningTool.getToolName().equals(template.getName())) { if (runningTool.getToolName().equals(template.getName())) {
return true; return true;
} }

View file

@ -745,8 +745,8 @@ public class FrontEndTool extends PluginTool implements OptionsChangeListener {
@Override @Override
public boolean canCloseDomainFile(DomainFile df) { public boolean canCloseDomainFile(DomainFile df) {
Tool[] tools = getProject().getToolManager().getRunningTools(); PluginTool[] tools = getProject().getToolManager().getRunningTools();
for (Tool tool : tools) { for (PluginTool tool : tools) {
DomainFile[] files = tool.getDomainFiles(); DomainFile[] files = tool.getDomainFiles();
for (DomainFile domainFile : files) { for (DomainFile domainFile : files) {
if (df == domainFile) { if (df == domainFile) {

View file

@ -34,6 +34,7 @@ import ghidra.app.util.GenericHelpTopics;
import ghidra.framework.client.*; import ghidra.framework.client.*;
import ghidra.framework.data.ConvertFileSystem; import ghidra.framework.data.ConvertFileSystem;
import ghidra.framework.model.*; import ghidra.framework.model.*;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.remote.User; import ghidra.framework.remote.User;
import ghidra.framework.store.local.*; import ghidra.framework.store.local.*;
import ghidra.util.*; import ghidra.util.*;
@ -456,10 +457,10 @@ public class ProjectInfoDialog extends DialogComponentProvider {
} }
private boolean filesAreOpen() { private boolean filesAreOpen() {
Tool[] tools = project.getToolManager().getRunningTools(); PluginTool[] tools = project.getToolManager().getRunningTools();
if (tools.length > 0) { if (tools.length > 0) {
for (Tool tool : tools) { for (PluginTool tool : tools) {
if (tool.getDomainFiles().length > 0) { if (tool.getDomainFiles().length > 0) {
return true; return true;
} }

View file

@ -23,12 +23,14 @@ import java.util.Map;
import javax.swing.*; import javax.swing.*;
import docking.DockingUtils; import docking.DockingUtils;
import ghidra.framework.model.*; import ghidra.framework.model.ToolTemplate;
import ghidra.framework.model.Workspace;
import ghidra.framework.plugintool.PluginTool;
class RunningToolsPanel extends JPanel { class RunningToolsPanel extends JPanel {
private JToolBar runningToolbar; private JToolBar runningToolbar;
private FrontEndPlugin plugin; private FrontEndPlugin plugin;
private Map<Tool, ToolButton> runningTools; private Map<PluginTool, ToolButton> runningTools;
RunningToolsPanel(FrontEndPlugin plugin, Workspace ws) { RunningToolsPanel(FrontEndPlugin plugin, Workspace ws) {
super(new BorderLayout(0, 0)); super(new BorderLayout(0, 0));
@ -55,12 +57,13 @@ class RunningToolsPanel extends JPanel {
// remove the default etched border // remove the default etched border
add(runningToolbar, BorderLayout.CENTER); add(runningToolbar, BorderLayout.CENTER);
runningTools = new HashMap<Tool, ToolButton>(WorkspacePanel.TYPICAL_NUM_RUNNING_TOOLS); runningTools =
new HashMap<PluginTool, ToolButton>(WorkspacePanel.TYPICAL_NUM_RUNNING_TOOLS);
// populate the toolbar if the workspace has running tools // populate the toolbar if the workspace has running tools
if (ws != null) { if (ws != null) {
Tool[] tools = ws.getTools(); PluginTool[] tools = ws.getTools();
for (Tool element : tools) { for (PluginTool element : tools) {
addTool(element); addTool(element);
} }
} }
@ -73,7 +76,7 @@ class RunningToolsPanel extends JPanel {
return runningToolbar.getPreferredSize(); return runningToolbar.getPreferredSize();
} }
void addTool(Tool runningTool) { void addTool(PluginTool runningTool) {
ToolButton toolButton = ToolButton toolButton =
new ToolButton(plugin, runningTool, runningTool.getToolTemplate(true)); new ToolButton(plugin, runningTool, runningTool.getToolTemplate(true));
runningToolbar.add(toolButton); runningToolbar.add(toolButton);
@ -83,7 +86,7 @@ class RunningToolsPanel extends JPanel {
repaint(); repaint();
} }
void removeTool(Tool tool) { void removeTool(PluginTool tool) {
ToolButton button = runningTools.get(tool); ToolButton button = runningTools.get(tool);
if (button == null) { if (button == null) {
return; return;
@ -97,13 +100,13 @@ class RunningToolsPanel extends JPanel {
} }
// parameter not used // parameter not used
void toolNameChanged(Tool changedTool) { void toolNameChanged(PluginTool changedTool) {
} }
/** /**
* Update the tool template for the tool button. * Update the tool template for the tool button.
*/ */
void updateToolButton(Tool tool, ToolTemplate template, Icon icon) { void updateToolButton(PluginTool tool, ToolTemplate template, Icon icon) {
ToolButton button = runningTools.get(tool); ToolButton button = runningTools.get(tool);
if (button != null) { if (button != null) {

View file

@ -307,7 +307,7 @@ class ToolActionManager implements ToolChestChangeListener {
} }
// only enable if project has more than 1 running tool // only enable if project has more than 1 running tool
ToolManager tm = project.getToolManager(); ToolManager tm = project.getToolManager();
Tool[] runningTools = tm.getRunningTools(); PluginTool[] runningTools = tm.getRunningTools();
connectToolsAction.setEnabled(runningTools.length > 1); connectToolsAction.setEnabled(runningTools.length > 1);
} }

View file

@ -65,7 +65,7 @@ class ToolButton extends EmptyBorderButton implements Draggable, Droppable {
private FrontEndPlugin plugin; private FrontEndPlugin plugin;
private ToolTemplate template; private ToolTemplate template;
private Tool associatedRunningTool; private PluginTool associatedRunningTool;
private DefaultToolChangeListener toolChangeListener; private DefaultToolChangeListener toolChangeListener;
private ToolServices toolServices; private ToolServices toolServices;
@ -83,7 +83,7 @@ class ToolButton extends EmptyBorderButton implements Draggable, Droppable {
* Construct a tool label that represents a running tool, using the * Construct a tool label that represents a running tool, using the
* default RUNNING_TOOL icon. * default RUNNING_TOOL icon.
*/ */
ToolButton(FrontEndPlugin plugin, Tool tool, ToolTemplate template) { ToolButton(FrontEndPlugin plugin, PluginTool tool, ToolTemplate template) {
this(plugin, tool, template, tool.getIconURL()); this(plugin, tool, template, tool.getIconURL());
setHelpLocation("Run_Tool"); setHelpLocation("Run_Tool");
} }
@ -91,7 +91,7 @@ class ToolButton extends EmptyBorderButton implements Draggable, Droppable {
/** /**
* Construct a tool label that represents a running tool. * Construct a tool label that represents a running tool.
*/ */
private ToolButton(FrontEndPlugin plugin, Tool tool, ToolTemplate template, private ToolButton(FrontEndPlugin plugin, PluginTool tool, ToolTemplate template,
ToolIconURL iconURL) { ToolIconURL iconURL) {
super(iconURL.getIcon()); super(iconURL.getIcon());
this.plugin = plugin; this.plugin = plugin;
@ -298,9 +298,9 @@ class ToolButton extends EmptyBorderButton implements Draggable, Droppable {
private void addFromToolButton(ToolButton toolButton) { private void addFromToolButton(ToolButton toolButton) {
plugin.setToolButtonTransferable(null); plugin.setToolButtonTransferable(null);
Tool tool = null; PluginTool tool = null;
if (associatedRunningTool != null && toolButton.associatedRunningTool != null) { if (associatedRunningTool != null && toolButton.associatedRunningTool != null) {
final Tool t2 = toolButton.associatedRunningTool; final PluginTool t2 = toolButton.associatedRunningTool;
SwingUtilities.invokeLater(() -> connectTools(associatedRunningTool, t2)); SwingUtilities.invokeLater(() -> connectTools(associatedRunningTool, t2));
return; return;
} }
@ -309,14 +309,14 @@ class ToolButton extends EmptyBorderButton implements Draggable, Droppable {
if (toolButton.associatedRunningTool == null) { if (toolButton.associatedRunningTool == null) {
tool = plugin.getActiveWorkspace().runTool(toolButton.template); tool = plugin.getActiveWorkspace().runTool(toolButton.template);
accepted = tool.acceptDomainFiles(associatedRunningTool.getDomainFiles()); accepted = tool.acceptDomainFiles(associatedRunningTool.getDomainFiles());
final Tool t = tool; final PluginTool t = tool;
SwingUtilities.invokeLater(() -> connectTools(t, associatedRunningTool)); SwingUtilities.invokeLater(() -> connectTools(t, associatedRunningTool));
} }
else { else {
tool = plugin.getActiveWorkspace().runTool(template); tool = plugin.getActiveWorkspace().runTool(template);
accepted = tool.acceptDomainFiles(toolButton.associatedRunningTool.getDomainFiles()); accepted = tool.acceptDomainFiles(toolButton.associatedRunningTool.getDomainFiles());
final Tool t = tool; final PluginTool t = tool;
final Tool t2 = toolButton.associatedRunningTool; final PluginTool t2 = toolButton.associatedRunningTool;
SwingUtilities.invokeLater(() -> connectTools(t, t2)); SwingUtilities.invokeLater(() -> connectTools(t, t2));
} }
@ -328,7 +328,7 @@ class ToolButton extends EmptyBorderButton implements Draggable, Droppable {
/** /**
* Connect the tools in both directions. * Connect the tools in both directions.
*/ */
private void connectTools(Tool t1, Tool t2) { private void connectTools(PluginTool t1, PluginTool t2) {
ToolManager tm = plugin.getActiveProject().getToolManager(); ToolManager tm = plugin.getActiveProject().getToolManager();
ToolConnection tc = tm.getConnection(t1, t2); ToolConnection tc = tm.getConnection(t1, t2);
connectAll(tc); connectAll(tc);
@ -514,7 +514,7 @@ class ToolButton extends EmptyBorderButton implements Draggable, Droppable {
associatedRunningTool.close(); associatedRunningTool.close();
} }
Tool getRunningTool() { PluginTool getRunningTool() {
return associatedRunningTool; return associatedRunningTool;
} }
@ -570,7 +570,7 @@ class ToolButton extends EmptyBorderButton implements Draggable, Droppable {
Msg.debug(this, "Found root frame without a GhidraGlassPane registered!"); Msg.debug(this, "Found root frame without a GhidraGlassPane registered!");
// try to recover without animation // try to recover without animation
Tool newTool = plugin.getActiveWorkspace().runTool(template); PluginTool newTool = plugin.getActiveWorkspace().runTool(template);
openDomainFiles(newTool, domainFiles); openDomainFiles(newTool, domainFiles);
finishedCallback.run(); finishedCallback.run();
return; return;
@ -621,7 +621,7 @@ class ToolButton extends EmptyBorderButton implements Draggable, Droppable {
try { try {
// cleanup any residual painting effects // cleanup any residual painting effects
toolGlassPane.paintImmediately(toolGlassPane.getBounds()); toolGlassPane.paintImmediately(toolGlassPane.getBounds());
Tool newTool = plugin.getActiveWorkspace().runTool(template); PluginTool newTool = plugin.getActiveWorkspace().runTool(template);
openDomainFiles(newTool, domainFiles); openDomainFiles(newTool, domainFiles);
} }
finally { finally {
@ -640,7 +640,7 @@ class ToolButton extends EmptyBorderButton implements Draggable, Droppable {
zoomRunner.run(); zoomRunner.run();
} }
private void openDomainFiles(Tool tool, DomainFile[] domainFiles) { private void openDomainFiles(PluginTool tool, DomainFile[] domainFiles) {
if (domainFiles == null) { if (domainFiles == null) {
return; return;
} }

Some files were not shown because too many files have changed in this diff Show more