3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { coalesce } from 'vs/base/common/arrays' ;
7
- import { Emitter , Event } from 'vs/base/common/event' ;
8
6
import { hash } from 'vs/base/common/hash' ;
9
7
import { Disposable } from 'vs/base/common/lifecycle' ;
10
8
import { joinPath } from 'vs/base/common/resources' ;
11
9
import { UriDto } from 'vs/base/common/types' ;
12
10
import { URI } from 'vs/base/common/uri' ;
11
+ import { localize } from 'vs/nls' ;
13
12
import { IEnvironmentService } from 'vs/platform/environment/common/environment' ;
14
- import { FileOperationError , FileOperationResult , IFileService } from 'vs/platform/files/common/files' ;
13
+ import { IFileService } from 'vs/platform/files/common/files' ;
15
14
import { createDecorator } from 'vs/platform/instantiation/common/instantiation' ;
16
15
import { ILogService } from 'vs/platform/log/common/log' ;
16
+ import { ISingleFolderWorkspaceIdentifier , IWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace' ;
17
+
18
+ export type ProfileOptions = {
19
+ settings ?: boolean ;
20
+ keybindings ?: boolean ;
21
+ tasks ?: boolean ;
22
+ snippets ?: boolean ;
23
+ extensions ?: boolean ;
24
+ uiState ?: boolean ;
25
+ } ;
26
+
27
+ export const DefaultOptions : ProfileOptions = {
28
+ settings : true ,
29
+ keybindings : true ,
30
+ tasks : true ,
31
+ snippets : true ,
32
+ extensions : true ,
33
+ uiState : true
34
+ } ;
17
35
18
36
export interface IUserDataProfile {
19
37
readonly id : string ;
@@ -28,30 +46,23 @@ export interface IUserDataProfile {
28
46
readonly extensionsResource : URI | undefined ;
29
47
}
30
48
31
- export type IUserDataProfileDto = UriDto < IUserDataProfile > ;
32
- export type IUserDataProfilesDto = {
33
- readonly current : IUserDataProfileDto ;
34
- readonly default : IUserDataProfileDto ;
35
- } ;
36
-
37
49
export const IUserDataProfilesService = createDecorator < IUserDataProfilesService > ( 'IUserDataProfilesService' ) ;
38
50
export interface IUserDataProfilesService {
39
51
readonly _serviceBrand : undefined ;
40
52
41
53
readonly profilesHome : URI ;
42
54
readonly defaultProfile : IUserDataProfile ;
43
-
44
- readonly onDidChangeCurrentProfile : Event < IUserDataProfile > ;
45
55
readonly currentProfile : IUserDataProfile ;
46
56
47
- createProfile ( name : string ) : IUserDataProfile ;
48
- setProfile ( name : string ) : Promise < void > ;
57
+ newProfile ( name : string , options ?: ProfileOptions ) : IUserDataProfile ;
58
+ createProfile ( profile : IUserDataProfile , options : ProfileOptions , workspaceIdentifier ?: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier ) : Promise < IUserDataProfile > ;
59
+ setProfileForWorkspace ( profile : IUserDataProfile , workspaceIdentifier : ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier ) : Promise < IUserDataProfile > ;
60
+ getProfile ( workspace : URI ) : IUserDataProfile ;
49
61
getAllProfiles ( ) : Promise < IUserDataProfile [ ] > ;
50
-
51
- serialize ( ) : IUserDataProfilesDto ;
62
+ removeProfile ( profile : IUserDataProfile ) : Promise < void > ;
52
63
}
53
64
54
- function reviveProfile ( profile : IUserDataProfile , scheme : string ) : IUserDataProfile {
65
+ export function reviveProfile ( profile : UriDto < IUserDataProfile > , scheme : string ) : IUserDataProfile {
55
66
return {
56
67
id : profile . id ,
57
68
isDefault : profile . isDefault ,
@@ -69,74 +80,49 @@ function reviveProfile(profile: IUserDataProfile, scheme: string): IUserDataProf
69
80
export class UserDataProfilesService extends Disposable implements IUserDataProfilesService {
70
81
readonly _serviceBrand : undefined ;
71
82
72
- protected static DEFAULT_PROFILE_NAME = 'default' ;
83
+ readonly profilesHome : URI ;
73
84
74
85
protected _currentProfile : IUserDataProfile ;
75
86
get currentProfile ( ) : IUserDataProfile { return this . _currentProfile ; }
76
87
77
- readonly profilesHome : URI ;
78
88
protected _defaultProfile : IUserDataProfile ;
79
89
get defaultProfile ( ) : IUserDataProfile { return this . _defaultProfile ; }
80
90
81
- private readonly _onDidChangeCurrentProfile = this . _register ( new Emitter < IUserDataProfile > ( ) ) ;
82
- readonly onDidChangeCurrentProfile = this . _onDidChangeCurrentProfile . event ;
83
-
84
91
constructor (
85
- defaultProfile : IUserDataProfile | undefined ,
86
- currentProfile : IUserDataProfile | undefined ,
87
- @IEnvironmentService private readonly environmentService : IEnvironmentService ,
92
+ defaultProfile : UriDto < IUserDataProfile > | undefined ,
93
+ currentProfile : UriDto < IUserDataProfile > | undefined ,
94
+ @IEnvironmentService protected readonly environmentService : IEnvironmentService ,
88
95
@IFileService protected readonly fileService : IFileService ,
89
96
@ILogService protected readonly logService : ILogService
90
97
) {
91
98
super ( ) ;
92
99
this . profilesHome = joinPath ( this . environmentService . userRoamingDataHome , 'profiles' ) ;
93
- this . _defaultProfile = defaultProfile ? reviveProfile ( defaultProfile , this . profilesHome . scheme ) : this . createProfile ( undefined ) ;
100
+ this . _defaultProfile = defaultProfile ? reviveProfile ( defaultProfile , this . profilesHome . scheme ) : this . toUserDataProfile ( localize ( 'defaultProfile' , "Default" ) , environmentService . userRoamingDataHome , { ... DefaultOptions , extensions : false } , true ) ;
94
101
this . _currentProfile = currentProfile ? reviveProfile ( currentProfile , this . profilesHome . scheme ) : this . _defaultProfile ;
95
102
}
96
103
97
- createProfile ( name : string | undefined ) : IUserDataProfile {
98
- const isDefault = ! name || name === UserDataProfilesService . DEFAULT_PROFILE_NAME ;
99
- const location = name && name !== UserDataProfilesService . DEFAULT_PROFILE_NAME ? joinPath ( this . profilesHome , name ) : this . environmentService . userRoamingDataHome ;
100
- return {
101
- id : hash ( location . toString ( ) ) . toString ( 16 ) ,
102
- isDefault,
103
- name : name ?? UserDataProfilesService . DEFAULT_PROFILE_NAME ,
104
- location,
105
- globalStorageHome : joinPath ( location , 'globalStorage' ) ,
106
- settingsResource : joinPath ( location , 'settings.json' ) ,
107
- keybindingsResource : joinPath ( location , 'keybindings.json' ) ,
108
- tasksResource : joinPath ( location , 'tasks.json' ) ,
109
- snippetsHome : joinPath ( location , 'snippets' ) ,
110
- extensionsResource : name ? joinPath ( location , 'extensions.json' ) : undefined
111
- } ;
112
- }
113
-
114
- async getAllProfiles ( ) : Promise < IUserDataProfile [ ] > {
115
- try {
116
- const stat = await this . fileService . resolve ( this . profilesHome ) ;
117
- const profiles = coalesce ( stat . children ?. map ( stat => stat . isDirectory ? this . createProfile ( stat . name ) : undefined ) ?? [ ] ) ;
118
- if ( profiles . length ) {
119
- profiles . unshift ( this . _defaultProfile ) ;
120
- }
121
- return profiles ;
122
- } catch ( error ) {
123
- if ( ( < FileOperationError > error ) . fileOperationResult !== FileOperationResult . FILE_NOT_FOUND ) {
124
- this . logService . error ( 'Error while getting all profiles' , error ) ;
125
- }
126
- }
127
- return [ ] ;
104
+ newProfile ( name : string , options : ProfileOptions = DefaultOptions ) : IUserDataProfile {
105
+ return this . toUserDataProfile ( name , joinPath ( this . profilesHome , hash ( name ) . toString ( 16 ) ) , options , this . defaultProfile ) ;
128
106
}
129
107
130
- protected createCurrentProfile ( profile : string | undefined ) : IUserDataProfile {
131
- return profile === UserDataProfilesService . DEFAULT_PROFILE_NAME ? this . _defaultProfile : this . createProfile ( profile ) ;
132
- }
133
-
134
- setProfile ( name : string ) : Promise < void > { throw new Error ( 'Not implemented' ) ; }
135
-
136
- serialize ( ) : IUserDataProfilesDto {
108
+ protected toUserDataProfile ( name : string , location : URI , options : ProfileOptions , defaultProfile : true | IUserDataProfile ) : IUserDataProfile {
137
109
return {
138
- default : this . defaultProfile ,
139
- current : this . currentProfile
110
+ id : hash ( location . toString ( ) ) . toString ( 16 ) ,
111
+ name : name ,
112
+ location : location ,
113
+ isDefault : defaultProfile === true ,
114
+ globalStorageHome : defaultProfile === true || options . uiState ? joinPath ( location , 'globalStorage' ) : defaultProfile . globalStorageHome ,
115
+ settingsResource : defaultProfile === true || options . settings ? joinPath ( location , 'settings.json' ) : defaultProfile . settingsResource ,
116
+ keybindingsResource : defaultProfile === true || options . keybindings ? joinPath ( location , 'keybindings.json' ) : defaultProfile . keybindingsResource ,
117
+ tasksResource : defaultProfile === true || options . tasks ? joinPath ( location , 'tasks.json' ) : defaultProfile . tasksResource ,
118
+ snippetsHome : defaultProfile === true || options . snippets ? joinPath ( location , 'snippets' ) : defaultProfile . snippetsHome ,
119
+ extensionsResource : defaultProfile === true && ! options . extensions ? undefined : joinPath ( location , 'extensions.json' ) ,
140
120
} ;
141
121
}
122
+
123
+ getAllProfiles ( ) : Promise < IUserDataProfile [ ] > { throw new Error ( 'Not implemented' ) ; }
124
+ createProfile ( profile : IUserDataProfile , options : ProfileOptions , workspaceIdentifier ?: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier ) : Promise < IUserDataProfile > { throw new Error ( 'Not implemented' ) ; }
125
+ setProfileForWorkspace ( profile : IUserDataProfile , workspaceIdentifier : ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier ) : Promise < IUserDataProfile > { throw new Error ( 'Not implemented' ) ; }
126
+ getProfile ( workspace : URI ) : IUserDataProfile { throw new Error ( 'Not implemented' ) ; }
127
+ removeProfile ( profile : IUserDataProfile ) : Promise < void > { throw new Error ( 'Not implemented' ) ; }
142
128
}
0 commit comments