@@ -270,9 +270,12 @@ class Dialog {
270
270
271
271
return ;
272
272
}
273
+
274
+ // If it's a directory, we want to navigate to it. If it's a file, then we
275
+ // only want to open it if opening files is supported.
273
276
if ( element . isDirectory ) {
274
277
this . path = element . fullPath ;
275
- } else if ( ! ( this . options as OpenDialogOptions ) . properties . openDirectory ) {
278
+ } else if ( ( this . options as OpenDialogOptions ) . properties . openFile ) {
276
279
this . selectEmitter . emit ( element . fullPath ) ;
277
280
}
278
281
} ) ;
@@ -288,16 +291,18 @@ class Dialog {
288
291
} ) ;
289
292
buttonsNode . appendChild ( cancelBtn ) ;
290
293
const confirmBtn = document . createElement ( "button" ) ;
291
- const openFile = ( this . options as OpenDialogOptions ) . properties . openFile ;
292
- confirmBtn . innerText = openFile ? "Open" : "Confirm" ;
294
+ const openDirectory = ( this . options as OpenDialogOptions ) . properties . openDirectory ;
295
+ confirmBtn . innerText = this . options . buttonLabel || "Confirm" ;
293
296
confirmBtn . addEventListener ( "click" , ( ) => {
294
- if ( this . _path && ! openFile ) {
297
+ if ( this . _path && openDirectory ) {
295
298
this . selectEmitter . emit ( this . _path ) ;
296
299
}
297
300
} ) ;
298
- // Since a single click opens a file, the only time this button can be
299
- // used is on a directory, which is invalid for opening files.
300
- if ( openFile ) {
301
+ // Disable if we can't open directories, otherwise you can open a directory
302
+ // as a file which won't work. This is because our button currently just
303
+ // always opens whatever directory is opened and will not open selected
304
+ // files. (A single click on a file is used to open it instead.)
305
+ if ( ! openDirectory ) {
301
306
confirmBtn . disabled = true ;
302
307
}
303
308
buttonsNode . appendChild ( confirmBtn ) ;
@@ -407,8 +412,9 @@ class Dialog {
407
412
isDirectory : stat . isDirectory ( ) ,
408
413
lastModified : stat . mtime . toDateString ( ) ,
409
414
size : stat . size ,
410
- // If we are opening a directory, show files as disabled.
411
- isDisabled : ! stat . isDirectory ( ) && ( this . options as OpenDialogOptions ) . properties . openDirectory ,
415
+ // If we can't open files, show them as disabled.
416
+ isDisabled : ! stat . isDirectory ( )
417
+ && ! ( this . options as OpenDialogOptions ) . properties . openFile ,
412
418
} ) ) ;
413
419
}
414
420
}
0 commit comments