UNPKG

@theia/core

Version:

Theia is a cloud & desktop IDE framework implemented in TypeScript.

95 lines • 3.85 kB
// ***************************************************************************** // Copyright (C) 2022 TypeFox and others. // // This program and the accompanying materials are made available under the // terms of the Eclipse Public License v. 2.0 which is available at // http://www.eclipse.org/legal/epl-2.0. // // This Source Code may also be made available under the following Secondary // Licenses when the conditions for such availability set forth in the Eclipse // Public License v. 2.0 are satisfied: GNU General Public License, version 2 // with the GNU Classpath Exception which is available at // https://www.gnu.org/software/classpath/license.html. // // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 // ***************************************************************************** import { __decorate } from "tslib"; import { NavigatableWidget } from '../navigatable-types.js'; import { inject, injectable } from 'inversify'; import { WindowTitleService } from './window-title-service.js'; import { LabelProvider } from '../label-provider.js'; import { Saveable } from '../saveable.js'; import { Disposable } from '../../common/index.js'; let WindowTitleUpdater = class WindowTitleUpdater { constructor() { this.toDisposeOnWidgetChanged = Disposable.NULL; } onStart(app) { app.shell.mainPanel.onDidChangeCurrent(title => this.handleWidgetChange(title?.owner)); this.handleWidgetChange(app.shell.getCurrentWidget('main')); } handleWidgetChange(widget) { this.toDisposeOnWidgetChanged.dispose(); const saveable = Saveable.get(widget); if (saveable) { this.toDisposeOnWidgetChanged = saveable.onDirtyChanged(() => this.windowTitleService.update({ dirty: saveable.dirty ? '●' : '' })); } else { this.toDisposeOnWidgetChanged = Disposable.NULL; } this.updateTitleWidget(widget); } /** * Updates the title of the application based on the currently opened widget. * * @param widget The current widget in the `main` application area. `undefined` if no widget is currently open in that area. */ updateTitleWidget(widget) { let activeEditorLong; let activeEditorMedium; let activeEditorShort; let activeFolderLong; let activeFolderMedium; let activeFolderShort; let dirty; const uri = NavigatableWidget.getUri(widget); if (uri) { activeEditorLong = uri.path.fsPath(); activeEditorMedium = this.labelProvider.getLongName(uri); activeEditorShort = this.labelProvider.getName(uri); const parent = uri.parent; activeFolderLong = parent.path.fsPath(); activeFolderMedium = this.labelProvider.getLongName(parent); activeFolderShort = this.labelProvider.getName(parent); } else if (widget) { const widgetTitle = widget.title.label; activeEditorLong = widgetTitle; activeEditorMedium = widgetTitle; activeEditorShort = widgetTitle; } if (Saveable.isDirty(widget)) { dirty = '●'; } this.windowTitleService.update({ activeEditorLong, activeEditorMedium, activeEditorShort, activeFolderLong, activeFolderMedium, activeFolderShort, dirty }); } }; __decorate([ inject(WindowTitleService) ], WindowTitleUpdater.prototype, "windowTitleService", void 0); __decorate([ inject(LabelProvider) ], WindowTitleUpdater.prototype, "labelProvider", void 0); WindowTitleUpdater = __decorate([ injectable() ], WindowTitleUpdater); export { WindowTitleUpdater }; //# sourceMappingURL=window-title-updater.js.map