@@ -18,7 +18,7 @@ import { IPathWithLineAndColumn, parseLineAndColumnAware } from 'vs/code/node/pa
1818import { ILifecycleService , UnloadReason , IWindowUnloadEvent , LifecycleService } from 'vs/platform/lifecycle/electron-main/lifecycleMain' ;
1919import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
2020import { ILogService } from 'vs/platform/log/common/log' ;
21- import { IWindowSettings , OpenContext , IPath , IWindowConfiguration , INativeOpenDialogOptions , IPathsToWaitFor , IEnterWorkspaceResult , IMessageBoxResult , INewWindowOptions } from 'vs/platform/windows/common/windows' ;
21+ import { IWindowSettings , OpenContext , IPath , IWindowConfiguration , INativeOpenDialogOptions , IPathsToWaitFor , IEnterWorkspaceResult , IMessageBoxResult , INewWindowOptions , OpenDialogOptions } from 'vs/platform/windows/common/windows' ;
2222import { getLastActiveWindow , findBestWindowOrFolderForFile , findWindowOnWorkspace , findWindowOnExtensionDevelopmentPath , findWindowOnWorkspaceOrFolderUri } from 'vs/code/node/windowsFinder' ;
2323import { Event as CommonEvent , Emitter } from 'vs/base/common/event' ;
2424import product from 'vs/platform/node/product' ;
@@ -50,7 +50,7 @@ interface INewWindowState extends ISingleWindowState {
5050interface IWindowState {
5151 workspace ?: IWorkspaceIdentifier ;
5252 folderUri ?: URI ;
53- backupPath : string ;
53+ backupPath ? : string ;
5454 remoteAuthority ?: string ;
5555 uiState : ISingleWindowState ;
5656}
@@ -131,7 +131,7 @@ export class WindowsManager implements IWindowsMainService {
131131 private initialUserEnv : IProcessEnvironment ;
132132
133133 private windowsState : IWindowsState ;
134- private lastClosedWindowState : IWindowState ;
134+ private lastClosedWindowState ? : IWindowState ;
135135
136136 private dialogs : Dialogs ;
137137 private workspacesManager : WorkspacesManager ;
@@ -188,8 +188,9 @@ export class WindowsManager implements IWindowsMainService {
188188 if ( windowState . folderUri ) {
189189 windowState . folderUri = URI . revive ( windowState . folderUri ) ;
190190 }
191- if ( ( < IBackwardCompatibleWindowState > windowState ) . folderPath ) {
192- windowState . folderUri = URI . file ( ( < IBackwardCompatibleWindowState > windowState ) . folderPath ) ;
191+ const folderPath = ( windowState as IBackwardCompatibleWindowState ) . folderPath ;
192+ if ( folderPath ) {
193+ windowState . folderUri = URI . file ( folderPath ) ;
193194 }
194195 return windowState ;
195196 }
@@ -403,12 +404,12 @@ export class WindowsManager implements IWindowsMainService {
403404 //
404405 // These are windows to open to show workspaces
405406 //
406- const workspacesToOpen = arrays . distinct ( pathsToOpen . filter ( win => ! ! win . workspace ) . map ( win => win . workspace ) , workspace => workspace . id ) ; // prevent duplicates
407+ const workspacesToOpen = arrays . distinct ( arrays . coalesce ( pathsToOpen . map ( win => win . workspace ) ) , workspace => workspace . id ) ; // prevent duplicates
407408
408409 //
409410 // These are windows to open to show either folders or files (including diffing files or creating them)
410411 //
411- const foldersToOpen = arrays . distinct ( pathsToOpen . filter ( win => win . folderUri && ! win . fileUri ) . map ( win => win . folderUri ) , folder => getComparisonKey ( folder ) ) ; // prevent duplicates
412+ const foldersToOpen = arrays . distinct ( arrays . coalesce ( pathsToOpen . filter ( win => win . folderUri && ! win . fileUri ) . map ( win => win . folderUri ) ) , folder => getComparisonKey ( folder ) ) ; // prevent duplicates
412413
413414 //
414415 // These are windows to restore because of hot-exit or from previous session (only performed once on startup!)
@@ -423,7 +424,7 @@ export class WindowsManager implements IWindowsMainService {
423424 workspacesToRestore . push ( ...this . workspacesMainService . getUntitledWorkspacesSync ( ) ) ; // collect from previous window session
424425
425426 emptyToRestore = this . backupMainService . getEmptyWindowBackupPaths ( ) ;
426- emptyToRestore . push ( ...pathsToOpen . filter ( w => ! w . workspace && ! w . folderUri && w . backupPath ) . map ( w => ( { backupFolder : basename ( w . backupPath ) , remoteAuthority : w . remoteAuthority } ) ) ) ; // add empty windows with backupPath
427+ emptyToRestore . push ( ...pathsToOpen . filter ( w => ! w . workspace && ! w . folderUri && w . backupPath ) . map ( w => ( { backupFolder : basename ( w . backupPath ! ) , remoteAuthority : w . remoteAuthority } ) ) ) ; // add empty windows with backupPath
427428 emptyToRestore = arrays . distinct ( emptyToRestore , info => info . backupFolder ) ; // prevent duplicates
428429 }
429430
@@ -444,9 +445,9 @@ export class WindowsManager implements IWindowsMainService {
444445
445446 // 1.) focus last active window if we are not instructed to open any paths
446447 if ( focusLastActive ) {
447- const lastActiveWindw = usedWindows . filter ( w => w . backupPath === this . windowsState . lastActiveWindow . backupPath ) ;
448- if ( lastActiveWindw . length ) {
449- lastActiveWindw [ 0 ] . focus ( ) ;
448+ const lastActiveWindow = usedWindows . filter ( w => w . backupPath === this . windowsState . lastActiveWindow ! . backupPath ) ;
449+ if ( lastActiveWindow . length ) {
450+ lastActiveWindow [ 0 ] . focus ( ) ;
450451 focusLastOpened = false ;
451452 focusLastWindow = false ;
452453 }
@@ -1593,7 +1594,7 @@ export class WindowsManager implements IWindowsMainService {
15931594 } ) ;
15941595 }
15951596
1596- getFocusedWindow ( ) : ICodeWindow {
1597+ getFocusedWindow ( ) : ICodeWindow | null {
15971598 const win = BrowserWindow . getFocusedWindow ( ) ;
15981599 if ( win ) {
15991600 return this . getWindowById ( win . id ) ;
@@ -1602,7 +1603,7 @@ export class WindowsManager implements IWindowsMainService {
16021603 return null ;
16031604 }
16041605
1605- getWindowById ( windowId : number ) : ICodeWindow {
1606+ getWindowById ( windowId : number ) : ICodeWindow | null {
16061607 const res = WindowsManager . WINDOWS . filter ( w => w . id === windowId ) ;
16071608 if ( res && res . length === 1 ) {
16081609 return res [ 0 ] ;
@@ -1719,9 +1720,8 @@ export class WindowsManager implements IWindowsMainService {
17191720 internalOptions . pickFolders = pickFolders ;
17201721 internalOptions . pickFiles = pickFiles ;
17211722
1722- if ( ! internalOptions . dialogOptions ) {
1723- internalOptions . dialogOptions = Object . create ( null ) ;
1724- }
1723+ const dialogOptions : OpenDialogOptions = internalOptions . dialogOptions || Object . create ( null ) ;
1724+ internalOptions . dialogOptions = dialogOptions ;
17251725
17261726 if ( ! internalOptions . dialogOptions . title ) {
17271727 if ( pickFolders && pickFiles ) {
@@ -1952,13 +1952,12 @@ class Dialogs {
19521952class WorkspacesManager {
19531953
19541954 constructor (
1955- private workspacesMainService : IWorkspacesMainService ,
1956- private backupMainService : IBackupMainService ,
1957- private environmentService : IEnvironmentService ,
1958- private historyMainService : IHistoryMainService ,
1959- private windowsMainService : IWindowsMainService ,
1960- ) {
1961- }
1955+ private readonly workspacesMainService : IWorkspacesMainService ,
1956+ private readonly backupMainService : IBackupMainService ,
1957+ private readonly environmentService : IEnvironmentService ,
1958+ private readonly historyMainService : IHistoryMainService ,
1959+ private readonly windowsMainService : IWindowsMainService ,
1960+ ) { }
19621961
19631962 enterWorkspace ( window : ICodeWindow , path : URI ) : Promise < IEnterWorkspaceResult | null > {
19641963 if ( ! window || ! window . win || ! window . isReady ) {
0 commit comments