UNPKG

5.01 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 WITH Classpath-exception-2.0
16// *****************************************************************************
17var __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};
23var __metadata = (this && this.__metadata) || function (k, v) {
24 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25};
26Object.defineProperty(exports, "__esModule", { value: true });
27exports.WindowTitleUpdater = void 0;
28const navigatable_types_1 = require("../navigatable-types");
29const inversify_1 = require("inversify");
30const window_title_service_1 = require("./window-title-service");
31const label_provider_1 = require("../label-provider");
32const saveable_1 = require("../saveable");
33const common_1 = require("../../common");
34let WindowTitleUpdater = class WindowTitleUpdater {
35 constructor() {
36 this.toDisposeOnWidgetChanged = common_1.Disposable.NULL;
37 }
38 onStart(app) {
39 app.shell.mainPanel.onDidChangeCurrent(title => this.handleWidgetChange(title === null || title === void 0 ? void 0 : title.owner));
40 this.handleWidgetChange(app.shell.getCurrentWidget('main'));
41 }
42 handleWidgetChange(widget) {
43 this.toDisposeOnWidgetChanged.dispose();
44 const saveable = saveable_1.Saveable.get(widget);
45 if (saveable) {
46 this.toDisposeOnWidgetChanged = saveable.onDirtyChanged(() => this.windowTitleService.update({ dirty: saveable.dirty ? '●' : '' }));
47 }
48 else {
49 this.toDisposeOnWidgetChanged = common_1.Disposable.NULL;
50 }
51 this.updateTitleWidget(widget);
52 }
53 /**
54 * Updates the title of the application based on the currently opened widget.
55 *
56 * @param widget The current widget in the `main` application area. `undefined` if no widget is currently open in that area.
57 */
58 updateTitleWidget(widget) {
59 let activeEditorLong;
60 let activeEditorMedium;
61 let activeEditorShort;
62 let activeFolderLong;
63 let activeFolderMedium;
64 let activeFolderShort;
65 let dirty;
66 const uri = navigatable_types_1.NavigatableWidget.getUri(widget);
67 if (uri) {
68 activeEditorLong = uri.path.fsPath();
69 activeEditorMedium = this.labelProvider.getLongName(uri);
70 activeEditorShort = this.labelProvider.getName(uri);
71 const parent = uri.parent;
72 activeFolderLong = parent.path.fsPath();
73 activeFolderMedium = this.labelProvider.getLongName(parent);
74 activeFolderShort = this.labelProvider.getName(parent);
75 }
76 else if (widget) {
77 const widgetTitle = widget.title.label;
78 activeEditorLong = widgetTitle;
79 activeEditorMedium = widgetTitle;
80 activeEditorShort = widgetTitle;
81 }
82 if (saveable_1.Saveable.isDirty(widget)) {
83 dirty = '●';
84 }
85 this.windowTitleService.update({
86 activeEditorLong,
87 activeEditorMedium,
88 activeEditorShort,
89 activeFolderLong,
90 activeFolderMedium,
91 activeFolderShort,
92 dirty
93 });
94 }
95};
96__decorate([
97 (0, inversify_1.inject)(window_title_service_1.WindowTitleService),
98 __metadata("design:type", window_title_service_1.WindowTitleService)
99], WindowTitleUpdater.prototype, "windowTitleService", void 0);
100__decorate([
101 (0, inversify_1.inject)(label_provider_1.LabelProvider),
102 __metadata("design:type", label_provider_1.LabelProvider)
103], WindowTitleUpdater.prototype, "labelProvider", void 0);
104WindowTitleUpdater = __decorate([
105 (0, inversify_1.injectable)()
106], WindowTitleUpdater);
107exports.WindowTitleUpdater = WindowTitleUpdater;
108//# sourceMappingURL=window-title-updater.js.map
\No newline at end of file