@@ -199,18 +199,21 @@ export class UserDataProfileImportExportService extends Disposable implements IU
199199 disposables . add ( toDisposable ( ( ) => this . isProfileImportInProgressContextKey . set ( false ) ) ) ;
200200
201201 try {
202+ const mode = options ?. mode ?? 'preview' ;
202203 const profileTemplate = await this . progressService . withProgress ( {
203204 location : ProgressLocation . Window ,
204205 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" ) ) ,
206207 } , ( ) => this . resolveProfileTemplate ( uri ) ) ;
207208 if ( ! profileTemplate ) {
208209 return ;
209210 }
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 ) ;
214217 }
215218 } finally {
216219 disposables . dispose ( ) ;
@@ -246,11 +249,11 @@ export class UserDataProfileImportExportService extends Disposable implements IU
246249 }
247250 }
248251
249- async createFromCurrentProfile ( name : string ) : Promise < void > {
252+ async SaveCurrentProfileAs ( name : string ) : Promise < void > {
250253 const userDataProfilesExportState = this . instantiationService . createInstance ( UserDataProfileExportState , this . userDataProfileService . currentProfile ) ;
251254 try {
252255 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" ) ) ;
254257 } finally {
255258 userDataProfilesExportState . dispose ( ) ;
256259 }
@@ -266,7 +269,7 @@ export class UserDataProfileImportExportService extends Disposable implements IU
266269 sticky : true ,
267270 } , async progress => {
268271 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 ) ;
270273 if ( profile ) {
271274 reportProgress ( localize ( 'progress extensions' , "Applying Extensions..." ) ) ;
272275 await this . instantiationService . createInstance ( ExtensionsResource ) . copy ( this . userDataProfileService . currentProfile , profile , true ) ;
@@ -359,21 +362,21 @@ export class UserDataProfileImportExportService extends Disposable implements IU
359362 return profileTemplate ;
360363 }
361364
362- private async previewProfile ( uri : URI , profileTemplate : IUserDataProfileTemplate ) : Promise < void > {
365+ private async importAndPreviewProfile ( uri : URI , profileTemplate : IUserDataProfileTemplate ) : Promise < void > {
363366 const disposables = new DisposableStore ( ) ;
364367
365368 try {
366369 const userDataProfileImportState = disposables . add ( this . instantiationService . createInstance ( UserDataProfileImportState , profileTemplate ) ) ;
367370 profileTemplate = await userDataProfileImportState . getProfileTemplateToImport ( ) ;
368371
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" ) ) ;
370373
371374 if ( ! importedProfile ) {
372375 return ;
373376 }
374377
375378 const barrier = new Barrier ( ) ;
376- const importAction = this . getImportAction ( barrier , userDataProfileImportState ) ;
379+ const importAction = this . getCreateAction ( barrier , userDataProfileImportState ) ;
377380 const primaryAction = isWeb
378381 ? new Action ( 'importInDesktop' , localize ( 'import in desktop' , "Create Profile in {0}" , this . productService . nameLong ) , undefined , true , async ( ) => this . openerService . open ( uri , { openExternal : true } ) )
379382 : importAction ;
@@ -432,69 +435,52 @@ export class UserDataProfileImportExportService extends Disposable implements IU
432435 }
433436 }
434437
435- private async doImportProfile ( profileTemplate : IUserDataProfileTemplate ) : Promise < void > {
438+ private async previewProfile ( profileTemplate : IUserDataProfileTemplate ) : Promise < void > {
436439 const disposables = new DisposableStore ( ) ;
437440 try {
438441 const userDataProfileImportState = disposables . add ( this . instantiationService . createInstance ( UserDataProfileImportState , profileTemplate ) ) ;
439- const barrier = new Barrier ( ) ;
440- const importAction = this . getImportAction ( barrier , userDataProfileImportState ) ;
441442 if ( userDataProfileImportState . isEmpty ( ) ) {
442- await importAction . run ( ) ;
443+ await this . createAndSwitch ( profileTemplate , false , true , localize ( 'create profile' , "Create Profile" ) ) ;
443444 } else {
445+ const barrier = new Barrier ( ) ;
446+ const importAction = this . getCreateAction ( barrier , userDataProfileImportState ) ;
444447 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 ) ;
445450 }
446- await barrier . wait ( ) ;
447- await this . hideProfilePreviewView ( IMPORT_PROFILE_PREVIEW_VIEW ) ;
448451 } finally {
449452 disposables . dispose ( ) ;
450453 }
451454 }
452455
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" ) ) ;
471461 } ) , this . notificationService ) ;
472462 return importAction ;
473463 }
474464
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 > {
476466 return this . progressService . withProgress ( {
477- location : ProgressLocation . Window ,
478- command : showWindowLogActionId ,
467+ location : ProgressLocation . Notification ,
468+ delay : 500 ,
469+ sticky : true ,
479470 } , 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 ;
482480 } ) ;
483481 }
484482
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 > {
498484 const profile = await this . getProfileToImport ( profileTemplate , temporaryProfile ) ;
499485 if ( ! profile ) {
500486 return undefined ;
0 commit comments