Component Provider - fixed bug that prevented some providers' close

button from working
This commit is contained in:
dragonmacher 2019-07-25 14:09:58 -04:00
parent cada47a258
commit 8f13b601d8
3 changed files with 40 additions and 2 deletions

View file

@ -339,6 +339,29 @@ public class ComponentProviderActionsTest extends AbstractGhidraHeadedIntegratio
assertProviderIsHidden(); assertProviderIsHidden();
} }
@Test
public void testEveryCloseButtonsActionContext() {
// grab the tool that has all the provider's loaded
env.closeTool(tool);
tool = env.launchDefaultTool();
DockingWindowManager dwm = tool.getWindowManager();
PlaceholderManager pm = dwm.getPlaceholderManager();
Set<ComponentProvider> allProviders = pm.getActiveProviders();
for (ComponentProvider cp : allProviders) {
ActionContext context = cp.getActionContext(null);
if (context == null) {
continue; // a null context is allowed
}
// this is a rule we need for context to work as intended for some actions (like the
// close button)
assertSame("Component provider did not make itself the context's provider",
context.getComponentProvider(), cp);
}
}
//================================================================================================== //==================================================================================================
// Private Methods // Private Methods
//================================================================================================== //==================================================================================================

View file

@ -100,7 +100,7 @@ public class ActionContext {
* Sets the sourceObject for this ActionContext. This method is used internally by the * Sets the sourceObject for this ActionContext. This method is used internally by the
* DockingWindowManager. ComponentProvider and action developers should * DockingWindowManager. ComponentProvider and action developers should
* only use this method for testing. * only use this method for testing.
* @param sourceObject * @param sourceObject the source object
*/ */
public void setSource(Object sourceObject) { public void setSource(Object sourceObject) {
this.sourceObject = sourceObject; this.sourceObject = sourceObject;
@ -125,4 +125,18 @@ public class ActionContext {
public MouseEvent getMouseEvent() { public MouseEvent getMouseEvent() {
return mouseEvent; return mouseEvent;
} }
@Override
public String toString() {
//@formatter:off
return "{\n" +
"\tprovider: " + provider + ",\n" +
"\tcontextObject: " + contextObject + ",\n" +
"\tsourceObject: " + sourceObject + ",\n" +
"\tmouseEvent: " + mouseEvent + "\n" +
"}";
//@formatter:on
}
} }

View file

@ -229,7 +229,8 @@ public class ToolBarItemManager implements PropertyChangeListener, ActionListene
private ActionContext getActionContext() { private ActionContext getActionContext() {
ComponentProvider provider = getComponentProvider(); ComponentProvider provider = getComponentProvider();
ActionContext context = provider == null ? null : provider.getActionContext(null); ActionContext context = provider == null ? null : provider.getActionContext(null);
final ActionContext actionContext = context == null ? new ActionContext() : context; final ActionContext actionContext =
context == null ? new ActionContext(provider, null) : context;
return actionContext; return actionContext;
} }