@@ -19,18 +19,17 @@ import { workbenchConfigurationNodeBase } from 'vs/workbench/common/configuratio
19
19
import { IWorkbenchContribution } from 'vs/workbench/common/contributions' ;
20
20
import { RenameProfileAction } from 'vs/workbench/contrib/userDataProfile/browser/userDataProfileActions' ;
21
21
import { ILifecycleService , LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle' ;
22
- import { CURRENT_PROFILE_CONTEXT , HAS_PROFILES_CONTEXT , isUserDataProfileTemplate , IS_CURRENT_PROFILE_TRANSIENT_CONTEXT , IUserDataProfileImportExportService , IUserDataProfileManagementService , IUserDataProfileService , IUserDataProfileTemplate , ManageProfilesSubMenu , PROFILES_CATEGORY , PROFILES_ENABLEMENT_CONTEXT , PROFILES_TTILE , PROFILE_EXTENSION , PROFILE_FILTER } from 'vs/workbench/services/userDataProfile/common/userDataProfile' ;
22
+ import { CURRENT_PROFILE_CONTEXT , HAS_PROFILES_CONTEXT , isUserDataProfileTemplate , IS_CURRENT_PROFILE_TRANSIENT_CONTEXT , IS_PROFILE_IMPORT_EXPORT_IN_PROGRESS_CONTEXT , IUserDataProfileImportExportService , IUserDataProfileManagementService , IUserDataProfileService , IUserDataProfileTemplate , ManageProfilesSubMenu , PROFILES_CATEGORY , PROFILES_ENABLEMENT_CONTEXT , PROFILES_TTILE , PROFILE_FILTER } from 'vs/workbench/services/userDataProfile/common/userDataProfile' ;
23
23
import { IQuickInputService , IQuickPickItem } from 'vs/platform/quickinput/common/quickInput' ;
24
24
import { INotificationService } from 'vs/platform/notification/common/notification' ;
25
25
import { charCount } from 'vs/base/common/strings' ;
26
26
import { ThemeIcon } from 'vs/platform/theme/common/themeService' ;
27
- import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles' ;
28
27
import { IDialogService , IFileDialogService } from 'vs/platform/dialogs/common/dialogs' ;
29
- import { joinPath } from 'vs/base/common/resources' ;
30
28
import { Codicon } from 'vs/base/common/codicons' ;
31
29
import { IFileService } from 'vs/platform/files/common/files' ;
32
30
import { asJson , asText , IRequestService } from 'vs/platform/request/common/request' ;
33
31
import { CancellationToken } from 'vs/base/common/cancellation' ;
32
+ import { URI } from 'vs/base/common/uri' ;
34
33
35
34
export class UserDataProfilesWorkbenchContribution extends Disposable implements IWorkbenchContribution {
36
35
@@ -262,6 +261,7 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
262
261
original : `Export (${ that . userDataProfileService . currentProfile . name } )...`
263
262
} ,
264
263
category : PROFILES_CATEGORY ,
264
+ precondition : IS_PROFILE_IMPORT_EXPORT_IN_PROGRESS_CONTEXT . toNegated ( ) ,
265
265
menu : [
266
266
{
267
267
id : ManageProfilesSubMenu ,
@@ -276,25 +276,8 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
276
276
}
277
277
278
278
async run ( accessor : ServicesAccessor ) {
279
- const textFileService = accessor . get ( ITextFileService ) ;
280
- const fileDialogService = accessor . get ( IFileDialogService ) ;
281
279
const userDataProfileImportExportService = accessor . get ( IUserDataProfileImportExportService ) ;
282
- const notificationService = accessor . get ( INotificationService ) ;
283
-
284
- const profileLocation = await fileDialogService . showSaveDialog ( {
285
- title : localize ( 'export profile dialog' , "Save Profile" ) ,
286
- filters : PROFILE_FILTER ,
287
- defaultUri : joinPath ( await fileDialogService . defaultFilePath ( ) , `profile.${ PROFILE_EXTENSION } ` ) ,
288
- } ) ;
289
-
290
- if ( ! profileLocation ) {
291
- return ;
292
- }
293
-
294
- const profile = await userDataProfileImportExportService . exportProfile ( { skipComments : true } ) ;
295
- await textFileService . create ( [ { resource : profileLocation , value : JSON . stringify ( profile ) , options : { overwrite : true } } ] ) ;
296
-
297
- notificationService . info ( localize ( 'export success' , "{0}: Exported successfully." , PROFILES_CATEGORY . value ) ) ;
280
+ return userDataProfileImportExportService . exportProfile ( ) ;
298
281
}
299
282
} ) ) ;
300
283
disposables . add ( MenuRegistry . appendMenuItem ( MenuId . MenubarShare , {
@@ -323,6 +306,7 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
323
306
} ,
324
307
category : PROFILES_CATEGORY ,
325
308
f1 : true ,
309
+ precondition : IS_PROFILE_IMPORT_EXPORT_IN_PROGRESS_CONTEXT . toNegated ( ) ,
326
310
menu : [
327
311
{
328
312
id : ManageProfilesSubMenu ,
@@ -358,11 +342,11 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
358
342
const disposables = new DisposableStore ( ) ;
359
343
const quickPick = disposables . add ( quickInputService . createQuickPick ( ) ) ;
360
344
const updateQuickPickItems = ( value ?: string ) => {
361
- const selectFromFileItem : IQuickPickItem = { label : isSettingProfilesEnabled ? localize ( 'select from file' , "Select Profile template file" ) : localize ( 'import from file' , "Import from profile file" ) } ;
362
- quickPick . items = value ? [ { label : isSettingProfilesEnabled ? localize ( 'select from url' , "Create from template URL" ) : localize ( 'import from url' , "Import from URL" ) , description : quickPick . value } , selectFromFileItem ] : [ selectFromFileItem ] ;
345
+ const selectFromFileItem : IQuickPickItem = { label : localize ( 'import from file' , "Import from profile file" ) } ;
346
+ quickPick . items = value ? [ { label : localize ( 'import from url' , "Import from URL" ) , description : quickPick . value } , selectFromFileItem ] : [ selectFromFileItem ] ;
363
347
} ;
364
- quickPick . title = isSettingProfilesEnabled ? localize ( 'create from profile template quick pick title' , "Create from Profile Template" ) : localize ( ' import profile quick pick title', "Import Settings from a Profile" ) ;
365
- quickPick . placeholder = isSettingProfilesEnabled ? localize ( 'create from profile template placeholder' , "Provide a template URL or Select a template file" ) : localize ( 'import profile placeholder' , "Provide profile URL or select profile file to import" ) ;
348
+ quickPick . title = localize ( 'import profile quick pick title' , "Import Profile" ) ;
349
+ quickPick . placeholder = localize ( 'import profile placeholder' , "Provide profile URL or select profile file to import" ) ;
366
350
quickPick . ignoreFocusOut = true ;
367
351
disposables . add ( quickPick . onDidChangeValue ( updateQuickPickItems ) ) ;
368
352
updateQuickPickItems ( ) ;
@@ -371,11 +355,14 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
371
355
disposables . add ( quickPick . onDidAccept ( async ( ) => {
372
356
try {
373
357
quickPick . hide ( ) ;
374
- const profile = quickPick . selectedItems [ 0 ] . description ? await this . getProfileFromURL ( quickPick . value , requestService ) : await this . getProfileFromFileSystem ( fileDialogService , fileService ) ;
375
- if ( profile ) {
376
- if ( isSettingProfilesEnabled ) {
358
+ if ( isSettingProfilesEnabled ) {
359
+ const profile = quickPick . selectedItems [ 0 ] . description ? URI . parse ( quickPick . value ) : await this . getProfileUriFromFileSystem ( fileDialogService ) ;
360
+ if ( profile ) {
377
361
await userDataProfileImportExportService . importProfile ( profile ) ;
378
- } else {
362
+ }
363
+ } else {
364
+ const profile = quickPick . selectedItems [ 0 ] . description ? await this . getProfileFromURL ( quickPick . value , requestService ) : await this . getProfileFromFileSystem ( fileDialogService , fileService ) ;
365
+ if ( profile ) {
379
366
await userDataProfileImportExportService . setProfile ( profile ) ;
380
367
}
381
368
}
@@ -387,7 +374,7 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
387
374
quickPick . show ( ) ;
388
375
}
389
376
390
- private async getProfileFromFileSystem ( fileDialogService : IFileDialogService , fileService : IFileService ) : Promise < IUserDataProfileTemplate | null > {
377
+ private async getProfileUriFromFileSystem ( fileDialogService : IFileDialogService ) : Promise < URI | null > {
391
378
const profileLocation = await fileDialogService . showOpenDialog ( {
392
379
canSelectFolders : false ,
393
380
canSelectFiles : true ,
@@ -398,7 +385,15 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
398
385
if ( ! profileLocation ) {
399
386
return null ;
400
387
}
401
- const content = ( await fileService . readFile ( profileLocation [ 0 ] ) ) . value . toString ( ) ;
388
+ return profileLocation [ 0 ] ;
389
+ }
390
+
391
+ private async getProfileFromFileSystem ( fileDialogService : IFileDialogService , fileService : IFileService ) : Promise < IUserDataProfileTemplate | null > {
392
+ const profileLocation = await this . getProfileUriFromFileSystem ( fileDialogService ) ;
393
+ if ( ! profileLocation ) {
394
+ return null ;
395
+ }
396
+ const content = ( await fileService . readFile ( profileLocation ) ) . value . toString ( ) ;
402
397
const parsed = JSON . parse ( content ) ;
403
398
return isUserDataProfileTemplate ( parsed ) ? parsed : null ;
404
399
}
0 commit comments