@@ -15,7 +15,7 @@ import { IUserDataProfile, IUserDataProfilesService, ProfileResourceType, UseDef
1515import { IWorkbenchContribution } from 'vs/workbench/common/contributions' ;
1616import { ILifecycleService , LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle' ;
1717import { CURRENT_PROFILE_CONTEXT , HAS_PROFILES_CONTEXT , IS_CURRENT_PROFILE_TRANSIENT_CONTEXT , IS_PROFILE_IMPORT_IN_PROGRESS_CONTEXT , IUserDataProfileImportExportService , IUserDataProfileManagementService , IUserDataProfileService , PROFILES_CATEGORY , PROFILE_FILTER , IS_PROFILE_EXPORT_IN_PROGRESS_CONTEXT , ProfilesMenu , PROFILES_ENABLEMENT_CONTEXT , PROFILES_TITLE } from 'vs/workbench/services/userDataProfile/common/userDataProfile' ;
18- import { IQuickInputService , IQuickPickItem } from 'vs/platform/quickinput/common/quickInput' ;
18+ import { IQuickInputService , IQuickPickItem , IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput' ;
1919import { INotificationService } from 'vs/platform/notification/common/notification' ;
2020import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs' ;
2121import { URI } from 'vs/base/common/uri' ;
@@ -42,6 +42,8 @@ interface IProfileTemplateInfo {
4242 readonly url : string ;
4343}
4444
45+ type IProfileTemplateQuickPickItem = IQuickPickItem & IProfileTemplateInfo ;
46+
4547export class UserDataProfilesWorkbenchContribution extends Disposable implements IWorkbenchContribution {
4648
4749 private readonly currentProfileContext : IContextKey < string > ;
@@ -308,6 +310,7 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
308310 private registerImportProfileAction ( ) : IDisposable {
309311 const disposables = new DisposableStore ( ) ;
310312 const id = 'workbench.profiles.actions.importProfile' ;
313+ const that = this ;
311314 disposables . add ( registerAction2 ( class ImportProfileAction extends Action2 {
312315 constructor ( ) {
313316 super ( {
@@ -340,21 +343,41 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
340343
341344 const disposables = new DisposableStore ( ) ;
342345 const quickPick = disposables . add ( quickInputService . createQuickPick ( ) ) ;
346+ const profileTemplateQuickPickItems = await that . getProfileTemplatesQuickPickItems ( ) ;
347+
343348 const updateQuickPickItems = ( value ?: string ) => {
344- const selectFromFileItem : IQuickPickItem = { label : localize ( 'import from file' , "Create from profile template file" ) } ;
345- quickPick . items = value ? [ { label : localize ( 'import from url' , "Create from profile template URL" ) , description : quickPick . value } , selectFromFileItem ] : [ selectFromFileItem ] ;
349+ const quickPickItems : ( IQuickPickItem | IQuickPickSeparator ) [ ] = [ ] ;
350+ if ( value ) {
351+ quickPickItems . push ( { label : quickPick . value , description : localize ( 'import from url' , "Import from URL" ) } ) ;
352+ }
353+ quickPickItems . push ( { label : localize ( 'import from file' , "Select File..." ) } ) ;
354+ if ( profileTemplateQuickPickItems . length ) {
355+ quickPickItems . push ( {
356+ type : 'separator' ,
357+ label : localize ( 'templates' , "Profile Templates" )
358+ } , ...profileTemplateQuickPickItems ) ;
359+ }
360+ quickPick . items = quickPickItems ;
346361 } ;
347- quickPick . title = localize ( 'import profile quick pick title' , "Create Profile from Profile Template..." ) ;
348- quickPick . placeholder = localize ( 'import profile placeholder' , "Provide profile template URL or select profile template file" ) ;
362+
363+ quickPick . title = localize ( 'import profile quick pick title' , "Import from Profile Template..." ) ;
364+ quickPick . placeholder = localize ( 'import profile placeholder' , "Provide Profile Template URL" ) ;
349365 quickPick . ignoreFocusOut = true ;
350366 disposables . add ( quickPick . onDidChangeValue ( updateQuickPickItems ) ) ;
351367 updateQuickPickItems ( ) ;
352368 quickPick . matchOnLabel = false ;
353369 quickPick . matchOnDescription = false ;
354370 disposables . add ( quickPick . onDidAccept ( async ( ) => {
371+ quickPick . hide ( ) ;
372+ const selectedItem = quickPick . selectedItems [ 0 ] ;
373+ if ( ! selectedItem ) {
374+ return ;
375+ }
355376 try {
356- quickPick . hide ( ) ;
357- const profile = quickPick . selectedItems [ 0 ] . description ? URI . parse ( quickPick . value ) : await this . getProfileUriFromFileSystem ( fileDialogService ) ;
377+ if ( ( < IProfileTemplateQuickPickItem > selectedItem ) . url ) {
378+ return await that . saveProfile ( undefined , ( < IProfileTemplateQuickPickItem > selectedItem ) . url ) ;
379+ }
380+ const profile = selectedItem . label === quickPick . value ? URI . parse ( quickPick . value ) : await this . getProfileUriFromFileSystem ( fileDialogService ) ;
358381 if ( profile ) {
359382 await userDataProfileImportExportService . importProfile ( profile ) ;
360383 }
@@ -541,18 +564,18 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
541564 selectBox . render ( append ( domNode , $ ( '.profile-type-select-container' ) ) ) ;
542565 quickPick . widget = domNode ;
543566
544- const updateOptions = ( ) => {
567+ const updateQuickpickInfo = ( ) => {
545568 const option = profileOptions [ findOptionIndex ( ) ] ;
546569 for ( const resource of resources ) {
547570 resource . picked = option . source && ! isString ( option . source ) ? ! option . source ?. useDefaultFlags ?. [ resource . id ] : true ;
548571 }
549572 update ( ) ;
550573 } ;
551574
552- updateOptions ( ) ;
575+ updateQuickpickInfo ( ) ;
553576 disposables . add ( selectBox . onDidSelect ( ( { index } ) => {
554577 source = profileOptions [ index ] . source ;
555- updateOptions ( ) ;
578+ updateQuickpickInfo ( ) ;
556579 } ) ) ;
557580 }
558581
@@ -701,6 +724,18 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
701724 } ) ) ;
702725 }
703726
727+ private async getProfileTemplatesQuickPickItems ( ) : Promise < IProfileTemplateQuickPickItem [ ] > {
728+ const quickPickItems : IProfileTemplateQuickPickItem [ ] = [ ] ;
729+ const profileTemplates = await this . getProfileTemplatesFromProduct ( ) ;
730+ for ( const template of profileTemplates ) {
731+ quickPickItems . push ( {
732+ label : template . name ,
733+ ...template
734+ } ) ;
735+ }
736+ return quickPickItems ;
737+ }
738+
704739 private async getProfileTemplatesFromProduct ( ) : Promise < IProfileTemplateInfo [ ] > {
705740 if ( this . productService . profileTemplatesUrl ) {
706741 try {
0 commit comments