forked from cerebral/overmind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevtoolsPanel.ts
More file actions
67 lines (59 loc) · 1.58 KB
/
DevtoolsPanel.ts
File metadata and controls
67 lines (59 loc) · 1.58 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
import * as vscode from 'vscode'
import { log } from './utils/Logger'
import * as path from 'path'
type Options = {
context: vscode.ExtensionContext
onMessage: (command: string, text: string) => void
onDispose: () => void
}
export class DevtoolsPanel {
public static viewType = 'overmindDevtools'
private readonly _options: Options
private _panel!: vscode.WebviewPanel
constructor(options: Options) {
this._options = options
}
show(content: string, panel?: vscode.WebviewPanel) {
if (this._panel) {
this._panel.dispose()
}
this._panel =
panel ||
vscode.window.createWebviewPanel(
DevtoolsPanel.viewType,
'Overmind',
{
viewColumn:
vscode.window.activeTextEditor &&
vscode.window.activeTextEditor.viewColumn
? vscode.window.activeTextEditor.viewColumn
: vscode.ViewColumn.One,
},
{
enableScripts: true,
retainContextWhenHidden: true,
localResourceRoots: [
vscode.Uri.file(
path.join(this._options.context.extensionPath, 'devtoolsDist')
),
],
}
)
this._panel.webview.onDidReceiveMessage(
(message) => {
this._options.onMessage(message.command, message.text)
},
null,
this._options.context.subscriptions
)
this._panel.onDidDispose(
() => {
delete this._panel
this._options.onDispose()
},
null,
this._options.context.subscriptions
)
this._panel.webview.html = content
}
}