";
var dirIcon = "
";
for (var i = 0; i < data.subFiles.length; i++) {
var obj = data.subFiles[i];
var divHtml = "";
var clickfun = "";
if (obj.subFiles == undefined) {
clickfun = "onclick = 'clickProjectFile(\"" + preFix + obj.name
+ "\")'" + " class='projectFileDiv' ";
} else {
clickfun = "onclick ='clickProjectDir(\"" + preFix + obj.name
+ "\")'" + " class='projectFileDiv' ";
}
if (obj.subFiles != undefined) {
divHtml = "
"
+ "
" + dirIcon + "" + obj.name
+ "
";
divHtml += "
";
divHtml += getProjectTreeHtml2(obj, clz, preFix + obj.name + "/",
extraPadding + 12, order + "_" + i);
divHtml += "
";
divHtml += "
";
} else {
divHtml = "
";
}
ret += divHtml;
}
if (data.subFiles.length == 0) {
divHtml = "
";
ret += divHtml;
}
ret += "
";
return ret;
};
// Tab related handlers============
var onListFile = function (obj) {
var data = JSON.parse(obj.data);
data.name = "...";
data.changed = false;
// .replace(/.*\//g,"");
data.isPrivate = obj.isPrivate;
mainVue.openedFiles.push(data);
setTimeout(function () {
clickTab(data.path);
}, 100);
};
var onStaticVerify = function (obj) {
var data = {};
data.name = data.path = "/tmp/result_" + (new Date().getTime() % 1000)
+ ".txt";
obj = JSON.parse(obj.data);
obj.result = JSON.parse(obj.result);
data.val = JSON.stringify(obj, null, 4);
mainVue.openedFiles.push(data);
setTimeout(function () {
clickTab(data.path);
}, 100);
}
var clickProjectDir = function () {
};
var clickProjectFile = function (tar) {
var pingObj = {};
pingObj.action = "listFile";
pingObj.path = tar;
pingObj.isPrivate = $("#privateprojecttab").hasClass("active");
for (var i = 0; i < mainVue.openedFiles.length; i++) {
var file = mainVue.openedFiles[i];
if (file.path == tar) {
clickTab(tar);
return;
}
}
global.filewssocket.send(JSON.stringify(pingObj));
};
var formatScriptEditor = function () {
var from = global.scriptEditor.getCursor(true);
var to = global.scriptEditor.getCursor(false);
if (from == to) {
from = {
line: 0,
ch: 0
};
to = {
line: global.scriptEditor.lastLine() + 1,
ch: 1
};
}
global.scriptEditor.autoFormatRange(from, to);
}
var adjustFileName = function (title) {
if (mainVue.openedFiles.length < 2)
return;
var totalLen = 90;
var average = (totalLen - title.length - 6)
/ (mainVue.openedFiles.length - 1);
average -= 4;
for (var i = 0; i < mainVue.openedFiles.length; i++) {
var file = mainVue.openedFiles[i];
if (file.path == title)
file.name = file.path;
else {
if (file.path.length > average + 5)
file.name = file.path.substr(0, average) + " ...";
else
file.name = file.path;
}
if (file.changed) {
file.name = "* " + file.name;
}
}
};
var clickTab = function (title) {
if (title.getAttribute != undefined) {
title = title.getAttribute("path");
}
if (global.currentFile != undefined && global.currentFile.val != undefined) {
var val = global.scriptEditor.getValue();
if (global.currentFile.val != val) {
global.currentFile.changed = true;
}
global.currentFile.val = val;
}
for (var i = 0; i < mainVue.openedFiles.length; i++) {
var file = mainVue.openedFiles[i];
if (file.path == title) {
if (file.val != undefined) {
global.scriptEditor.setOption("mode", "application/javascript");
if (file.path.endsWith(".css")) {
global.scriptEditor.setOption("mode", "text/css");
}
if (file.path.endsWith(".html")) {
global.scriptEditor.setOption("mode", "text/html");
}
if (file.path.endsWith(".js")) {
global.scriptEditor.setOption("mode",
"application/javascript");
}
global.scriptEditor.setValue(file.val);
} else {
global.scriptEditor.setValue("not text file!");
}
$("#myFileTab a").removeClass("active");
$("#myFileTab a")[i].classList.add("active");
global.currentFile = file;
adjustFileName(title);
return;
}
}
// it is Hello
if (title == "Hello") {
$("#myFileTab a")[0].classList.add("active");
global.scriptEditor.setValue("Hello Page");
adjustFileName(title);
}
};
var closeTab = function (ele) {
var path = ele.getAttribute("path");
var newList = [];
var pos = 0;
for (var i = 0; i < mainVue.openedFiles.length; i++) {
var file = mainVue.openedFiles[i];
if (file.path == global.currentFile.path) {
pos = i;
}
if (file.path == path) {
continue;
}
newList.push(file);
}
mainVue.openedFiles = newList;
if (pos < mainVue.openedFiles.length) {
clickTab(mainVue.openedFiles[pos].path);
} else {
pos--;
if (pos >= 0)
clickTab(mainVue.openedFiles[pos].path);
}
};
// Tab related handlers============
var getProjectTreeHtml = function (data, clz, preFix) {
if (data == undefined || data.subFiles == undefined)
return "";
var ret = "