From 866447934e397e5a0fd4359be6fafb2de0bd3c3c Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Wed, 10 Apr 2019 16:15:39 -0400 Subject: [PATCH] promptForPathToOpen() uses an existing window when only files are chosen --- src/main-process/atom-application.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main-process/atom-application.js b/src/main-process/atom-application.js index ed1c2dc91..481ece658 100644 --- a/src/main-process/atom-application.js +++ b/src/main-process/atom-application.js @@ -1424,14 +1424,32 @@ class AtomApplication extends EventEmitter { // should be in dev mode or not. // :safeMode - A Boolean which controls whether any newly opened windows // should be in safe mode or not. - // :window - An {AtomWindow} to use for opening a selected file path. + // :window - An {AtomWindow} to use for opening selected file paths as long as + // all are files. // :path - An optional String which controls the default path to which the // file dialog opens. promptForPathToOpen (type, {devMode, safeMode, window}, path = null) { return this.promptForPath( type, - pathsToOpen => { - return this.openPaths({pathsToOpen, devMode, safeMode, window}) + async pathsToOpen => { + let targetWindow + + // Open in :window as long as no chosen paths are folders. If any chosen path is a folder, open in a + // new window instead. + if (type === 'folder') { + targetWindow = null + } else if (type === 'file') { + targetWindow = window + } else if (type === 'all') { + const areDirectories = await Promise.all( + pathsToOpen.map(pathToOpen => new Promise(resolve => fs.isDirectory(pathToOpen, resolve))) + ) + if (!areDirectories.some(Boolean)) { + targetWindow = window + } + } + + return this.openPaths({pathsToOpen, devMode, safeMode, window: targetWindow}) }, path )