@@ -15,7 +15,7 @@ import { IUserDataProfile, IUserDataProfilesService, ProfileResourceType, UseDef
15
15
import { IWorkbenchContribution } from 'vs/workbench/common/contributions' ;
16
16
import { ILifecycleService , LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle' ;
17
17
import { 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' ;
19
19
import { INotificationService } from 'vs/platform/notification/common/notification' ;
20
20
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs' ;
21
21
import { URI } from 'vs/base/common/uri' ;
@@ -42,6 +42,8 @@ interface IProfileTemplateInfo {
42
42
readonly url : string ;
43
43
}
44
44
45
+ type IProfileTemplateQuickPickItem = IQuickPickItem & IProfileTemplateInfo ;
46
+
45
47
export class UserDataProfilesWorkbenchContribution extends Disposable implements IWorkbenchContribution {
46
48
47
49
private readonly currentProfileContext : IContextKey < string > ;
@@ -308,6 +310,7 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
308
310
private registerImportProfileAction ( ) : IDisposable {
309
311
const disposables = new DisposableStore ( ) ;
310
312
const id = 'workbench.profiles.actions.importProfile' ;
313
+ const that = this ;
311
314
disposables . add ( registerAction2 ( class ImportProfileAction extends Action2 {
312
315
constructor ( ) {
313
316
super ( {
@@ -340,21 +343,41 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
340
343
341
344
const disposables = new DisposableStore ( ) ;
342
345
const quickPick = disposables . add ( quickInputService . createQuickPick ( ) ) ;
346
+ const profileTemplateQuickPickItems = await that . getProfileTemplatesQuickPickItems ( ) ;
347
+
343
348
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 ;
346
361
} ;
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" ) ;
349
365
quickPick . ignoreFocusOut = true ;
350
366
disposables . add ( quickPick . onDidChangeValue ( updateQuickPickItems ) ) ;
351
367
updateQuickPickItems ( ) ;
352
368
quickPick . matchOnLabel = false ;
353
369
quickPick . matchOnDescription = false ;
354
370
disposables . add ( quickPick . onDidAccept ( async ( ) => {
371
+ quickPick . hide ( ) ;
372
+ const selectedItem = quickPick . selectedItems [ 0 ] ;
373
+ if ( ! selectedItem ) {
374
+ return ;
375
+ }
355
376
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 ) ;
358
381
if ( profile ) {
359
382
await userDataProfileImportExportService . importProfile ( profile ) ;
360
383
}
@@ -541,18 +564,18 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
541
564
selectBox . render ( append ( domNode , $ ( '.profile-type-select-container' ) ) ) ;
542
565
quickPick . widget = domNode ;
543
566
544
- const updateOptions = ( ) => {
567
+ const updateQuickpickInfo = ( ) => {
545
568
const option = profileOptions [ findOptionIndex ( ) ] ;
546
569
for ( const resource of resources ) {
547
570
resource . picked = option . source && ! isString ( option . source ) ? ! option . source ?. useDefaultFlags ?. [ resource . id ] : true ;
548
571
}
549
572
update ( ) ;
550
573
} ;
551
574
552
- updateOptions ( ) ;
575
+ updateQuickpickInfo ( ) ;
553
576
disposables . add ( selectBox . onDidSelect ( ( { index } ) => {
554
577
source = profileOptions [ index ] . source ;
555
- updateOptions ( ) ;
578
+ updateQuickpickInfo ( ) ;
556
579
} ) ) ;
557
580
}
558
581
@@ -701,6 +724,18 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
701
724
} ) ) ;
702
725
}
703
726
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
+
704
739
private async getProfileTemplatesFromProduct ( ) : Promise < IProfileTemplateInfo [ ] > {
705
740
if ( this . productService . profileTemplatesUrl ) {
706
741
try {
0 commit comments