4242import org .scijava .log .LogService ;
4343import org .scijava .plugin .Parameter ;
4444import 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