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.WindowTitleService = exports.InitialWindowTitleParts = void 0;
|
19 | const tslib_1 = require("tslib");
|
20 | const inversify_1 = require("inversify");
|
21 | const strings_1 = require("../../common/strings");
|
22 | const event_1 = require("../../common/event");
|
23 | const core_preferences_1 = require("../core-preferences");
|
24 | const frontend_application_config_provider_1 = require("../frontend-application-config-provider");
|
25 | exports.InitialWindowTitleParts = {
|
26 | activeEditorShort: undefined,
|
27 | activeEditorMedium: undefined,
|
28 | activeEditorLong: undefined,
|
29 | activeFolderShort: undefined,
|
30 | activeFolderMedium: undefined,
|
31 | activeFolderLong: undefined,
|
32 | folderName: undefined,
|
33 | folderPath: undefined,
|
34 | rootName: undefined,
|
35 | rootPath: undefined,
|
36 | appName: frontend_application_config_provider_1.FrontendApplicationConfigProvider.get().applicationName,
|
37 | remoteName: undefined,
|
38 | dirty: undefined,
|
39 | developmentHost: undefined
|
40 | };
|
41 | let WindowTitleService = class WindowTitleService {
|
42 | constructor() {
|
43 | this._title = '';
|
44 | this.onDidChangeTitleEmitter = new event_1.Emitter();
|
45 | this.titleParts = new Map(Object.entries(exports.InitialWindowTitleParts));
|
46 | this.separator = ' - ';
|
47 | }
|
48 | init() {
|
49 | this.titleTemplate = this.preferences['window.title'];
|
50 | this.separator = this.preferences['window.titleSeparator'];
|
51 | this.updateTitle();
|
52 | this.preferences.onPreferenceChanged(e => {
|
53 | if (e.preferenceName === 'window.title') {
|
54 | this.titleTemplate = e.newValue;
|
55 | this.updateTitle();
|
56 | }
|
57 | else if (e.preferenceName === 'window.titleSeparator') {
|
58 | this.separator = e.newValue;
|
59 | this.updateTitle();
|
60 | }
|
61 | });
|
62 | }
|
63 | get onDidChangeTitle() {
|
64 | return this.onDidChangeTitleEmitter.event;
|
65 | }
|
66 | get title() {
|
67 | return this._title;
|
68 | }
|
69 | update(parts) {
|
70 | for (const [key, value] of Object.entries(parts)) {
|
71 | this.titleParts.set(key, value);
|
72 | }
|
73 | this.updateTitle();
|
74 | }
|
75 | updateTitle() {
|
76 | if (!this.titleTemplate) {
|
77 | this._title = '';
|
78 | }
|
79 | else {
|
80 | let title = this.titleTemplate;
|
81 | for (const [key, value] of this.titleParts.entries()) {
|
82 | if (key !== 'developmentHost') {
|
83 | const label = `$\{${key}\}`;
|
84 | const regex = new RegExp((0, strings_1.escapeRegExpCharacters)(label), 'g');
|
85 | title = title.replace(regex, value !== null && value !== void 0 ? value : '');
|
86 | }
|
87 | }
|
88 | const separatedTitle = title.split('${separator}').filter(e => e.trim().length > 0);
|
89 | this._title = separatedTitle.join(this.separator);
|
90 | }
|
91 | const developmentHost = this.titleParts.get('developmentHost');
|
92 | if (developmentHost) {
|
93 | this._title = developmentHost + this.separator + this._title;
|
94 | }
|
95 | document.title = this._title || frontend_application_config_provider_1.FrontendApplicationConfigProvider.get().applicationName;
|
96 | this.onDidChangeTitleEmitter.fire(this._title);
|
97 | }
|
98 | };
|
99 | (0, tslib_1.__decorate)([
|
100 | (0, inversify_1.inject)(core_preferences_1.CorePreferences),
|
101 | (0, tslib_1.__metadata)("design:type", Object)
|
102 | ], WindowTitleService.prototype, "preferences", void 0);
|
103 | (0, tslib_1.__decorate)([
|
104 | (0, inversify_1.postConstruct)(),
|
105 | (0, tslib_1.__metadata)("design:type", Function),
|
106 | (0, tslib_1.__metadata)("design:paramtypes", []),
|
107 | (0, tslib_1.__metadata)("design:returntype", void 0)
|
108 | ], WindowTitleService.prototype, "init", null);
|
109 | WindowTitleService = (0, tslib_1.__decorate)([
|
110 | (0, inversify_1.injectable)()
|
111 | ], WindowTitleService);
|
112 | exports.WindowTitleService = WindowTitleService;
|
113 |
|
\ | No newline at end of file |