Skip to content

Commit e8e9644

Browse files
committed
OptionsPlugin: fix bug with cancelation
After canceling an options plugin, it would not run again. Great idea Curtis to make OptionsPlugins singletons... >_<
1 parent a67c719 commit e8e9644

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/main/java/org/scijava/command/DynamicCommand.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,8 @@ public String getCancelReason() {
140140
return cancelReason;
141141
}
142142

143+
// HACK: For OptionsPlugin.
144+
public void uncancel() {
145+
cancelReason = null;
146+
}
143147
}

src/main/java/org/scijava/options/OptionsPlugin.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,20 @@ public void reset() {
108108
prefService.clear(getClass());
109109
}
110110

111+
// -- Module methods --
112+
113+
@Override
114+
public void cancel() {
115+
resetState();
116+
}
117+
111118
// -- Runnable methods --
112119

113120
@Override
114121
public void run() {
115122
save();
116-
117-
// NB: Clear "resolved" status of all inputs.
118-
// Otherwise, no inputs are harvested on next run.
119-
for (final ModuleItem<?> input : getInfo().inputs()) {
120-
unresolveInput(input.getName());
121-
}
122-
123123
eventService.publish(new OptionsEvent(this));
124+
resetState();
124125
}
125126

126127
// -- Helper methods --
@@ -135,4 +136,15 @@ private <T> void saveInput(final ModuleItem<T> input) {
135136
moduleService.save(input, value);
136137
}
137138

139+
private void resetState() {
140+
// NB: Clear "resolved" status of all inputs.
141+
// Otherwise, no inputs are harvested on next run.
142+
for (final ModuleItem<?> input : getInfo().inputs()) {
143+
unresolveInput(input.getName());
144+
}
145+
146+
// NB: Clear "canceled" status.
147+
// Otherwise, the command cannot run again.
148+
uncancel();
149+
}
138150
}

0 commit comments

Comments
 (0)