Skip to content

Commit c53149e

Browse files
committed
OpenArgument: defer opening until UI is visible
Otherwise, the data is opened, but then not displayed.
1 parent 17ead5d commit c53149e

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/main/java/org/scijava/io/console/OpenArgument.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.scijava.log.LogService;
4343
import org.scijava.plugin.Parameter;
4444
import org.scijava.plugin.Plugin;
45+
import org.scijava.startup.StartupService;
4546

4647
/**
4748
* Handles the {@code --open} command line argument.
@@ -57,6 +58,9 @@ public class OpenArgument extends AbstractConsoleArgument {
5758
@Parameter(required = false)
5859
private DisplayService displayService;
5960

61+
@Parameter(required = false)
62+
private StartupService startupService;
63+
6064
@Parameter(required = false)
6165
private LogService log;
6266

@@ -75,19 +79,23 @@ public void handle(final LinkedList<String> args) {
7579
args.removeFirst(); // --open
7680
final String source = args.removeFirst();
7781

78-
try {
79-
final Object o = ioService.open(source);
80-
displayService.createDisplay(o);
81-
}
82-
catch (IOException exc) {
83-
if (log != null) log.error(exc);
84-
}
82+
// open the source after the UI is shown
83+
startupService.addOperation(() -> {
84+
try {
85+
final Object o = ioService.open(source);
86+
displayService.createDisplay(o);
87+
}
88+
catch (final IOException exc) {
89+
if (log != null) log.error(exc);
90+
}
91+
});
8592
}
8693

8794
// -- Typed methods --
8895

8996
@Override
9097
public boolean supports(final LinkedList<String> args) {
91-
return ioService != null && displayService != null && super.supports(args);
98+
return startupService != null && ioService != null &&
99+
displayService != null && super.supports(args);
92100
}
93101
}

0 commit comments

Comments
 (0)