@theia/preferences 1.45.1 → 1.46.0-next.72
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.
- package/README.md +81 -81
- package/lib/browser/abstract-resource-preference-provider.d.ts +47 -47
- package/lib/browser/abstract-resource-preference-provider.js +240 -240
- package/lib/browser/abstract-resource-preference-provider.spec.d.ts +1 -1
- package/lib/browser/abstract-resource-preference-provider.spec.js +83 -83
- package/lib/browser/folder-preference-provider.d.ts +20 -20
- package/lib/browser/folder-preference-provider.js +59 -59
- package/lib/browser/folders-preferences-provider.d.ts +27 -27
- package/lib/browser/folders-preferences-provider.js +245 -245
- package/lib/browser/index.d.ts +7 -7
- package/lib/browser/index.js +34 -34
- package/lib/browser/monaco-jsonc-editor.d.ts +9 -9
- package/lib/browser/monaco-jsonc-editor.js +80 -80
- package/lib/browser/package.spec.js +25 -25
- package/lib/browser/preference-bindings.d.ts +4 -4
- package/lib/browser/preference-bindings.js +63 -63
- package/lib/browser/preference-frontend-module.d.ts +6 -6
- package/lib/browser/preference-frontend-module.js +52 -52
- package/lib/browser/preference-open-handler.d.ts +9 -9
- package/lib/browser/preference-open-handler.js +64 -64
- package/lib/browser/preference-transaction-manager.d.ts +100 -100
- package/lib/browser/preference-transaction-manager.js +293 -293
- package/lib/browser/preference-tree-model.d.ts +60 -60
- package/lib/browser/preference-tree-model.js +243 -243
- package/lib/browser/preferences-contribution.d.ts +37 -37
- package/lib/browser/preferences-contribution.js +280 -280
- package/lib/browser/preferences-json-schema-contribution.d.ts +17 -17
- package/lib/browser/preferences-json-schema-contribution.js +91 -91
- package/lib/browser/preferences-monaco-contribution.d.ts +1 -1
- package/lib/browser/preferences-monaco-contribution.js +27 -27
- package/lib/browser/section-preference-provider.d.ts +21 -21
- package/lib/browser/section-preference-provider.js +96 -96
- package/lib/browser/user-configs-preference-provider.d.ts +22 -22
- package/lib/browser/user-configs-preference-provider.js +137 -137
- package/lib/browser/user-preference-provider.d.ts +13 -13
- package/lib/browser/user-preference-provider.js +41 -41
- package/lib/browser/util/preference-scope-command-manager.d.ts +17 -17
- package/lib/browser/util/preference-scope-command-manager.js +87 -87
- package/lib/browser/util/preference-tree-generator.d.ts +31 -31
- package/lib/browser/util/preference-tree-generator.js +237 -237
- package/lib/browser/util/preference-tree-label-provider.d.ts +11 -11
- package/lib/browser/util/preference-tree-label-provider.js +77 -77
- package/lib/browser/util/preference-tree-label-provider.spec.d.ts +1 -1
- package/lib/browser/util/preference-tree-label-provider.spec.js +87 -87
- package/lib/browser/util/preference-types.d.ts +62 -62
- package/lib/browser/util/preference-types.js +128 -128
- package/lib/browser/views/components/preference-array-input.d.ts +28 -28
- package/lib/browser/views/components/preference-array-input.js +180 -180
- package/lib/browser/views/components/preference-boolean-input.d.ts +17 -17
- package/lib/browser/views/components/preference-boolean-input.js +79 -79
- package/lib/browser/views/components/preference-file-input.d.ts +29 -29
- package/lib/browser/views/components/preference-file-input.js +110 -110
- package/lib/browser/views/components/preference-json-input.d.ts +19 -19
- package/lib/browser/views/components/preference-json-input.js +93 -93
- package/lib/browser/views/components/preference-markdown-renderer.d.ts +12 -12
- package/lib/browser/views/components/preference-markdown-renderer.js +81 -81
- package/lib/browser/views/components/preference-node-renderer-creator.d.ts +48 -48
- package/lib/browser/views/components/preference-node-renderer-creator.js +132 -132
- package/lib/browser/views/components/preference-node-renderer.d.ts +112 -112
- package/lib/browser/views/components/preference-node-renderer.js +441 -441
- package/lib/browser/views/components/preference-number-input.d.ts +34 -34
- package/lib/browser/views/components/preference-number-input.js +142 -142
- package/lib/browser/views/components/preference-select-input.d.ts +28 -28
- package/lib/browser/views/components/preference-select-input.js +138 -138
- package/lib/browser/views/components/preference-string-input.d.ts +17 -17
- package/lib/browser/views/components/preference-string-input.js +89 -89
- package/lib/browser/views/preference-editor-widget.d.ts +67 -67
- package/lib/browser/views/preference-editor-widget.js +363 -363
- package/lib/browser/views/preference-scope-tabbar-widget.d.ts +54 -54
- package/lib/browser/views/preference-scope-tabbar-widget.js +343 -343
- package/lib/browser/views/preference-searchbar-widget.d.ts +53 -53
- package/lib/browser/views/preference-searchbar-widget.js +173 -173
- package/lib/browser/views/preference-tree-widget.d.ts +17 -17
- package/lib/browser/views/preference-tree-widget.js +104 -104
- package/lib/browser/views/preference-widget-bindings.d.ts +3 -3
- package/lib/browser/views/preference-widget-bindings.js +87 -87
- package/lib/browser/views/preference-widget.d.ts +36 -36
- package/lib/browser/views/preference-widget.js +126 -126
- package/lib/browser/workspace-file-preference-provider.d.ts +23 -23
- package/lib/browser/workspace-file-preference-provider.js +110 -110
- package/lib/browser/workspace-preference-provider.d.ts +28 -28
- package/lib/browser/workspace-preference-provider.js +142 -142
- package/package.json +10 -10
- package/src/browser/abstract-resource-preference-provider.spec.ts +95 -95
- package/src/browser/abstract-resource-preference-provider.ts +232 -232
- package/src/browser/folder-preference-provider.ts +58 -58
- package/src/browser/folders-preferences-provider.ts +244 -244
- package/src/browser/index.ts +23 -23
- package/src/browser/monaco-jsonc-editor.ts +67 -67
- package/src/browser/package.spec.ts +28 -28
- package/src/browser/preference-bindings.ts +65 -65
- package/src/browser/preference-frontend-module.ts +57 -57
- package/src/browser/preference-open-handler.ts +53 -53
- package/src/browser/preference-transaction-manager.ts +287 -287
- package/src/browser/preference-tree-model.ts +250 -250
- package/src/browser/preferences-contribution.ts +263 -263
- package/src/browser/preferences-json-schema-contribution.ts +86 -86
- package/src/browser/preferences-monaco-contribution.ts +27 -27
- package/src/browser/section-preference-provider.ts +83 -83
- package/src/browser/style/index.css +506 -506
- package/src/browser/style/preference-array.css +94 -94
- package/src/browser/style/preference-context-menu.css +74 -74
- package/src/browser/style/preference-file.css +31 -31
- package/src/browser/style/preference-object.css +49 -49
- package/src/browser/style/search-input.css +66 -66
- package/src/browser/user-configs-preference-provider.ts +127 -127
- package/src/browser/user-preference-provider.ts +35 -35
- package/src/browser/util/preference-scope-command-manager.ts +75 -75
- package/src/browser/util/preference-tree-generator.ts +226 -226
- package/src/browser/util/preference-tree-label-provider.spec.ts +108 -108
- package/src/browser/util/preference-tree-label-provider.ts +64 -64
- package/src/browser/util/preference-types.ts +169 -169
- package/src/browser/views/components/preference-array-input.ts +174 -174
- package/src/browser/views/components/preference-boolean-input.ts +69 -69
- package/src/browser/views/components/preference-file-input.ts +104 -104
- package/src/browser/views/components/preference-json-input.ts +78 -78
- package/src/browser/views/components/preference-markdown-renderer.ts +68 -68
- package/src/browser/views/components/preference-node-renderer-creator.ts +141 -141
- package/src/browser/views/components/preference-node-renderer.ts +477 -477
- package/src/browser/views/components/preference-number-input.ts +147 -147
- package/src/browser/views/components/preference-select-input.ts +131 -131
- package/src/browser/views/components/preference-string-input.ts +76 -76
- package/src/browser/views/preference-editor-widget.ts +349 -349
- package/src/browser/views/preference-scope-tabbar-widget.tsx +344 -344
- package/src/browser/views/preference-searchbar-widget.tsx +183 -183
- package/src/browser/views/preference-tree-widget.tsx +93 -93
- package/src/browser/views/preference-widget-bindings.ts +102 -102
- package/src/browser/views/preference-widget.tsx +117 -117
- package/src/browser/workspace-file-preference-provider.ts +100 -100
- package/src/browser/workspace-preference-provider.ts +134 -134
|
@@ -1,477 +1,477 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2020 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 { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
|
|
18
|
-
import {
|
|
19
|
-
PreferenceService, ContextMenuRenderer, PreferenceInspection,
|
|
20
|
-
PreferenceScope, PreferenceProvider, codicon, OpenerService, open, PreferenceDataProperty
|
|
21
|
-
} from '@theia/core/lib/browser';
|
|
22
|
-
import { Preference, PreferenceMenus } from '../../util/preference-types';
|
|
23
|
-
import { PreferenceTreeLabelProvider } from '../../util/preference-tree-label-provider';
|
|
24
|
-
import { PreferencesScopeTabBar } from '../preference-scope-tabbar-widget';
|
|
25
|
-
import { Disposable, nls } from '@theia/core/lib/common';
|
|
26
|
-
import { JSONValue } from '@theia/core/shared/@phosphor/coreutils';
|
|
27
|
-
import debounce = require('@theia/core/shared/lodash.debounce');
|
|
28
|
-
import { PreferenceTreeModel } from '../../preference-tree-model';
|
|
29
|
-
import { PreferencesSearchbarWidget } from '../preference-searchbar-widget';
|
|
30
|
-
import * as DOMPurify from '@theia/core/shared/dompurify';
|
|
31
|
-
import URI from '@theia/core/lib/common/uri';
|
|
32
|
-
import { PreferenceMarkdownRenderer } from './preference-markdown-renderer';
|
|
33
|
-
|
|
34
|
-
export const PreferenceNodeRendererFactory = Symbol('PreferenceNodeRendererFactory');
|
|
35
|
-
export type PreferenceNodeRendererFactory = (node: Preference.TreeNode) => PreferenceNodeRenderer;
|
|
36
|
-
export const HEADER_CLASS = 'settings-section-category-title';
|
|
37
|
-
export const SUBHEADER_CLASS = 'settings-section-subcategory-title';
|
|
38
|
-
|
|
39
|
-
export interface GeneralPreferenceNodeRenderer extends Disposable {
|
|
40
|
-
node: HTMLElement;
|
|
41
|
-
id: string;
|
|
42
|
-
schema?: PreferenceDataProperty;
|
|
43
|
-
group: string;
|
|
44
|
-
nodeId: string;
|
|
45
|
-
visible: boolean;
|
|
46
|
-
insertBefore(nextSibling: HTMLElement): void;
|
|
47
|
-
insertAfter(previousSibling: HTMLElement): void;
|
|
48
|
-
appendTo(parent: HTMLElement): void;
|
|
49
|
-
prependTo(parent: HTMLElement): void;
|
|
50
|
-
handleValueChange?(): void;
|
|
51
|
-
handleSearchChange?(isFiltered?: boolean): void;
|
|
52
|
-
handleScopeChange?(isFiltered?: boolean): void;
|
|
53
|
-
hide(): void;
|
|
54
|
-
show(): void;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
@injectable()
|
|
58
|
-
export abstract class PreferenceNodeRenderer implements Disposable, GeneralPreferenceNodeRenderer {
|
|
59
|
-
@inject(Preference.Node) protected readonly preferenceNode: Preference.Node;
|
|
60
|
-
@inject(PreferenceTreeLabelProvider) protected readonly labelProvider: PreferenceTreeLabelProvider;
|
|
61
|
-
|
|
62
|
-
protected attached = false;
|
|
63
|
-
|
|
64
|
-
_id: string;
|
|
65
|
-
_group: string;
|
|
66
|
-
_subgroup: string;
|
|
67
|
-
protected domNode: HTMLElement;
|
|
68
|
-
|
|
69
|
-
get node(): HTMLElement {
|
|
70
|
-
return this.domNode;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
get nodeId(): string {
|
|
74
|
-
return this.preferenceNode.id;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
get id(): string {
|
|
78
|
-
return this._id;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
get group(): string {
|
|
82
|
-
return this._group;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
get visible(): boolean {
|
|
86
|
-
return !this.node.classList.contains('hidden');
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
@postConstruct()
|
|
90
|
-
protected init(): void {
|
|
91
|
-
this.setId();
|
|
92
|
-
this.domNode = this.createDomNode();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
protected setId(): void {
|
|
96
|
-
const { id, group } = Preference.TreeNode.getGroupAndIdFromNodeId(this.preferenceNode.id);
|
|
97
|
-
const segments = id.split('.');
|
|
98
|
-
this._id = id;
|
|
99
|
-
this._group = group;
|
|
100
|
-
this._subgroup = (group === segments[0] ? segments[1] : segments[0]) ?? '';
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
protected abstract createDomNode(): HTMLElement;
|
|
104
|
-
|
|
105
|
-
protected getAdditionalNodeClassnames(): Iterable<string> {
|
|
106
|
-
return [];
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
insertBefore(nextSibling: HTMLElement): void {
|
|
110
|
-
nextSibling.insertAdjacentElement('beforebegin', this.domNode);
|
|
111
|
-
this.attached = true;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
insertAfter(previousSibling: HTMLElement): void {
|
|
115
|
-
previousSibling.insertAdjacentElement('afterend', this.domNode);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
appendTo(parent: HTMLElement): void {
|
|
119
|
-
parent.appendChild(this.domNode);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
prependTo(parent: HTMLElement): void {
|
|
123
|
-
parent.prepend(this.domNode);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
hide(): void {
|
|
127
|
-
this.domNode.classList.add('hidden');
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
show(): void {
|
|
131
|
-
this.domNode.classList.remove('hidden');
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
dispose(): void {
|
|
135
|
-
this.domNode.remove();
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export class PreferenceHeaderRenderer extends PreferenceNodeRenderer {
|
|
140
|
-
protected createDomNode(): HTMLElement {
|
|
141
|
-
const wrapper = document.createElement('ul');
|
|
142
|
-
wrapper.className = 'settings-section';
|
|
143
|
-
wrapper.id = `${this.preferenceNode.id}-editor`;
|
|
144
|
-
const isCategory = Preference.TreeNode.isTopLevel(this.preferenceNode);
|
|
145
|
-
const hierarchyClassName = isCategory ? HEADER_CLASS : SUBHEADER_CLASS;
|
|
146
|
-
const name = this.labelProvider.getName(this.preferenceNode);
|
|
147
|
-
const label = document.createElement('li');
|
|
148
|
-
label.classList.add('settings-section-title', hierarchyClassName);
|
|
149
|
-
label.textContent = name;
|
|
150
|
-
wrapper.appendChild(label);
|
|
151
|
-
return wrapper;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
@injectable()
|
|
156
|
-
export abstract class PreferenceLeafNodeRenderer<ValueType extends JSONValue, InteractableType extends HTMLElement>
|
|
157
|
-
extends PreferenceNodeRenderer
|
|
158
|
-
implements Required<GeneralPreferenceNodeRenderer> {
|
|
159
|
-
@inject(Preference.Node) protected override readonly preferenceNode: Preference.LeafNode;
|
|
160
|
-
@inject(PreferenceService) protected readonly preferenceService: PreferenceService;
|
|
161
|
-
@inject(ContextMenuRenderer) protected readonly menuRenderer: ContextMenuRenderer;
|
|
162
|
-
@inject(PreferencesScopeTabBar) protected readonly scopeTracker: PreferencesScopeTabBar;
|
|
163
|
-
@inject(PreferenceTreeModel) protected readonly model: PreferenceTreeModel;
|
|
164
|
-
@inject(PreferencesSearchbarWidget) protected readonly searchbar: PreferencesSearchbarWidget;
|
|
165
|
-
@inject(OpenerService) protected readonly openerService: OpenerService;
|
|
166
|
-
@inject(PreferenceMarkdownRenderer) protected readonly markdownRenderer: PreferenceMarkdownRenderer;
|
|
167
|
-
|
|
168
|
-
protected headlineWrapper: HTMLDivElement;
|
|
169
|
-
protected gutter: HTMLDivElement;
|
|
170
|
-
protected interactable: InteractableType;
|
|
171
|
-
protected inspection: PreferenceInspection<ValueType> | undefined;
|
|
172
|
-
protected isModifiedFromDefault = false;
|
|
173
|
-
|
|
174
|
-
get schema(): PreferenceDataProperty {
|
|
175
|
-
return this.preferenceNode.preference.data;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
@postConstruct()
|
|
179
|
-
protected override init(): void {
|
|
180
|
-
this.setId();
|
|
181
|
-
this.updateInspection();
|
|
182
|
-
this.domNode = this.createDomNode();
|
|
183
|
-
this.updateModificationStatus();
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
protected updateInspection(): void {
|
|
187
|
-
this.inspection = this.preferenceService.inspect<ValueType>(this.id, this.scopeTracker.currentScope.uri);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
protected openLink(event: MouseEvent): void {
|
|
191
|
-
if (event.target instanceof HTMLAnchorElement) {
|
|
192
|
-
event.preventDefault();
|
|
193
|
-
event.stopPropagation();
|
|
194
|
-
// Exclude right click
|
|
195
|
-
if (event.button < 2) {
|
|
196
|
-
const uri = new URI(event.target.href);
|
|
197
|
-
open(this.openerService, uri);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
protected createDomNode(): HTMLLIElement {
|
|
203
|
-
const wrapper = document.createElement('li');
|
|
204
|
-
wrapper.classList.add('single-pref');
|
|
205
|
-
wrapper.id = `${this.id}-editor`;
|
|
206
|
-
wrapper.tabIndex = 0;
|
|
207
|
-
wrapper.setAttribute('data-pref-id', this.id);
|
|
208
|
-
wrapper.setAttribute('data-node-id', this.preferenceNode.id);
|
|
209
|
-
|
|
210
|
-
const headlineWrapper = document.createElement('div');
|
|
211
|
-
headlineWrapper.classList.add('pref-name');
|
|
212
|
-
headlineWrapper.title = this.id;
|
|
213
|
-
this.headlineWrapper = headlineWrapper;
|
|
214
|
-
wrapper.appendChild(headlineWrapper);
|
|
215
|
-
|
|
216
|
-
this.updateHeadline();
|
|
217
|
-
|
|
218
|
-
const gutter = document.createElement('div');
|
|
219
|
-
gutter.classList.add('pref-context-gutter');
|
|
220
|
-
this.gutter = gutter;
|
|
221
|
-
wrapper.appendChild(gutter);
|
|
222
|
-
|
|
223
|
-
const cog = document.createElement('i');
|
|
224
|
-
cog.className = `${codicon('settings-gear', true)} settings-context-menu-btn`;
|
|
225
|
-
cog.setAttribute('aria-label', 'Open Context Menu');
|
|
226
|
-
cog.setAttribute('role', 'button');
|
|
227
|
-
cog.onclick = this.handleCogAction.bind(this);
|
|
228
|
-
cog.onkeydown = this.handleCogAction.bind(this);
|
|
229
|
-
cog.title = nls.localizeByDefault('More Actions...');
|
|
230
|
-
gutter.appendChild(cog);
|
|
231
|
-
|
|
232
|
-
const contentWrapper = document.createElement('div');
|
|
233
|
-
contentWrapper.classList.add('pref-content-container', ...this.getAdditionalNodeClassnames());
|
|
234
|
-
wrapper.appendChild(contentWrapper);
|
|
235
|
-
|
|
236
|
-
const { description, markdownDescription } = this.preferenceNode.preference.data;
|
|
237
|
-
if (markdownDescription || description) {
|
|
238
|
-
const descriptionWrapper = document.createElement('div');
|
|
239
|
-
descriptionWrapper.classList.add('pref-description');
|
|
240
|
-
if (markdownDescription) {
|
|
241
|
-
const renderedDescription = this.markdownRenderer.render(markdownDescription);
|
|
242
|
-
descriptionWrapper.onauxclick = this.openLink.bind(this);
|
|
243
|
-
descriptionWrapper.onclick = this.openLink.bind(this);
|
|
244
|
-
descriptionWrapper.oncontextmenu = () => false;
|
|
245
|
-
descriptionWrapper.innerHTML = DOMPurify.sanitize(renderedDescription, {
|
|
246
|
-
ALLOW_UNKNOWN_PROTOCOLS: true
|
|
247
|
-
});
|
|
248
|
-
} else if (description) {
|
|
249
|
-
descriptionWrapper.textContent = description;
|
|
250
|
-
}
|
|
251
|
-
contentWrapper.appendChild(descriptionWrapper);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const interactableWrapper = document.createElement('div');
|
|
255
|
-
interactableWrapper.classList.add('pref-input');
|
|
256
|
-
contentWrapper.appendChild(interactableWrapper);
|
|
257
|
-
this.createInteractable(interactableWrapper);
|
|
258
|
-
|
|
259
|
-
return wrapper;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
protected handleCogAction({ currentTarget }: KeyboardEvent | MouseEvent): void {
|
|
263
|
-
const value = Preference.getValueInScope(this.inspection, this.scopeTracker.currentScope.scope) ?? this.inspection?.defaultValue;
|
|
264
|
-
const target = currentTarget as HTMLElement | undefined;
|
|
265
|
-
if (target && value !== undefined) {
|
|
266
|
-
this.showCog();
|
|
267
|
-
const domRect = target.getBoundingClientRect();
|
|
268
|
-
this.menuRenderer.render({
|
|
269
|
-
menuPath: PreferenceMenus.PREFERENCE_EDITOR_CONTEXT_MENU,
|
|
270
|
-
anchor: { x: domRect.left, y: domRect.bottom },
|
|
271
|
-
args: [{ id: this.id, value }],
|
|
272
|
-
onHide: () => this.hideCog()
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
protected addModifiedMarking(): void {
|
|
278
|
-
this.gutter.classList.add('theia-mod-item-modified');
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
protected removeModifiedMarking(): void {
|
|
282
|
-
this.gutter.classList.remove('theia-mod-item-modified');
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
protected showCog(): void {
|
|
286
|
-
this.gutter.classList.add('show-cog');
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
protected hideCog(): void {
|
|
290
|
-
this.gutter.classList.remove('show-cog');
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
protected updateModificationStatus(knownCurrentValue?: JSONValue): void {
|
|
294
|
-
const wasModified = this.isModifiedFromDefault;
|
|
295
|
-
const { inspection } = this;
|
|
296
|
-
const valueInCurrentScope = knownCurrentValue ?? Preference.getValueInScope(inspection, this.scopeTracker.currentScope.scope);
|
|
297
|
-
this.isModifiedFromDefault = valueInCurrentScope !== undefined && !PreferenceProvider.deepEqual(valueInCurrentScope, inspection?.defaultValue);
|
|
298
|
-
if (wasModified !== this.isModifiedFromDefault) {
|
|
299
|
-
this.gutter.classList.toggle('theia-mod-item-modified', this.isModifiedFromDefault);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
protected updateHeadline(filtered = this.model.isFiltered): void {
|
|
304
|
-
const { headlineWrapper } = this;
|
|
305
|
-
if (this.headlineWrapper.childElementCount === 0) {
|
|
306
|
-
const name = this.labelProvider.getName(this.preferenceNode);
|
|
307
|
-
const nameWrapper = document.createElement('span');
|
|
308
|
-
nameWrapper.classList.add('preference-leaf-headline-name');
|
|
309
|
-
nameWrapper.textContent = name;
|
|
310
|
-
headlineWrapper.appendChild(nameWrapper);
|
|
311
|
-
}
|
|
312
|
-
const prefix = this.labelProvider.getPrefix(this.preferenceNode, filtered);
|
|
313
|
-
const currentFirstChild = headlineWrapper.children[0];
|
|
314
|
-
const currentFirstChildIsPrefix = currentFirstChild.classList.contains('preference-leaf-headline-prefix');
|
|
315
|
-
if (prefix) {
|
|
316
|
-
let prefixWrapper;
|
|
317
|
-
if (currentFirstChildIsPrefix) {
|
|
318
|
-
prefixWrapper = currentFirstChild;
|
|
319
|
-
} else {
|
|
320
|
-
prefixWrapper = document.createElement('span');
|
|
321
|
-
prefixWrapper.classList.add('preference-leaf-headline-prefix');
|
|
322
|
-
headlineWrapper.insertBefore(prefixWrapper, currentFirstChild);
|
|
323
|
-
}
|
|
324
|
-
prefixWrapper.textContent = prefix;
|
|
325
|
-
} else if (currentFirstChildIsPrefix) {
|
|
326
|
-
headlineWrapper.removeChild(currentFirstChild);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const currentLastChild = headlineWrapper.lastChild as HTMLElement;
|
|
330
|
-
if (currentLastChild.classList.contains('preference-leaf-headline-suffix')) {
|
|
331
|
-
this.compareOtherModifiedScopes(headlineWrapper, currentLastChild);
|
|
332
|
-
} else {
|
|
333
|
-
this.createOtherModifiedScopes(headlineWrapper);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
protected compareOtherModifiedScopes(headlineWrapper: HTMLDivElement, currentSuffix: HTMLElement): void {
|
|
338
|
-
const modifiedScopes = this.getModifiedScopesAsStrings();
|
|
339
|
-
if (modifiedScopes.length === 0) {
|
|
340
|
-
headlineWrapper.removeChild(currentSuffix);
|
|
341
|
-
} else {
|
|
342
|
-
|
|
343
|
-
const modifiedMessagePrefix = currentSuffix.children[0] as HTMLElement;
|
|
344
|
-
const newMessagePrefix = this.getModifiedMessagePrefix();
|
|
345
|
-
if (modifiedMessagePrefix.textContent !== newMessagePrefix) {
|
|
346
|
-
modifiedMessagePrefix.textContent = newMessagePrefix;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
const [firstModifiedScope, secondModifiedScope] = modifiedScopes;
|
|
350
|
-
|
|
351
|
-
const firstScopeMessage = currentSuffix.children[1] as HTMLElement;
|
|
352
|
-
const secondScopeMessage = currentSuffix.children[2] as HTMLElement;
|
|
353
|
-
firstScopeMessage.children[0].textContent = PreferenceScope[firstModifiedScope];
|
|
354
|
-
this.addEventHandlerToModifiedScope(firstModifiedScope, firstScopeMessage.children[0] as HTMLElement);
|
|
355
|
-
if (modifiedScopes.length === 1 && secondScopeMessage) {
|
|
356
|
-
currentSuffix.removeChild(secondScopeMessage);
|
|
357
|
-
} else if (modifiedScopes.length === 2 && !secondScopeMessage) {
|
|
358
|
-
const newSecondMessage = this.createModifiedScopeMessage(secondModifiedScope);
|
|
359
|
-
currentSuffix.appendChild(newSecondMessage);
|
|
360
|
-
}
|
|
361
|
-
// If both scopes are modified and both messages are present, do nothing.
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
protected createOtherModifiedScopes(headlineWrapper: HTMLDivElement): void {
|
|
366
|
-
const modifiedScopes = this.getModifiedScopesAsStrings();
|
|
367
|
-
if (modifiedScopes.length !== 0) {
|
|
368
|
-
const wrapper = document.createElement('i');
|
|
369
|
-
wrapper.classList.add('preference-leaf-headline-suffix');
|
|
370
|
-
headlineWrapper.appendChild(wrapper);
|
|
371
|
-
|
|
372
|
-
const messagePrefix = this.getModifiedMessagePrefix();
|
|
373
|
-
const messageWrapper = document.createElement('span');
|
|
374
|
-
messageWrapper.classList.add('preference-other-modified-scope-alert');
|
|
375
|
-
messageWrapper.textContent = messagePrefix;
|
|
376
|
-
wrapper.appendChild(messageWrapper);
|
|
377
|
-
modifiedScopes.forEach((scopeName, i) => {
|
|
378
|
-
const scopeWrapper = this.createModifiedScopeMessage(scopeName);
|
|
379
|
-
wrapper.appendChild(scopeWrapper);
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
protected createModifiedScopeMessage(scope: PreferenceScope): HTMLSpanElement {
|
|
385
|
-
const scopeWrapper = document.createElement('span');
|
|
386
|
-
scopeWrapper.classList.add('preference-modified-scope-wrapper');
|
|
387
|
-
const scopeInteractable = document.createElement('span');
|
|
388
|
-
scopeInteractable.classList.add('preference-scope-underlined');
|
|
389
|
-
const scopeName = PreferenceScope[scope];
|
|
390
|
-
this.addEventHandlerToModifiedScope(scope, scopeInteractable);
|
|
391
|
-
scopeInteractable.textContent = scopeName;
|
|
392
|
-
scopeWrapper.appendChild(scopeInteractable);
|
|
393
|
-
return scopeWrapper;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
protected getModifiedMessagePrefix(): string {
|
|
397
|
-
return (this.isModifiedFromDefault ? nls.localizeByDefault('Also modified in') : nls.localizeByDefault('Modified in')) + ': ';
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
protected addEventHandlerToModifiedScope(scope: PreferenceScope, scopeWrapper: HTMLElement): void {
|
|
401
|
-
if (scope === PreferenceScope.User || scope === PreferenceScope.Workspace) {
|
|
402
|
-
const eventHandler = () => {
|
|
403
|
-
this.scopeTracker.setScope(scope);
|
|
404
|
-
this.searchbar.updateSearchTerm(this.id);
|
|
405
|
-
};
|
|
406
|
-
scopeWrapper.onclick = eventHandler;
|
|
407
|
-
scopeWrapper.onkeydown = eventHandler;
|
|
408
|
-
scopeWrapper.tabIndex = 0;
|
|
409
|
-
} else {
|
|
410
|
-
scopeWrapper.onclick = null; // eslint-disable-line no-null/no-null
|
|
411
|
-
scopeWrapper.onkeydown = null; // eslint-disable-line no-null/no-null
|
|
412
|
-
scopeWrapper.tabIndex = -1;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
protected getModifiedScopesAsStrings(): PreferenceScope[] {
|
|
417
|
-
const currentScopeInView = this.scopeTracker.currentScope.scope;
|
|
418
|
-
const { inspection } = this;
|
|
419
|
-
const modifiedScopes = [];
|
|
420
|
-
if (inspection) {
|
|
421
|
-
for (const otherScope of [PreferenceScope.User, PreferenceScope.Workspace]) {
|
|
422
|
-
if (otherScope !== currentScopeInView) {
|
|
423
|
-
const valueInOtherScope = Preference.getValueInScope(inspection, otherScope);
|
|
424
|
-
if (valueInOtherScope !== undefined && !PreferenceProvider.deepEqual(valueInOtherScope, inspection.defaultValue)) {
|
|
425
|
-
modifiedScopes.push(otherScope);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
return modifiedScopes;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
// Many preferences allow `null` and even use it as a default regardless of the declared type.
|
|
434
|
-
protected getValue(): ValueType | null {
|
|
435
|
-
let currentValue = Preference.getValueInScope(this.inspection, this.scopeTracker.currentScope.scope);
|
|
436
|
-
if (currentValue === undefined) {
|
|
437
|
-
currentValue = this.inspection?.defaultValue;
|
|
438
|
-
}
|
|
439
|
-
return currentValue !== undefined ? currentValue : this.getFallbackValue();
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
protected setPreferenceWithDebounce = debounce(this.setPreferenceImmediately.bind(this), 500, { leading: false, trailing: true });
|
|
443
|
-
|
|
444
|
-
protected setPreferenceImmediately(value: ValueType | undefined): Promise<void> {
|
|
445
|
-
return this.preferenceService.set(this.id, value, this.scopeTracker.currentScope.scope, this.scopeTracker.currentScope.uri)
|
|
446
|
-
.catch(() => this.handleValueChange());
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
handleSearchChange(isFiltered = this.model.isFiltered): void {
|
|
450
|
-
this.updateHeadline(isFiltered);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
handleScopeChange(isFiltered = this.model.isFiltered): void {
|
|
454
|
-
this.handleValueChange();
|
|
455
|
-
this.updateHeadline(isFiltered);
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
handleValueChange(): void {
|
|
459
|
-
this.doHandleValueChange();
|
|
460
|
-
this.updateHeadline();
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
/**
|
|
464
|
-
* Should create an HTML element that the user can interact with to change the value of the preference.
|
|
465
|
-
* @param container the parent element for the interactable. This method is responsible for adding the new element to its parent.
|
|
466
|
-
*/
|
|
467
|
-
protected abstract createInteractable(container: HTMLElement): void;
|
|
468
|
-
/**
|
|
469
|
-
* @returns a fallback default value for a preference of the type implemented by a concrete leaf renderer
|
|
470
|
-
* This function is only called if the default value for a given preference is not specified in its schema.
|
|
471
|
-
*/
|
|
472
|
-
protected abstract getFallbackValue(): ValueType;
|
|
473
|
-
/**
|
|
474
|
-
* This function is responsible for reconciling the display of the preference value with the value reported by the PreferenceService.
|
|
475
|
-
*/
|
|
476
|
-
protected abstract doHandleValueChange(): void;
|
|
477
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2020 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 { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
|
|
18
|
+
import {
|
|
19
|
+
PreferenceService, ContextMenuRenderer, PreferenceInspection,
|
|
20
|
+
PreferenceScope, PreferenceProvider, codicon, OpenerService, open, PreferenceDataProperty
|
|
21
|
+
} from '@theia/core/lib/browser';
|
|
22
|
+
import { Preference, PreferenceMenus } from '../../util/preference-types';
|
|
23
|
+
import { PreferenceTreeLabelProvider } from '../../util/preference-tree-label-provider';
|
|
24
|
+
import { PreferencesScopeTabBar } from '../preference-scope-tabbar-widget';
|
|
25
|
+
import { Disposable, nls } from '@theia/core/lib/common';
|
|
26
|
+
import { JSONValue } from '@theia/core/shared/@phosphor/coreutils';
|
|
27
|
+
import debounce = require('@theia/core/shared/lodash.debounce');
|
|
28
|
+
import { PreferenceTreeModel } from '../../preference-tree-model';
|
|
29
|
+
import { PreferencesSearchbarWidget } from '../preference-searchbar-widget';
|
|
30
|
+
import * as DOMPurify from '@theia/core/shared/dompurify';
|
|
31
|
+
import URI from '@theia/core/lib/common/uri';
|
|
32
|
+
import { PreferenceMarkdownRenderer } from './preference-markdown-renderer';
|
|
33
|
+
|
|
34
|
+
export const PreferenceNodeRendererFactory = Symbol('PreferenceNodeRendererFactory');
|
|
35
|
+
export type PreferenceNodeRendererFactory = (node: Preference.TreeNode) => PreferenceNodeRenderer;
|
|
36
|
+
export const HEADER_CLASS = 'settings-section-category-title';
|
|
37
|
+
export const SUBHEADER_CLASS = 'settings-section-subcategory-title';
|
|
38
|
+
|
|
39
|
+
export interface GeneralPreferenceNodeRenderer extends Disposable {
|
|
40
|
+
node: HTMLElement;
|
|
41
|
+
id: string;
|
|
42
|
+
schema?: PreferenceDataProperty;
|
|
43
|
+
group: string;
|
|
44
|
+
nodeId: string;
|
|
45
|
+
visible: boolean;
|
|
46
|
+
insertBefore(nextSibling: HTMLElement): void;
|
|
47
|
+
insertAfter(previousSibling: HTMLElement): void;
|
|
48
|
+
appendTo(parent: HTMLElement): void;
|
|
49
|
+
prependTo(parent: HTMLElement): void;
|
|
50
|
+
handleValueChange?(): void;
|
|
51
|
+
handleSearchChange?(isFiltered?: boolean): void;
|
|
52
|
+
handleScopeChange?(isFiltered?: boolean): void;
|
|
53
|
+
hide(): void;
|
|
54
|
+
show(): void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@injectable()
|
|
58
|
+
export abstract class PreferenceNodeRenderer implements Disposable, GeneralPreferenceNodeRenderer {
|
|
59
|
+
@inject(Preference.Node) protected readonly preferenceNode: Preference.Node;
|
|
60
|
+
@inject(PreferenceTreeLabelProvider) protected readonly labelProvider: PreferenceTreeLabelProvider;
|
|
61
|
+
|
|
62
|
+
protected attached = false;
|
|
63
|
+
|
|
64
|
+
_id: string;
|
|
65
|
+
_group: string;
|
|
66
|
+
_subgroup: string;
|
|
67
|
+
protected domNode: HTMLElement;
|
|
68
|
+
|
|
69
|
+
get node(): HTMLElement {
|
|
70
|
+
return this.domNode;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
get nodeId(): string {
|
|
74
|
+
return this.preferenceNode.id;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get id(): string {
|
|
78
|
+
return this._id;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get group(): string {
|
|
82
|
+
return this._group;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get visible(): boolean {
|
|
86
|
+
return !this.node.classList.contains('hidden');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@postConstruct()
|
|
90
|
+
protected init(): void {
|
|
91
|
+
this.setId();
|
|
92
|
+
this.domNode = this.createDomNode();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
protected setId(): void {
|
|
96
|
+
const { id, group } = Preference.TreeNode.getGroupAndIdFromNodeId(this.preferenceNode.id);
|
|
97
|
+
const segments = id.split('.');
|
|
98
|
+
this._id = id;
|
|
99
|
+
this._group = group;
|
|
100
|
+
this._subgroup = (group === segments[0] ? segments[1] : segments[0]) ?? '';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
protected abstract createDomNode(): HTMLElement;
|
|
104
|
+
|
|
105
|
+
protected getAdditionalNodeClassnames(): Iterable<string> {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
insertBefore(nextSibling: HTMLElement): void {
|
|
110
|
+
nextSibling.insertAdjacentElement('beforebegin', this.domNode);
|
|
111
|
+
this.attached = true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
insertAfter(previousSibling: HTMLElement): void {
|
|
115
|
+
previousSibling.insertAdjacentElement('afterend', this.domNode);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
appendTo(parent: HTMLElement): void {
|
|
119
|
+
parent.appendChild(this.domNode);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
prependTo(parent: HTMLElement): void {
|
|
123
|
+
parent.prepend(this.domNode);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
hide(): void {
|
|
127
|
+
this.domNode.classList.add('hidden');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
show(): void {
|
|
131
|
+
this.domNode.classList.remove('hidden');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
dispose(): void {
|
|
135
|
+
this.domNode.remove();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export class PreferenceHeaderRenderer extends PreferenceNodeRenderer {
|
|
140
|
+
protected createDomNode(): HTMLElement {
|
|
141
|
+
const wrapper = document.createElement('ul');
|
|
142
|
+
wrapper.className = 'settings-section';
|
|
143
|
+
wrapper.id = `${this.preferenceNode.id}-editor`;
|
|
144
|
+
const isCategory = Preference.TreeNode.isTopLevel(this.preferenceNode);
|
|
145
|
+
const hierarchyClassName = isCategory ? HEADER_CLASS : SUBHEADER_CLASS;
|
|
146
|
+
const name = this.labelProvider.getName(this.preferenceNode);
|
|
147
|
+
const label = document.createElement('li');
|
|
148
|
+
label.classList.add('settings-section-title', hierarchyClassName);
|
|
149
|
+
label.textContent = name;
|
|
150
|
+
wrapper.appendChild(label);
|
|
151
|
+
return wrapper;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@injectable()
|
|
156
|
+
export abstract class PreferenceLeafNodeRenderer<ValueType extends JSONValue, InteractableType extends HTMLElement>
|
|
157
|
+
extends PreferenceNodeRenderer
|
|
158
|
+
implements Required<GeneralPreferenceNodeRenderer> {
|
|
159
|
+
@inject(Preference.Node) protected override readonly preferenceNode: Preference.LeafNode;
|
|
160
|
+
@inject(PreferenceService) protected readonly preferenceService: PreferenceService;
|
|
161
|
+
@inject(ContextMenuRenderer) protected readonly menuRenderer: ContextMenuRenderer;
|
|
162
|
+
@inject(PreferencesScopeTabBar) protected readonly scopeTracker: PreferencesScopeTabBar;
|
|
163
|
+
@inject(PreferenceTreeModel) protected readonly model: PreferenceTreeModel;
|
|
164
|
+
@inject(PreferencesSearchbarWidget) protected readonly searchbar: PreferencesSearchbarWidget;
|
|
165
|
+
@inject(OpenerService) protected readonly openerService: OpenerService;
|
|
166
|
+
@inject(PreferenceMarkdownRenderer) protected readonly markdownRenderer: PreferenceMarkdownRenderer;
|
|
167
|
+
|
|
168
|
+
protected headlineWrapper: HTMLDivElement;
|
|
169
|
+
protected gutter: HTMLDivElement;
|
|
170
|
+
protected interactable: InteractableType;
|
|
171
|
+
protected inspection: PreferenceInspection<ValueType> | undefined;
|
|
172
|
+
protected isModifiedFromDefault = false;
|
|
173
|
+
|
|
174
|
+
get schema(): PreferenceDataProperty {
|
|
175
|
+
return this.preferenceNode.preference.data;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
@postConstruct()
|
|
179
|
+
protected override init(): void {
|
|
180
|
+
this.setId();
|
|
181
|
+
this.updateInspection();
|
|
182
|
+
this.domNode = this.createDomNode();
|
|
183
|
+
this.updateModificationStatus();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
protected updateInspection(): void {
|
|
187
|
+
this.inspection = this.preferenceService.inspect<ValueType>(this.id, this.scopeTracker.currentScope.uri);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
protected openLink(event: MouseEvent): void {
|
|
191
|
+
if (event.target instanceof HTMLAnchorElement) {
|
|
192
|
+
event.preventDefault();
|
|
193
|
+
event.stopPropagation();
|
|
194
|
+
// Exclude right click
|
|
195
|
+
if (event.button < 2) {
|
|
196
|
+
const uri = new URI(event.target.href);
|
|
197
|
+
open(this.openerService, uri);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
protected createDomNode(): HTMLLIElement {
|
|
203
|
+
const wrapper = document.createElement('li');
|
|
204
|
+
wrapper.classList.add('single-pref');
|
|
205
|
+
wrapper.id = `${this.id}-editor`;
|
|
206
|
+
wrapper.tabIndex = 0;
|
|
207
|
+
wrapper.setAttribute('data-pref-id', this.id);
|
|
208
|
+
wrapper.setAttribute('data-node-id', this.preferenceNode.id);
|
|
209
|
+
|
|
210
|
+
const headlineWrapper = document.createElement('div');
|
|
211
|
+
headlineWrapper.classList.add('pref-name');
|
|
212
|
+
headlineWrapper.title = this.id;
|
|
213
|
+
this.headlineWrapper = headlineWrapper;
|
|
214
|
+
wrapper.appendChild(headlineWrapper);
|
|
215
|
+
|
|
216
|
+
this.updateHeadline();
|
|
217
|
+
|
|
218
|
+
const gutter = document.createElement('div');
|
|
219
|
+
gutter.classList.add('pref-context-gutter');
|
|
220
|
+
this.gutter = gutter;
|
|
221
|
+
wrapper.appendChild(gutter);
|
|
222
|
+
|
|
223
|
+
const cog = document.createElement('i');
|
|
224
|
+
cog.className = `${codicon('settings-gear', true)} settings-context-menu-btn`;
|
|
225
|
+
cog.setAttribute('aria-label', 'Open Context Menu');
|
|
226
|
+
cog.setAttribute('role', 'button');
|
|
227
|
+
cog.onclick = this.handleCogAction.bind(this);
|
|
228
|
+
cog.onkeydown = this.handleCogAction.bind(this);
|
|
229
|
+
cog.title = nls.localizeByDefault('More Actions...');
|
|
230
|
+
gutter.appendChild(cog);
|
|
231
|
+
|
|
232
|
+
const contentWrapper = document.createElement('div');
|
|
233
|
+
contentWrapper.classList.add('pref-content-container', ...this.getAdditionalNodeClassnames());
|
|
234
|
+
wrapper.appendChild(contentWrapper);
|
|
235
|
+
|
|
236
|
+
const { description, markdownDescription } = this.preferenceNode.preference.data;
|
|
237
|
+
if (markdownDescription || description) {
|
|
238
|
+
const descriptionWrapper = document.createElement('div');
|
|
239
|
+
descriptionWrapper.classList.add('pref-description');
|
|
240
|
+
if (markdownDescription) {
|
|
241
|
+
const renderedDescription = this.markdownRenderer.render(markdownDescription);
|
|
242
|
+
descriptionWrapper.onauxclick = this.openLink.bind(this);
|
|
243
|
+
descriptionWrapper.onclick = this.openLink.bind(this);
|
|
244
|
+
descriptionWrapper.oncontextmenu = () => false;
|
|
245
|
+
descriptionWrapper.innerHTML = DOMPurify.sanitize(renderedDescription, {
|
|
246
|
+
ALLOW_UNKNOWN_PROTOCOLS: true
|
|
247
|
+
});
|
|
248
|
+
} else if (description) {
|
|
249
|
+
descriptionWrapper.textContent = description;
|
|
250
|
+
}
|
|
251
|
+
contentWrapper.appendChild(descriptionWrapper);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const interactableWrapper = document.createElement('div');
|
|
255
|
+
interactableWrapper.classList.add('pref-input');
|
|
256
|
+
contentWrapper.appendChild(interactableWrapper);
|
|
257
|
+
this.createInteractable(interactableWrapper);
|
|
258
|
+
|
|
259
|
+
return wrapper;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
protected handleCogAction({ currentTarget }: KeyboardEvent | MouseEvent): void {
|
|
263
|
+
const value = Preference.getValueInScope(this.inspection, this.scopeTracker.currentScope.scope) ?? this.inspection?.defaultValue;
|
|
264
|
+
const target = currentTarget as HTMLElement | undefined;
|
|
265
|
+
if (target && value !== undefined) {
|
|
266
|
+
this.showCog();
|
|
267
|
+
const domRect = target.getBoundingClientRect();
|
|
268
|
+
this.menuRenderer.render({
|
|
269
|
+
menuPath: PreferenceMenus.PREFERENCE_EDITOR_CONTEXT_MENU,
|
|
270
|
+
anchor: { x: domRect.left, y: domRect.bottom },
|
|
271
|
+
args: [{ id: this.id, value }],
|
|
272
|
+
onHide: () => this.hideCog()
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
protected addModifiedMarking(): void {
|
|
278
|
+
this.gutter.classList.add('theia-mod-item-modified');
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
protected removeModifiedMarking(): void {
|
|
282
|
+
this.gutter.classList.remove('theia-mod-item-modified');
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
protected showCog(): void {
|
|
286
|
+
this.gutter.classList.add('show-cog');
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
protected hideCog(): void {
|
|
290
|
+
this.gutter.classList.remove('show-cog');
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
protected updateModificationStatus(knownCurrentValue?: JSONValue): void {
|
|
294
|
+
const wasModified = this.isModifiedFromDefault;
|
|
295
|
+
const { inspection } = this;
|
|
296
|
+
const valueInCurrentScope = knownCurrentValue ?? Preference.getValueInScope(inspection, this.scopeTracker.currentScope.scope);
|
|
297
|
+
this.isModifiedFromDefault = valueInCurrentScope !== undefined && !PreferenceProvider.deepEqual(valueInCurrentScope, inspection?.defaultValue);
|
|
298
|
+
if (wasModified !== this.isModifiedFromDefault) {
|
|
299
|
+
this.gutter.classList.toggle('theia-mod-item-modified', this.isModifiedFromDefault);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
protected updateHeadline(filtered = this.model.isFiltered): void {
|
|
304
|
+
const { headlineWrapper } = this;
|
|
305
|
+
if (this.headlineWrapper.childElementCount === 0) {
|
|
306
|
+
const name = this.labelProvider.getName(this.preferenceNode);
|
|
307
|
+
const nameWrapper = document.createElement('span');
|
|
308
|
+
nameWrapper.classList.add('preference-leaf-headline-name');
|
|
309
|
+
nameWrapper.textContent = name;
|
|
310
|
+
headlineWrapper.appendChild(nameWrapper);
|
|
311
|
+
}
|
|
312
|
+
const prefix = this.labelProvider.getPrefix(this.preferenceNode, filtered);
|
|
313
|
+
const currentFirstChild = headlineWrapper.children[0];
|
|
314
|
+
const currentFirstChildIsPrefix = currentFirstChild.classList.contains('preference-leaf-headline-prefix');
|
|
315
|
+
if (prefix) {
|
|
316
|
+
let prefixWrapper;
|
|
317
|
+
if (currentFirstChildIsPrefix) {
|
|
318
|
+
prefixWrapper = currentFirstChild;
|
|
319
|
+
} else {
|
|
320
|
+
prefixWrapper = document.createElement('span');
|
|
321
|
+
prefixWrapper.classList.add('preference-leaf-headline-prefix');
|
|
322
|
+
headlineWrapper.insertBefore(prefixWrapper, currentFirstChild);
|
|
323
|
+
}
|
|
324
|
+
prefixWrapper.textContent = prefix;
|
|
325
|
+
} else if (currentFirstChildIsPrefix) {
|
|
326
|
+
headlineWrapper.removeChild(currentFirstChild);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const currentLastChild = headlineWrapper.lastChild as HTMLElement;
|
|
330
|
+
if (currentLastChild.classList.contains('preference-leaf-headline-suffix')) {
|
|
331
|
+
this.compareOtherModifiedScopes(headlineWrapper, currentLastChild);
|
|
332
|
+
} else {
|
|
333
|
+
this.createOtherModifiedScopes(headlineWrapper);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
protected compareOtherModifiedScopes(headlineWrapper: HTMLDivElement, currentSuffix: HTMLElement): void {
|
|
338
|
+
const modifiedScopes = this.getModifiedScopesAsStrings();
|
|
339
|
+
if (modifiedScopes.length === 0) {
|
|
340
|
+
headlineWrapper.removeChild(currentSuffix);
|
|
341
|
+
} else {
|
|
342
|
+
|
|
343
|
+
const modifiedMessagePrefix = currentSuffix.children[0] as HTMLElement;
|
|
344
|
+
const newMessagePrefix = this.getModifiedMessagePrefix();
|
|
345
|
+
if (modifiedMessagePrefix.textContent !== newMessagePrefix) {
|
|
346
|
+
modifiedMessagePrefix.textContent = newMessagePrefix;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const [firstModifiedScope, secondModifiedScope] = modifiedScopes;
|
|
350
|
+
|
|
351
|
+
const firstScopeMessage = currentSuffix.children[1] as HTMLElement;
|
|
352
|
+
const secondScopeMessage = currentSuffix.children[2] as HTMLElement;
|
|
353
|
+
firstScopeMessage.children[0].textContent = PreferenceScope[firstModifiedScope];
|
|
354
|
+
this.addEventHandlerToModifiedScope(firstModifiedScope, firstScopeMessage.children[0] as HTMLElement);
|
|
355
|
+
if (modifiedScopes.length === 1 && secondScopeMessage) {
|
|
356
|
+
currentSuffix.removeChild(secondScopeMessage);
|
|
357
|
+
} else if (modifiedScopes.length === 2 && !secondScopeMessage) {
|
|
358
|
+
const newSecondMessage = this.createModifiedScopeMessage(secondModifiedScope);
|
|
359
|
+
currentSuffix.appendChild(newSecondMessage);
|
|
360
|
+
}
|
|
361
|
+
// If both scopes are modified and both messages are present, do nothing.
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
protected createOtherModifiedScopes(headlineWrapper: HTMLDivElement): void {
|
|
366
|
+
const modifiedScopes = this.getModifiedScopesAsStrings();
|
|
367
|
+
if (modifiedScopes.length !== 0) {
|
|
368
|
+
const wrapper = document.createElement('i');
|
|
369
|
+
wrapper.classList.add('preference-leaf-headline-suffix');
|
|
370
|
+
headlineWrapper.appendChild(wrapper);
|
|
371
|
+
|
|
372
|
+
const messagePrefix = this.getModifiedMessagePrefix();
|
|
373
|
+
const messageWrapper = document.createElement('span');
|
|
374
|
+
messageWrapper.classList.add('preference-other-modified-scope-alert');
|
|
375
|
+
messageWrapper.textContent = messagePrefix;
|
|
376
|
+
wrapper.appendChild(messageWrapper);
|
|
377
|
+
modifiedScopes.forEach((scopeName, i) => {
|
|
378
|
+
const scopeWrapper = this.createModifiedScopeMessage(scopeName);
|
|
379
|
+
wrapper.appendChild(scopeWrapper);
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
protected createModifiedScopeMessage(scope: PreferenceScope): HTMLSpanElement {
|
|
385
|
+
const scopeWrapper = document.createElement('span');
|
|
386
|
+
scopeWrapper.classList.add('preference-modified-scope-wrapper');
|
|
387
|
+
const scopeInteractable = document.createElement('span');
|
|
388
|
+
scopeInteractable.classList.add('preference-scope-underlined');
|
|
389
|
+
const scopeName = PreferenceScope[scope];
|
|
390
|
+
this.addEventHandlerToModifiedScope(scope, scopeInteractable);
|
|
391
|
+
scopeInteractable.textContent = scopeName;
|
|
392
|
+
scopeWrapper.appendChild(scopeInteractable);
|
|
393
|
+
return scopeWrapper;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
protected getModifiedMessagePrefix(): string {
|
|
397
|
+
return (this.isModifiedFromDefault ? nls.localizeByDefault('Also modified in') : nls.localizeByDefault('Modified in')) + ': ';
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
protected addEventHandlerToModifiedScope(scope: PreferenceScope, scopeWrapper: HTMLElement): void {
|
|
401
|
+
if (scope === PreferenceScope.User || scope === PreferenceScope.Workspace) {
|
|
402
|
+
const eventHandler = () => {
|
|
403
|
+
this.scopeTracker.setScope(scope);
|
|
404
|
+
this.searchbar.updateSearchTerm(this.id);
|
|
405
|
+
};
|
|
406
|
+
scopeWrapper.onclick = eventHandler;
|
|
407
|
+
scopeWrapper.onkeydown = eventHandler;
|
|
408
|
+
scopeWrapper.tabIndex = 0;
|
|
409
|
+
} else {
|
|
410
|
+
scopeWrapper.onclick = null; // eslint-disable-line no-null/no-null
|
|
411
|
+
scopeWrapper.onkeydown = null; // eslint-disable-line no-null/no-null
|
|
412
|
+
scopeWrapper.tabIndex = -1;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
protected getModifiedScopesAsStrings(): PreferenceScope[] {
|
|
417
|
+
const currentScopeInView = this.scopeTracker.currentScope.scope;
|
|
418
|
+
const { inspection } = this;
|
|
419
|
+
const modifiedScopes = [];
|
|
420
|
+
if (inspection) {
|
|
421
|
+
for (const otherScope of [PreferenceScope.User, PreferenceScope.Workspace]) {
|
|
422
|
+
if (otherScope !== currentScopeInView) {
|
|
423
|
+
const valueInOtherScope = Preference.getValueInScope(inspection, otherScope);
|
|
424
|
+
if (valueInOtherScope !== undefined && !PreferenceProvider.deepEqual(valueInOtherScope, inspection.defaultValue)) {
|
|
425
|
+
modifiedScopes.push(otherScope);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return modifiedScopes;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// Many preferences allow `null` and even use it as a default regardless of the declared type.
|
|
434
|
+
protected getValue(): ValueType | null {
|
|
435
|
+
let currentValue = Preference.getValueInScope(this.inspection, this.scopeTracker.currentScope.scope);
|
|
436
|
+
if (currentValue === undefined) {
|
|
437
|
+
currentValue = this.inspection?.defaultValue;
|
|
438
|
+
}
|
|
439
|
+
return currentValue !== undefined ? currentValue : this.getFallbackValue();
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
protected setPreferenceWithDebounce = debounce(this.setPreferenceImmediately.bind(this), 500, { leading: false, trailing: true });
|
|
443
|
+
|
|
444
|
+
protected setPreferenceImmediately(value: ValueType | undefined): Promise<void> {
|
|
445
|
+
return this.preferenceService.set(this.id, value, this.scopeTracker.currentScope.scope, this.scopeTracker.currentScope.uri)
|
|
446
|
+
.catch(() => this.handleValueChange());
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
handleSearchChange(isFiltered = this.model.isFiltered): void {
|
|
450
|
+
this.updateHeadline(isFiltered);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
handleScopeChange(isFiltered = this.model.isFiltered): void {
|
|
454
|
+
this.handleValueChange();
|
|
455
|
+
this.updateHeadline(isFiltered);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
handleValueChange(): void {
|
|
459
|
+
this.doHandleValueChange();
|
|
460
|
+
this.updateHeadline();
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Should create an HTML element that the user can interact with to change the value of the preference.
|
|
465
|
+
* @param container the parent element for the interactable. This method is responsible for adding the new element to its parent.
|
|
466
|
+
*/
|
|
467
|
+
protected abstract createInteractable(container: HTMLElement): void;
|
|
468
|
+
/**
|
|
469
|
+
* @returns a fallback default value for a preference of the type implemented by a concrete leaf renderer
|
|
470
|
+
* This function is only called if the default value for a given preference is not specified in its schema.
|
|
471
|
+
*/
|
|
472
|
+
protected abstract getFallbackValue(): ValueType;
|
|
473
|
+
/**
|
|
474
|
+
* This function is responsible for reconciling the display of the preference value with the value reported by the PreferenceService.
|
|
475
|
+
*/
|
|
476
|
+
protected abstract doHandleValueChange(): void;
|
|
477
|
+
}
|