1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
18 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
19 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
20 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
21 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
22 | };
|
23 | var __metadata = (this && this.__metadata) || function (k, v) {
|
24 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
25 | };
|
26 | Object.defineProperty(exports, "__esModule", { value: true });
|
27 | exports.IconThemeService = exports.NoneIconTheme = void 0;
|
28 | const inversify_1 = require("inversify");
|
29 | const event_1 = require("../common/event");
|
30 | const disposable_1 = require("../common/disposable");
|
31 | const frontend_application_config_provider_1 = require("./frontend-application-config-provider");
|
32 | const preferences_1 = require("./preferences");
|
33 | const debounce = require("lodash.debounce");
|
34 | const ICON_THEME_PREFERENCE_KEY = 'workbench.iconTheme';
|
35 | let NoneIconTheme = class NoneIconTheme {
|
36 | constructor() {
|
37 | this.id = 'none';
|
38 | this.label = 'None';
|
39 | this.description = 'Disable file icons';
|
40 | this.hasFileIcons = true;
|
41 | this.hasFolderIcons = true;
|
42 | this.onDidChangeEmitter = new event_1.Emitter();
|
43 | this.onDidChange = this.onDidChangeEmitter.event;
|
44 | this.toDeactivate = new disposable_1.DisposableCollection();
|
45 | }
|
46 | activate() {
|
47 | if (this.toDeactivate.disposed) {
|
48 | this.toDeactivate.push(disposable_1.Disposable.create(() => this.fireDidChange()));
|
49 | this.fireDidChange();
|
50 | }
|
51 | return this.toDeactivate;
|
52 | }
|
53 | fireDidChange() {
|
54 | this.onDidChangeEmitter.fire({ affects: () => true });
|
55 | }
|
56 | canHandle() {
|
57 | if (this.toDeactivate.disposed) {
|
58 | return 0;
|
59 | }
|
60 | return Number.MAX_SAFE_INTEGER - 1024;
|
61 | }
|
62 | getIcon() {
|
63 | return '';
|
64 | }
|
65 | };
|
66 | NoneIconTheme = __decorate([
|
67 | (0, inversify_1.injectable)()
|
68 | ], NoneIconTheme);
|
69 | exports.NoneIconTheme = NoneIconTheme;
|
70 | let IconThemeService = class IconThemeService {
|
71 | constructor() {
|
72 | this.onDidChangeEmitter = new event_1.Emitter();
|
73 | this.onDidChange = this.onDidChangeEmitter.event;
|
74 | this._iconThemes = new Map();
|
75 | this.onDidChangeCurrentEmitter = new event_1.Emitter();
|
76 | this.onDidChangeCurrent = this.onDidChangeCurrentEmitter.event;
|
77 | this.toDeactivate = new disposable_1.DisposableCollection();
|
78 | this.updateIconThemePreference = debounce(() => this.doUpdateIconThemePreference(), 500);
|
79 | }
|
80 | get ids() {
|
81 | return this._iconThemes.keys();
|
82 | }
|
83 | get definitions() {
|
84 | return this._iconThemes.values();
|
85 | }
|
86 | getDefinition(id) {
|
87 | return this._iconThemes.get(id);
|
88 | }
|
89 | init() {
|
90 | this.register(this.fallback);
|
91 | this.setCurrent(this.fallback, false);
|
92 | this.preferences.ready.then(() => {
|
93 | this.validateActiveTheme();
|
94 | this.updateIconThemePreference();
|
95 | this.preferences.onPreferencesChanged(changes => {
|
96 | if (ICON_THEME_PREFERENCE_KEY in changes) {
|
97 | this.validateActiveTheme();
|
98 | }
|
99 | });
|
100 | });
|
101 | }
|
102 | register(iconTheme) {
|
103 | if (this._iconThemes.has(iconTheme.id)) {
|
104 | console.warn(new Error(`Icon theme '${iconTheme.id}' has already been registered, skipping.`));
|
105 | return disposable_1.Disposable.NULL;
|
106 | }
|
107 | this._iconThemes.set(iconTheme.id, iconTheme);
|
108 | this.onDidChangeEmitter.fire(undefined);
|
109 | this.validateActiveTheme();
|
110 | this.updateIconThemePreference();
|
111 | return disposable_1.Disposable.create(() => {
|
112 | this.unregister(iconTheme.id);
|
113 | this.updateIconThemePreference();
|
114 | });
|
115 | }
|
116 | unregister(id) {
|
117 | const iconTheme = this._iconThemes.get(id);
|
118 | if (!iconTheme) {
|
119 | return undefined;
|
120 | }
|
121 | this._iconThemes.delete(id);
|
122 | this.onDidChangeEmitter.fire(undefined);
|
123 | if (id === this.getCurrent().id) {
|
124 | this.setCurrent(this.default, false);
|
125 | }
|
126 | return iconTheme;
|
127 | }
|
128 | get current() {
|
129 | return this.getCurrent().id;
|
130 | }
|
131 | set current(id) {
|
132 | const newCurrent = this._iconThemes.get(id);
|
133 | if (newCurrent && this.getCurrent().id !== newCurrent.id) {
|
134 | this.setCurrent(newCurrent);
|
135 | }
|
136 | }
|
137 | getCurrent() {
|
138 | return this.activeTheme;
|
139 | }
|
140 | |
141 |
|
142 |
|
143 | setCurrent(newCurrent, persistSetting = true) {
|
144 | if (newCurrent !== this.getCurrent()) {
|
145 | this.activeTheme = newCurrent;
|
146 | this.toDeactivate.dispose();
|
147 | this.toDeactivate.push(newCurrent.activate());
|
148 | this.onDidChangeCurrentEmitter.fire(newCurrent.id);
|
149 | }
|
150 | if (persistSetting) {
|
151 | this.preferences.updateValue(ICON_THEME_PREFERENCE_KEY, newCurrent.id);
|
152 | }
|
153 | }
|
154 | getConfiguredTheme() {
|
155 | const configuredId = this.preferences.get(ICON_THEME_PREFERENCE_KEY);
|
156 | return configuredId ? this._iconThemes.get(configuredId) : undefined;
|
157 | }
|
158 | validateActiveTheme() {
|
159 | if (this.preferences.isReady) {
|
160 | const configured = this.getConfiguredTheme();
|
161 | if (configured && configured !== this.getCurrent()) {
|
162 | this.setCurrent(configured, false);
|
163 | }
|
164 | }
|
165 | }
|
166 | doUpdateIconThemePreference() {
|
167 | const preference = this.schemaProvider.getSchemaProperty(ICON_THEME_PREFERENCE_KEY);
|
168 | if (preference) {
|
169 | const sortedThemes = Array.from(this.definitions).sort((a, b) => a.label.localeCompare(b.label));
|
170 | this.schemaProvider.updateSchemaProperty(ICON_THEME_PREFERENCE_KEY, {
|
171 | ...preference,
|
172 | enum: sortedThemes.map(e => e.id),
|
173 | enumItemLabels: sortedThemes.map(e => e.label)
|
174 | });
|
175 | }
|
176 | }
|
177 | get default() {
|
178 | return this._iconThemes.get(frontend_application_config_provider_1.FrontendApplicationConfigProvider.get().defaultIconTheme) || this.fallback;
|
179 | }
|
180 | get fallback() {
|
181 | return this.noneIconTheme;
|
182 | }
|
183 | };
|
184 | IconThemeService.STORAGE_KEY = 'iconTheme';
|
185 | __decorate([
|
186 | (0, inversify_1.inject)(NoneIconTheme),
|
187 | __metadata("design:type", NoneIconTheme)
|
188 | ], IconThemeService.prototype, "noneIconTheme", void 0);
|
189 | __decorate([
|
190 | (0, inversify_1.inject)(preferences_1.PreferenceService),
|
191 | __metadata("design:type", Object)
|
192 | ], IconThemeService.prototype, "preferences", void 0);
|
193 | __decorate([
|
194 | (0, inversify_1.inject)(preferences_1.PreferenceSchemaProvider),
|
195 | __metadata("design:type", preferences_1.PreferenceSchemaProvider)
|
196 | ], IconThemeService.prototype, "schemaProvider", void 0);
|
197 | __decorate([
|
198 | (0, inversify_1.postConstruct)(),
|
199 | __metadata("design:type", Function),
|
200 | __metadata("design:paramtypes", []),
|
201 | __metadata("design:returntype", void 0)
|
202 | ], IconThemeService.prototype, "init", null);
|
203 | IconThemeService = __decorate([
|
204 | (0, inversify_1.injectable)()
|
205 | ], IconThemeService);
|
206 | exports.IconThemeService = IconThemeService;
|
207 |
|
\ | No newline at end of file |