mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
GT-1 Fixed ActionBuilder so that not specifying an "enabledWhen"
condition doesn't interfere with manual action enablement.
This commit is contained in:
parent
c50d32c792
commit
04de745ddd
2 changed files with 19 additions and 2 deletions
|
@ -160,7 +160,7 @@ public abstract class AbstractActionBuilder<T extends DockingActionIf, C extends
|
|||
/**
|
||||
* Predicate for determining if an action is enabled for a given context
|
||||
*/
|
||||
private Predicate<C> enabledPredicate = ALWAYS_TRUE;
|
||||
private Predicate<C> enabledPredicate = null;
|
||||
|
||||
/**
|
||||
* Predicate for determining if an action should be included on the pop-up menu
|
||||
|
@ -664,7 +664,10 @@ public abstract class AbstractActionBuilder<T extends DockingActionIf, C extends
|
|||
action.setHelpLocation(helpLocation);
|
||||
}
|
||||
|
||||
action.enabledWhen(adaptPredicate(enabledPredicate));
|
||||
if (enabledPredicate != null) {
|
||||
action.enabledWhen(adaptPredicate(enabledPredicate));
|
||||
}
|
||||
|
||||
action.validContextWhen(adaptPredicate(validContextPredicate));
|
||||
action.popupWhen(adaptPredicate(popupPredicate));
|
||||
}
|
||||
|
|
|
@ -237,6 +237,20 @@ public class ActionBuilderTest {
|
|||
assertTrue(action.isEnabledForContext(new FooActionContext()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManualEnablement() {
|
||||
DockingAction action = new ActionBuilder("Test", "Test")
|
||||
.onAction(e -> actionCount++)
|
||||
.enabled(false)
|
||||
.build();
|
||||
|
||||
assertFalse(action.isEnabledForContext(new ActionContext()));
|
||||
action.setEnabled(true);
|
||||
assertTrue(action.isEnabledForContext(new ActionContext()));
|
||||
action.setEnabled(true);
|
||||
assertTrue(action.isEnabledForContext(new ActionContext()));
|
||||
}
|
||||
|
||||
static class FooActionContext extends ActionContext {
|
||||
public boolean foo() {
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue