UNPKG

4.37 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2022 TypeFox and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.WindowTitleUpdater = void 0;
19const tslib_1 = require("tslib");
20const navigatable_types_1 = require("../navigatable-types");
21const inversify_1 = require("inversify");
22const window_title_service_1 = require("./window-title-service");
23const label_provider_1 = require("../label-provider");
24const saveable_1 = require("../saveable");
25const common_1 = require("../../common");
26let WindowTitleUpdater = class WindowTitleUpdater {
27 constructor() {
28 this.toDisposeOnWidgetChanged = common_1.Disposable.NULL;
29 }
30 onStart(app) {
31 app.shell.mainPanel.onDidChangeCurrent(title => this.handleWidgetChange(title === null || title === void 0 ? void 0 : title.owner));
32 this.handleWidgetChange(app.shell.getCurrentWidget('main'));
33 }
34 handleWidgetChange(widget) {
35 this.toDisposeOnWidgetChanged.dispose();
36 const saveable = saveable_1.Saveable.get(widget);
37 if (saveable) {
38 this.toDisposeOnWidgetChanged = saveable.onDirtyChanged(() => this.windowTitleService.update({ dirty: saveable.dirty ? '●' : '' }));
39 }
40 else {
41 this.toDisposeOnWidgetChanged = common_1.Disposable.NULL;
42 }
43 this.updateTitleWidget(widget);
44 }
45 /**
46 * Updates the title of the application based on the currently opened widget.
47 *
48 * @param widget The current widget in the `main` application area. `undefined` if no widget is currently open in that area.
49 */
50 updateTitleWidget(widget) {
51 let activeEditorLong;
52 let activeEditorMedium;
53 let activeEditorShort;
54 let activeFolderLong;
55 let activeFolderMedium;
56 let activeFolderShort;
57 let dirty;
58 const uri = navigatable_types_1.NavigatableWidget.getUri(widget);
59 if (uri) {
60 activeEditorLong = uri.path.fsPath();
61 activeEditorMedium = this.labelProvider.getLongName(uri);
62 activeEditorShort = this.labelProvider.getName(uri);
63 const parent = uri.parent;
64 activeFolderLong = parent.path.fsPath();
65 activeFolderMedium = this.labelProvider.getLongName(parent);
66 activeFolderShort = this.labelProvider.getName(parent);
67 }
68 else if (widget) {
69 const widgetTitle = widget.title.label;
70 activeEditorLong = widgetTitle;
71 activeEditorMedium = widgetTitle;
72 activeEditorShort = widgetTitle;
73 }
74 if (saveable_1.Saveable.isDirty(widget)) {
75 dirty = '●';
76 }
77 this.windowTitleService.update({
78 activeEditorLong,
79 activeEditorMedium,
80 activeEditorShort,
81 activeFolderLong,
82 activeFolderMedium,
83 activeFolderShort,
84 dirty
85 });
86 }
87};
88(0, tslib_1.__decorate)([
89 (0, inversify_1.inject)(window_title_service_1.WindowTitleService),
90 (0, tslib_1.__metadata)("design:type", window_title_service_1.WindowTitleService)
91], WindowTitleUpdater.prototype, "windowTitleService", void 0);
92(0, tslib_1.__decorate)([
93 (0, inversify_1.inject)(label_provider_1.LabelProvider),
94 (0, tslib_1.__metadata)("design:type", label_provider_1.LabelProvider)
95], WindowTitleUpdater.prototype, "labelProvider", void 0);
96WindowTitleUpdater = (0, tslib_1.__decorate)([
97 (0, inversify_1.injectable)()
98], WindowTitleUpdater);
99exports.WindowTitleUpdater = WindowTitleUpdater;
100//# sourceMappingURL=window-title-updater.js.map
\No newline at end of file