UNPKG

2.25 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2021 Ericsson 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.CurrentWidgetCommandAdapter = void 0;
19/**
20 * Creates a command handler that acts on either the widget targeted by a DOM event or the current widget.
21 */
22class CurrentWidgetCommandAdapter {
23 constructor(shell, handler) {
24 this.execute = (event) => handler.execute(...this.transformArguments(shell, event));
25 if (handler.isEnabled) {
26 this.isEnabled = (event) => { var _a; return !!((_a = handler.isEnabled) === null || _a === void 0 ? void 0 : _a.call(handler, ...this.transformArguments(shell, event))); };
27 }
28 if (handler.isVisible) {
29 this.isVisible = (event) => { var _a; return !!((_a = handler.isVisible) === null || _a === void 0 ? void 0 : _a.call(handler, ...this.transformArguments(shell, event))); };
30 }
31 if (handler.isToggled) {
32 this.isToggled = (event) => { var _a; return !!((_a = handler.isToggled) === null || _a === void 0 ? void 0 : _a.call(handler, ...this.transformArguments(shell, event))); };
33 }
34 }
35 transformArguments(shell, event) {
36 const tabBar = shell.findTabBar(event);
37 const title = tabBar && shell.findTitle(tabBar, event);
38 return [title, tabBar, event];
39 }
40}
41exports.CurrentWidgetCommandAdapter = CurrentWidgetCommandAdapter;
42//# sourceMappingURL=current-widget-command-adapter.js.map
\No newline at end of file