wide/static/js/wide.js

768 lines
28 KiB
JavaScript
Raw Normal View History

2015-01-01 05:06:33 +03:00
/*
2015-12-30 11:13:43 +03:00
* Copyright (c) 2014-2016, b3log.org & hacpai.com
2015-01-01 05:06:33 +03:00
*
2014-11-12 18:13:14 +03:00
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
2015-01-01 05:06:33 +03:00
*
2014-11-12 18:13:14 +03:00
* http://www.apache.org/licenses/LICENSE-2.0
2015-01-01 05:06:33 +03:00
*
2014-11-12 18:13:14 +03:00
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
2014-11-14 06:42:20 +03:00
*/
2014-11-12 18:13:14 +03:00
/*
2015-12-08 18:48:16 +03:00
* @file wide.js
*
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
2015-12-08 18:48:16 +03:00
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.1, Dec 8, 2015
*/
2014-08-18 17:45:43 +04:00
var wide = {
2014-08-29 13:24:08 +04:00
curNode: undefined,
curEditor: undefined,
2014-12-11 18:11:10 +03:00
curProcessId: undefined, // curent running process id (pid)
2015-01-02 13:14:58 +03:00
refreshOutline: function () {
2015-01-03 11:01:24 +03:00
if (!wide.curEditor ||
(wide.curEditor && wide.curEditor.doc.getMode().name !== "go")) {
2015-01-02 13:14:58 +03:00
$("#outline").html('');
return false;
}
2015-01-03 11:01:24 +03:00
2015-01-02 13:14:58 +03:00
var request = newWideRequest();
request.code = wide.curEditor.getValue();
$.ajax({
type: 'POST',
2015-01-04 10:31:03 +03:00
async: false,
2015-01-02 13:14:58 +03:00
url: config.context + '/outline',
data: JSON.stringify(request),
dataType: "json",
2015-11-24 11:30:37 +03:00
success: function (result) {
if (!result.succ) {
2015-01-02 13:14:58 +03:00
return;
}
2015-01-03 11:01:24 +03:00
2015-11-24 11:30:37 +03:00
var data = result.data;
2015-01-02 18:14:41 +03:00
var outlineHTML = '<ul class="list">',
2015-01-03 11:01:24 +03:00
decls = ['constDecls', 'varDecls', 'funcDecls',
'structDecls', 'interfaceDecls', 'typeDecls'];
2015-01-02 13:14:58 +03:00
for (var i = 0, max = decls.length; i < max; i++) {
var key = decls[i];
for (var j = 0, maxj = data[key].length; j < maxj; j++) {
2015-01-03 11:01:24 +03:00
var obj = data[key][j];
outlineHTML += '<li data-ch="' + obj.Ch + '" data-line="'
+ obj.Line + '"><span class="ico ico-'
+ key.replace('Decls', '') + '"></span> ' + obj.Name + '</li>';
2015-01-02 13:14:58 +03:00
}
}
$("#outline").html(outlineHTML + '</ul>');
2015-01-03 11:01:24 +03:00
$("#outline li").dblclick(function () {
var $it = $(this),
2015-01-04 06:21:44 +03:00
cursor = CodeMirror.Pos($it.data('line'), $it.data("ch"));
2015-01-04 05:11:08 +03:00
var editor = wide.curEditor;
editor.setCursor(cursor);
var half = Math.floor(editor.getScrollInfo().clientHeight / editor.defaultTextHeight() / 2);
var cursorCoords = editor.cursorCoords({line: cursor.line - half, ch: 0}, "local");
editor.scrollTo(0, cursorCoords.top);
editor.focus();
2015-01-03 11:01:24 +03:00
});
2015-01-02 13:14:58 +03:00
}
});
},
2014-09-24 08:07:20 +04:00
_initDialog: function () {
$(".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,
2015-08-04 16:37:14 +03:00
"height": 40,
"width": 350,
2014-09-24 07:35:03 +04:00
"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
$("#dialogRemoveConfirm").dialog({
2014-10-20 18:27:19 +04:00
"modal": true,
2014-12-22 13:13:50 +03:00
"height": 36,
"width": 260,
"title": config.label.delete,
"okText": config.label.delete,
"cancelText": config.label.cancel,
2014-09-24 08:07:20 +04:00
"afterOpen": function () {
$("#dialogRemoveConfirm > b").html('"' + wide.curNode.name + '"');
},
2014-09-24 08:07:20 +04:00
"ok": function () {
var request = newWideRequest();
request.path = wide.curNode.path;
$.ajax({
type: 'POST',
2014-12-11 10:32:24 +03:00
url: config.context + '/file/remove',
data: JSON.stringify(request),
dataType: "json",
2015-11-24 12:39:35 +03:00
success: function (result) {
if (!result.succ) {
2014-11-07 18:11:37 +03:00
$("#dialogRemoveConfirm").dialog("close");
bottomGroup.tabs.setCurrent("notification");
windows.flowBottom();
$(".bottom-window-group .notification").focus();
return false;
}
$("#dialogRemoveConfirm").dialog("close");
}
});
}
});
$("#dialogNewFilePrompt").dialog({
2014-10-20 18:27:19 +04:00
"modal": true,
"height": 52,
"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 () {
$("#dialogNewFilePrompt > input").val('').focus();
$("#dialogNewFilePrompt").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled", true);
},
2014-09-24 08:07:20 +04:00
"ok": function () {
var request = newWideRequest(),
name = $("#dialogNewFilePrompt > input").val();
2015-07-23 11:31:37 +03:00
request.path = wide.curNode.path + "/" + name;
request.fileType = "f";
$.ajax({
type: 'POST',
2014-12-11 10:32:24 +03:00
url: config.context + '/file/new',
data: JSON.stringify(request),
dataType: "json",
2015-11-24 12:39:35 +03:00
success: function (result) {
if (!result.succ) {
2014-11-07 18:11:37 +03:00
$("#dialogNewFilePrompt").dialog("close");
bottomGroup.tabs.setCurrent("notification");
windows.flowBottom();
$(".bottom-window-group .notification").focus();
return false;
}
2015-11-24 09:55:09 +03:00
$("#dialogNewFilePrompt").dialog("close");
2015-11-24 09:55:09 +03:00
setTimeout(function () { // Delay, waiting the file change notified and then open it
var tId = tree.getTIdByPath(request.path);
tree.openFile(tree.fileTree.getNodeByTId(tId));
tree.fileTree.selectNode(wide.curNode);
}, 100);
}
});
}
});
$("#dialogNewDirPrompt").dialog({
2014-10-20 18:27:19 +04:00
"modal": true,
"height": 52,
"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 () {
$("#dialogNewDirPrompt > input").val('').focus();
$("#dialogNewDirPrompt").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled", true);
},
2014-09-24 08:07:20 +04:00
"ok": function () {
var name = $("#dialogNewDirPrompt > input").val(),
request = newWideRequest();
2015-07-23 11:31:37 +03:00
request.path = wide.curNode.path + "/" + name;
request.fileType = "d";
$.ajax({
type: 'POST',
2014-12-11 10:32:24 +03:00
url: config.context + '/file/new',
data: JSON.stringify(request),
dataType: "json",
2015-11-24 12:39:35 +03:00
success: function (result) {
if (!result.succ) {
2014-11-07 18:11:37 +03:00
$("#dialogNewDirPrompt").dialog("close");
bottomGroup.tabs.setCurrent("notification");
windows.flowBottom();
$(".bottom-window-group .notification").focus();
return false;
}
$("#dialogNewDirPrompt").dialog("close");
}
});
}
});
2014-11-14 06:42:20 +03:00
$("#dialogGoFilePrompt").dialog({
"modal": true,
2014-12-05 12:59:42 +03:00
"height": 320,
2014-11-14 06:42:20 +03:00
"width": 660,
"title": config.label.goto_file,
"okText": config.label.go,
"cancelText": config.label.cancel,
2014-11-14 12:06:13 +03:00
"afterInit": function () {
2014-11-17 12:35:35 +03:00
$("#dialogGoFilePrompt").on("dblclick", "li", function () {
var tId = tree.getTIdByPath($(this).find(".ft-small").text());
tree.openFile(tree.fileTree.getNodeByTId(tId));
2014-11-18 05:29:08 +03:00
tree.fileTree.selectNode(wide.curNode);
2014-11-17 12:35:35 +03:00
$("#dialogGoFilePrompt").dialog("close");
2014-12-25 05:42:04 +03:00
wide.curEditor.focus();
2014-11-17 12:35:35 +03:00
});
$("#dialogGoFilePrompt").on("click", "li", function () {
2014-12-16 11:34:00 +03:00
var $list = $("#dialogGoFilePrompt > .list");
2014-11-17 12:35:35 +03:00
$list.find("li").removeClass("selected");
$list.data("index", $(this).data("index"));
$(this).addClass("selected");
});
2014-11-14 12:06:13 +03:00
hotkeys.bindList($("#dialogGoFilePrompt > input"), $("#dialogGoFilePrompt > .list"), function ($selected) {
2014-11-17 12:35:35 +03:00
var tId = tree.getTIdByPath($selected.find(".ft-small").text());
2014-11-14 12:06:13 +03:00
tree.openFile(tree.fileTree.getNodeByTId(tId));
2014-11-18 05:29:08 +03:00
tree.fileTree.selectNode(wide.curNode);
2014-11-14 12:06:13 +03:00
$("#dialogGoFilePrompt").dialog("close");
2014-12-16 11:34:00 +03:00
wide.curEditor.focus();
2014-11-14 12:06:13 +03:00
});
2014-11-14 06:42:20 +03:00
2014-11-17 12:35:35 +03:00
$("#dialogGoFilePrompt > input").bind("input", function () {
2014-11-14 12:06:13 +03:00
var name = $("#dialogGoFilePrompt > input").val();
2014-11-14 06:42:20 +03:00
2014-11-14 12:06:13 +03:00
var request = newWideRequest();
2014-11-14 12:22:57 +03:00
request.path = '';
2014-11-14 12:06:13 +03:00
request.name = '*' + name + '*';
2014-11-14 12:22:57 +03:00
if (wide.curNode) {
request.path = wide.curNode.path;
}
2014-11-14 10:03:30 +03:00
2014-11-14 12:06:13 +03:00
$.ajax({
type: 'POST',
2014-12-11 10:32:24 +03:00
url: config.context + '/file/find/name',
2014-11-14 12:06:13 +03:00
data: JSON.stringify(request),
dataType: "json",
2015-11-24 11:30:37 +03:00
success: function (result) {
if (!result.succ) {
2014-11-14 12:06:13 +03:00
return;
}
2014-11-14 10:03:30 +03:00
2015-11-24 11:30:37 +03:00
var data = result.data;
2014-11-14 12:06:13 +03:00
var goFileHTML = '';
2015-11-24 11:30:37 +03:00
for (var i = 0, max = data.length; i < max; i++) {
var path = data[i].path,
2015-07-23 11:31:37 +03:00
name = path.substr(path.lastIndexOf("/") + 1),
2014-11-17 12:35:35 +03:00
icoSkin = wide.getClassBySuffix(name.split(".")[1]);
2014-11-14 12:06:13 +03:00
if (i === 0) {
2014-11-17 12:35:35 +03:00
goFileHTML += '<li data-index="' + i + '" class="selected" title="'
+ path + '"><span class="'
+ icoSkin + 'ico"></span>'
+ name + '&nbsp;&nbsp;&nbsp;&nbsp;<span class="ft-small">'
+ path + '</span></li>';
2014-11-14 12:06:13 +03:00
} else {
2014-11-17 12:35:35 +03:00
goFileHTML += '<li data-index="' + i + '" title="'
+ path + '"><span class="' + icoSkin + 'ico"></span>'
+ name + '&nbsp;&nbsp;&nbsp;&nbsp;<span class="ft-small">'
+ path + '</span></li>';
2014-11-14 12:06:13 +03:00
}
}
$("#dialogGoFilePrompt > ul").html(goFileHTML);
}
});
2014-11-14 06:42:20 +03:00
});
2014-11-14 12:06:13 +03:00
},
"afterOpen": function () {
$("#dialogGoFilePrompt > input").val('').focus();
$("#dialogGoFilePrompt").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled", true);
$("#dialogGoFilePrompt .list").html('').data("index", 0);
},
"ok": function () {
2014-11-17 12:35:35 +03:00
var tId = tree.getTIdByPath($("#dialogGoFilePrompt .selected .ft-small").text());
2014-11-14 12:06:13 +03:00
tree.openFile(tree.fileTree.getNodeByTId(tId));
2014-11-18 05:29:08 +03:00
tree.fileTree.selectNode(wide.curNode);
2014-11-14 12:06:13 +03:00
$("#dialogGoFilePrompt").dialog("close");
2014-12-16 11:34:00 +03:00
wide.curEditor.focus();
2014-11-14 06:42:20 +03:00
}
});
$("#dialogGoLinePrompt").dialog({
2014-10-20 18:27:19 +04:00
"modal": true,
"height": 52,
"width": 260,
"title": config.label.goto_line,
2014-10-23 19:14:34 +04:00
"okText": config.label.go,
"cancelText": config.label.cancel,
2014-09-24 08:07:20 +04:00
"afterOpen": function () {
$("#dialogGoLinePrompt > input").val('').focus();
$("#dialogGoLinePrompt").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled", true);
},
2014-09-24 08:07:20 +04:00
"ok": function () {
var line = parseInt($("#dialogGoLinePrompt > input").val()) - 1;
$("#dialogGoLinePrompt").dialog("close");
2014-11-07 18:11:37 +03:00
2014-11-04 19:27:43 +03:00
var editor = wide.curEditor;
var cursor = editor.getCursor();
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);
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();
}
});
2015-03-07 19:01:06 +03:00
$("#dialogGitClonePrompt").dialog({
"modal": true,
"height": 52,
"width": 360,
2015-03-08 03:59:21 +03:00
"title": config.label.git_clone,
"okText": config.label.confirm,
2015-03-07 19:01:06 +03:00
"cancelText": config.label.cancel,
"afterOpen": function () {
$("#dialogGitClonePrompt > input").val('').focus();
$("#dialogGitClonePrompt").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled", true);
},
"ok": function () {
$("#dialogGitClonePrompt").dialog("close");
2015-04-12 03:15:28 +03:00
2015-03-07 19:01:06 +03:00
var request = newWideRequest();
request.path = wide.curNode.path;
2015-03-08 03:59:21 +03:00
request.repository = $("#dialogGitClonePrompt > input").val();
2015-03-07 19:01:06 +03:00
$.ajax({
type: 'POST',
url: config.context + '/git/clone',
data: JSON.stringify(request),
dataType: "json",
2015-11-24 12:39:35 +03:00
success: function (result) {
2015-03-07 19:01:06 +03:00
}
});
}
});
2014-11-14 12:22:57 +03:00
},
2014-09-24 08:07:20 +04:00
_initWS: function () {
2014-12-11 10:32:24 +03:00
var outputWS = new ReconnectingWebSocket(config.channel + '/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',
2014-12-11 10:32:24 +03:00
url: config.context + '/run',
2014-09-24 08:07:20 +04:00
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) {
2014-11-27 04:46:09 +03:00
case 'run':
2015-01-14 09:52:39 +03:00
var content = $('.bottom-window-group .output > div').html();
if (!wide.curProcessId || '' === content) {
bottomGroup.fillOutput(content + '<pre>' + data.output + '</pre>');
} else {
bottomGroup.fillOutput(content.replace(/<\/pre>$/g, data.output + '</pre>'));
2014-11-26 18:09:17 +03:00
}
2014-11-27 04:46:09 +03:00
2014-10-22 17:41:14 +04:00
wide.curProcessId = data.pid;
break;
2014-11-27 04:46:09 +03:00
case 'run-done':
2015-01-14 06:09:10 +03:00
bottomGroup.fillOutput($('.bottom-window-group .output > div').html().replace(/<\/pre>$/g, data.output + '</pre>'));
2015-01-28 11:21:35 +03:00
2014-10-22 17:41:14 +04:00
wide.curProcessId = undefined;
2014-12-13 17:58:43 +03:00
$("#buildRun").removeClass("ico-stop")
2014-10-22 17:41:14 +04:00
.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-12-31 13:02:04 +03:00
case 'start-vet':
2014-10-22 17:57:21 +04:00
case 'start-install':
2014-10-22 18:35:14 +04:00
case 'start-get':
2015-03-07 19:01:06 +03:00
case 'start-git_clone':
2014-11-28 09:02:02 +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-12-31 13:02:04 +03:00
case 'go vet':
2014-10-22 17:41:14 +04:00
case 'go install':
case 'go get':
2014-11-28 09:02:02 +03:00
bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);
2014-09-24 08:07:20 +04:00
2015-03-07 19:01:06 +03:00
break;
case 'git clone':
bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);
2015-03-08 07:43:04 +03:00
tree.fileTree.reAsyncChildNodes(wide.curNode, "refresh", false);
2015-03-07 19:01:06 +03:00
2014-10-22 17:41:14 +04:00
break;
case 'build':
2015-08-04 16:37:14 +03:00
case 'cross-build':
2014-11-28 09:02:02 +03:00
bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);
2014-09-24 08:07:20 +04:00
2014-11-27 04:46:09 +03:00
if (data.lints) { // has build error
2014-12-11 18:11:10 +03:00
var files = {};
2014-10-22 17:41:14 +04:00
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});
2014-12-11 18:11:10 +03:00
files[lint.file] = lint.file;
2014-10-22 17:41:14 +04:00
}
2014-12-13 17:58:43 +03:00
$("#buildRun").removeClass("ico-stop")
2014-10-22 17:41:14 +04:00
.addClass("ico-buildrun").attr("title", config.label.build_n_run);
2014-09-24 08:07:20 +04:00
2014-12-11 18:11:10 +03:00
// trigger gutter lint
for (var path in files) {
var editor = editors.getEditorByPath(path);
CodeMirror.signal(editor, "change", editor);
}
2015-08-04 16:37:14 +03:00
} else {
if ('cross-build' === data.cmd) {
var request = newWideRequest(),
2015-11-24 10:42:28 +03:00
path = null;
2015-08-04 16:37:14 +03:00
request.path = data.executable;
request.name = data.name;
$.ajax({
async: false,
type: 'POST',
url: config.context + '/file/zip/new',
data: JSON.stringify(request),
dataType: "json",
2015-11-24 10:42:28 +03:00
success: function (result) {
if (!result.succ) {
$("#dialogAlert").dialog("open", result.msg);
2015-08-04 16:37:14 +03:00
return false;
}
2015-11-24 10:42:28 +03:00
path = result.data;
2015-08-04 16:37:14 +03:00
}
});
2015-11-24 10:42:28 +03:00
if (path) {
window.open(config.context + '/file/zip?path=' + path + ".zip");
}
2015-08-04 16:37:14 +03:00
}
2014-12-11 18:11:10 +03:00
}
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) {
2015-09-27 02:36:34 +03:00
console.log('[output onerror]');
2014-09-24 08:07:20 +04:00
};
},
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
// 点击隐藏弹出层
2015-01-04 06:21:44 +03:00
$("body").bind("mouseup", function (event) {
2015-01-28 11:23:53 +03:00
// MAC 右键文件树失效
2015-01-28 11:21:35 +03:00
if (event.which === 3) {
return false;
}
2015-03-07 19:01:06 +03:00
2015-01-04 06:21:44 +03:00
$(".frame").hide();
2014-09-10 14:08:35 +04:00
2015-01-04 06:21:44 +03:00
if (!($(event.target).closest(".frame").length === 1 || event.target.className === "frame")) {
2015-01-03 11:01:24 +03:00
$(".menu > ul > li").unbind().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
this._initDialog();
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-12-11 10:32:24 +03:00
url: config.context + '/file/save',
2014-08-18 17:45:43 +04:00
data: JSON.stringify(request),
dataType: "json",
2015-11-24 11:30:37 +03:00
success: function (result) {
2014-11-04 11:20:51 +03:00
// reset the save state
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-12-25 05:42:04 +03:00
// build the file at once
var request = newWideRequest();
request.file = path;
request.code = editor.getValue();
request.nextCmd = ""; // build only, no following operation
$.ajax({
type: 'POST',
url: config.context + '/build',
data: JSON.stringify(request),
dataType: "json",
2015-11-24 11:44:34 +03:00
beforeSend: function () {
2014-12-25 05:42:04 +03:00
bottomGroup.resetOutput();
},
2015-11-24 11:30:37 +03:00
success: function (result) {
2014-12-25 05:42:04 +03:00
}
});
2014-12-30 11:51:19 +03:00
2015-01-02 13:14:58 +03:00
// refresh outline
2015-01-03 11:01:24 +03:00
wide.refreshOutline();
2014-12-25 05:42:04 +03: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
stop: function () {
2014-12-13 17:58:43 +03:00
if ($("#buildRun").hasClass("ico-buildrun")) {
2014-11-18 05:03:08 +03:00
menu.run();
2014-09-24 08:07:20 +04:00
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',
2014-12-11 10:32:24 +03:00
url: config.context + '/stop',
2014-09-24 08:07:20 +04:00
data: JSON.stringify(request),
dataType: "json",
2015-11-24 11:44:34 +03:00
success: function (result) {
2014-12-13 17:58:43 +03:00
$("#buildRun").removeClass("ico-stop")
2014-09-24 11:24:37 +04:00
.addClass("ico-buildrun").attr("title", config.label.build_n_run);
2014-09-24 08:07:20 +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',
2014-12-11 10:32:24 +03:00
url: config.context + '/go/fmt',
2014-11-04 11:20:51 +03:00
data: JSON.stringify(request),
dataType: "json",
2015-11-24 12:39:35 +03:00
success: function (result) {
if (result.succ) {
editor.setValue(result.data.code);
2014-11-04 11:20:51 +03:00
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',
2014-12-11 10:32:24 +03:00
url: config.context + '/go/fmt',
2014-09-07 13:31:57 +04:00
data: JSON.stringify(request),
dataType: "json",
2015-11-24 12:39:35 +03:00
success: function (result) {
if (result.succ) {
formatted = result.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
},
2014-11-17 12:35:35 +03:00
getClassBySuffix: function (suffix) {
var iconSkin = "ico-ztree-other ";
switch (suffix) {
2014-12-03 06:26:05 +03:00
case "html":
case "htm":
2014-11-17 12:35:35 +03:00
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;
2014-12-03 06:26:05 +03:00
case "jpg":
case "jpeg":
case "bmp":
case "gif":
case "png":
case "svg":
case "ico":
2014-11-17 12:35:35 +03:00
iconSkin = "ico-ztree-img ";
break;
}
return iconSkin;
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();
hotkeys.init();
2014-09-23 17:03:44 +04:00
session.init();
2015-09-27 02:36:34 +03:00
notification.init();
2014-09-26 11:39:13 +04:00
editors.init();
windows.init();
2014-11-06 06:58:55 +03:00
bottomGroup.init();
2014-11-26 18:09:17 +03:00
});