@@ -25,14 +25,14 @@ import product from 'vs/platform/product/node/product';
2525import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
2626import { IWindowsMainService , IOpenConfiguration , IWindowsCountChangedEvent , ICodeWindow , IWindowState as ISingleWindowState , WindowMode } from 'vs/platform/windows/electron-main/windows' ;
2727import { IHistoryMainService } from 'vs/platform/history/common/history' ;
28- import { IProcessEnvironment , isLinux , isMacintosh , isWindows } from 'vs/base/common/platform' ;
28+ import { IProcessEnvironment , isMacintosh , isWindows } from 'vs/base/common/platform' ;
2929import { IWorkspacesMainService , IWorkspaceIdentifier , WORKSPACE_FILTER , ISingleFolderWorkspaceIdentifier , isSingleFolderWorkspaceIdentifier , hasWorkspaceFileExtension } from 'vs/platform/workspaces/common/workspaces' ;
3030import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
3131import { mnemonicButtonLabel } from 'vs/base/common/labels' ;
3232import { Schemas } from 'vs/base/common/network' ;
3333import { normalizeNFC } from 'vs/base/common/normalization' ;
3434import { URI } from 'vs/base/common/uri' ;
35- import { Queue , timeout } from 'vs/base/common/async' ;
35+ import { Queue } from 'vs/base/common/async' ;
3636import { exists } from 'vs/base/node/pfs' ;
3737import { getComparisonKey , isEqual , normalizePath , basename as resourcesBasename , originalFSPath , hasTrailingPathSeparator , removeTrailingPathSeparator } from 'vs/base/common/resources' ;
3838import { getRemoteAuthority } from 'vs/platform/remote/common/remoteHosts' ;
@@ -197,7 +197,7 @@ export class WindowsManager implements IWindowsMainService {
197197 }
198198
199199 this . dialogs = new Dialogs ( environmentService , telemetryService , stateService , this ) ;
200- this . workspacesManager = new WorkspacesManager ( workspacesMainService , backupMainService , environmentService , historyMainService , this ) ;
200+ this . workspacesManager = new WorkspacesManager ( workspacesMainService , backupMainService , this ) ;
201201 }
202202
203203 ready ( initialUserEnv : IProcessEnvironment ) : void {
@@ -1544,23 +1544,6 @@ export class WindowsManager implements IWindowsMainService {
15441544 this . workspacesMainService . deleteUntitledWorkspaceSync ( workspace ) ;
15451545 return ;
15461546 }
1547-
1548- if ( windowClosing && ! isMacintosh && this . getWindowCount ( ) === 1 ) {
1549- return ; // Windows/Linux: quits when last window is closed, so do not ask then
1550- }
1551-
1552- // Handle untitled workspaces with prompt as needed
1553- e . veto ( this . workspacesManager . promptToSaveUntitledWorkspace ( this . getWindowById ( e . window . id ) , workspace ) . then ( ( veto ) : boolean | Promise < boolean > => {
1554- if ( veto ) {
1555- return veto ;
1556- }
1557-
1558- // Bug in electron: somehow we need this timeout so that the window closes properly. That
1559- // might be related to the fact that the untitled workspace prompt shows up async and this
1560- // code can execute before the dialog is fully closed which then blocks the window from closing.
1561- // Issue: https://github.com/Microsoft/vscode/issues/41989
1562- return timeout ( 0 ) . then ( ( ) => veto ) ;
1563- } ) ) ;
15641547 }
15651548
15661549 focusLastActive ( cli : ParsedArgs , context : OpenContext ) : ICodeWindow {
@@ -1994,8 +1977,6 @@ class WorkspacesManager {
19941977 constructor (
19951978 private readonly workspacesMainService : IWorkspacesMainService ,
19961979 private readonly backupMainService : IBackupMainService ,
1997- private readonly environmentService : IEnvironmentService ,
1998- private readonly historyMainService : IHistoryMainService ,
19991980 private readonly windowsMainService : IWindowsMainService ,
20001981 ) { }
20011982
@@ -2079,92 +2060,4 @@ class WorkspacesManager {
20792060 telemetryExtraData : options . telemetryExtraData
20802061 } ) ;
20812062 }
2082-
2083- promptToSaveUntitledWorkspace ( window : ICodeWindow | undefined , workspace : IWorkspaceIdentifier ) : Promise < boolean > {
2084- enum ConfirmResult {
2085- SAVE ,
2086- DONT_SAVE ,
2087- CANCEL
2088- }
2089-
2090- const save = { label : mnemonicButtonLabel ( localize ( { key : 'save' , comment : [ '&& denotes a mnemonic' ] } , "&&Save" ) ) , result : ConfirmResult . SAVE } ;
2091- const dontSave = { label : mnemonicButtonLabel ( localize ( { key : 'doNotSave' , comment : [ '&& denotes a mnemonic' ] } , "Do&&n't Save" ) ) , result : ConfirmResult . DONT_SAVE } ;
2092- const cancel = { label : localize ( 'cancel' , "Cancel" ) , result : ConfirmResult . CANCEL } ;
2093-
2094- const buttons : { label : string ; result : ConfirmResult ; } [ ] = [ ] ;
2095- if ( isWindows ) {
2096- buttons . push ( save , dontSave , cancel ) ;
2097- } else if ( isLinux ) {
2098- buttons . push ( dontSave , cancel , save ) ;
2099- } else {
2100- buttons . push ( save , cancel , dontSave ) ;
2101- }
2102-
2103- const options : Electron . MessageBoxOptions = {
2104- title : this . environmentService . appNameLong ,
2105- message : localize ( 'saveWorkspaceMessage' , "Do you want to save your workspace configuration as a file?" ) ,
2106- detail : localize ( 'saveWorkspaceDetail' , "Save your workspace if you plan to open it again." ) ,
2107- noLink : true ,
2108- type : 'warning' ,
2109- buttons : buttons . map ( button => button . label ) ,
2110- cancelId : buttons . indexOf ( cancel )
2111- } ;
2112-
2113- if ( isLinux ) {
2114- options . defaultId = 2 ;
2115- }
2116-
2117- return this . windowsMainService . showMessageBox ( options , window ) . then ( res => {
2118- switch ( buttons [ res . button ] . result ) {
2119-
2120- // Cancel: veto unload
2121- case ConfirmResult . CANCEL :
2122- return true ;
2123-
2124- // Don't Save: delete workspace
2125- case ConfirmResult . DONT_SAVE :
2126- this . workspacesMainService . deleteUntitledWorkspaceSync ( workspace ) ;
2127- return false ;
2128-
2129- // Save: save workspace, but do not veto unload
2130- case ConfirmResult . SAVE : {
2131- return this . windowsMainService . showSaveDialog ( {
2132- buttonLabel : mnemonicButtonLabel ( localize ( { key : 'save' , comment : [ '&& denotes a mnemonic' ] } , "&&Save" ) ) ,
2133- title : localize ( 'saveWorkspace' , "Save Workspace" ) ,
2134- filters : WORKSPACE_FILTER ,
2135- defaultPath : this . getUntitledWorkspaceSaveDialogDefaultPath ( workspace )
2136- } , window ) . then ( target => {
2137- if ( target ) {
2138- return this . workspacesMainService . saveWorkspaceAs ( workspace , target ) . then ( savedWorkspace => {
2139- this . historyMainService . addRecentlyOpened ( [ savedWorkspace ] , [ ] ) ;
2140- this . workspacesMainService . deleteUntitledWorkspaceSync ( workspace ) ;
2141- return false ;
2142- } , ( ) => false ) ;
2143- }
2144-
2145- return true ; // keep veto if no target was provided
2146- } ) ;
2147- }
2148- }
2149- } ) ;
2150- }
2151-
2152- private getUntitledWorkspaceSaveDialogDefaultPath ( workspace ?: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier ) : string | undefined {
2153- if ( workspace ) {
2154- if ( isSingleFolderWorkspaceIdentifier ( workspace ) ) {
2155- return workspace . scheme === Schemas . file ? dirname ( workspace . fsPath ) : undefined ;
2156- }
2157-
2158- const resolvedWorkspace = workspace . configPath . scheme === Schemas . file && this . workspacesMainService . resolveLocalWorkspaceSync ( workspace . configPath ) ;
2159- if ( resolvedWorkspace && resolvedWorkspace . folders . length > 0 ) {
2160- for ( const folder of resolvedWorkspace . folders ) {
2161- if ( folder . uri . scheme === Schemas . file ) {
2162- return dirname ( folder . uri . fsPath ) ;
2163- }
2164- }
2165- }
2166- }
2167-
2168- return undefined ;
2169- }
21702063}
0 commit comments