2014-08-18 17:45:43 +04:00
|
|
|
|
var wide = {
|
2014-08-29 13:24:08 +04:00
|
|
|
|
curNode: undefined,
|
|
|
|
|
curEditor: undefined,
|
2014-09-24 09:40:19 +04:00
|
|
|
|
curProcessId: undefined, // 当前正在运行的进程 id(pid)
|
2014-09-24 08:07:20 +04:00
|
|
|
|
_initDialog: function () {
|
2014-10-13 07:43:22 +04:00
|
|
|
|
$(".dialog-prompt > input").keyup(function (event) {
|
|
|
|
|
var $okBtn = $(this).closest(".dialog-main").find(".dialog-footer > button:eq(0)");
|
|
|
|
|
if (event.which === 13 && !$okBtn.prop("disabled")) {
|
|
|
|
|
$okBtn.click();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($.trim($(this).val()) === "") {
|
|
|
|
|
$okBtn.prop("disabled", true);
|
|
|
|
|
} else {
|
|
|
|
|
$okBtn.prop("disabled", false);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2014-09-24 07:35:03 +04:00
|
|
|
|
$("#dialogAlert").dialog({
|
2014-10-20 18:27:19 +04:00
|
|
|
|
"modal": true,
|
2014-09-24 07:35:03 +04:00
|
|
|
|
"height": 26,
|
|
|
|
|
"width": 260,
|
|
|
|
|
"title": config.label.tip,
|
|
|
|
|
"hiddenOk": true,
|
|
|
|
|
"cancelText": config.label.confirm,
|
2014-09-24 08:07:20 +04:00
|
|
|
|
"afterOpen": function (msg) {
|
2014-09-24 07:35:03 +04:00
|
|
|
|
$("#dialogAlert").html(msg);
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-09-24 08:07:20 +04:00
|
|
|
|
|
2014-09-22 13:44:34 +04:00
|
|
|
|
$("#dialogRemoveConfirm").dialog({
|
2014-10-20 18:27:19 +04:00
|
|
|
|
"modal": true,
|
2014-09-22 13:44:34 +04:00
|
|
|
|
"height": 26,
|
|
|
|
|
"width": 260,
|
|
|
|
|
"title": config.label.delete,
|
|
|
|
|
"okText": config.label.delete,
|
|
|
|
|
"cancelText": config.label.cancel,
|
2014-09-24 08:07:20 +04:00
|
|
|
|
"afterOpen": function () {
|
2014-09-22 13:44:34 +04:00
|
|
|
|
$("#dialogRemoveConfirm > b").html('"' + wide.curNode.name + '"');
|
|
|
|
|
},
|
2014-09-24 08:07:20 +04:00
|
|
|
|
"ok": function () {
|
2014-09-22 13:44:34 +04:00
|
|
|
|
var request = newWideRequest();
|
|
|
|
|
request.path = wide.curNode.path;
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
|
|
|
|
url: '/file/remove',
|
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
2014-09-24 08:07:20 +04:00
|
|
|
|
success: function (data) {
|
2014-09-22 13:44:34 +04:00
|
|
|
|
if (!data.succ) {
|
2014-11-07 18:11:37 +03:00
|
|
|
|
$("#dialogRemoveConfirm").dialog("close");
|
|
|
|
|
bottomGroup.tabs.setCurrent("notification");
|
|
|
|
|
windows.flowBottom();
|
|
|
|
|
$(".bottom-window-group .notification").focus();
|
2014-09-22 13:44:34 +04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$("#dialogRemoveConfirm").dialog("close");
|
|
|
|
|
tree.fileTree.removeNode(wide.curNode);
|
|
|
|
|
|
2014-11-06 10:47:05 +03:00
|
|
|
|
if (!tree.isDir()) {
|
2014-09-22 13:44:34 +04:00
|
|
|
|
// 是文件的话,查看 editor 中是否被打开,如打开则移除
|
|
|
|
|
for (var i = 0, ii = editors.data.length; i < ii; i++) {
|
|
|
|
|
if (editors.data[i].id === wide.curNode.tId) {
|
2014-09-25 12:40:05 +04:00
|
|
|
|
$(".edit-panel .tabs > div[data-index=" + wide.curNode.tId + "]").find(".ico-close").click();
|
2014-09-22 13:44:34 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (var i = 0, ii = editors.data.length; i < ii; i++) {
|
|
|
|
|
if (tree._isParents(editors.data[i].id, wide.curNode.tId)) {
|
2014-09-25 12:40:05 +04:00
|
|
|
|
$(".edit-panel .tabs > div[data-index=" + editors.data[i].id + "]").find(".ico-close").click();
|
2014-09-22 13:44:34 +04:00
|
|
|
|
i--;
|
|
|
|
|
ii--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2014-11-07 18:11:37 +03:00
|
|
|
|
$("#dialogRenamePrompt").dialog({
|
|
|
|
|
"modal": true,
|
|
|
|
|
"height": 52,
|
|
|
|
|
"width": 260,
|
|
|
|
|
"title": config.label.rename,
|
|
|
|
|
"okText": config.label.rename,
|
|
|
|
|
"cancelText": config.label.cancel,
|
|
|
|
|
"afterOpen": function () {
|
|
|
|
|
var index = wide.curNode.name.lastIndexOf(".");
|
|
|
|
|
$("#dialogRenamePrompt > input").val(wide.curNode.name.substring(0, index)).focus();
|
2014-11-07 18:17:56 +03:00
|
|
|
|
// TODO: 全选
|
2014-11-07 18:11:37 +03:00
|
|
|
|
$("#dialogRenamePrompt").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled", true);
|
|
|
|
|
},
|
|
|
|
|
"ok": function () {
|
|
|
|
|
var name = $("#dialogRenamePrompt > input").val(),
|
|
|
|
|
request = newWideRequest();
|
|
|
|
|
|
|
|
|
|
request.oldPath = wide.curNode.path;
|
|
|
|
|
|
|
|
|
|
var pathIndex = wide.curNode.path.lastIndexOf(config.pathSeparator),
|
|
|
|
|
nameIndex = wide.curNode.name.lastIndexOf("."),
|
|
|
|
|
ext = wide.curNode.name.substring(nameIndex, wide.curNode.name.length);
|
|
|
|
|
request.newPath = wide.curNode.path.substring(0, pathIndex) + config.pathSeparator
|
|
|
|
|
+ name + ext;
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
|
|
|
|
url: '/file/rename',
|
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
|
|
|
|
success: function (data) {
|
|
|
|
|
if (!data.succ) {
|
|
|
|
|
$("#dialogRenamePrompt").dialog("close");
|
|
|
|
|
bottomGroup.tabs.setCurrent("notification");
|
|
|
|
|
windows.flowBottom();
|
|
|
|
|
$(".bottom-window-group .notification").focus();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$("#dialogRenamePrompt").dialog("close");
|
|
|
|
|
|
|
|
|
|
// update tree node
|
|
|
|
|
wide.curNode.name = name + ext;
|
|
|
|
|
wide.curNode.title = request.newPath;
|
|
|
|
|
wide.curNode.path = request.newPath;
|
|
|
|
|
tree.fileTree.updateNode(wide.curNode);
|
|
|
|
|
|
|
|
|
|
// update open editor tab name
|
|
|
|
|
var $currentSpan = $(".edit-panel .tabs > div[data-index=" + wide.curNode.tId + "] > span:eq(0)");
|
|
|
|
|
$currentSpan.attr("title", request.newPath);
|
|
|
|
|
$currentSpan.html($currentSpan.find("span").html() + wide.curNode.name);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2014-09-22 13:44:34 +04:00
|
|
|
|
$("#dialogNewFilePrompt").dialog({
|
2014-10-20 18:27:19 +04:00
|
|
|
|
"modal": true,
|
2014-09-22 14:09:16 +04:00
|
|
|
|
"height": 52,
|
2014-09-22 13:44:34 +04:00
|
|
|
|
"width": 260,
|
|
|
|
|
"title": config.label.create_file,
|
|
|
|
|
"okText": config.label.create,
|
|
|
|
|
"cancelText": config.label.cancel,
|
2014-09-24 08:07:20 +04:00
|
|
|
|
"afterOpen": function () {
|
2014-09-22 13:44:34 +04:00
|
|
|
|
$("#dialogNewFilePrompt > input").val('').focus();
|
2014-10-13 07:43:22 +04:00
|
|
|
|
$("#dialogNewFilePrompt").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled", true);
|
2014-09-22 13:44:34 +04:00
|
|
|
|
},
|
2014-09-24 08:07:20 +04:00
|
|
|
|
"ok": function () {
|
2014-09-22 13:44:34 +04:00
|
|
|
|
var request = newWideRequest(),
|
2014-09-22 14:09:16 +04:00
|
|
|
|
name = $("#dialogNewFilePrompt > input").val();
|
|
|
|
|
|
2014-10-13 10:40:55 +04:00
|
|
|
|
request.path = wide.curNode.path + config.pathSeparator + name;
|
2014-09-22 13:44:34 +04:00
|
|
|
|
request.fileType = "f";
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
|
|
|
|
url: '/file/new',
|
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
2014-09-24 08:07:20 +04:00
|
|
|
|
success: function (data) {
|
2014-09-22 13:44:34 +04:00
|
|
|
|
if (!data.succ) {
|
2014-11-07 18:11:37 +03:00
|
|
|
|
$("#dialogNewFilePrompt").dialog("close");
|
|
|
|
|
bottomGroup.tabs.setCurrent("notification");
|
|
|
|
|
windows.flowBottom();
|
|
|
|
|
$(".bottom-window-group .notification").focus();
|
2014-09-22 13:44:34 +04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-11-07 18:11:37 +03:00
|
|
|
|
|
2014-09-22 13:44:34 +04:00
|
|
|
|
$("#dialogNewFilePrompt").dialog("close");
|
|
|
|
|
var suffix = name.split(".")[1],
|
|
|
|
|
iconSkin = "ico-ztree-other ";
|
|
|
|
|
switch (suffix) {
|
|
|
|
|
case "html", "htm":
|
|
|
|
|
iconSkin = "ico-ztree-html ";
|
|
|
|
|
break;
|
|
|
|
|
case "go":
|
|
|
|
|
iconSkin = "ico-ztree-go ";
|
|
|
|
|
break;
|
|
|
|
|
case "css":
|
|
|
|
|
iconSkin = "ico-ztree-css ";
|
|
|
|
|
break;
|
|
|
|
|
case "txt":
|
|
|
|
|
iconSkin = "ico-ztree-text ";
|
|
|
|
|
break;
|
|
|
|
|
case "sql":
|
|
|
|
|
iconSkin = "ico-ztree-sql ";
|
|
|
|
|
break;
|
|
|
|
|
case "properties":
|
|
|
|
|
iconSkin = "ico-ztree-pro ";
|
|
|
|
|
break;
|
|
|
|
|
case "md":
|
|
|
|
|
iconSkin = "ico-ztree-md ";
|
|
|
|
|
break;
|
|
|
|
|
case "js", "json":
|
|
|
|
|
iconSkin = "ico-ztree-js ";
|
|
|
|
|
break;
|
|
|
|
|
case "xml":
|
|
|
|
|
iconSkin = "ico-ztree-xml ";
|
|
|
|
|
break;
|
|
|
|
|
case "jpg", "jpeg", "bmp", "gif", "png", "svg", "ico":
|
|
|
|
|
iconSkin = "ico-ztree-img ";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tree.fileTree.addNodes(wide.curNode, [{
|
|
|
|
|
"name": name,
|
|
|
|
|
"iconSkin": iconSkin,
|
|
|
|
|
"path": request.path,
|
2014-11-06 12:55:07 +03:00
|
|
|
|
"mode": data.mode,
|
|
|
|
|
"removable": true,
|
|
|
|
|
"creatable": true
|
2014-09-22 13:44:34 +04:00
|
|
|
|
}]);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$("#dialogNewDirPrompt").dialog({
|
2014-10-20 18:27:19 +04:00
|
|
|
|
"modal": true,
|
2014-09-22 14:09:16 +04:00
|
|
|
|
"height": 52,
|
2014-09-22 13:44:34 +04:00
|
|
|
|
"width": 260,
|
|
|
|
|
"title": config.label.create_dir,
|
|
|
|
|
"okText": config.label.create,
|
|
|
|
|
"cancelText": config.label.cancel,
|
2014-09-24 08:07:20 +04:00
|
|
|
|
"afterOpen": function () {
|
2014-09-22 13:44:34 +04:00
|
|
|
|
$("#dialogNewDirPrompt > input").val('').focus();
|
2014-10-13 07:43:22 +04:00
|
|
|
|
$("#dialogNewDirPrompt").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled", true);
|
2014-09-22 13:44:34 +04:00
|
|
|
|
},
|
2014-09-24 08:07:20 +04:00
|
|
|
|
"ok": function () {
|
2014-09-22 13:44:34 +04:00
|
|
|
|
var name = $("#dialogNewDirPrompt > input").val(),
|
|
|
|
|
request = newWideRequest();
|
2014-10-13 07:43:22 +04:00
|
|
|
|
|
2014-10-13 10:46:27 +04:00
|
|
|
|
request.path = wide.curNode.path + config.pathSeparator + name;
|
2014-09-22 13:44:34 +04:00
|
|
|
|
request.fileType = "d";
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
|
|
|
|
url: '/file/new',
|
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
2014-09-24 08:07:20 +04:00
|
|
|
|
success: function (data) {
|
2014-09-22 13:44:34 +04:00
|
|
|
|
if (!data.succ) {
|
2014-11-07 18:11:37 +03:00
|
|
|
|
$("#dialogNewDirPrompt").dialog("close");
|
|
|
|
|
bottomGroup.tabs.setCurrent("notification");
|
|
|
|
|
windows.flowBottom();
|
|
|
|
|
$(".bottom-window-group .notification").focus();
|
2014-09-22 13:44:34 +04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$("#dialogNewDirPrompt").dialog("close");
|
|
|
|
|
|
|
|
|
|
tree.fileTree.addNodes(wide.curNode, [{
|
|
|
|
|
"name": name,
|
|
|
|
|
"iconSkin": "ico-ztree-dir ",
|
2014-11-06 12:55:07 +03:00
|
|
|
|
"path": request.path,
|
|
|
|
|
"removable": true,
|
|
|
|
|
"creatable": true
|
2014-09-22 13:44:34 +04:00
|
|
|
|
}]);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$("#dialogGoLinePrompt").dialog({
|
2014-10-20 18:27:19 +04:00
|
|
|
|
"modal": true,
|
2014-09-22 14:09:16 +04:00
|
|
|
|
"height": 52,
|
2014-09-22 13:44:34 +04:00
|
|
|
|
"width": 260,
|
|
|
|
|
"title": config.label.goto_line,
|
2014-10-23 19:14:34 +04:00
|
|
|
|
"okText": config.label.go,
|
2014-09-22 13:44:34 +04:00
|
|
|
|
"cancelText": config.label.cancel,
|
2014-09-24 08:07:20 +04:00
|
|
|
|
"afterOpen": function () {
|
2014-09-22 13:44:34 +04:00
|
|
|
|
$("#dialogGoLinePrompt > input").val('').focus();
|
2014-10-13 07:43:22 +04:00
|
|
|
|
$("#dialogGoLinePrompt").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled", true);
|
2014-09-22 13:44:34 +04:00
|
|
|
|
},
|
2014-09-24 08:07:20 +04:00
|
|
|
|
"ok": function () {
|
2014-11-07 09:13:55 +03:00
|
|
|
|
var line = parseInt($("#dialogGoLinePrompt > input").val()) - 1;
|
2014-09-22 13:44:34 +04:00
|
|
|
|
$("#dialogGoLinePrompt").dialog("close");
|
2014-11-07 18:11:37 +03:00
|
|
|
|
|
2014-11-04 19:27:43 +03:00
|
|
|
|
var editor = wide.curEditor;
|
2014-11-07 09:13:55 +03:00
|
|
|
|
var cursor = editor.getCursor();
|
2014-11-05 11:41:53 +03:00
|
|
|
|
|
2014-11-07 09:13:55 +03:00
|
|
|
|
editor.setCursor(CodeMirror.Pos(line, cursor.ch));
|
2014-11-04 19:27:43 +03:00
|
|
|
|
|
|
|
|
|
var half = Math.floor(editor.getScrollInfo().clientHeight / editor.defaultTextHeight() / 2);
|
2014-11-07 09:13:55 +03:00
|
|
|
|
var cursorCoords = editor.cursorCoords({line: line - half, ch: cursor.ch}, "local");
|
|
|
|
|
editor.scrollTo(0, cursorCoords.top);
|
2014-11-04 19:27:43 +03:00
|
|
|
|
|
|
|
|
|
editor.focus();
|
2014-09-22 13:44:34 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
2014-10-12 09:40:07 +04:00
|
|
|
|
|
2014-10-13 07:43:22 +04:00
|
|
|
|
$("#dialogSearchForm > input:eq(0)").keyup(function (event) {
|
|
|
|
|
var $okBtn = $(this).closest(".dialog-main").find(".dialog-footer > button:eq(0)");
|
|
|
|
|
if (event.which === 13 && !$okBtn.prop("disabled")) {
|
|
|
|
|
$okBtn.click();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($.trim($(this).val()) === "") {
|
|
|
|
|
$okBtn.prop("disabled", true);
|
|
|
|
|
} else {
|
|
|
|
|
$okBtn.prop("disabled", false);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$("#dialogSearchForm > input:eq(1)").keyup(function (event) {
|
|
|
|
|
var $okBtn = $(this).closest(".dialog-main").find(".dialog-footer > button:eq(0)");
|
|
|
|
|
if (event.which === 13 && !$okBtn.prop("disabled")) {
|
|
|
|
|
$okBtn.click();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2014-10-12 09:40:07 +04:00
|
|
|
|
$("#dialogSearchForm").dialog({
|
2014-10-20 18:27:19 +04:00
|
|
|
|
"modal": true,
|
2014-10-13 07:43:22 +04:00
|
|
|
|
"height": 62,
|
2014-10-12 09:40:07 +04:00
|
|
|
|
"width": 260,
|
2014-10-12 18:00:26 +04:00
|
|
|
|
"title": config.label.search,
|
|
|
|
|
"okText": config.label.search,
|
2014-10-12 09:40:07 +04:00
|
|
|
|
"cancelText": config.label.cancel,
|
|
|
|
|
"afterOpen": function () {
|
|
|
|
|
$("#dialogSearchForm > input:eq(0)").val('').focus();
|
2014-10-13 07:43:22 +04:00
|
|
|
|
$("#dialogSearchForm > input:eq(1)").val('');
|
|
|
|
|
$("#dialogSearchForm").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled", true);
|
2014-10-12 09:40:07 +04:00
|
|
|
|
},
|
|
|
|
|
"ok": function () {
|
|
|
|
|
var request = newWideRequest();
|
|
|
|
|
request.dir = wide.curNode.path;
|
|
|
|
|
request.text = $("#dialogSearchForm > input:eq(0)").val();
|
|
|
|
|
request.extension = $("#dialogSearchForm > input:eq(1)").val();
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
|
|
|
|
url: '/file/search/text',
|
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
|
|
|
|
success: function (data) {
|
|
|
|
|
if (!data.succ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-10-13 07:43:22 +04:00
|
|
|
|
|
2014-10-12 18:00:26 +04:00
|
|
|
|
$("#dialogSearchForm").dialog("close");
|
|
|
|
|
editors.appendSearch(data.founds, 'founds', request.text);
|
2014-10-12 09:40:07 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-10-22 13:31:25 +04:00
|
|
|
|
|
|
|
|
|
$("#dialogAbout").load('/about', function () {
|
|
|
|
|
$("#dialogAbout").dialog({
|
|
|
|
|
"modal": true,
|
|
|
|
|
"height": 460,
|
2014-10-23 14:13:07 +04:00
|
|
|
|
"width": 800,
|
2014-10-22 13:31:25 +04:00
|
|
|
|
"title": config.label.about,
|
2014-10-23 14:13:07 +04:00
|
|
|
|
"hideFooter": true,
|
|
|
|
|
"afterOpen": function () {
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: "http://rhythm.b3log.org/version/wide/latest",
|
|
|
|
|
type: "GET",
|
|
|
|
|
dataType: "jsonp",
|
|
|
|
|
jsonp: "callback",
|
|
|
|
|
success: function (data, textStatus) {
|
2014-10-31 09:26:08 +03:00
|
|
|
|
if ($("#dialogAbout .version").text() === data.wideVersion) {
|
|
|
|
|
$(".upgrade").text(config.label.uptodate);
|
|
|
|
|
} else {
|
|
|
|
|
$(".upgrade").html(config.label.new_version_available + config.label.colon
|
|
|
|
|
+ "<a href='" + data.wideDownload
|
2014-10-23 19:14:34 +04:00
|
|
|
|
+ "' target='_blank'>" + data.wideVersion + "</a>");
|
2014-10-31 09:26:08 +03:00
|
|
|
|
}
|
2014-10-23 14:13:07 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-10-22 13:31:25 +04:00
|
|
|
|
});
|
|
|
|
|
});
|
2014-09-22 13:44:34 +04:00
|
|
|
|
},
|
2014-09-24 08:07:20 +04:00
|
|
|
|
_initLayout: function () {
|
2014-11-06 12:09:32 +03:00
|
|
|
|
var mainH = $(window).height() - $(".menu").height() - $(".footer").height(),
|
2014-09-24 12:25:26 +04:00
|
|
|
|
bottomH = Math.floor(mainH * 0.3);
|
2014-11-06 12:09:32 +03:00
|
|
|
|
// 减小初始化界面抖动
|
|
|
|
|
$(".content").height(mainH).css("position", "relative");
|
2014-09-25 07:04:17 +04:00
|
|
|
|
$(".side .tabs-panel").height(mainH - 20);
|
2014-09-05 10:33:43 +04:00
|
|
|
|
|
2014-10-12 08:15:51 +04:00
|
|
|
|
$(".bottom-window-group > .tabs-panel > div > div").height(bottomH - 20);
|
2014-09-02 14:09:01 +04:00
|
|
|
|
},
|
2014-09-24 08:07:20 +04:00
|
|
|
|
_initWS: function () {
|
2014-10-23 09:07:48 +04:00
|
|
|
|
var outputWS = new ReconnectingWebSocket(config.channel.output + '/output/ws?sid=' + config.wideSessionId);
|
2014-09-24 08:07:20 +04:00
|
|
|
|
outputWS.onopen = function () {
|
|
|
|
|
console.log('[output onopen] connected');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
outputWS.onmessage = function (e) {
|
|
|
|
|
console.log('[output onmessage]' + e.data);
|
|
|
|
|
var data = JSON.parse(e.data);
|
|
|
|
|
|
|
|
|
|
if (goLintFound) {
|
|
|
|
|
goLintFound = [];
|
2014-10-22 17:41:14 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-24 08:07:20 +04:00
|
|
|
|
if ('run' === data.nextCmd) {
|
|
|
|
|
var request = newWideRequest();
|
|
|
|
|
request.executable = data.executable;
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
|
|
|
|
url: '/run',
|
|
|
|
|
data: JSON.stringify(request),
|
2014-10-23 07:50:28 +04:00
|
|
|
|
dataType: "json"
|
2014-09-24 08:07:20 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 17:41:14 +04:00
|
|
|
|
switch (data.cmd) {
|
|
|
|
|
case 'run': // 正在运行
|
2014-11-06 06:58:55 +03:00
|
|
|
|
bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);
|
2014-10-22 17:41:14 +04:00
|
|
|
|
wide.curProcessId = data.pid;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case 'run-done': // 运行结束
|
|
|
|
|
wide.curProcessId = undefined;
|
|
|
|
|
// 运行结束后修改 [构建&运行] 图标状态为可用状态
|
|
|
|
|
$(".toolbars .ico-stop").removeClass("ico-stop")
|
|
|
|
|
.addClass("ico-buildrun").attr("title", config.label.build_n_run);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case 'start-build':
|
2014-10-27 18:02:15 +03:00
|
|
|
|
case 'start-test':
|
2014-10-22 17:57:21 +04:00
|
|
|
|
case 'start-install':
|
2014-10-22 18:35:14 +04:00
|
|
|
|
case 'start-get':
|
2014-11-06 06:58:55 +03:00
|
|
|
|
bottomGroup.fillOutput(data.output);
|
2014-10-22 17:41:14 +04:00
|
|
|
|
|
|
|
|
|
break;
|
2014-10-27 18:02:15 +03:00
|
|
|
|
case 'go test':
|
2014-10-22 17:41:14 +04:00
|
|
|
|
case 'go install':
|
|
|
|
|
case 'go get':
|
2014-11-06 06:58:55 +03:00
|
|
|
|
bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);
|
2014-09-24 08:07:20 +04:00
|
|
|
|
|
2014-10-22 17:41:14 +04:00
|
|
|
|
break;
|
|
|
|
|
case 'build':
|
2014-11-06 06:58:55 +03:00
|
|
|
|
bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);
|
2014-09-24 08:07:20 +04:00
|
|
|
|
|
2014-10-22 17:41:14 +04:00
|
|
|
|
if (data.lints) { // 说明编译有错误输出
|
|
|
|
|
for (var i = 0; i < data.lints.length; i++) {
|
|
|
|
|
var lint = data.lints[i];
|
|
|
|
|
|
|
|
|
|
goLintFound.push({from: CodeMirror.Pos(lint.lineNo, 0),
|
|
|
|
|
to: CodeMirror.Pos(lint.lineNo, 0),
|
|
|
|
|
message: lint.msg, severity: lint.severity});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(".toolbars .ico-stop").removeClass("ico-stop")
|
|
|
|
|
.addClass("ico-buildrun").attr("title", config.label.build_n_run);
|
2014-09-24 08:07:20 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 17:41:14 +04:00
|
|
|
|
// 触发一次 gutter lint
|
|
|
|
|
CodeMirror.signal(wide.curEditor, "change", wide.curEditor);
|
2014-09-24 08:07:20 +04:00
|
|
|
|
|
2014-10-22 17:41:14 +04:00
|
|
|
|
break;
|
2014-09-24 08:07:20 +04:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
outputWS.onclose = function (e) {
|
|
|
|
|
console.log('[output onclose] disconnected (' + e.code + ')');
|
|
|
|
|
};
|
|
|
|
|
outputWS.onerror = function (e) {
|
|
|
|
|
console.log('[output onerror] ' + e);
|
|
|
|
|
};
|
|
|
|
|
},
|
2014-09-25 12:03:14 +04:00
|
|
|
|
_initFooter: function () {
|
|
|
|
|
$(".footer .cursor").dblclick(function () {
|
|
|
|
|
$("#dialogGoLinePrompt").dialog("open");
|
|
|
|
|
});
|
|
|
|
|
},
|
2014-09-24 08:07:20 +04:00
|
|
|
|
init: function () {
|
2014-09-25 12:03:14 +04:00
|
|
|
|
this._initFooter();
|
2014-09-24 11:24:37 +04:00
|
|
|
|
|
2014-09-24 12:25:26 +04:00
|
|
|
|
this._initWS();
|
2014-09-17 06:04:41 +04:00
|
|
|
|
|
2014-10-21 11:11:28 +04:00
|
|
|
|
// 点击隐藏弹出层
|
2014-09-24 08:07:20 +04:00
|
|
|
|
$("body").bind("mousedown", function (event) {
|
2014-08-18 17:45:43 +04:00
|
|
|
|
if (!(event.target.id === "dirRMenu" || $(event.target).closest("#dirRMenu").length > 0)) {
|
|
|
|
|
$("#dirRMenu").hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(event.target.id === "fileRMenu" || $(event.target).closest("#fileRMenu").length > 0)) {
|
|
|
|
|
$("#fileRMenu").hide();
|
|
|
|
|
}
|
2014-09-10 14:08:35 +04:00
|
|
|
|
|
|
|
|
|
if (!($(event.target).closest(".frame").length > 0 || event.target.className === "frame")) {
|
|
|
|
|
$(".frame").hide();
|
2014-11-05 10:09:39 +03:00
|
|
|
|
$(".menu > ul > li > a, .menu > ul> li > span").unbind("mouseover").removeClass("selected");
|
2014-09-10 14:08:35 +04:00
|
|
|
|
menu.subMenu();
|
|
|
|
|
}
|
2014-08-18 17:45:43 +04:00
|
|
|
|
});
|
2014-09-13 20:07:03 +04:00
|
|
|
|
|
2014-10-21 11:11:28 +04:00
|
|
|
|
// 刷新提示
|
2014-10-21 10:47:07 +04:00
|
|
|
|
window.onbeforeunload = function () {
|
|
|
|
|
if (editors.data.length > 0) {
|
|
|
|
|
return config.label.confirm_save;
|
|
|
|
|
}
|
|
|
|
|
};
|
2014-10-22 09:49:40 +04:00
|
|
|
|
|
2014-10-21 11:11:28 +04:00
|
|
|
|
// 禁止鼠标右键菜单
|
|
|
|
|
document.oncontextmenu = function () {
|
|
|
|
|
return false;
|
|
|
|
|
};
|
2014-10-21 10:47:07 +04:00
|
|
|
|
|
2014-09-22 13:44:34 +04:00
|
|
|
|
this._initDialog();
|
2014-09-24 12:25:26 +04:00
|
|
|
|
|
|
|
|
|
this._initLayout();
|
2014-11-07 05:51:55 +03:00
|
|
|
|
|
|
|
|
|
$(window).resize(function () {
|
|
|
|
|
wide._initLayout();
|
|
|
|
|
var editorDatas = editors.data,
|
|
|
|
|
height = $(".edit-panel").height() - $(".edit-panel .tabs").height();
|
|
|
|
|
for (var i = 0, ii = editorDatas.length; i < ii; i++) {
|
|
|
|
|
editorDatas[i].editor.setSize("100%", height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
2014-08-18 17:45:43 +04:00
|
|
|
|
},
|
2014-11-04 11:20:51 +03:00
|
|
|
|
_save: function (path, editor) {
|
|
|
|
|
if (!path) {
|
2014-10-17 10:47:29 +04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-17 06:04:41 +04:00
|
|
|
|
var request = newWideRequest();
|
2014-11-04 11:20:51 +03:00
|
|
|
|
request.file = path;
|
|
|
|
|
request.code = editor.getValue();
|
2014-09-17 06:04:41 +04:00
|
|
|
|
|
2014-08-18 17:45:43 +04:00
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
2014-08-22 06:09:48 +04:00
|
|
|
|
url: '/file/save',
|
2014-08-18 17:45:43 +04:00
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
2014-09-24 08:07:20 +04:00
|
|
|
|
success: function (data) {
|
2014-11-04 11:20:51 +03:00
|
|
|
|
// reset the save state
|
2014-11-04 19:27:43 +03:00
|
|
|
|
|
2014-11-04 11:20:51 +03:00
|
|
|
|
editor.doc.markClean();
|
|
|
|
|
$(".edit-panel .tabs > div").each(function () {
|
|
|
|
|
var $span = $(this).find("span:eq(0)");
|
|
|
|
|
if ($span.attr("title") === path) {
|
|
|
|
|
$span.removeClass("changed");
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-08-18 17:45:43 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2014-09-24 08:07:20 +04:00
|
|
|
|
saveFile: function () {
|
2014-11-04 11:20:51 +03:00
|
|
|
|
var path = editors.getCurrentPath();
|
|
|
|
|
if (!path) {
|
2014-10-17 10:47:29 +04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-11-04 19:27:43 +03:00
|
|
|
|
|
2014-11-04 11:20:51 +03:00
|
|
|
|
var editor = wide.curEditor;
|
|
|
|
|
if (editor.doc.isClean()) { // no modification
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ("text/x-go" === editor.getOption("mode")) {
|
|
|
|
|
wide.gofmt(path, wide.curEditor); // go fmt will save
|
2014-10-21 10:08:11 +04:00
|
|
|
|
|
2014-11-04 11:20:51 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wide._save(path, wide.curEditor);
|
2014-09-20 07:54:33 +04:00
|
|
|
|
},
|
2014-09-24 08:07:20 +04:00
|
|
|
|
saveAllFiles: function () {
|
2014-10-13 13:01:44 +04:00
|
|
|
|
if ($(".menu li.save-all").hasClass("disabled")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-09-22 13:44:34 +04:00
|
|
|
|
for (var i = 0, ii = editors.data.length; i < ii; i++) {
|
2014-11-04 11:20:51 +03:00
|
|
|
|
var path = tree.fileTree.getNodeByTId(editors.data[i].id).path;
|
|
|
|
|
var editor = editors.data[i].editor;
|
|
|
|
|
|
|
|
|
|
if ("text/x-go" === editor.getOption("mode")) {
|
|
|
|
|
wide.fmt(path, editor);
|
|
|
|
|
} else {
|
|
|
|
|
wide._save(path, editor);
|
|
|
|
|
}
|
2014-09-22 13:44:34 +04:00
|
|
|
|
}
|
2014-09-10 18:43:34 +04:00
|
|
|
|
},
|
2014-09-24 08:07:20 +04:00
|
|
|
|
closeAllFiles: function () {
|
2014-10-13 13:01:44 +04:00
|
|
|
|
if ($(".menu li.close-all").hasClass("disabled")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-11-01 16:28:18 +03:00
|
|
|
|
|
|
|
|
|
// 设置全部关闭标识
|
|
|
|
|
var removeData = [];
|
|
|
|
|
$(".edit-panel .tabs > div").each(function (i) {
|
|
|
|
|
if (i !== 0) {
|
|
|
|
|
removeData.push($(this).data("index"));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
$("#dialogCloseEditor").data("removeData", removeData);
|
|
|
|
|
// 开始关闭
|
|
|
|
|
$(".edit-panel .tabs .ico-close:eq(0)").click();
|
2014-09-10 18:43:34 +04:00
|
|
|
|
},
|
2014-09-24 08:07:20 +04:00
|
|
|
|
exit: function () {
|
2014-10-15 17:50:28 +04:00
|
|
|
|
var request = newWideRequest();
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
|
|
|
|
url: '/logout',
|
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
|
|
|
|
success: function (data) {
|
|
|
|
|
if (data.succ) {
|
|
|
|
|
window.location.href = "/login";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-09-10 18:43:34 +04:00
|
|
|
|
},
|
2014-09-24 08:07:20 +04:00
|
|
|
|
stop: function () {
|
2014-09-24 11:24:37 +04:00
|
|
|
|
if ($(".toolbars .ico-buildrun").length === 1) {
|
2014-09-24 08:07:20 +04:00
|
|
|
|
wide.run();
|
|
|
|
|
return false;
|
2014-09-24 11:24:37 +04:00
|
|
|
|
}
|
2014-10-31 09:26:08 +03:00
|
|
|
|
|
|
|
|
|
if (!wide.curProcessId) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-09-24 11:24:37 +04:00
|
|
|
|
|
2014-09-24 08:07:20 +04:00
|
|
|
|
var request = newWideRequest();
|
2014-09-24 09:40:19 +04:00
|
|
|
|
request.pid = wide.curProcessId;
|
2014-09-24 08:07:20 +04:00
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
|
|
|
|
url: '/stop',
|
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
|
|
|
|
success: function (data) {
|
2014-09-24 11:24:37 +04:00
|
|
|
|
$(".toolbars .ico-stop").removeClass("ico-stop")
|
|
|
|
|
.addClass("ico-buildrun").attr("title", config.label.build_n_run);
|
2014-09-24 08:07:20 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2014-10-22 09:49:40 +04:00
|
|
|
|
// 构建.
|
|
|
|
|
build: function () {
|
2014-10-22 12:55:38 +04:00
|
|
|
|
wide.saveAllFiles();
|
2014-10-22 17:41:14 +04:00
|
|
|
|
|
2014-10-22 11:51:48 +04:00
|
|
|
|
var currentPath = editors.getCurrentPath();
|
|
|
|
|
if (!currentPath) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-10-31 09:26:08 +03:00
|
|
|
|
|
2014-10-27 18:02:15 +03:00
|
|
|
|
if ($(".menu li.build").hasClass("disabled")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-10-22 11:51:48 +04:00
|
|
|
|
|
|
|
|
|
var request = newWideRequest();
|
|
|
|
|
request.file = currentPath;
|
|
|
|
|
request.code = wide.curEditor.getValue();
|
|
|
|
|
request.nextCmd = ""; // 只构建,无下一步操作
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
|
|
|
|
url: '/build',
|
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
|
|
|
|
beforeSend: function (data) {
|
2014-11-06 10:04:33 +03:00
|
|
|
|
bottomGroup.resetOutput();
|
2014-10-22 11:51:48 +04:00
|
|
|
|
},
|
|
|
|
|
success: function (data) {
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-10-22 09:49:40 +04:00
|
|
|
|
},
|
|
|
|
|
// 构建并运行.
|
2014-09-24 08:07:20 +04:00
|
|
|
|
run: function () {
|
2014-10-22 12:55:38 +04:00
|
|
|
|
wide.saveAllFiles();
|
2014-10-22 17:41:14 +04:00
|
|
|
|
|
2014-10-17 10:47:29 +04:00
|
|
|
|
var currentPath = editors.getCurrentPath();
|
|
|
|
|
if (!currentPath) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-13 13:01:44 +04:00
|
|
|
|
if ($(".menu li.run").hasClass("disabled")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-24 08:07:20 +04:00
|
|
|
|
if ($(".toolbars .ico-stop").length === 1) {
|
|
|
|
|
wide.stop();
|
|
|
|
|
return false;
|
2014-09-24 11:24:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-17 06:04:41 +04:00
|
|
|
|
var request = newWideRequest();
|
2014-10-17 10:47:29 +04:00
|
|
|
|
request.file = currentPath;
|
2014-09-17 06:04:41 +04:00
|
|
|
|
request.code = wide.curEditor.getValue();
|
2014-10-22 11:51:48 +04:00
|
|
|
|
request.nextCmd = "run";
|
2014-08-29 13:24:08 +04:00
|
|
|
|
|
2014-08-18 17:45:43 +04:00
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
2014-08-22 07:57:05 +04:00
|
|
|
|
url: '/build',
|
2014-08-18 17:45:43 +04:00
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
2014-09-24 08:07:20 +04:00
|
|
|
|
beforeSend: function (data) {
|
2014-11-06 10:04:33 +03:00
|
|
|
|
bottomGroup.resetOutput();
|
2014-08-18 17:45:43 +04:00
|
|
|
|
},
|
2014-09-24 08:07:20 +04:00
|
|
|
|
success: function (data) {
|
2014-09-24 11:24:37 +04:00
|
|
|
|
$(".toolbars .ico-buildrun").addClass("ico-stop")
|
|
|
|
|
.removeClass("ico-buildrun").attr("title", config.label.stop);
|
2014-09-05 08:18:50 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2014-10-27 18:02:15 +03:00
|
|
|
|
// 测试.
|
|
|
|
|
test: function () {
|
|
|
|
|
wide.saveAllFiles();
|
|
|
|
|
|
|
|
|
|
var currentPath = editors.getCurrentPath();
|
|
|
|
|
if (!currentPath) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-10-31 09:26:08 +03:00
|
|
|
|
|
2014-10-27 18:02:15 +03:00
|
|
|
|
if ($(".menu li.test").hasClass("disabled")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var request = newWideRequest();
|
|
|
|
|
request.file = currentPath;
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
|
|
|
|
url: '/go/test',
|
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
|
|
|
|
beforeSend: function (data) {
|
2014-11-06 10:04:33 +03:00
|
|
|
|
bottomGroup.resetOutput();
|
2014-10-27 18:02:15 +03:00
|
|
|
|
},
|
|
|
|
|
success: function (data) {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2014-09-24 08:07:20 +04:00
|
|
|
|
goget: function () {
|
2014-10-23 12:04:52 +04:00
|
|
|
|
wide.saveAllFiles();
|
2014-10-23 14:13:07 +04:00
|
|
|
|
|
2014-10-17 10:47:29 +04:00
|
|
|
|
var currentPath = editors.getCurrentPath();
|
|
|
|
|
if (!currentPath) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-13 13:01:44 +04:00
|
|
|
|
if ($(".menu li.go-get").hasClass("disabled")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-17 06:04:41 +04:00
|
|
|
|
var request = newWideRequest();
|
2014-10-17 10:47:29 +04:00
|
|
|
|
request.file = currentPath;
|
2014-08-29 13:24:08 +04:00
|
|
|
|
|
2014-09-05 08:18:50 +04:00
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
|
|
|
|
url: '/go/get',
|
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
2014-09-24 08:07:20 +04:00
|
|
|
|
beforeSend: function (data) {
|
2014-11-06 10:04:33 +03:00
|
|
|
|
bottomGroup.resetOutput();
|
2014-09-09 13:01:22 +04:00
|
|
|
|
},
|
2014-09-24 08:07:20 +04:00
|
|
|
|
success: function (data) {
|
2014-09-09 13:01:22 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2014-09-24 08:07:20 +04:00
|
|
|
|
goinstall: function () {
|
2014-10-22 12:55:38 +04:00
|
|
|
|
wide.saveAllFiles();
|
2014-10-22 17:41:14 +04:00
|
|
|
|
|
2014-10-17 10:47:29 +04:00
|
|
|
|
var currentPath = editors.getCurrentPath();
|
|
|
|
|
if (!currentPath) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-13 13:01:44 +04:00
|
|
|
|
if ($(".menu li.go-install").hasClass("disabled")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-17 06:04:41 +04:00
|
|
|
|
var request = newWideRequest();
|
2014-10-17 10:47:29 +04:00
|
|
|
|
request.file = currentPath;
|
2014-09-09 13:01:22 +04:00
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
|
|
|
|
url: '/go/install',
|
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
2014-09-24 08:07:20 +04:00
|
|
|
|
beforeSend: function (data) {
|
2014-11-06 10:04:33 +03:00
|
|
|
|
bottomGroup.resetOutput();
|
2014-09-05 08:18:50 +04:00
|
|
|
|
},
|
2014-09-24 08:07:20 +04:00
|
|
|
|
success: function (data) {
|
2014-08-18 17:45:43 +04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2014-11-04 11:20:51 +03:00
|
|
|
|
gofmt: function (path, editor) {
|
|
|
|
|
var cursor = editor.getCursor();
|
|
|
|
|
var scrollInfo = editor.getScrollInfo();
|
2014-11-01 07:36:42 +03:00
|
|
|
|
|
2014-11-04 11:20:51 +03:00
|
|
|
|
var request = newWideRequest();
|
|
|
|
|
request.file = path;
|
|
|
|
|
request.code = editor.getValue();
|
|
|
|
|
request.cursorLine = cursor.line;
|
|
|
|
|
request.cursorCh = cursor.ch;
|
2014-09-07 13:31:57 +04:00
|
|
|
|
|
2014-11-04 11:20:51 +03:00
|
|
|
|
$.ajax({
|
|
|
|
|
async: false, // sync
|
|
|
|
|
type: 'POST',
|
|
|
|
|
url: '/go/fmt',
|
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
|
|
|
|
success: function (data) {
|
|
|
|
|
if (data.succ) {
|
|
|
|
|
editor.setValue(data.code);
|
|
|
|
|
editor.setCursor(cursor);
|
|
|
|
|
editor.scrollTo(null, scrollInfo.top);
|
|
|
|
|
|
|
|
|
|
wide._save(path, editor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
fmt: function (path, editor) {
|
|
|
|
|
var mode = editor.getOption("mode");
|
|
|
|
|
|
|
|
|
|
var cursor = editor.getCursor();
|
|
|
|
|
var scrollInfo = editor.getScrollInfo();
|
2014-10-21 10:47:07 +04:00
|
|
|
|
|
2014-09-17 06:04:41 +04:00
|
|
|
|
var request = newWideRequest();
|
|
|
|
|
request.file = path;
|
2014-11-04 11:20:51 +03:00
|
|
|
|
request.code = editor.getValue();
|
2014-10-21 10:08:11 +04:00
|
|
|
|
request.cursorLine = cursor.line;
|
|
|
|
|
request.cursorCh = cursor.ch;
|
2014-09-07 13:31:57 +04:00
|
|
|
|
|
2014-10-31 09:54:44 +03:00
|
|
|
|
var formatted = null;
|
|
|
|
|
|
2014-09-07 13:31:57 +04:00
|
|
|
|
switch (mode) {
|
2014-10-31 09:26:08 +03:00
|
|
|
|
case "text/x-go":
|
2014-09-07 13:31:57 +04:00
|
|
|
|
$.ajax({
|
2014-11-04 11:20:51 +03:00
|
|
|
|
async: false, // sync
|
2014-09-07 13:31:57 +04:00
|
|
|
|
type: 'POST',
|
|
|
|
|
url: '/go/fmt',
|
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
|
dataType: "json",
|
2014-09-24 08:07:20 +04:00
|
|
|
|
success: function (data) {
|
2014-09-07 13:31:57 +04:00
|
|
|
|
if (data.succ) {
|
2014-11-02 05:58:13 +03:00
|
|
|
|
formatted = data.code;
|
2014-09-07 13:31:57 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
break;
|
2014-10-31 09:26:08 +03:00
|
|
|
|
case "text/html":
|
2014-11-04 11:20:51 +03:00
|
|
|
|
formatted = html_beautify(editor.getValue());
|
2014-09-07 14:13:55 +04:00
|
|
|
|
break;
|
2014-10-31 09:54:44 +03:00
|
|
|
|
case "text/javascript":
|
2014-09-07 14:13:55 +04:00
|
|
|
|
case "application/json":
|
2014-11-04 11:20:51 +03:00
|
|
|
|
formatted = js_beautify(editor.getValue());
|
2014-10-31 09:54:44 +03:00
|
|
|
|
break;
|
|
|
|
|
case "text/css":
|
2014-11-04 11:20:51 +03:00
|
|
|
|
formatted = css_beautify(editor.getValue());
|
2014-09-07 13:31:57 +04:00
|
|
|
|
break;
|
|
|
|
|
default :
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-10-31 09:54:44 +03:00
|
|
|
|
|
|
|
|
|
if (formatted) {
|
2014-11-04 11:20:51 +03:00
|
|
|
|
editor.setValue(formatted);
|
|
|
|
|
editor.setCursor(cursor);
|
|
|
|
|
editor.scrollTo(null, scrollInfo.top);
|
|
|
|
|
|
|
|
|
|
wide._save(path, editor);
|
2014-11-02 05:58:13 +03:00
|
|
|
|
}
|
2014-10-20 18:27:19 +04:00
|
|
|
|
},
|
|
|
|
|
openAbout: function () {
|
2014-10-22 13:31:25 +04:00
|
|
|
|
$("#dialogAbout").dialog("open");
|
2014-08-18 17:45:43 +04:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-09-24 08:07:20 +04:00
|
|
|
|
$(document).ready(function () {
|
2014-08-18 17:45:43 +04:00
|
|
|
|
wide.init();
|
|
|
|
|
tree.init();
|
2014-09-10 14:08:35 +04:00
|
|
|
|
menu.init();
|
2014-09-15 12:06:49 +04:00
|
|
|
|
hotkeys.init();
|
2014-09-19 13:58:29 +04:00
|
|
|
|
notification.init();
|
2014-09-23 17:03:44 +04:00
|
|
|
|
session.init();
|
2014-09-26 11:39:13 +04:00
|
|
|
|
editors.init();
|
|
|
|
|
windows.init();
|
2014-11-06 06:58:55 +03:00
|
|
|
|
bottomGroup.init();
|
2014-08-18 17:45:43 +04:00
|
|
|
|
});
|