-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
message.ts
85 lines (69 loc) · 2.97 KB
/
message.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import * as vscode from "vscode";
/**
* Shows emacs-like status bar message which disappears when any other command is invoked.
*/
export class MessageManager implements vscode.Disposable {
/**
* MessageManager uses singleton pattern.
*/
public static get instance(): MessageManager {
if (!this.inst) {
this.inst = new MessageManager();
}
return this.inst;
}
public static registerDispose(context: vscode.ExtensionContext): void {
context.subscriptions.push(this.instance);
}
public static showMessage(text: string): void {
if (this.instance) {
this.instance.showMessage(text);
}
}
private static inst: MessageManager;
private timeout: number;
private messageDisposable: vscode.Disposable | null = null;
private disposables: vscode.Disposable[] = [];
private constructor(timeout = 10000) {
this.timeout = timeout;
this.onInterrupt = this.onInterrupt.bind(this);
vscode.window.onDidChangeActiveTerminal(this.onInterrupt, this, this.disposables);
vscode.window.onDidChangeActiveTextEditor(this.onInterrupt, this, this.disposables);
vscode.window.onDidChangeTextEditorOptions(this.onInterrupt, this, this.disposables);
vscode.window.onDidChangeTextEditorSelection(this.onInterrupt, this, this.disposables);
vscode.window.onDidChangeTextEditorViewColumn(this.onInterrupt, this, this.disposables);
vscode.window.onDidChangeTextEditorVisibleRanges(this.onInterrupt, this, this.disposables);
vscode.window.onDidChangeVisibleTextEditors(this.onInterrupt, this, this.disposables);
vscode.window.onDidChangeWindowState(this.onInterrupt, this, this.disposables);
vscode.window.onDidCloseTerminal(this.onInterrupt, this, this.disposables);
vscode.window.onDidOpenTerminal(this.onInterrupt, this, this.disposables);
vscode.workspace.onDidChangeConfiguration(this.onInterrupt, this, this.disposables);
vscode.workspace.onDidChangeTextDocument(this.onInterrupt, this, this.disposables);
vscode.workspace.onDidChangeWorkspaceFolders(this.onInterrupt, this, this.disposables);
vscode.workspace.onDidCloseTextDocument(this.onInterrupt, this, this.disposables);
vscode.workspace.onDidOpenTextDocument(this.onInterrupt, this, this.disposables);
vscode.workspace.onDidSaveTextDocument(this.onInterrupt, this, this.disposables);
vscode.workspace.onWillSaveTextDocument(this.onInterrupt, this, this.disposables);
}
public onInterrupt(): void {
if (this.messageDisposable === null) {
return;
}
this.messageDisposable.dispose();
this.messageDisposable = null;
}
public showMessage(text: string): void {
if (this.messageDisposable) {
this.messageDisposable.dispose();
}
this.messageDisposable = vscode.window.setStatusBarMessage(text, this.timeout);
}
public dispose(): void {
if (this.messageDisposable !== null) {
this.messageDisposable.dispose();
}
for (const disposable of this.disposables) {
disposable.dispose();
}
}
}