forked from cerebral/overmind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevtoolsPanel_old.ts
More file actions
92 lines (77 loc) · 2.26 KB
/
DevtoolsPanel_old.ts
File metadata and controls
92 lines (77 loc) · 2.26 KB
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
86
87
88
89
90
91
92
import * as vscode from 'vscode'
import { log } from './utils/Logger'
import * as path from 'path'
export class DevtoolsPanel {
public static currentPanel: DevtoolsPanel | undefined
public static viewType = 'overmindDevtools'
private readonly _panel: vscode.WebviewPanel
private _disposables: vscode.Disposable[] = []
public static markup: string = ''
private constructor(panel: vscode.WebviewPanel, extensionPath: string) {
this._panel = panel
this.update()
this._panel.onDidDispose(() => this.dispose(), null, this._disposables)
this._panel.onDidChangeViewState(
(e) => {
if (this._panel.visible) {
this.update()
}
},
null,
this._disposables
)
this._panel.webview.onDidReceiveMessage(
(message) => {
switch (message.command) {
case 'alert':
vscode.window.showErrorMessage(message.text)
}
},
null,
this._disposables
)
}
dispose(): any {
DevtoolsPanel.currentPanel = undefined
this._panel.dispose()
while (this._disposables.length) {
const x = this._disposables.pop()
if (x) {
x.dispose()
}
}
}
private update() {
log('Extension.update')
this._panel.webview.html = this.getHtmlForWevbiew()
}
private getHtmlForWevbiew(): string {
return DevtoolsPanel.markup
}
static createOrShow(extensionPath: string, onDispose: (e: void) => any) {
const column = vscode.window.activeTextEditor
? vscode.window.activeTextEditor.viewColumn
: undefined
if (DevtoolsPanel.currentPanel) {
DevtoolsPanel.currentPanel._panel.reveal(column)
return
}
const panel = vscode.window.createWebviewPanel(
DevtoolsPanel.viewType,
'Overmind',
column || vscode.ViewColumn.One,
{
enableScripts: true,
retainContextWhenHidden: true,
localResourceRoots: [
vscode.Uri.file(path.join(extensionPath, 'devtoolsDist')),
],
}
)
panel.onDidDispose(onDispose)
DevtoolsPanel.currentPanel = new DevtoolsPanel(panel, extensionPath)
}
static revive(webViewPanel: vscode.WebviewPanel, extensionPath: string) {
DevtoolsPanel.currentPanel = new DevtoolsPanel(webViewPanel, extensionPath)
}
}