@theia/core
Version:
Theia is a cloud & desktop IDE framework implemented in TypeScript.
162 lines • 6.62 kB
JavaScript
"use strict";
// *****************************************************************************
// Copyright (C) 2018 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
// *****************************************************************************
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbstractViewContribution = exports.bindViewContribution = void 0;
const tslib_1 = require("tslib");
const inversify_1 = require("inversify");
const common_1 = require("../../common");
const keybinding_1 = require("../keybinding");
const widget_manager_1 = require("../widget-manager");
const common_frontend_contribution_1 = require("../common-frontend-contribution");
const application_shell_1 = require("./application-shell");
const quick_input_1 = require("../quick-input");
function bindViewContribution(bind, identifier) {
const syntax = bind(identifier).toSelf().inSingletonScope();
bind(common_1.CommandContribution).toService(identifier);
bind(keybinding_1.KeybindingContribution).toService(identifier);
bind(common_1.MenuContribution).toService(identifier);
return syntax;
}
exports.bindViewContribution = bindViewContribution;
/**
* An abstract superclass for frontend contributions that add a view to the application shell.
*/
let AbstractViewContribution = class AbstractViewContribution {
constructor(options) {
this.options = options;
if (options.toggleCommandId) {
this.toggleCommand = {
id: options.toggleCommandId,
category: common_1.nls.localizeByDefault('View'),
label: common_1.nls.localizeByDefault('Toggle {0}', this.viewLabel)
};
}
}
get viewId() {
return this.options.widgetId;
}
get viewLabel() {
return this.options.widgetName;
}
get defaultViewOptions() {
return this.options.defaultWidgetOptions;
}
get widget() {
return this.widgetManager.getOrCreateWidget(this.viewId);
}
tryGetWidget() {
return this.widgetManager.tryGetWidget(this.viewId);
}
async openView(args = {}) {
const shell = this.shell;
const widget = await this.widgetManager.getOrCreateWidget(this.options.viewContainerId || this.viewId);
const tabBar = shell.getTabBarFor(widget);
const area = shell.getAreaFor(widget);
if (!tabBar) {
// The widget is not attached yet, so add it to the shell
const widgetArgs = {
...this.defaultViewOptions,
...args
};
await shell.addWidget(widget, widgetArgs);
}
else if (args.toggle && area && shell.isExpanded(area) && tabBar.currentTitle === widget.title) {
// The widget is attached and visible, so collapse the containing panel (toggle)
switch (area) {
case 'left':
case 'right':
await shell.collapsePanel(area);
break;
case 'bottom':
// Don't collapse the bottom panel if it's currently split
if (shell.bottomAreaTabBars.length === 1) {
await shell.collapsePanel('bottom');
}
break;
default:
// The main area cannot be collapsed, so close the widget
await this.closeView();
}
return this.widget;
}
if (widget.isAttached && args.activate) {
await shell.activateWidget(this.viewId);
}
else if (widget.isAttached && args.reveal) {
await shell.revealWidget(this.viewId);
}
return this.widget;
}
registerCommands(commands) {
var _a;
if (this.toggleCommand) {
commands.registerCommand(this.toggleCommand, {
execute: () => this.toggleView()
});
}
(_a = this.quickView) === null || _a === void 0 ? void 0 : _a.registerItem({
label: this.viewLabel,
open: () => this.openView({ activate: true })
});
}
async closeView() {
const widget = await this.shell.closeWidget(this.viewId);
return widget;
}
toggleView() {
return this.openView({
toggle: true,
activate: true
});
}
registerMenus(menus) {
if (this.toggleCommand) {
menus.registerMenuAction(common_frontend_contribution_1.CommonMenus.VIEW_VIEWS, {
commandId: this.toggleCommand.id,
label: this.viewLabel
});
}
}
registerKeybindings(keybindings) {
if (this.toggleCommand && this.options.toggleKeybinding) {
keybindings.registerKeybinding({
command: this.toggleCommand.id,
keybinding: this.options.toggleKeybinding
});
}
}
};
exports.AbstractViewContribution = AbstractViewContribution;
tslib_1.__decorate([
(0, inversify_1.inject)(widget_manager_1.WidgetManager),
tslib_1.__metadata("design:type", widget_manager_1.WidgetManager)
], AbstractViewContribution.prototype, "widgetManager", void 0);
tslib_1.__decorate([
(0, inversify_1.inject)(application_shell_1.ApplicationShell),
tslib_1.__metadata("design:type", application_shell_1.ApplicationShell)
], AbstractViewContribution.prototype, "shell", void 0);
tslib_1.__decorate([
(0, inversify_1.inject)(quick_input_1.QuickViewService),
(0, inversify_1.optional)(),
tslib_1.__metadata("design:type", quick_input_1.QuickViewService)
], AbstractViewContribution.prototype, "quickView", void 0);
exports.AbstractViewContribution = AbstractViewContribution = tslib_1.__decorate([
(0, inversify_1.injectable)(),
tslib_1.__param(0, (0, inversify_1.unmanaged)()),
tslib_1.__metadata("design:paramtypes", [Object])
], AbstractViewContribution);
//# sourceMappingURL=view-contribution.js.map