1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var __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 | };
|
23 | var __metadata = (this && this.__metadata) || function (k, v) {
|
24 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
25 | };
|
26 | var __param = (this && this.__param) || function (paramIndex, decorator) {
|
27 | return function (target, key) { decorator(target, key, paramIndex); }
|
28 | };
|
29 | Object.defineProperty(exports, "__esModule", { value: true });
|
30 | exports.StatusBarImpl = exports.StatusBarAlignment = exports.StatusBar = void 0;
|
31 | const React = require("react");
|
32 | const inversify_1 = require("inversify");
|
33 | const debounce = require("lodash.debounce");
|
34 | const common_1 = require("../../common");
|
35 | const react_widget_1 = require("../widgets/react-widget");
|
36 | const frontend_application_state_1 = require("../frontend-application-state");
|
37 | const label_parser_1 = require("../label-parser");
|
38 | const preferences_1 = require("../preferences");
|
39 | const status_bar_types_1 = require("./status-bar-types");
|
40 | Object.defineProperty(exports, "StatusBar", { enumerable: true, get: function () { return status_bar_types_1.StatusBar; } });
|
41 | Object.defineProperty(exports, "StatusBarAlignment", { enumerable: true, get: function () { return status_bar_types_1.StatusBarAlignment; } });
|
42 | const status_bar_view_model_1 = require("./status-bar-view-model");
|
43 | const hover_service_1 = require("../hover-service");
|
44 | const widgets_1 = require("../widgets");
|
45 | let StatusBarImpl = class StatusBarImpl extends react_widget_1.ReactWidget {
|
46 | constructor(commands, entryService, applicationStateService, preferences, viewModel, hoverService) {
|
47 | super();
|
48 | this.commands = commands;
|
49 | this.entryService = entryService;
|
50 | this.applicationStateService = applicationStateService;
|
51 | this.preferences = preferences;
|
52 | this.viewModel = viewModel;
|
53 | this.hoverService = hoverService;
|
54 | this.debouncedUpdate = debounce(() => this.update(), 50);
|
55 | delete this.scrollOptions;
|
56 | this.id = 'theia-statusBar';
|
57 | this.addClass('noselect');
|
58 |
|
59 | this.hide();
|
60 | this.preferences.ready.then(() => {
|
61 | const preferenceValue = this.preferences.get('workbench.statusBar.visible', true);
|
62 | this.setHidden(!preferenceValue);
|
63 | });
|
64 | this.toDispose.push(this.preferences.onPreferenceChanged(preference => {
|
65 | if (preference.preferenceName === 'workbench.statusBar.visible') {
|
66 | this.setHidden(!preference.newValue);
|
67 | }
|
68 | }));
|
69 | this.toDispose.push(this.viewModel.onDidChange(() => this.debouncedUpdate()));
|
70 | }
|
71 | get ready() {
|
72 | return this.applicationStateService.reachedAnyState('initialized_layout', 'ready');
|
73 | }
|
74 | async setElement(id, entry) {
|
75 | await this.ready;
|
76 | this.viewModel.set(id, entry);
|
77 | }
|
78 | async removeElement(id) {
|
79 | await this.ready;
|
80 | this.viewModel.remove(id);
|
81 | }
|
82 | async setBackgroundColor(color) {
|
83 | await this.ready;
|
84 | this.internalSetBackgroundColor(color);
|
85 | this.update();
|
86 | }
|
87 | internalSetBackgroundColor(color) {
|
88 | this.backgroundColor = color;
|
89 | this.node.style.backgroundColor = this.backgroundColor || '';
|
90 | }
|
91 | async setColor(color) {
|
92 | await this.ready;
|
93 | this.internalSetColor(color);
|
94 | this.update();
|
95 | }
|
96 | internalSetColor(color) {
|
97 | this.color = color;
|
98 | }
|
99 | render() {
|
100 | const leftEntries = Array.from(this.viewModel.getLeft(), entry => this.renderElement(entry));
|
101 | const rightEntries = Array.from(this.viewModel.getRight(), entry => this.renderElement(entry));
|
102 | return React.createElement(React.Fragment, null,
|
103 | React.createElement("div", { className: 'area left' }, leftEntries),
|
104 | React.createElement("div", { className: 'area right' }, rightEntries));
|
105 | }
|
106 | onclick(entry) {
|
107 | return () => {
|
108 | if (entry.command) {
|
109 | const args = entry.arguments || [];
|
110 | this.commands.executeCommand(entry.command, ...args);
|
111 | }
|
112 | };
|
113 | }
|
114 | createAttributes(viewEntry) {
|
115 | const attrs = {};
|
116 | const entry = viewEntry.entry;
|
117 | attrs.id = 'status-bar-' + viewEntry.id;
|
118 | attrs.className = 'element';
|
119 | if (entry.command || entry.onclick || entry.tooltip) {
|
120 | attrs.className += ' hasCommand';
|
121 | }
|
122 | if (entry.command) {
|
123 | attrs.onClick = this.onclick(entry);
|
124 | }
|
125 | else if (entry.onclick) {
|
126 | attrs.onClick = e => { var _a; return (_a = entry.onclick) === null || _a === void 0 ? void 0 : _a.call(entry, e.nativeEvent); };
|
127 | }
|
128 | if (viewEntry.compact && viewEntry.alignment !== undefined) {
|
129 | attrs.className += viewEntry.alignment === status_bar_types_1.StatusBarAlignment.RIGHT ? ' compact-right' : ' compact-left';
|
130 | }
|
131 | if (entry.tooltip) {
|
132 | attrs.onMouseEnter = e => this.hoverService.requestHover({
|
133 | content: entry.tooltip,
|
134 | target: e.currentTarget,
|
135 | position: 'top'
|
136 | });
|
137 | }
|
138 | if (entry.className) {
|
139 | attrs.className += ' ' + entry.className;
|
140 | }
|
141 | if (entry.accessibilityInformation) {
|
142 | attrs['aria-label'] = entry.accessibilityInformation.label;
|
143 | attrs.role = entry.accessibilityInformation.role;
|
144 | }
|
145 | else {
|
146 | attrs['aria-label'] = [entry.text, entry.tooltip].join(', ');
|
147 | }
|
148 | if (entry.backgroundColor) {
|
149 | attrs.className += ' has-background';
|
150 | }
|
151 | attrs.style = {
|
152 | color: entry.color || this.color,
|
153 | backgroundColor: entry.backgroundColor
|
154 | };
|
155 | return attrs;
|
156 | }
|
157 | renderElement(entry) {
|
158 | const childStrings = this.entryService.parse(entry.entry.text);
|
159 | const children = [];
|
160 | childStrings.forEach((val, key) => {
|
161 | if (label_parser_1.LabelIcon.is(val)) {
|
162 | const animation = val.animation ? ` fa-${val.animation}` : '';
|
163 | if (val.name.startsWith('codicon-')) {
|
164 | children.push(React.createElement("span", { key: key, className: `codicon ${val.name}${animation}` }));
|
165 | }
|
166 | else if (val.name.startsWith('fa-')) {
|
167 | children.push(React.createElement("span", { key: key, className: `fa ${val.name}${animation}` }));
|
168 | }
|
169 | else {
|
170 | children.push(React.createElement("span", { key: key, className: `${(0, widgets_1.codicon)(val.name)}${animation}` }));
|
171 | }
|
172 | }
|
173 | else {
|
174 | children.push(React.createElement("span", { key: key }, val));
|
175 | }
|
176 | });
|
177 | return React.createElement("div", { key: entry.id, ...this.createAttributes(entry) }, children);
|
178 | }
|
179 | };
|
180 | StatusBarImpl = __decorate([
|
181 | (0, inversify_1.injectable)(),
|
182 | __param(0, (0, inversify_1.inject)(common_1.CommandService)),
|
183 | __param(1, (0, inversify_1.inject)(label_parser_1.LabelParser)),
|
184 | __param(2, (0, inversify_1.inject)(frontend_application_state_1.FrontendApplicationStateService)),
|
185 | __param(3, (0, inversify_1.inject)(preferences_1.PreferenceService)),
|
186 | __param(4, (0, inversify_1.inject)(status_bar_view_model_1.StatusBarViewModel)),
|
187 | __param(5, (0, inversify_1.inject)(hover_service_1.HoverService)),
|
188 | __metadata("design:paramtypes", [Object, label_parser_1.LabelParser,
|
189 | frontend_application_state_1.FrontendApplicationStateService, Object, status_bar_view_model_1.StatusBarViewModel,
|
190 | hover_service_1.HoverService])
|
191 | ], StatusBarImpl);
|
192 | exports.StatusBarImpl = StatusBarImpl;
|
193 |
|
\ | No newline at end of file |