-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathpreview.manager.ts
66 lines (56 loc) · 1.63 KB
/
preview.manager.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
import {Uri} from 'vscode';
import {DataPreview} from './data.preview';
export class PreviewManager {
// singleton instance
private static _instance: PreviewManager;
// tracked previews for config/restore updates
private _previews: DataPreview[] = [];
private constructor() {
}
/**
* Creates preview manager singleton instance.
*/
public static get Instance() {
return this._instance || (this._instance = new this());
}
/**
* Adds new preview instance for config/restore tracking.
* @param preview preview instance to add.
*/
public add(preview: DataPreview): void {
this._previews.push(preview!);
}
/**
* Removes preview instance from previews tracking collection.
* @param preview preview instance to remove.
*/
public remove(preview: DataPreview): void {
let found = this._previews.indexOf(preview!);
if (found >= 0) {
this._previews.splice(found, 1);
}
}
/**
* Returns matching preview for the specified data uri.
* @param dataUri Data Uri to find for open data previews.
*/
public find(dataUri: Uri): Array<DataPreview> {
const dataUrl: string = dataUri.toString(true); // skip uri encoding
return this._previews.filter(p => p.dataUrl === dataUrl);
}
/**
* Returns active preview instance.
*/
public active(): DataPreview {
return this._previews.find(p => p.visible);
}
/**
* Reloads open previews on extension config changes.
*/
public configure(): void {
this._previews.forEach(p => p.configure());
}
}
// export preview manager singleton
export const previewManager = PreviewManager.Instance;