@theia/preferences 1.53.0-next.55 → 1.53.0-next.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +81 -81
  2. package/package.json +8 -8
  3. package/src/browser/abstract-resource-preference-provider.spec.ts +95 -95
  4. package/src/browser/abstract-resource-preference-provider.ts +232 -232
  5. package/src/browser/folder-preference-provider.ts +58 -58
  6. package/src/browser/folders-preferences-provider.ts +244 -244
  7. package/src/browser/index.ts +23 -23
  8. package/src/browser/monaco-jsonc-editor.ts +67 -67
  9. package/src/browser/package.spec.ts +28 -28
  10. package/src/browser/preference-bindings.ts +65 -65
  11. package/src/browser/preference-frontend-contribution.ts +38 -38
  12. package/src/browser/preference-frontend-module.ts +66 -66
  13. package/src/browser/preference-open-handler.ts +53 -53
  14. package/src/browser/preference-transaction-manager.ts +287 -287
  15. package/src/browser/preference-tree-model.ts +260 -260
  16. package/src/browser/preferences-contribution.ts +263 -263
  17. package/src/browser/preferences-json-schema-contribution.ts +86 -86
  18. package/src/browser/preferences-monaco-contribution.ts +27 -27
  19. package/src/browser/section-preference-provider.ts +83 -83
  20. package/src/browser/style/index.css +506 -506
  21. package/src/browser/style/preference-array.css +94 -94
  22. package/src/browser/style/preference-context-menu.css +74 -74
  23. package/src/browser/style/preference-file.css +31 -31
  24. package/src/browser/style/preference-object.css +49 -49
  25. package/src/browser/style/search-input.css +66 -66
  26. package/src/browser/user-configs-preference-provider.ts +127 -127
  27. package/src/browser/user-preference-provider.ts +35 -35
  28. package/src/browser/util/preference-layout.ts +381 -381
  29. package/src/browser/util/preference-scope-command-manager.ts +75 -75
  30. package/src/browser/util/preference-tree-generator.ts +260 -260
  31. package/src/browser/util/preference-tree-label-provider.spec.ts +110 -110
  32. package/src/browser/util/preference-tree-label-provider.ts +72 -72
  33. package/src/browser/util/preference-types.ts +177 -177
  34. package/src/browser/views/components/preference-array-input.ts +174 -174
  35. package/src/browser/views/components/preference-boolean-input.ts +69 -69
  36. package/src/browser/views/components/preference-file-input.ts +104 -104
  37. package/src/browser/views/components/preference-json-input.ts +78 -78
  38. package/src/browser/views/components/preference-markdown-renderer.ts +68 -68
  39. package/src/browser/views/components/preference-node-renderer-creator.ts +141 -141
  40. package/src/browser/views/components/preference-node-renderer.ts +477 -477
  41. package/src/browser/views/components/preference-number-input.ts +147 -147
  42. package/src/browser/views/components/preference-select-input.ts +131 -131
  43. package/src/browser/views/components/preference-string-input.ts +76 -76
  44. package/src/browser/views/preference-editor-widget.ts +349 -349
  45. package/src/browser/views/preference-scope-tabbar-widget.tsx +344 -344
  46. package/src/browser/views/preference-searchbar-widget.tsx +183 -183
  47. package/src/browser/views/preference-tree-widget.tsx +102 -102
  48. package/src/browser/views/preference-widget-bindings.ts +102 -102
  49. package/src/browser/views/preference-widget.tsx +118 -118
  50. package/src/browser/workspace-file-preference-provider.ts +100 -100
  51. package/src/browser/workspace-preference-provider.ts +134 -134
  52. package/src/common/cli-preferences.ts +22 -22
  53. package/src/node/preference-backend-module.ts +33 -33
  54. package/src/node/preference-cli-contribution.ts +48 -48
@@ -1,232 +1,232 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 Ericsson and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- /* eslint-disable @typescript-eslint/no-explicit-any */
18
- /* eslint-disable no-null/no-null */
19
-
20
- import * as jsoncparser from 'jsonc-parser';
21
- import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
22
- import { Disposable } from '@theia/core/lib/common/disposable';
23
- import { PreferenceProvider, PreferenceSchemaProvider, PreferenceScope, PreferenceProviderDataChange } from '@theia/core/lib/browser';
24
- import URI from '@theia/core/lib/common/uri';
25
- import { PreferenceConfigurations } from '@theia/core/lib/browser/preferences/preference-configurations';
26
- import { Deferred } from '@theia/core/lib/common/promise-util';
27
- import { FileService } from '@theia/filesystem/lib/browser/file-service';
28
- import { PreferenceContext, PreferenceTransaction, PreferenceTransactionFactory } from './preference-transaction-manager';
29
- import { Emitter, Event } from '@theia/core';
30
-
31
- @injectable()
32
- export abstract class AbstractResourcePreferenceProvider extends PreferenceProvider {
33
-
34
- protected preferences: Record<string, any> = {};
35
- protected _fileExists = false;
36
- protected readonly loading = new Deferred();
37
- protected transaction: PreferenceTransaction | undefined;
38
- protected readonly onDidChangeValidityEmitter = new Emitter<boolean>();
39
-
40
- set fileExists(exists: boolean) {
41
- if (exists !== this._fileExists) {
42
- this._fileExists = exists;
43
- this.onDidChangeValidityEmitter.fire(exists);
44
- }
45
- }
46
-
47
- get onDidChangeValidity(): Event<boolean> {
48
- return this.onDidChangeValidityEmitter.event;
49
- }
50
-
51
- @inject(PreferenceTransactionFactory) protected readonly transactionFactory: PreferenceTransactionFactory;
52
- @inject(PreferenceSchemaProvider) protected readonly schemaProvider: PreferenceSchemaProvider;
53
- @inject(FileService) protected readonly fileService: FileService;
54
- @inject(PreferenceConfigurations) protected readonly configurations: PreferenceConfigurations;
55
-
56
- @postConstruct()
57
- protected init(): void {
58
- this.doInit();
59
- }
60
-
61
- protected async doInit(): Promise<void> {
62
- const uri = this.getUri();
63
- this.toDispose.push(Disposable.create(() => this.loading.reject(new Error(`Preference provider for '${uri}' was disposed.`))));
64
- await this.readPreferencesFromFile();
65
- this._ready.resolve();
66
- this.loading.resolve();
67
- const storageUri = this.toFileManager().getConfigUri();
68
- this.toDispose.pushAll([
69
- this.fileService.watch(storageUri),
70
- this.fileService.onDidFilesChange(e => {
71
- if (e.contains(storageUri)) {
72
- this.readPreferencesFromFile();
73
- }
74
- }),
75
- Disposable.create(() => this.reset()),
76
- ]);
77
- }
78
-
79
- protected abstract getUri(): URI;
80
- abstract getScope(): PreferenceScope;
81
-
82
- get valid(): boolean {
83
- return this._fileExists;
84
- }
85
-
86
- override getConfigUri(): URI;
87
- override getConfigUri(resourceUri: string | undefined): URI | undefined;
88
- override getConfigUri(resourceUri?: string): URI | undefined {
89
- if (!resourceUri) {
90
- return this.getUri();
91
- }
92
- return this.valid && this.contains(resourceUri) ? this.getUri() : undefined;
93
- }
94
-
95
- contains(resourceUri: string | undefined): boolean {
96
- if (!resourceUri) {
97
- return true;
98
- }
99
- const domain = this.getDomain();
100
- if (!domain) {
101
- return true;
102
- }
103
- const resourcePath = new URI(resourceUri).path;
104
- return domain.some(uri => new URI(uri).path.relativity(resourcePath) >= 0);
105
- }
106
-
107
- getPreferences(resourceUri?: string): { [key: string]: any } {
108
- return this.valid && this.contains(resourceUri) ? this.preferences : {};
109
- }
110
-
111
- async setPreference(key: string, value: any, resourceUri?: string): Promise<boolean> {
112
- let path: string[] | undefined;
113
- if (this.toDispose.disposed || !(path = this.getPath(key)) || !this.contains(resourceUri)) {
114
- return false;
115
- }
116
- return this.doSetPreference(key, path, value);
117
- }
118
-
119
- protected async doSetPreference(key: string, path: string[], value: unknown): Promise<boolean> {
120
- if (!this.transaction?.open) {
121
- const current = this.transaction;
122
- this.transaction = this.transactionFactory(this.toFileManager(), current?.result);
123
- this.transaction.onWillConclude(({ status, waitUntil }) => {
124
- if (status) {
125
- waitUntil((async () => {
126
- await this.readPreferencesFromFile();
127
- await this.fireDidPreferencesChanged(); // Ensure all consumers of the event have received it.
128
- })());
129
- }
130
- });
131
- this.toDispose.push(this.transaction);
132
- }
133
- return this.transaction.enqueueAction(key, path, value);
134
- }
135
-
136
- /**
137
- * Use this method as intermediary for interactions with actual files.
138
- * Allows individual providers to modify where they store their files without disrupting the preference system's
139
- * conventions about scope and file location.
140
- */
141
- protected toFileManager(): PreferenceContext {
142
- return this;
143
- }
144
-
145
- protected getPath(preferenceName: string): string[] | undefined {
146
- const asOverride = this.preferenceOverrideService.overriddenPreferenceName(preferenceName);
147
- if (asOverride?.overrideIdentifier) {
148
- return [this.preferenceOverrideService.markLanguageOverride(asOverride.overrideIdentifier), asOverride.preferenceName];
149
- }
150
- return [preferenceName];
151
- }
152
-
153
- protected async readPreferencesFromFile(): Promise<void> {
154
- const content = await this.fileService.read(this.toFileManager().getConfigUri())
155
- .then(value => {
156
- this.fileExists = true;
157
- return value;
158
- })
159
- .catch(() => {
160
- this.fileExists = false;
161
- return { value: '' };
162
- });
163
- this.readPreferencesFromContent(content.value);
164
- }
165
-
166
- protected readPreferencesFromContent(content: string): void {
167
- let preferencesInJson;
168
- try {
169
- preferencesInJson = this.parse(content);
170
- } catch {
171
- preferencesInJson = {};
172
- }
173
- const parsedPreferences = this.getParsedContent(preferencesInJson);
174
- this.handlePreferenceChanges(parsedPreferences);
175
- }
176
-
177
- protected parse(content: string): any {
178
- content = content.trim();
179
- if (!content) {
180
- return undefined;
181
- }
182
- const strippedContent = jsoncparser.stripComments(content);
183
- return jsoncparser.parse(strippedContent);
184
- }
185
-
186
- protected handlePreferenceChanges(newPrefs: { [key: string]: any }): void {
187
- const oldPrefs = Object.assign({}, this.preferences);
188
- this.preferences = newPrefs;
189
- const prefNames = new Set([...Object.keys(oldPrefs), ...Object.keys(newPrefs)]);
190
- const prefChanges: PreferenceProviderDataChange[] = [];
191
- const uri = this.getUri();
192
- for (const prefName of prefNames.values()) {
193
- const oldValue = oldPrefs[prefName];
194
- const newValue = newPrefs[prefName];
195
- const schemaProperties = this.schemaProvider.getCombinedSchema().properties[prefName];
196
- if (schemaProperties) {
197
- const scope = schemaProperties.scope;
198
- // do not emit the change event if the change is made out of the defined preference scope
199
- if (!this.schemaProvider.isValidInScope(prefName, this.getScope())) {
200
- console.warn(`Preference ${prefName} in ${uri} can only be defined in scopes: ${PreferenceScope.getScopeNames(scope).join(', ')}.`);
201
- continue;
202
- }
203
- }
204
- if (!PreferenceProvider.deepEqual(newValue, oldValue)) {
205
- prefChanges.push({
206
- preferenceName: prefName, newValue, oldValue, scope: this.getScope(), domain: this.getDomain()
207
- });
208
- }
209
- }
210
-
211
- if (prefChanges.length > 0) {
212
- this.emitPreferencesChangedEvent(prefChanges);
213
- }
214
- }
215
-
216
- protected reset(): void {
217
- const preferences = this.preferences;
218
- this.preferences = {};
219
- const changes: PreferenceProviderDataChange[] = [];
220
- for (const prefName of Object.keys(preferences)) {
221
- const value = preferences[prefName];
222
- if (value !== undefined) {
223
- changes.push({
224
- preferenceName: prefName, newValue: undefined, oldValue: value, scope: this.getScope(), domain: this.getDomain()
225
- });
226
- }
227
- }
228
- if (changes.length > 0) {
229
- this.emitPreferencesChangedEvent(changes);
230
- }
231
- }
232
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ /* eslint-disable @typescript-eslint/no-explicit-any */
18
+ /* eslint-disable no-null/no-null */
19
+
20
+ import * as jsoncparser from 'jsonc-parser';
21
+ import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
22
+ import { Disposable } from '@theia/core/lib/common/disposable';
23
+ import { PreferenceProvider, PreferenceSchemaProvider, PreferenceScope, PreferenceProviderDataChange } from '@theia/core/lib/browser';
24
+ import URI from '@theia/core/lib/common/uri';
25
+ import { PreferenceConfigurations } from '@theia/core/lib/browser/preferences/preference-configurations';
26
+ import { Deferred } from '@theia/core/lib/common/promise-util';
27
+ import { FileService } from '@theia/filesystem/lib/browser/file-service';
28
+ import { PreferenceContext, PreferenceTransaction, PreferenceTransactionFactory } from './preference-transaction-manager';
29
+ import { Emitter, Event } from '@theia/core';
30
+
31
+ @injectable()
32
+ export abstract class AbstractResourcePreferenceProvider extends PreferenceProvider {
33
+
34
+ protected preferences: Record<string, any> = {};
35
+ protected _fileExists = false;
36
+ protected readonly loading = new Deferred();
37
+ protected transaction: PreferenceTransaction | undefined;
38
+ protected readonly onDidChangeValidityEmitter = new Emitter<boolean>();
39
+
40
+ set fileExists(exists: boolean) {
41
+ if (exists !== this._fileExists) {
42
+ this._fileExists = exists;
43
+ this.onDidChangeValidityEmitter.fire(exists);
44
+ }
45
+ }
46
+
47
+ get onDidChangeValidity(): Event<boolean> {
48
+ return this.onDidChangeValidityEmitter.event;
49
+ }
50
+
51
+ @inject(PreferenceTransactionFactory) protected readonly transactionFactory: PreferenceTransactionFactory;
52
+ @inject(PreferenceSchemaProvider) protected readonly schemaProvider: PreferenceSchemaProvider;
53
+ @inject(FileService) protected readonly fileService: FileService;
54
+ @inject(PreferenceConfigurations) protected readonly configurations: PreferenceConfigurations;
55
+
56
+ @postConstruct()
57
+ protected init(): void {
58
+ this.doInit();
59
+ }
60
+
61
+ protected async doInit(): Promise<void> {
62
+ const uri = this.getUri();
63
+ this.toDispose.push(Disposable.create(() => this.loading.reject(new Error(`Preference provider for '${uri}' was disposed.`))));
64
+ await this.readPreferencesFromFile();
65
+ this._ready.resolve();
66
+ this.loading.resolve();
67
+ const storageUri = this.toFileManager().getConfigUri();
68
+ this.toDispose.pushAll([
69
+ this.fileService.watch(storageUri),
70
+ this.fileService.onDidFilesChange(e => {
71
+ if (e.contains(storageUri)) {
72
+ this.readPreferencesFromFile();
73
+ }
74
+ }),
75
+ Disposable.create(() => this.reset()),
76
+ ]);
77
+ }
78
+
79
+ protected abstract getUri(): URI;
80
+ abstract getScope(): PreferenceScope;
81
+
82
+ get valid(): boolean {
83
+ return this._fileExists;
84
+ }
85
+
86
+ override getConfigUri(): URI;
87
+ override getConfigUri(resourceUri: string | undefined): URI | undefined;
88
+ override getConfigUri(resourceUri?: string): URI | undefined {
89
+ if (!resourceUri) {
90
+ return this.getUri();
91
+ }
92
+ return this.valid && this.contains(resourceUri) ? this.getUri() : undefined;
93
+ }
94
+
95
+ contains(resourceUri: string | undefined): boolean {
96
+ if (!resourceUri) {
97
+ return true;
98
+ }
99
+ const domain = this.getDomain();
100
+ if (!domain) {
101
+ return true;
102
+ }
103
+ const resourcePath = new URI(resourceUri).path;
104
+ return domain.some(uri => new URI(uri).path.relativity(resourcePath) >= 0);
105
+ }
106
+
107
+ getPreferences(resourceUri?: string): { [key: string]: any } {
108
+ return this.valid && this.contains(resourceUri) ? this.preferences : {};
109
+ }
110
+
111
+ async setPreference(key: string, value: any, resourceUri?: string): Promise<boolean> {
112
+ let path: string[] | undefined;
113
+ if (this.toDispose.disposed || !(path = this.getPath(key)) || !this.contains(resourceUri)) {
114
+ return false;
115
+ }
116
+ return this.doSetPreference(key, path, value);
117
+ }
118
+
119
+ protected async doSetPreference(key: string, path: string[], value: unknown): Promise<boolean> {
120
+ if (!this.transaction?.open) {
121
+ const current = this.transaction;
122
+ this.transaction = this.transactionFactory(this.toFileManager(), current?.result);
123
+ this.transaction.onWillConclude(({ status, waitUntil }) => {
124
+ if (status) {
125
+ waitUntil((async () => {
126
+ await this.readPreferencesFromFile();
127
+ await this.fireDidPreferencesChanged(); // Ensure all consumers of the event have received it.
128
+ })());
129
+ }
130
+ });
131
+ this.toDispose.push(this.transaction);
132
+ }
133
+ return this.transaction.enqueueAction(key, path, value);
134
+ }
135
+
136
+ /**
137
+ * Use this method as intermediary for interactions with actual files.
138
+ * Allows individual providers to modify where they store their files without disrupting the preference system's
139
+ * conventions about scope and file location.
140
+ */
141
+ protected toFileManager(): PreferenceContext {
142
+ return this;
143
+ }
144
+
145
+ protected getPath(preferenceName: string): string[] | undefined {
146
+ const asOverride = this.preferenceOverrideService.overriddenPreferenceName(preferenceName);
147
+ if (asOverride?.overrideIdentifier) {
148
+ return [this.preferenceOverrideService.markLanguageOverride(asOverride.overrideIdentifier), asOverride.preferenceName];
149
+ }
150
+ return [preferenceName];
151
+ }
152
+
153
+ protected async readPreferencesFromFile(): Promise<void> {
154
+ const content = await this.fileService.read(this.toFileManager().getConfigUri())
155
+ .then(value => {
156
+ this.fileExists = true;
157
+ return value;
158
+ })
159
+ .catch(() => {
160
+ this.fileExists = false;
161
+ return { value: '' };
162
+ });
163
+ this.readPreferencesFromContent(content.value);
164
+ }
165
+
166
+ protected readPreferencesFromContent(content: string): void {
167
+ let preferencesInJson;
168
+ try {
169
+ preferencesInJson = this.parse(content);
170
+ } catch {
171
+ preferencesInJson = {};
172
+ }
173
+ const parsedPreferences = this.getParsedContent(preferencesInJson);
174
+ this.handlePreferenceChanges(parsedPreferences);
175
+ }
176
+
177
+ protected parse(content: string): any {
178
+ content = content.trim();
179
+ if (!content) {
180
+ return undefined;
181
+ }
182
+ const strippedContent = jsoncparser.stripComments(content);
183
+ return jsoncparser.parse(strippedContent);
184
+ }
185
+
186
+ protected handlePreferenceChanges(newPrefs: { [key: string]: any }): void {
187
+ const oldPrefs = Object.assign({}, this.preferences);
188
+ this.preferences = newPrefs;
189
+ const prefNames = new Set([...Object.keys(oldPrefs), ...Object.keys(newPrefs)]);
190
+ const prefChanges: PreferenceProviderDataChange[] = [];
191
+ const uri = this.getUri();
192
+ for (const prefName of prefNames.values()) {
193
+ const oldValue = oldPrefs[prefName];
194
+ const newValue = newPrefs[prefName];
195
+ const schemaProperties = this.schemaProvider.getCombinedSchema().properties[prefName];
196
+ if (schemaProperties) {
197
+ const scope = schemaProperties.scope;
198
+ // do not emit the change event if the change is made out of the defined preference scope
199
+ if (!this.schemaProvider.isValidInScope(prefName, this.getScope())) {
200
+ console.warn(`Preference ${prefName} in ${uri} can only be defined in scopes: ${PreferenceScope.getScopeNames(scope).join(', ')}.`);
201
+ continue;
202
+ }
203
+ }
204
+ if (!PreferenceProvider.deepEqual(newValue, oldValue)) {
205
+ prefChanges.push({
206
+ preferenceName: prefName, newValue, oldValue, scope: this.getScope(), domain: this.getDomain()
207
+ });
208
+ }
209
+ }
210
+
211
+ if (prefChanges.length > 0) {
212
+ this.emitPreferencesChangedEvent(prefChanges);
213
+ }
214
+ }
215
+
216
+ protected reset(): void {
217
+ const preferences = this.preferences;
218
+ this.preferences = {};
219
+ const changes: PreferenceProviderDataChange[] = [];
220
+ for (const prefName of Object.keys(preferences)) {
221
+ const value = preferences[prefName];
222
+ if (value !== undefined) {
223
+ changes.push({
224
+ preferenceName: prefName, newValue: undefined, oldValue: value, scope: this.getScope(), domain: this.getDomain()
225
+ });
226
+ }
227
+ }
228
+ if (changes.length > 0) {
229
+ this.emitPreferencesChangedEvent(changes);
230
+ }
231
+ }
232
+ }
@@ -1,58 +1,58 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2019 Ericsson and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { inject, injectable } from '@theia/core/shared/inversify';
18
- import URI from '@theia/core/lib/common/uri';
19
- import { PreferenceScope } from '@theia/core/lib/browser';
20
- import { FileStat } from '@theia/filesystem/lib/common/files';
21
- import { SectionPreferenceProvider } from './section-preference-provider';
22
-
23
- export const FolderPreferenceProviderFactory = Symbol('FolderPreferenceProviderFactory');
24
- export interface FolderPreferenceProviderFactory {
25
- (uri: URI, section: string, folder: FileStat): FolderPreferenceProvider;
26
- }
27
-
28
- export const FolderPreferenceProviderFolder = Symbol('FolderPreferenceProviderFolder');
29
- export interface FolderPreferenceProviderOptions {
30
- readonly configUri: URI;
31
- readonly sectionName: string | undefined;
32
- }
33
-
34
- @injectable()
35
- export class FolderPreferenceProvider extends SectionPreferenceProvider {
36
-
37
- @inject(FolderPreferenceProviderFolder) protected readonly folder: FileStat;
38
-
39
- private _folderUri: URI;
40
-
41
- get folderUri(): URI {
42
- if (!this._folderUri) {
43
- this._folderUri = this.folder.resource;
44
- }
45
- return this._folderUri;
46
- }
47
- getScope(): PreferenceScope {
48
- if (!this.workspaceService.isMultiRootWorkspaceOpened) {
49
- // when FolderPreferenceProvider is used as a delegate of WorkspacePreferenceProvider in a one-folder workspace
50
- return PreferenceScope.Workspace;
51
- }
52
- return PreferenceScope.Folder;
53
- }
54
-
55
- override getDomain(): string[] {
56
- return [this.folderUri.toString()];
57
- }
58
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2019 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { inject, injectable } from '@theia/core/shared/inversify';
18
+ import URI from '@theia/core/lib/common/uri';
19
+ import { PreferenceScope } from '@theia/core/lib/browser';
20
+ import { FileStat } from '@theia/filesystem/lib/common/files';
21
+ import { SectionPreferenceProvider } from './section-preference-provider';
22
+
23
+ export const FolderPreferenceProviderFactory = Symbol('FolderPreferenceProviderFactory');
24
+ export interface FolderPreferenceProviderFactory {
25
+ (uri: URI, section: string, folder: FileStat): FolderPreferenceProvider;
26
+ }
27
+
28
+ export const FolderPreferenceProviderFolder = Symbol('FolderPreferenceProviderFolder');
29
+ export interface FolderPreferenceProviderOptions {
30
+ readonly configUri: URI;
31
+ readonly sectionName: string | undefined;
32
+ }
33
+
34
+ @injectable()
35
+ export class FolderPreferenceProvider extends SectionPreferenceProvider {
36
+
37
+ @inject(FolderPreferenceProviderFolder) protected readonly folder: FileStat;
38
+
39
+ private _folderUri: URI;
40
+
41
+ get folderUri(): URI {
42
+ if (!this._folderUri) {
43
+ this._folderUri = this.folder.resource;
44
+ }
45
+ return this._folderUri;
46
+ }
47
+ getScope(): PreferenceScope {
48
+ if (!this.workspaceService.isMultiRootWorkspaceOpened) {
49
+ // when FolderPreferenceProvider is used as a delegate of WorkspacePreferenceProvider in a one-folder workspace
50
+ return PreferenceScope.Workspace;
51
+ }
52
+ return PreferenceScope.Folder;
53
+ }
54
+
55
+ override getDomain(): string[] {
56
+ return [this.folderUri.toString()];
57
+ }
58
+ }