1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import { LocationProgress, ProgressLocationService } from './progress-location-service';
|
18 | import { DisposableCollection, Disposable } from '../common';
|
19 | import { injectable, inject, postConstruct } from 'inversify';
|
20 | import { ProgressBarOptions } from './progress-bar-factory';
|
21 |
|
22 | @injectable()
|
23 | export class ProgressBar implements Disposable {
|
24 |
|
25 | @inject(ProgressLocationService)
|
26 | protected readonly progressLocationService: ProgressLocationService;
|
27 |
|
28 | @inject(ProgressBarOptions)
|
29 | protected readonly options: ProgressBarOptions;
|
30 |
|
31 | protected readonly toDispose = new DisposableCollection();
|
32 | dispose(): void {
|
33 | this.toDispose.dispose();
|
34 | }
|
35 |
|
36 | protected progressBar: HTMLDivElement;
|
37 | protected progressBarContainer: HTMLDivElement;
|
38 |
|
39 | constructor() {
|
40 | this.progressBar = document.createElement('div');
|
41 | this.progressBar.className = 'theia-progress-bar';
|
42 | this.progressBar.style.display = 'none';
|
43 | this.progressBarContainer = document.createElement('div');
|
44 | this.progressBarContainer.className = 'theia-progress-bar-container';
|
45 | this.progressBarContainer.append(this.progressBar);
|
46 | }
|
47 |
|
48 | @postConstruct()
|
49 | protected init(): void {
|
50 | const { container, insertMode, locationId } = this.options;
|
51 | if (insertMode === 'prepend') {
|
52 | container.prepend(this.progressBarContainer);
|
53 | } else {
|
54 | container.append(this.progressBarContainer);
|
55 | }
|
56 | this.toDispose.push(Disposable.create(() => this.progressBarContainer.remove()));
|
57 | const onProgress = this.progressLocationService.onProgress(locationId);
|
58 | this.toDispose.push(onProgress(event => this.onProgress(event)));
|
59 | const current = this.progressLocationService.getProgress(locationId);
|
60 | if (current) {
|
61 | this.onProgress(current);
|
62 | }
|
63 | }
|
64 |
|
65 | protected onProgress(event: LocationProgress): void {
|
66 | if (this.toDispose.disposed) {
|
67 | return;
|
68 | }
|
69 | this.setVisible(event.show);
|
70 | }
|
71 |
|
72 | protected setVisible(visible: boolean): void {
|
73 | this.progressBar.style.display = visible ? 'block' : 'none';
|
74 | }
|
75 |
|
76 | }
|