-
Notifications
You must be signed in to change notification settings - Fork 7
/
extension.js
116 lines (102 loc) · 2.92 KB
/
extension.js
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const fs = require('fs');
const path = require('path');
const vscode = require('vscode');
const getWebviewContent = require('./lib/content');
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
function activate(context) {
let panel;
const _disposables = [];
context.subscriptions.push(
vscode.commands.registerCommand('fsmViewer.view', () => {
panel = vscode.window.createWebviewPanel(
'fsmViewer',
'FSM Viewer',
vscode.ViewColumn.Two,
{
// Enable scripts in the webview
enableScripts: true
}
);
vscode.workspace.onDidChangeTextDocument(
e => {
if (e.document === vscode.window.activeTextEditor.document) {
panel.webview.html = getWebviewContent(context);
}
},
null,
_disposables
);
vscode.window.onDidChangeTextEditorSelection(
e => {
if (e.textEditor === vscode.window.activeTextEditor) {
panel.webview.html = getWebviewContent(context);
}
},
null,
_disposables
);
vscode.window.onDidChangeActiveTextEditor(
e => {
// panel.webview.html = getWebviewContent(context);
},
null,
_disposables
);
panel.webview.onDidReceiveMessage(
async message => {
switch (message.command) {
case 'svg':
const filename = await vscode.window.showInputBox({
prompt: 'Relative to project root',
placeHolder: 'Type the ouput filename'
});
filename &&
fs.writeFileSync(
path.join(vscode.workspace.rootPath, filename),
message.content
);
break;
default:
}
},
null,
_disposables
);
panel.onDidDispose(
() => {
console.log('panel closed');
while (_disposables.length) {
const item = _disposables.pop();
if (item) {
item.dispose();
}
}
vscode.commands.executeCommand(
'setContext',
'fsmViewer:canExport',
false
);
},
null,
context.subscriptions
);
panel.webview.html = getWebviewContent(context);
})
);
context.subscriptions.push(
vscode.commands.registerCommand('fsmViewer.save', () => {
panel.webview.postMessage({
command: 'save'
});
})
);
}
exports.activate = activate;
// this method is called when your extension is deactivated
function deactivate() {
console.log('deactivate');
}
exports.deactivate = deactivate;