@@ -270,9 +270,12 @@ class Dialog {
270270
271271 return ;
272272 }
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.
273276 if ( element . isDirectory ) {
274277 this . path = element . fullPath ;
275- } else if ( ! ( this . options as OpenDialogOptions ) . properties . openDirectory ) {
278+ } else if ( ( this . options as OpenDialogOptions ) . properties . openFile ) {
276279 this . selectEmitter . emit ( element . fullPath ) ;
277280 }
278281 } ) ;
@@ -288,16 +291,18 @@ class Dialog {
288291 } ) ;
289292 buttonsNode . appendChild ( cancelBtn ) ;
290293 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" ;
293296 confirmBtn . addEventListener ( "click" , ( ) => {
294- if ( this . _path && ! openFile ) {
297+ if ( this . _path && openDirectory ) {
295298 this . selectEmitter . emit ( this . _path ) ;
296299 }
297300 } ) ;
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 ) {
301306 confirmBtn . disabled = true ;
302307 }
303308 buttonsNode . appendChild ( confirmBtn ) ;
@@ -407,8 +412,9 @@ class Dialog {
407412 isDirectory : stat . isDirectory ( ) ,
408413 lastModified : stat . mtime . toDateString ( ) ,
409414 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 ,
412418 } ) ) ;
413419 }
414420}
0 commit comments