Welcome to mirror list, hosted at ThFree Co, Russian Federation.

userDataProfileImportExportService.ts « common « userDataProfile « services « workbench « vs « src - github.com/microsoft/vscode.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cd2aa2d8c2329649e1cf566d188b7c6026f1c000 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { localize } from 'vs/nls';
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress';
import { ExtensionsProfile } from 'vs/workbench/services/userDataProfile/common/extensionsProfile';
import { GlobalStateProfile } from 'vs/workbench/services/userDataProfile/common/globalStateProfile';
import { IUserDataProfileTemplate, IUserDataProfileImportExportService, PROFILES_CATEGORY, IUserDataProfileManagementService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
import { SettingsProfile } from 'vs/workbench/services/userDataProfile/common/settingsProfile';
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';

export class UserDataProfileImportExportService implements IUserDataProfileImportExportService {

	readonly _serviceBrand: undefined;

	private readonly settingsProfile: SettingsProfile;
	private readonly globalStateProfile: GlobalStateProfile;
	private readonly extensionsProfile: ExtensionsProfile;

	constructor(
		@IInstantiationService instantiationService: IInstantiationService,
		@IProgressService private readonly progressService: IProgressService,
		@INotificationService private readonly notificationService: INotificationService,
		@IUserDataProfileManagementService private readonly userDataProfileManagementService: IUserDataProfileManagementService,
		@IQuickInputService private readonly quickInputService: IQuickInputService,
	) {
		this.settingsProfile = instantiationService.createInstance(SettingsProfile);
		this.globalStateProfile = instantiationService.createInstance(GlobalStateProfile);
		this.extensionsProfile = instantiationService.createInstance(ExtensionsProfile);
	}

	async exportProfile(options?: { skipComments: boolean }): Promise<IUserDataProfileTemplate> {
		const settings = await this.settingsProfile.getProfileContent(options);
		const globalState = await this.globalStateProfile.getProfileContent();
		const extensions = await this.extensionsProfile.getProfileContent();
		return {
			settings,
			globalState,
			extensions
		};
	}

	async importProfile(profileTemplate: IUserDataProfileTemplate): Promise<void> {
		const name = await this.quickInputService.input({
			placeHolder: localize('name', "Profile name"),
			title: localize('save profile as', "Create from Current Profile..."),
		});
		if (!name) {
			return undefined;
		}

		await this.progressService.withProgress({
			location: ProgressLocation.Notification,
			title: localize('profiles.importing', "{0}: Importing...", PROFILES_CATEGORY.value),
		}, async progress => {
			await this.userDataProfileManagementService.createAndEnterProfile(name);
			if (profileTemplate.settings) {
				await this.settingsProfile.applyProfile(profileTemplate.settings);
			}
			if (profileTemplate.globalState) {
				await this.globalStateProfile.applyProfile(profileTemplate.globalState);
			}
			if (profileTemplate.extensions) {
				await this.extensionsProfile.applyProfile(profileTemplate.extensions);
			}
		});

		this.notificationService.info(localize('imported profile', "{0}: Imported successfully.", PROFILES_CATEGORY.value));
	}

	async setProfile(profile: IUserDataProfileTemplate): Promise<void> {
		await this.progressService.withProgress({
			location: ProgressLocation.Notification,
			title: localize('profiles.applying', "{0}: Applying...", PROFILES_CATEGORY.value),
		}, async progress => {
			if (profile.settings) {
				await this.settingsProfile.applyProfile(profile.settings);
			}
			if (profile.globalState) {
				await this.globalStateProfile.applyProfile(profile.globalState);
			}
			if (profile.extensions) {
				await this.extensionsProfile.applyProfile(profile.extensions);
			}
		});
		this.notificationService.info(localize('applied profile', "{0}: Applied successfully.", PROFILES_CATEGORY.value));
	}

}

registerSingleton(IUserDataProfileImportExportService, UserDataProfileImportExportService, InstantiationType.Delayed);