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 | Object.defineProperty(exports, "__esModule", { value: true });
|
27 | exports.ProgressStatusBarItem = void 0;
|
28 | const inversify_1 = require("inversify");
|
29 | const common_1 = require("../common");
|
30 | const status_bar_1 = require("./status-bar");
|
31 | const promise_util_1 = require("../common/promise-util");
|
32 | const throttle = require("lodash.throttle");
|
33 | let 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);
|
86 | ProgressStatusBarItem = __decorate([
|
87 | (0, inversify_1.injectable)()
|
88 | ], ProgressStatusBarItem);
|
89 | exports.ProgressStatusBarItem = ProgressStatusBarItem;
|
90 |
|
\ | No newline at end of file |