UNPKG

4.25 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2019 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-only 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.ProgressStatusBarItem = void 0;
28const inversify_1 = require("inversify");
29const common_1 = require("../common");
30const status_bar_1 = require("./status-bar");
31const promise_util_1 = require("../common/promise-util");
32const throttle = require("lodash.throttle");
33let ProgressStatusBarItem = class ProgressStatusBarItem {
34 constructor() {
35 this.id = 'theia-progress-status-bar-item';
36 this.messagesByProgress = new Map();
37 this.incomingQueue = new Array();
38 this.triggerUpdate = throttle(() => this.update(this.currentProgress), 250, { leading: true, trailing: true });
39 }
40 get currentProgress() {
41 return this.incomingQueue.slice(-1)[0];
42 }
43 showProgress(progressId, message, cancellationToken) {
44 const result = new promise_util_1.Deferred();
45 cancellationToken.onCancellationRequested(() => {
46 this.processEvent(progressId, 'done');
47 result.resolve(common_1.ProgressMessage.Cancel);
48 });
49 this.processEvent(progressId, 'start', message.text);
50 return result.promise;
51 }
52 processEvent(progressId, event, message) {
53 if (event === 'start') {
54 this.incomingQueue.push(progressId);
55 this.messagesByProgress.set(progressId, message);
56 }
57 else {
58 this.incomingQueue = this.incomingQueue.filter(id => id !== progressId);
59 this.messagesByProgress.delete(progressId);
60 }
61 this.triggerUpdate();
62 }
63 async reportProgress(progressId, update, originalMessage, _cancellationToken) {
64 const newMessage = update.message ? `${originalMessage.text}: ${update.message}` : originalMessage.text;
65 this.messagesByProgress.set(progressId, newMessage);
66 this.triggerUpdate();
67 }
68 update(progressId) {
69 const message = progressId && this.messagesByProgress.get(progressId);
70 if (!progressId || !message) {
71 this.statusBar.removeElement(this.id);
72 return;
73 }
74 const text = `$(codicon-sync~spin) ${message}`;
75 this.statusBar.setElement(this.id, {
76 text,
77 alignment: status_bar_1.StatusBarAlignment.LEFT,
78 priority: 1
79 });
80 }
81};
82__decorate([
83 (0, inversify_1.inject)(status_bar_1.StatusBar),
84 __metadata("design:type", Object)
85], ProgressStatusBarItem.prototype, "statusBar", void 0);
86ProgressStatusBarItem = __decorate([
87 (0, inversify_1.injectable)()
88], ProgressStatusBarItem);
89exports.ProgressStatusBarItem = ProgressStatusBarItem;
90//# sourceMappingURL=progress-status-bar-item.js.map
\No newline at end of file