@theia/preferences 1.53.0-next.4 → 1.53.0-next.55
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/preference-tree-model.d.ts.map +1 -1
- package/lib/browser/preference-tree-model.js +5 -2
- package/lib/browser/preference-tree-model.js.map +1 -1
- package/lib/browser/util/preference-layout.d.ts.map +1 -1
- package/lib/browser/util/preference-layout.js +4 -0
- package/lib/browser/util/preference-layout.js.map +1 -1
- package/lib/browser/util/preference-tree-generator.d.ts +14 -2
- package/lib/browser/util/preference-tree-generator.d.ts.map +1 -1
- package/lib/browser/util/preference-tree-generator.js +89 -26
- package/lib/browser/util/preference-tree-generator.js.map +1 -1
- package/lib/browser/util/preference-tree-label-provider.d.ts.map +1 -1
- package/lib/browser/util/preference-tree-label-provider.js +4 -11
- package/lib/browser/util/preference-tree-label-provider.js.map +1 -1
- package/lib/browser/util/preference-types.d.ts +4 -2
- package/lib/browser/util/preference-types.d.ts.map +1 -1
- package/lib/browser/util/preference-types.js.map +1 -1
- package/lib/browser/views/preference-tree-widget.d.ts +2 -0
- package/lib/browser/views/preference-tree-widget.d.ts.map +1 -1
- package/lib/browser/views/preference-tree-widget.js +10 -1
- package/lib/browser/views/preference-tree-widget.js.map +1 -1
- package/package.json +9 -9
- 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-contribution.ts +38 -38
- package/src/browser/preference-frontend-module.ts +66 -66
- 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 +260 -257
- 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-layout.ts +381 -377
- package/src/browser/util/preference-scope-command-manager.ts +75 -75
- package/src/browser/util/preference-tree-generator.ts +260 -190
- package/src/browser/util/preference-tree-label-provider.spec.ts +110 -110
- package/src/browser/util/preference-tree-label-provider.ts +72 -78
- package/src/browser/util/preference-types.ts +177 -175
- 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 +102 -93
- package/src/browser/views/preference-widget-bindings.ts +102 -102
- package/src/browser/views/preference-widget.tsx +118 -118
- package/src/browser/workspace-file-preference-provider.ts +100 -100
- package/src/browser/workspace-preference-provider.ts +134 -134
- package/src/common/cli-preferences.ts +22 -22
- package/src/node/preference-backend-module.ts +33 -33
- package/src/node/preference-cli-contribution.ts +48 -48
|
@@ -1,183 +1,183 @@
|
|
|
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 { codicon, ReactWidget, StatefulWidget, Widget } from '@theia/core/lib/browser';
|
|
18
|
-
import { injectable, postConstruct, unmanaged } from '@theia/core/shared/inversify';
|
|
19
|
-
import * as React from '@theia/core/shared/react';
|
|
20
|
-
import debounce = require('p-debounce');
|
|
21
|
-
import { Emitter } from '@theia/core';
|
|
22
|
-
import { nls } from '@theia/core/lib/common/nls';
|
|
23
|
-
|
|
24
|
-
export interface PreferencesSearchbarState {
|
|
25
|
-
searchTerm: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@injectable()
|
|
29
|
-
export class PreferencesSearchbarWidget extends ReactWidget implements StatefulWidget {
|
|
30
|
-
static readonly ID = 'settings.header';
|
|
31
|
-
static readonly LABEL = 'Settings Header';
|
|
32
|
-
static readonly SEARCHBAR_ID = 'preference-searchbar';
|
|
33
|
-
|
|
34
|
-
protected readonly onFilterStringChangedEmitter = new Emitter<string>();
|
|
35
|
-
readonly onFilterChanged = this.onFilterStringChangedEmitter.event;
|
|
36
|
-
|
|
37
|
-
protected searchbarRef: React.RefObject<HTMLInputElement> = React.createRef<HTMLInputElement>();
|
|
38
|
-
protected resultsCount: number = 0;
|
|
39
|
-
|
|
40
|
-
constructor(@unmanaged() options?: Widget.IOptions) {
|
|
41
|
-
super(options);
|
|
42
|
-
this.focus = this.focus.bind(this);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@postConstruct()
|
|
46
|
-
protected init(): void {
|
|
47
|
-
this.id = PreferencesSearchbarWidget.ID;
|
|
48
|
-
this.title.label = PreferencesSearchbarWidget.LABEL;
|
|
49
|
-
this.update();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
protected handleSearch = (e: React.ChangeEvent<HTMLInputElement>): Promise<void> => this.search(e.target.value);
|
|
53
|
-
|
|
54
|
-
protected search = debounce(async (value: string) => {
|
|
55
|
-
this.onFilterStringChangedEmitter.fire(value);
|
|
56
|
-
this.update();
|
|
57
|
-
}, 200);
|
|
58
|
-
|
|
59
|
-
focus(): void {
|
|
60
|
-
if (this.searchbarRef.current) {
|
|
61
|
-
this.searchbarRef.current.focus();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Clears the search input and all search results.
|
|
67
|
-
* @param e on-click mouse event.
|
|
68
|
-
*/
|
|
69
|
-
protected clearSearchResults = async (e: React.MouseEvent): Promise<void> => {
|
|
70
|
-
const search = document.getElementById(PreferencesSearchbarWidget.SEARCHBAR_ID) as HTMLInputElement;
|
|
71
|
-
if (search) {
|
|
72
|
-
search.value = '';
|
|
73
|
-
await this.search(search.value);
|
|
74
|
-
this.update();
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Renders all search bar options.
|
|
80
|
-
*/
|
|
81
|
-
protected renderOptionContainer(): React.ReactNode {
|
|
82
|
-
const resultsCount = this.renderResultsCountOption();
|
|
83
|
-
const clearAllOption = this.renderClearAllOption();
|
|
84
|
-
return <div className="option-buttons"> {resultsCount} {clearAllOption} </div>;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Renders a badge displaying search results count.
|
|
89
|
-
*/
|
|
90
|
-
protected renderResultsCountOption(): React.ReactNode {
|
|
91
|
-
let resultsFound: string;
|
|
92
|
-
if (this.resultsCount === 0) {
|
|
93
|
-
resultsFound = nls.localizeByDefault('No Settings Found');
|
|
94
|
-
} else if (this.resultsCount === 1) {
|
|
95
|
-
resultsFound = nls.localizeByDefault('1 Setting Found');
|
|
96
|
-
} else {
|
|
97
|
-
resultsFound = nls.localizeByDefault('{0} Settings Found', this.resultsCount.toFixed(0));
|
|
98
|
-
}
|
|
99
|
-
return this.searchTermExists() ?
|
|
100
|
-
(<span
|
|
101
|
-
className="results-found"
|
|
102
|
-
title={resultsFound}>
|
|
103
|
-
{resultsFound}
|
|
104
|
-
</span>)
|
|
105
|
-
: '';
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Renders a clear all button.
|
|
110
|
-
*/
|
|
111
|
-
protected renderClearAllOption(): React.ReactNode {
|
|
112
|
-
return <span
|
|
113
|
-
className={`${codicon('clear-all')} option ${(this.searchTermExists() ? 'enabled' : '')}`}
|
|
114
|
-
title={nls.localizeByDefault('Clear Search Results')}
|
|
115
|
-
onClick={this.clearSearchResults}
|
|
116
|
-
/>;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Determines whether the search input currently has a value.
|
|
121
|
-
* @returns true, if the search input currently has a value; false, otherwise.
|
|
122
|
-
*/
|
|
123
|
-
protected searchTermExists(): boolean {
|
|
124
|
-
return !!this.searchbarRef.current?.value;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
protected getSearchTerm(): string {
|
|
128
|
-
const search = document.getElementById(PreferencesSearchbarWidget.SEARCHBAR_ID) as HTMLInputElement;
|
|
129
|
-
return search?.value;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async updateSearchTerm(searchTerm: string): Promise<void> {
|
|
133
|
-
const search = document.getElementById(PreferencesSearchbarWidget.SEARCHBAR_ID) as HTMLInputElement;
|
|
134
|
-
if (!search || search.value === searchTerm) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
search.value = searchTerm;
|
|
138
|
-
await this.search(search.value);
|
|
139
|
-
this.update();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
render(): React.ReactNode {
|
|
143
|
-
const optionContainer = this.renderOptionContainer();
|
|
144
|
-
return (
|
|
145
|
-
<div className='settings-header'>
|
|
146
|
-
<div className="settings-search-container" ref={this.focus}>
|
|
147
|
-
<input
|
|
148
|
-
type="text"
|
|
149
|
-
id={PreferencesSearchbarWidget.SEARCHBAR_ID}
|
|
150
|
-
spellCheck={false}
|
|
151
|
-
placeholder={nls.localizeByDefault('Search settings')}
|
|
152
|
-
className="settings-search-input theia-input"
|
|
153
|
-
onChange={this.handleSearch}
|
|
154
|
-
ref={this.searchbarRef}
|
|
155
|
-
/>
|
|
156
|
-
{optionContainer}
|
|
157
|
-
</div>
|
|
158
|
-
</div >
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Updates the search result count.
|
|
164
|
-
* @param count the result count.
|
|
165
|
-
*/
|
|
166
|
-
updateResultsCount(count: number): void {
|
|
167
|
-
this.resultsCount = count;
|
|
168
|
-
this.update();
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
storeState(): PreferencesSearchbarState {
|
|
172
|
-
return {
|
|
173
|
-
searchTerm: this.getSearchTerm()
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
restoreState(oldState: PreferencesSearchbarState): void {
|
|
178
|
-
const searchInputExists = this.onDidChangeVisibility(() => {
|
|
179
|
-
this.updateSearchTerm(oldState.searchTerm || '');
|
|
180
|
-
searchInputExists.dispose();
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
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 { codicon, ReactWidget, StatefulWidget, Widget } from '@theia/core/lib/browser';
|
|
18
|
+
import { injectable, postConstruct, unmanaged } from '@theia/core/shared/inversify';
|
|
19
|
+
import * as React from '@theia/core/shared/react';
|
|
20
|
+
import debounce = require('p-debounce');
|
|
21
|
+
import { Emitter } from '@theia/core';
|
|
22
|
+
import { nls } from '@theia/core/lib/common/nls';
|
|
23
|
+
|
|
24
|
+
export interface PreferencesSearchbarState {
|
|
25
|
+
searchTerm: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@injectable()
|
|
29
|
+
export class PreferencesSearchbarWidget extends ReactWidget implements StatefulWidget {
|
|
30
|
+
static readonly ID = 'settings.header';
|
|
31
|
+
static readonly LABEL = 'Settings Header';
|
|
32
|
+
static readonly SEARCHBAR_ID = 'preference-searchbar';
|
|
33
|
+
|
|
34
|
+
protected readonly onFilterStringChangedEmitter = new Emitter<string>();
|
|
35
|
+
readonly onFilterChanged = this.onFilterStringChangedEmitter.event;
|
|
36
|
+
|
|
37
|
+
protected searchbarRef: React.RefObject<HTMLInputElement> = React.createRef<HTMLInputElement>();
|
|
38
|
+
protected resultsCount: number = 0;
|
|
39
|
+
|
|
40
|
+
constructor(@unmanaged() options?: Widget.IOptions) {
|
|
41
|
+
super(options);
|
|
42
|
+
this.focus = this.focus.bind(this);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@postConstruct()
|
|
46
|
+
protected init(): void {
|
|
47
|
+
this.id = PreferencesSearchbarWidget.ID;
|
|
48
|
+
this.title.label = PreferencesSearchbarWidget.LABEL;
|
|
49
|
+
this.update();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
protected handleSearch = (e: React.ChangeEvent<HTMLInputElement>): Promise<void> => this.search(e.target.value);
|
|
53
|
+
|
|
54
|
+
protected search = debounce(async (value: string) => {
|
|
55
|
+
this.onFilterStringChangedEmitter.fire(value);
|
|
56
|
+
this.update();
|
|
57
|
+
}, 200);
|
|
58
|
+
|
|
59
|
+
focus(): void {
|
|
60
|
+
if (this.searchbarRef.current) {
|
|
61
|
+
this.searchbarRef.current.focus();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Clears the search input and all search results.
|
|
67
|
+
* @param e on-click mouse event.
|
|
68
|
+
*/
|
|
69
|
+
protected clearSearchResults = async (e: React.MouseEvent): Promise<void> => {
|
|
70
|
+
const search = document.getElementById(PreferencesSearchbarWidget.SEARCHBAR_ID) as HTMLInputElement;
|
|
71
|
+
if (search) {
|
|
72
|
+
search.value = '';
|
|
73
|
+
await this.search(search.value);
|
|
74
|
+
this.update();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Renders all search bar options.
|
|
80
|
+
*/
|
|
81
|
+
protected renderOptionContainer(): React.ReactNode {
|
|
82
|
+
const resultsCount = this.renderResultsCountOption();
|
|
83
|
+
const clearAllOption = this.renderClearAllOption();
|
|
84
|
+
return <div className="option-buttons"> {resultsCount} {clearAllOption} </div>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Renders a badge displaying search results count.
|
|
89
|
+
*/
|
|
90
|
+
protected renderResultsCountOption(): React.ReactNode {
|
|
91
|
+
let resultsFound: string;
|
|
92
|
+
if (this.resultsCount === 0) {
|
|
93
|
+
resultsFound = nls.localizeByDefault('No Settings Found');
|
|
94
|
+
} else if (this.resultsCount === 1) {
|
|
95
|
+
resultsFound = nls.localizeByDefault('1 Setting Found');
|
|
96
|
+
} else {
|
|
97
|
+
resultsFound = nls.localizeByDefault('{0} Settings Found', this.resultsCount.toFixed(0));
|
|
98
|
+
}
|
|
99
|
+
return this.searchTermExists() ?
|
|
100
|
+
(<span
|
|
101
|
+
className="results-found"
|
|
102
|
+
title={resultsFound}>
|
|
103
|
+
{resultsFound}
|
|
104
|
+
</span>)
|
|
105
|
+
: '';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Renders a clear all button.
|
|
110
|
+
*/
|
|
111
|
+
protected renderClearAllOption(): React.ReactNode {
|
|
112
|
+
return <span
|
|
113
|
+
className={`${codicon('clear-all')} option ${(this.searchTermExists() ? 'enabled' : '')}`}
|
|
114
|
+
title={nls.localizeByDefault('Clear Search Results')}
|
|
115
|
+
onClick={this.clearSearchResults}
|
|
116
|
+
/>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Determines whether the search input currently has a value.
|
|
121
|
+
* @returns true, if the search input currently has a value; false, otherwise.
|
|
122
|
+
*/
|
|
123
|
+
protected searchTermExists(): boolean {
|
|
124
|
+
return !!this.searchbarRef.current?.value;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
protected getSearchTerm(): string {
|
|
128
|
+
const search = document.getElementById(PreferencesSearchbarWidget.SEARCHBAR_ID) as HTMLInputElement;
|
|
129
|
+
return search?.value;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async updateSearchTerm(searchTerm: string): Promise<void> {
|
|
133
|
+
const search = document.getElementById(PreferencesSearchbarWidget.SEARCHBAR_ID) as HTMLInputElement;
|
|
134
|
+
if (!search || search.value === searchTerm) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
search.value = searchTerm;
|
|
138
|
+
await this.search(search.value);
|
|
139
|
+
this.update();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
render(): React.ReactNode {
|
|
143
|
+
const optionContainer = this.renderOptionContainer();
|
|
144
|
+
return (
|
|
145
|
+
<div className='settings-header'>
|
|
146
|
+
<div className="settings-search-container" ref={this.focus}>
|
|
147
|
+
<input
|
|
148
|
+
type="text"
|
|
149
|
+
id={PreferencesSearchbarWidget.SEARCHBAR_ID}
|
|
150
|
+
spellCheck={false}
|
|
151
|
+
placeholder={nls.localizeByDefault('Search settings')}
|
|
152
|
+
className="settings-search-input theia-input"
|
|
153
|
+
onChange={this.handleSearch}
|
|
154
|
+
ref={this.searchbarRef}
|
|
155
|
+
/>
|
|
156
|
+
{optionContainer}
|
|
157
|
+
</div>
|
|
158
|
+
</div >
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Updates the search result count.
|
|
164
|
+
* @param count the result count.
|
|
165
|
+
*/
|
|
166
|
+
updateResultsCount(count: number): void {
|
|
167
|
+
this.resultsCount = count;
|
|
168
|
+
this.update();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
storeState(): PreferencesSearchbarState {
|
|
172
|
+
return {
|
|
173
|
+
searchTerm: this.getSearchTerm()
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
restoreState(oldState: PreferencesSearchbarState): void {
|
|
178
|
+
const searchInputExists = this.onDidChangeVisibility(() => {
|
|
179
|
+
this.updateSearchTerm(oldState.searchTerm || '');
|
|
180
|
+
searchInputExists.dispose();
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
@@ -1,93 +1,102 @@
|
|
|
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 { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
18
|
-
import {
|
|
19
|
-
ExpandableTreeNode,
|
|
20
|
-
TreeNode,
|
|
21
|
-
TreeProps,
|
|
22
|
-
TreeWidget,
|
|
23
|
-
TREE_NODE_CONTENT_CLASS,
|
|
24
|
-
} from '@theia/core/lib/browser';
|
|
25
|
-
import React = require('@theia/core/shared/react');
|
|
26
|
-
import { PreferenceTreeModel, PreferenceTreeNodeRow, PreferenceTreeNodeProps } from '../preference-tree-model';
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
protected
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
@inject(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
this.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return
|
|
92
|
-
}
|
|
93
|
-
|
|
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 { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
18
|
+
import {
|
|
19
|
+
ExpandableTreeNode,
|
|
20
|
+
TreeNode,
|
|
21
|
+
TreeProps,
|
|
22
|
+
TreeWidget,
|
|
23
|
+
TREE_NODE_CONTENT_CLASS,
|
|
24
|
+
} from '@theia/core/lib/browser';
|
|
25
|
+
import React = require('@theia/core/shared/react');
|
|
26
|
+
import { PreferenceTreeModel, PreferenceTreeNodeRow, PreferenceTreeNodeProps } from '../preference-tree-model';
|
|
27
|
+
import { Preference } from '../util/preference-types';
|
|
28
|
+
|
|
29
|
+
@injectable()
|
|
30
|
+
export class PreferencesTreeWidget extends TreeWidget {
|
|
31
|
+
static ID = 'preferences.tree';
|
|
32
|
+
|
|
33
|
+
protected shouldFireSelectionEvents: boolean = true;
|
|
34
|
+
protected firstVisibleLeafNodeID: string;
|
|
35
|
+
|
|
36
|
+
@inject(PreferenceTreeModel) override readonly model: PreferenceTreeModel;
|
|
37
|
+
@inject(TreeProps) protected readonly treeProps: TreeProps;
|
|
38
|
+
|
|
39
|
+
@postConstruct()
|
|
40
|
+
override init(): void {
|
|
41
|
+
super.init();
|
|
42
|
+
this.id = PreferencesTreeWidget.ID;
|
|
43
|
+
this.toDispose.pushAll([
|
|
44
|
+
this.model.onFilterChanged(() => {
|
|
45
|
+
this.updateRows();
|
|
46
|
+
}),
|
|
47
|
+
]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
override doUpdateRows(): void {
|
|
51
|
+
this.rows = new Map();
|
|
52
|
+
let index = 0;
|
|
53
|
+
for (const [id, nodeRow] of this.model.currentRows.entries()) {
|
|
54
|
+
if (nodeRow.visibleChildren > 0 && this.isVisibleNode(nodeRow.node)) {
|
|
55
|
+
this.rows.set(id, { ...nodeRow, index: index++ });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
this.updateScrollToRow();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected isVisibleNode(node: Preference.TreeNode): boolean {
|
|
62
|
+
if (Preference.TreeNode.isTopLevel(node)) {
|
|
63
|
+
return true;
|
|
64
|
+
} else {
|
|
65
|
+
return ExpandableTreeNode.isExpanded(node.parent) && Preference.TreeNode.is(node.parent) && this.isVisibleNode(node.parent);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
protected override doRenderNodeRow({ depth, visibleChildren, node, isExpansible }: PreferenceTreeNodeRow): React.ReactNode {
|
|
70
|
+
return this.renderNode(node, { depth, visibleChildren, isExpansible });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
protected override renderNode(node: TreeNode, props: PreferenceTreeNodeProps): React.ReactNode {
|
|
74
|
+
if (!TreeNode.isVisible(node)) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const attributes = this.createNodeAttributes(node, props);
|
|
79
|
+
|
|
80
|
+
const content = <div className={TREE_NODE_CONTENT_CLASS}>
|
|
81
|
+
{this.renderExpansionToggle(node, props)}
|
|
82
|
+
{this.renderCaption(node, props)}
|
|
83
|
+
</div>;
|
|
84
|
+
return React.createElement('div', attributes, content);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
protected override renderExpansionToggle(node: TreeNode, props: PreferenceTreeNodeProps): React.ReactNode {
|
|
88
|
+
if (ExpandableTreeNode.is(node) && !props.isExpansible) {
|
|
89
|
+
return <div className='preferences-tree-spacer' />;
|
|
90
|
+
}
|
|
91
|
+
return super.renderExpansionToggle(node, props);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
protected override toNodeName(node: TreeNode): string {
|
|
95
|
+
const visibleChildren = this.model.currentRows.get(node.id)?.visibleChildren;
|
|
96
|
+
const baseName = this.labelProvider.getName(node);
|
|
97
|
+
const printedNameWithVisibleChildren = this.model.isFiltered && visibleChildren !== undefined
|
|
98
|
+
? `${baseName} (${visibleChildren})`
|
|
99
|
+
: baseName;
|
|
100
|
+
return printedNameWithVisibleChildren;
|
|
101
|
+
}
|
|
102
|
+
}
|