@@ -14,7 +14,7 @@ import { IBackupMainService } from 'vs/platform/backup/common/backup';
1414import { IEnvironmentService , ParsedArgs } from 'vs/platform/environment/common/environment' ;
1515import { IStorageService } from 'vs/platform/storage/node/storage' ;
1616import { CodeWindow , IWindowState as ISingleWindowState , defaultWindowState , WindowMode } from 'vs/code/electron-main/window' ;
17- import { ipcMain as ipc , app , screen , BrowserWindow , dialog } from 'electron' ;
17+ import { ipcMain as ipc , screen , BrowserWindow , dialog } from 'electron' ;
1818import { IPathWithLineAndColumn , parseLineAndColumnAware } from 'vs/code/node/paths' ;
1919import { ILifecycleService , UnloadReason } from 'vs/platform/lifecycle/electron-main/lifecycleMain' ;
2020import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
@@ -231,15 +231,15 @@ export class WindowsManager implements IWindowsMainService {
231231 let foldersToRestore = ( openConfig . initialStartup && ! openConfig . cli . extensionDevelopmentPath ) ? this . backupService . getWorkspaceBackupPaths ( ) : [ ] ;
232232 let filesToOpen : IPath [ ] = [ ] ;
233233 let filesToDiff : IPath [ ] = [ ] ;
234+ let filesToCreate = pathsToOpen . filter ( iPath => ! ! iPath . filePath && iPath . createFilePath ) ;
234235 let emptyToOpen = pathsToOpen . filter ( iPath => ! iPath . workspacePath && ! iPath . filePath ) ;
235236 let emptyToRestore = ( openConfig . initialStartup && ! openConfig . cli . extensionDevelopmentPath ) ? this . backupService . getEmptyWorkspaceBackupPaths ( ) : [ ] ;
236- let filesToCreate = pathsToOpen . filter ( iPath => ! ! iPath . filePath && iPath . createFilePath ) ;
237237
238238 // Diff mode needs special care
239- const candidates = pathsToOpen . filter ( iPath => ! ! iPath . filePath && ! iPath . createFilePath ) ;
239+ const filesToOpenCandidates = pathsToOpen . filter ( iPath => ! ! iPath . filePath && ! iPath . createFilePath ) ;
240240 if ( openConfig . diffMode ) {
241- if ( candidates . length === 2 ) {
242- filesToDiff = candidates ;
241+ if ( filesToOpenCandidates . length === 2 ) {
242+ filesToDiff = filesToOpenCandidates ;
243243 } else {
244244 emptyToOpen = [ Object . create ( null ) ] ; // improper use of diffMode, open empty
245245 }
@@ -248,34 +248,16 @@ export class WindowsManager implements IWindowsMainService {
248248 foldersToRestore = [ ] ; // diff is always in empty workspace
249249 filesToCreate = [ ] ; // diff ignores other files that do not exist
250250 } else {
251- filesToOpen = candidates ;
251+ filesToOpen = filesToOpenCandidates ;
252252 }
253253
254- // let the user settings override how folders are open in a new window or same window unless we are forced
255- const windowConfig = this . configurationService . getConfiguration < IWindowSettings > ( 'window' ) ;
256- let openFolderInNewWindow = ( openConfig . preferNewWindow || openConfig . forceNewWindow ) && ! openConfig . forceReuseWindow ;
257- if ( ! openConfig . forceNewWindow && ! openConfig . forceReuseWindow && windowConfig && ( windowConfig . openFoldersInNewWindow === 'on' || windowConfig . openFoldersInNewWindow === 'off' ) ) {
258- openFolderInNewWindow = ( windowConfig . openFoldersInNewWindow === 'on' ) ;
259- }
254+ // Settings can decide if files/folders open in new window or not
255+ let { openFolderInNewWindow, openFilesInNewWindow } = this . shouldOpenNewWindow ( openConfig ) ;
260256
261257 // Handle files to open/diff or to create when we dont open a folder and we do not restore any folder/untitled from hot-exit
262258 const usedWindows : CodeWindow [ ] = [ ] ;
263259 if ( ! foldersToOpen . length && ! foldersToRestore . length && ! emptyToRestore . length && ( filesToOpen . length > 0 || filesToCreate . length > 0 || filesToDiff . length > 0 ) ) {
264260
265- // let the user settings override how files are open in a new window or same window unless we are forced (not for extension development though)
266- let openFilesInNewWindow : boolean ;
267- if ( openConfig . forceNewWindow || openConfig . forceReuseWindow ) {
268- openFilesInNewWindow = openConfig . forceNewWindow && ! openConfig . forceReuseWindow ;
269- } else {
270- if ( openConfig . context === OpenContext . DOCK ) {
271- openFilesInNewWindow = true ; // only on macOS do we allow to open files in a new window if this is triggered via DOCK context
272- }
273-
274- if ( ! openConfig . cli . extensionDevelopmentPath && windowConfig && ( windowConfig . openFilesInNewWindow === 'on' || windowConfig . openFilesInNewWindow === 'off' ) ) {
275- openFilesInNewWindow = ( windowConfig . openFilesInNewWindow === 'on' ) ;
276- }
277- }
278-
279261 // Open Files in last instance if any and flag tells us so
280262 const fileToCheck = filesToOpen [ 0 ] || filesToCreate [ 0 ] || filesToDiff [ 0 ] ;
281263 const windowOrFolder = findBestWindowOrFolder ( {
@@ -286,6 +268,7 @@ export class WindowsManager implements IWindowsMainService {
286268 filePath : fileToCheck && fileToCheck . filePath ,
287269 userHome : this . environmentService . userHome
288270 } ) ;
271+
289272 if ( windowOrFolder instanceof CodeWindow ) {
290273 windowOrFolder . focus ( ) ;
291274 const files = { filesToOpen, filesToCreate, filesToDiff } ; // copy to object because they get reset shortly after
@@ -328,6 +311,7 @@ export class WindowsManager implements IWindowsMainService {
328311 if ( windowsOnWorkspacePath . length > 0 ) {
329312 const browserWindow = windowsOnWorkspacePath [ 0 ] ;
330313 browserWindow . focus ( ) ; // just focus one of them
314+
331315 const files = { filesToOpen, filesToCreate, filesToDiff } ; // copy to object because they get reset shortly after
332316 browserWindow . ready ( ) . then ( readyWindow => {
333317 readyWindow . send ( 'vscode:openFiles' , files ) ;
@@ -418,7 +402,6 @@ export class WindowsManager implements IWindowsMainService {
418402
419403 pathsToOpen . forEach ( iPath => {
420404 if ( iPath . filePath || iPath . workspacePath ) {
421- app . addRecentDocument ( iPath . filePath || iPath . workspacePath ) ;
422405 recentPaths . push ( { path : iPath . filePath || iPath . workspacePath , isFile : ! ! iPath . filePath } ) ;
423406 }
424407 } ) ;
@@ -576,6 +559,32 @@ export class WindowsManager implements IWindowsMainService {
576559 return null ;
577560 }
578561
562+ private shouldOpenNewWindow ( openConfig : IOpenConfiguration ) : { openFolderInNewWindow : boolean ; openFilesInNewWindow : boolean ; } {
563+
564+ // let the user settings override how folders are open in a new window or same window unless we are forced
565+ const windowConfig = this . configurationService . getConfiguration < IWindowSettings > ( 'window' ) ;
566+ let openFolderInNewWindow = ( openConfig . preferNewWindow || openConfig . forceNewWindow ) && ! openConfig . forceReuseWindow ;
567+ if ( ! openConfig . forceNewWindow && ! openConfig . forceReuseWindow && windowConfig && ( windowConfig . openFoldersInNewWindow === 'on' || windowConfig . openFoldersInNewWindow === 'off' ) ) {
568+ openFolderInNewWindow = ( windowConfig . openFoldersInNewWindow === 'on' ) ;
569+ }
570+
571+ // let the user settings override how files are open in a new window or same window unless we are forced (not for extension development though)
572+ let openFilesInNewWindow : boolean ;
573+ if ( openConfig . forceNewWindow || openConfig . forceReuseWindow ) {
574+ openFilesInNewWindow = openConfig . forceNewWindow && ! openConfig . forceReuseWindow ;
575+ } else {
576+ if ( openConfig . context === OpenContext . DOCK ) {
577+ openFilesInNewWindow = true ; // only on macOS do we allow to open files in a new window if this is triggered via DOCK context
578+ }
579+
580+ if ( ! openConfig . cli . extensionDevelopmentPath && windowConfig && ( windowConfig . openFilesInNewWindow === 'on' || windowConfig . openFilesInNewWindow === 'off' ) ) {
581+ openFilesInNewWindow = ( windowConfig . openFilesInNewWindow === 'on' ) ;
582+ }
583+ }
584+
585+ return { openFolderInNewWindow, openFilesInNewWindow } ;
586+ }
587+
579588 public openExtensionDevelopmentHostWindow ( openConfig : IOpenConfiguration ) : void {
580589
581590 // Reload an existing extension development host window on the same path
0 commit comments