forked from jaime-olivares/vscode-yuml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
132 lines (109 loc) · 4.7 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const vscode = require('vscode');
require('./scripts/yumldoc-utils.js')();
exports.activate = function(context)
{
class yUMLDocumentContentProvider
{
constructor () {
this._onDidChange = new vscode.EventEmitter();
this.diagram = "";
}
provideTextDocumentContent (uri, token) {
var doc = `<!DOCTYPE html>
<html>
<head>
<script>
function showDiagram()
{
var isLight = document.body.classList.contains('vscode-light');
var toHide = document.getElementById(isLight ? "dark" : "light");
toHide.style.display = "none";
var styleSheet = document.getElementById('themed');
var color = isLight ? "#404040" : "#C0C0C0";
styleSheet.innerHtml = "#topbar { color:" + color + "; }";
}
</script>
<style>
#topbar {
background-color:rgba(255,102,0,0.1);
height:24px;
line-height:24px;
margin:0 -5px 15px -5px;
padding-left: 10px;
white-space: nowrap;
}
.links {
display: none;
}
#topbar:hover {
background-color: rgba(255,102,0,0.5);
}
#topbar:hover .links {
display: inline-block;
}
a {
margin-left: 15px;
}
</style>
<style id="themed">
</style>
</head>
<body style="margin:10px;" onload="showDiagram()">
<div id="topbar">▶ yUML <div class="links">
<a href="https://github.com/jaime-olivares/vscode-yuml/wiki">Wiki</a>
<a href="https://marketplace.visualstudio.com/items?itemName=JaimeOlivares.yuml#review-details">Write a review</a>
<a href="https://github.com/jaime-olivares/vscode-yuml/issues">Bug reports & feature requests</a>
</div></div>
${this.diagram}
</body>
</html>`;
var editor = vscode.window.activeTextEditor;
if (editor)
editor.show();
return doc;
}
get onDidChange () {
return this._onDidChange.event;
}
load(uri, isOpen) {
const editor = vscode.window.activeTextEditor;
if (!editor || !editor.document)
return;
const text = editor.document.getText();
const filename = editor.document.fileName;
this.diagram = processYumlDocument(text, filename, false);
this._onDidChange.fire(uri);
}
update(uri) {
const editor = vscode.window.activeTextEditor;
if (!editor || !editor.document)
return;
const text = editor.document.getText();
const filename = editor.document.fileName;
const diagram = processYumlDocument(text, filename, true);
if (diagram == "")
this.diagram = "";
else if (!diagram)
this.diagram = "Error composing the yuml invocation";
else
this.diagram = diagram;
this._onDidChange.fire(uri);
}
}
const registerCommand = vscode.commands.registerCommand;
const previewUri = vscode.Uri.parse('vscode-yuml://authority/vscode-yuml');
let provider = new yUMLDocumentContentProvider();
let registration = vscode.workspace.registerTextDocumentContentProvider('vscode-yuml', provider);
console.log('The extension "vscode-yuml" is now active.');
let command = registerCommand('extension.viewYumlDiagram', () => {
var disp = vscode.commands.executeCommand('vscode.previewHtml', previewUri, vscode.ViewColumn.Two).then(
(success) => { provider.update(previewUri); },
(reason) => { vscode.window.showErrorMessage(reason); });
return disp;
});
vscode.workspace.onDidSaveTextDocument((e) => { provider.update(previewUri); });
vscode.workspace.onDidOpenTextDocument((e) => { provider.load(previewUri); });
vscode.window.onDidChangeActiveTextEditor((e) => { provider.load(previewUri); });
context.subscriptions.push(command, registration);
}
exports.deactivate = function() {};