@@ -104,6 +104,17 @@ private IOPlugin<?> getEagerHandler(String path) {
104
104
public Object open (String path , final int planeIndex ,
105
105
final boolean displayResult )
106
106
{
107
+ // There are many ways this code can get hit and the return value is
108
+ // critical in ensuring the proper subsequent behavior is taken.
109
+ // In the cases of Open Recent, path will be non-null. HOWEVER, if we do
110
+ // not handle the opening here we MUST return null to ensure the original
111
+ // ImageJ picks it up appropriately.
112
+ // In cases of File > Open..., path will be null and we will display a file
113
+ // chooser. If we do not handle the opening here, we MUST return the path
114
+ // that was selected - otherwise a second file chooser will be displayed
115
+ // when falling back to the original ImageJ.
116
+ // See https://github.com/imagej/imagej-legacy/issues/314
117
+ String returnPath = null ;
107
118
final Context c = IJ1Helper .getLegacyContext ();
108
119
109
120
legacyService = getCached (legacyService , LegacyService .class , c );
@@ -139,6 +150,9 @@ public Object open(String path, final int planeIndex,
139
150
return Boolean .TRUE ; // cancel the operation
140
151
}
141
152
path = selectedPath [0 ];
153
+ // Since we displayed an opener dialog to the user, here we do want to
154
+ // update the returnPath, to avoid triggering a second opener dialog
155
+ returnPath = path ;
142
156
}
143
157
if (path == null ) return Boolean .TRUE ; // cancel the operation
144
158
@@ -151,12 +165,12 @@ public Object open(String path, final int planeIndex,
151
165
final IOPlugin <?> opener = ioService .getOpener (path );
152
166
if (opener == null ) {
153
167
logService .warn ("No appropriate format found: " + path );
154
- return path ;
168
+ return returnPath ;
155
169
}
156
170
data = opener .open (path );
157
171
if (data == null ) {
158
172
logService .warn ("Opening was canceled." );
159
- return path ;
173
+ return returnPath ;
160
174
}
161
175
}
162
176
else {
@@ -173,23 +187,23 @@ public Object open(String path, final int planeIndex,
173
187
final IOPlugin <?> io = getEagerHandler (path );
174
188
if (io == null ) {
175
189
logService .debug ("No appropriate eager I/O plugin found: " + path );
176
- return path ; // fall back to original ImageJ
190
+ return returnPath ; // fall back to original ImageJ
177
191
}
178
192
data = io .open (path );
179
193
if (data == null ) {
180
194
logService .debug ("Eager I/O plugin '" + io .getClass ().getName () + "' opened nothing." );
181
- return path ; // fall back to original ImageJ
195
+ return returnPath ; // fall back to original ImageJ
182
196
}
183
197
}
184
198
catch (final IOException exc ) {
185
199
legacyService .handleException (exc );
186
- return path ; // fall back to original ImageJ
200
+ return returnPath ; // fall back to original ImageJ
187
201
}
188
202
}
189
203
}
190
204
catch (final IOException exc ) {
191
205
legacyService .handleException (exc );
192
- return path ; // fall back to original ImageJ
206
+ return returnPath ; // fall back to original ImageJ
193
207
}
194
208
195
209
return handleData (c , data , path , displayResult );
0 commit comments