1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.StylingService = exports.StylingParticipant = void 0;
|
19 | const tslib_1 = require("tslib");
|
20 | const inversify_1 = require("inversify");
|
21 | const contribution_provider_1 = require("../common/contribution-provider");
|
22 | const color_registry_1 = require("./color-registry");
|
23 | const decoration_style_1 = require("./decoration-style");
|
24 | const theming_1 = require("./theming");
|
25 | const secondary_window_handler_1 = require("./secondary-window-handler");
|
26 | exports.StylingParticipant = Symbol('StylingParticipant');
|
27 | let StylingService = class StylingService {
|
28 | constructor() {
|
29 | this.cssElements = new Map();
|
30 | }
|
31 | onStart() {
|
32 | this.registerWindow(window);
|
33 | this.secondaryWindowHandler.onWillAddWidget(([widget, window]) => {
|
34 | this.registerWindow(window);
|
35 | });
|
36 | this.secondaryWindowHandler.onWillRemoveWidget(([widget, window]) => {
|
37 | this.cssElements.delete(window);
|
38 | });
|
39 | this.themeService.onDidColorThemeChange(e => this.applyStylingToWindows(e.newTheme));
|
40 | }
|
41 | registerWindow(win) {
|
42 | const cssElement = decoration_style_1.DecorationStyle.createStyleElement('contributedColorTheme', win.document.head);
|
43 | this.cssElements.set(win, cssElement);
|
44 | this.applyStyling(this.themeService.getCurrentTheme(), cssElement);
|
45 | }
|
46 | applyStylingToWindows(theme) {
|
47 | this.cssElements.forEach(cssElement => this.applyStyling(theme, cssElement));
|
48 | }
|
49 | applyStyling(theme, cssElement) {
|
50 | const rules = [];
|
51 | const colorTheme = {
|
52 | type: theme.type,
|
53 | label: theme.label,
|
54 | getColor: color => this.colorRegistry.getCurrentColor(color)
|
55 | };
|
56 | const styleCollector = {
|
57 | addRule: rule => rules.push(rule)
|
58 | };
|
59 | for (const themingParticipant of this.themingParticipants.getContributions()) {
|
60 | themingParticipant.registerThemeStyle(colorTheme, styleCollector);
|
61 | }
|
62 | const fullCss = rules.join('\n');
|
63 | cssElement.innerText = fullCss;
|
64 | }
|
65 | };
|
66 | (0, tslib_1.__decorate)([
|
67 | (0, inversify_1.inject)(theming_1.ThemeService),
|
68 | (0, tslib_1.__metadata)("design:type", theming_1.ThemeService)
|
69 | ], StylingService.prototype, "themeService", void 0);
|
70 | (0, tslib_1.__decorate)([
|
71 | (0, inversify_1.inject)(color_registry_1.ColorRegistry),
|
72 | (0, tslib_1.__metadata)("design:type", color_registry_1.ColorRegistry)
|
73 | ], StylingService.prototype, "colorRegistry", void 0);
|
74 | (0, tslib_1.__decorate)([
|
75 | (0, inversify_1.inject)(contribution_provider_1.ContributionProvider),
|
76 | (0, inversify_1.named)(exports.StylingParticipant),
|
77 | (0, tslib_1.__metadata)("design:type", Object)
|
78 | ], StylingService.prototype, "themingParticipants", void 0);
|
79 | (0, tslib_1.__decorate)([
|
80 | (0, inversify_1.inject)(secondary_window_handler_1.SecondaryWindowHandler),
|
81 | (0, tslib_1.__metadata)("design:type", secondary_window_handler_1.SecondaryWindowHandler)
|
82 | ], StylingService.prototype, "secondaryWindowHandler", void 0);
|
83 | StylingService = (0, tslib_1.__decorate)([
|
84 | (0, inversify_1.injectable)()
|
85 | ], StylingService);
|
86 | exports.StylingService = StylingService;
|
87 |
|
\ | No newline at end of file |