@@ -199,18 +199,21 @@ export class UserDataProfileImportExportService extends Disposable implements IU
199
199
disposables . add ( toDisposable ( ( ) => this . isProfileImportInProgressContextKey . set ( false ) ) ) ;
200
200
201
201
try {
202
+ const mode = options ?. mode ?? 'preview' ;
202
203
const profileTemplate = await this . progressService . withProgress ( {
203
204
location : ProgressLocation . Window ,
204
205
command : showWindowLogActionId ,
205
- title : localize ( 'resolving uri' , "{0}: Resolving profile content..." , options ?. preview ? localize ( 'preview profile' , "Preview Profile" ) : localize ( 'import profile' , "Create Profile" ) ) ,
206
+ title : localize ( 'resolving uri' , "{0}: Resolving profile content..." , options ?. mode ? localize ( 'preview profile' , "Preview Profile" ) : localize ( 'import profile' , "Create Profile" ) ) ,
206
207
} , ( ) => this . resolveProfileTemplate ( uri ) ) ;
207
208
if ( ! profileTemplate ) {
208
209
return ;
209
210
}
210
- if ( options ?. preview ) {
211
- await this . previewProfile ( uri , profileTemplate ) ;
212
- } else {
213
- await this . doImportProfile ( profileTemplate ) ;
211
+ if ( mode === 'preview' ) {
212
+ await this . previewProfile ( profileTemplate ) ;
213
+ } else if ( mode === 'apply' ) {
214
+ await this . createAndSwitch ( profileTemplate , false , true , localize ( 'create profile' , "Create Profile" ) ) ;
215
+ } else if ( mode === 'both' ) {
216
+ await this . importAndPreviewProfile ( uri , profileTemplate ) ;
214
217
}
215
218
} finally {
216
219
disposables . dispose ( ) ;
@@ -246,11 +249,11 @@ export class UserDataProfileImportExportService extends Disposable implements IU
246
249
}
247
250
}
248
251
249
- async createFromCurrentProfile ( name : string ) : Promise < void > {
252
+ async SaveCurrentProfileAs ( name : string ) : Promise < void > {
250
253
const userDataProfilesExportState = this . instantiationService . createInstance ( UserDataProfileExportState , this . userDataProfileService . currentProfile ) ;
251
254
try {
252
255
const profileTemplate = await userDataProfilesExportState . getProfileTemplate ( name , undefined ) ;
253
- await this . doImportProfile ( profileTemplate ) ;
256
+ await this . createAndSwitch ( profileTemplate , false , true , localize ( 'save profile as' , "Save Profile As" ) ) ;
254
257
} finally {
255
258
userDataProfilesExportState . dispose ( ) ;
256
259
}
@@ -266,7 +269,7 @@ export class UserDataProfileImportExportService extends Disposable implements IU
266
269
sticky : true ,
267
270
} , async progress => {
268
271
const reportProgress = ( message : string ) => progress . report ( { message : localize ( 'troubleshoot profile progress' , "Setting up Troubleshoot Profile: {0}" , message ) } ) ;
269
- const profile = await this . importWithProgress ( profileTemplate , true , false , reportProgress ) ;
272
+ const profile = await this . createProfile ( profileTemplate , true , false , reportProgress ) ;
270
273
if ( profile ) {
271
274
reportProgress ( localize ( 'progress extensions' , "Applying Extensions..." ) ) ;
272
275
await this . instantiationService . createInstance ( ExtensionsResource ) . copy ( this . userDataProfileService . currentProfile , profile , true ) ;
@@ -359,21 +362,21 @@ export class UserDataProfileImportExportService extends Disposable implements IU
359
362
return profileTemplate ;
360
363
}
361
364
362
- private async previewProfile ( uri : URI , profileTemplate : IUserDataProfileTemplate ) : Promise < void > {
365
+ private async importAndPreviewProfile ( uri : URI , profileTemplate : IUserDataProfileTemplate ) : Promise < void > {
363
366
const disposables = new DisposableStore ( ) ;
364
367
365
368
try {
366
369
const userDataProfileImportState = disposables . add ( this . instantiationService . createInstance ( UserDataProfileImportState , profileTemplate ) ) ;
367
370
profileTemplate = await userDataProfileImportState . getProfileTemplateToImport ( ) ;
368
371
369
- const importedProfile = await this . importAndSwitch ( profileTemplate , true , false , localize ( 'preview profile' , "Preview Profile" ) ) ;
372
+ const importedProfile = await this . createAndSwitch ( profileTemplate , true , false , localize ( 'preview profile' , "Preview Profile" ) ) ;
370
373
371
374
if ( ! importedProfile ) {
372
375
return ;
373
376
}
374
377
375
378
const barrier = new Barrier ( ) ;
376
- const importAction = this . getImportAction ( barrier , userDataProfileImportState ) ;
379
+ const importAction = this . getCreateAction ( barrier , userDataProfileImportState ) ;
377
380
const primaryAction = isWeb
378
381
? new Action ( 'importInDesktop' , localize ( 'import in desktop' , "Create Profile in {0}" , this . productService . nameLong ) , undefined , true , async ( ) => this . openerService . open ( uri , { openExternal : true } ) )
379
382
: importAction ;
@@ -432,69 +435,52 @@ export class UserDataProfileImportExportService extends Disposable implements IU
432
435
}
433
436
}
434
437
435
- private async doImportProfile ( profileTemplate : IUserDataProfileTemplate ) : Promise < void > {
438
+ private async previewProfile ( profileTemplate : IUserDataProfileTemplate ) : Promise < void > {
436
439
const disposables = new DisposableStore ( ) ;
437
440
try {
438
441
const userDataProfileImportState = disposables . add ( this . instantiationService . createInstance ( UserDataProfileImportState , profileTemplate ) ) ;
439
- const barrier = new Barrier ( ) ;
440
- const importAction = this . getImportAction ( barrier , userDataProfileImportState ) ;
441
442
if ( userDataProfileImportState . isEmpty ( ) ) {
442
- await importAction . run ( ) ;
443
+ await this . createAndSwitch ( profileTemplate , false , true , localize ( 'create profile' , "Create Profile" ) ) ;
443
444
} else {
445
+ const barrier = new Barrier ( ) ;
446
+ const importAction = this . getCreateAction ( barrier , userDataProfileImportState ) ;
444
447
await this . showProfilePreviewView ( IMPORT_PROFILE_PREVIEW_VIEW , profileTemplate . name , importAction , new BarrierAction ( barrier , new Action ( 'cancel' , localize ( 'cancel' , "Cancel" ) ) , this . notificationService ) , false , userDataProfileImportState ) ;
448
+ await barrier . wait ( ) ;
449
+ await this . hideProfilePreviewView ( IMPORT_PROFILE_PREVIEW_VIEW ) ;
445
450
}
446
- await barrier . wait ( ) ;
447
- await this . hideProfilePreviewView ( IMPORT_PROFILE_PREVIEW_VIEW ) ;
448
451
} finally {
449
452
disposables . dispose ( ) ;
450
453
}
451
454
}
452
455
453
- private getImportAction ( barrier : Barrier , userDataProfileImportState : UserDataProfileImportState ) : IAction {
454
- const title = localize ( 'import' , "Create Profile" , userDataProfileImportState . profile . name ) ;
455
- const importAction = new BarrierAction ( barrier , new Action ( 'import' , title , undefined , true , ( ) => {
456
- const importProfileFn = async ( ) => {
457
- importAction . enabled = false ;
458
- const profileTemplate = await userDataProfileImportState . getProfileTemplateToImport ( ) ;
459
- const importedProfile = await this . importAndSwitch ( profileTemplate , false , true , title ) ;
460
- if ( ! importedProfile ) {
461
- return ;
462
- }
463
- } ;
464
- if ( userDataProfileImportState . isEmpty ( ) ) {
465
- return importProfileFn ( ) ;
466
- } else {
467
- return this . progressService . withProgress ( {
468
- location : IMPORT_PROFILE_PREVIEW_VIEW ,
469
- } , ( ) => importProfileFn ( ) ) ;
470
- }
456
+ private getCreateAction ( barrier : Barrier , userDataProfileImportState : UserDataProfileImportState ) : IAction {
457
+ const importAction = new BarrierAction ( barrier , new Action ( 'title' , localize ( 'import' , "Create Profile" ) , undefined , true , async ( ) => {
458
+ importAction . enabled = false ;
459
+ const profileTemplate = await userDataProfileImportState . getProfileTemplateToImport ( ) ;
460
+ return this . createAndSwitch ( profileTemplate , false , true , localize ( 'create profile' , "Create Profile" ) ) ;
471
461
} ) , this . notificationService ) ;
472
462
return importAction ;
473
463
}
474
464
475
- private async importAndSwitch ( profileTemplate : IUserDataProfileTemplate , temporaryProfile : boolean , extensions : boolean , title : string ) : Promise < IUserDataProfile | undefined > {
465
+ private async createAndSwitch ( profileTemplate : IUserDataProfileTemplate , temporaryProfile : boolean , extensions : boolean , title : string ) : Promise < IUserDataProfile | undefined > {
476
466
return this . progressService . withProgress ( {
477
- location : ProgressLocation . Window ,
478
- command : showWindowLogActionId ,
467
+ location : ProgressLocation . Notification ,
468
+ delay : 500 ,
469
+ sticky : true ,
479
470
} , async ( progress ) => {
480
- progress . report ( { message : localize ( 'Importing profile' , "{0} ({1})..." , title , profileTemplate . name ) } ) ;
481
- return this . importAndSwitchWithProgress ( profileTemplate , temporaryProfile , extensions , message => progress . report ( { message : `${ title } (${ profileTemplate . name } ): ${ message } ` } ) ) ;
471
+ title = `${ title } (${ profileTemplate . name } )` ;
472
+ progress . report ( { message : title } ) ;
473
+ const reportProgress = ( message : string ) => progress . report ( { message : `${ title } : ${ message } ` } ) ;
474
+ const profile = await this . createProfile ( profileTemplate , temporaryProfile , extensions , reportProgress ) ;
475
+ if ( profile ) {
476
+ reportProgress ( localize ( 'switching profile' , "Switching Profile..." ) ) ;
477
+ await this . userDataProfileManagementService . switchProfile ( profile ) ;
478
+ }
479
+ return profile ;
482
480
} ) ;
483
481
}
484
482
485
- private async importAndSwitchWithProgress ( profileTemplate : IUserDataProfileTemplate , temporaryProfile : boolean , extensions : boolean , progress : ( message : string ) => void ) : Promise < IUserDataProfile | undefined > {
486
- const profile = await this . importWithProgress ( profileTemplate , temporaryProfile , extensions , progress ) ;
487
-
488
- if ( ! profile ) {
489
- return ;
490
- }
491
-
492
- progress ( localize ( 'switching profile' , "Switching Profile..." ) ) ;
493
- await this . userDataProfileManagementService . switchProfile ( profile ) ;
494
- return profile ;
495
- }
496
-
497
- private async importWithProgress ( profileTemplate : IUserDataProfileTemplate , temporaryProfile : boolean , extensions : boolean , progress : ( message : string ) => void ) : Promise < IUserDataProfile | undefined > {
483
+ private async createProfile ( profileTemplate : IUserDataProfileTemplate , temporaryProfile : boolean , extensions : boolean , progress : ( message : string ) => void ) : Promise < IUserDataProfile | undefined > {
498
484
const profile = await this . getProfileToImport ( profileTemplate , temporaryProfile ) ;
499
485
if ( ! profile ) {
500
486
return undefined ;
0 commit comments