forked from Vhornets/brackets-builder
-
Notifications
You must be signed in to change notification settings - Fork 7
/
results-panel.js
108 lines (93 loc) · 3.74 KB
/
results-panel.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
/*jslint plusplus: true, vars: true, nomen: true */
/*global define, brackets, console, setTimeout, $, document, alert */
define(function (require, exports, module) {
"use strict";
var WorkspaceManager = brackets.getModule("view/WorkspaceManager"),
DocumentManager = brackets.getModule("document/DocumentManager"),
EditorManager = brackets.getModule("editor/EditorManager"),
decorate = require("decorate");
var panel,
panelHTML = require('text!results-panel.html'),
panelIsVisible = false;
panel = WorkspaceManager.createBottomPanel("brackets-builder-panel", $(panelHTML), 100);
$('#builder-panel .close').on('click', function () {
panel.hide();
});
function _processCmdOutput(data) {
data = data.replace(/^[ ]*(\\n)+/, ''); // remove starting new lines
//data = JSON.stringify(data);
//data = data.replace(/\\n/g, '<br />').replace(/\\t/g, '');
data.replace(/^[ ]*\"/, '').replace(/\"[ ]*$/, ''); // remove quotes
return data;
}
function onPanelClickMaker(filename, errObj, lastErrors) {
var line = errObj.line;
return function () {
console.log("Setting doc to " + filename);
var doc = DocumentManager.getDocumentForPath(filename);
doc.then(function (doc) {
DocumentManager.setCurrentDocument(doc);
decorate.setCurrentFile();
decorate.add_errors_to_file(lastErrors);
// set cursor TODO: non working
var dm = DocumentManager.getCurrentDocument()._masterEditor;
var cm = dm._codeMirror;
cm.setCursor(line);
cm.scrollIntoView({
line: line,
ch: 0
});
EditorManager.focusEditor();
}).done();
};
}
function setPanel(data, compilerFail) {
if (!data) {
data = "";
$('#builder-panel .builder-content-errors').empty();
panel.hide();
return;
}
if (typeof data === "string") {
$('#builder-panel .resizable-content-error').hide();
$('#builder-panel .builder-content-result').show().text(_processCmdOutput(data));
} else {
$('#builder-panel .builder-content-result').hide();
$('#builder-panel .resizable-content-error').show();
$('#builder-panel .builder-content-errors').append(data);
}
if (compilerFail) {
$('.build-success').hide();
} else {
$('.build-success').show();
}
panel.show();
}
function cleanFilename(file) {
return file.replace(/^[\w\W]*[\\\/]/, '');
}
function setErrors(lastErrors) {
var filename,
n;
for (filename in lastErrors) {
if (lastErrors.hasOwnProperty(filename)) {
var o = lastErrors[filename];
for (n = 0; n < o.length; n++) {
var panel_txt = "<tr class='panel_error'>";
panel_txt += "<td class='error-icon'></td>";
panel_txt += "<td><pre>" + _processCmdOutput(o[n].error) + "</pre></td>";
panel_txt += "<td>" + cleanFilename(filename) + "</td><td>" + (+(o[n].line) + 1) + "</td>";
panel_txt += "</tr>";
var panel_node = $(panel_txt);
panel_node.on("click", onPanelClickMaker(filename, o[n], lastErrors));
//console.log("panel_txt " + panel_txt);
setPanel(panel_node, true);
}
}
}
}
module.exports = {
setPanel: setPanel,
setErrors: setErrors
};
});