diff --git a/output/outputs.go b/output/outputs.go index d40fa10..f38a52e 100644 --- a/output/outputs.go +++ b/output/outputs.go @@ -272,8 +272,8 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { if nil != session.OutputWS[sid] { // 在前端 output 中显示“开始构建” - channelRet["output"] = i18n - channelRet["cmd"] = "pre-build" + channelRet["output"] = i18n.Get(r, "start-build").(string) + "\n" + channelRet["cmd"] = "start-build" wsChannel := session.OutputWS[sid] @@ -313,7 +313,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { if 0 == count { // 说明构建成功,没有错误信息输出 // 设置下一次执行命令(前端会根据这个发送请求) channelRet["nextCmd"] = args["nextCmd"] - channelRet["output"] = "Build Succ" + channelRet["output"] = i18n.Get(r, "build-succ").(string) + "\n" go func() { // 运行 go install,生成的库用于 gocode lib-path cmd := exec.Command("go", "install") @@ -329,7 +329,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { } else { // 构建失败 // 解析错误信息,返回给编辑器 gutter lint errOut := string(buf[:count]) - channelRet["output"] = "Build Failed\n" + errOut + channelRet["output"] = i18n.Get(r, "build-failed").(string) + "\n" + errOut lines := strings.Split(errOut, "\n") diff --git a/static/js/wide.js b/static/js/wide.js index bcb7b5f..3a86c24 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -276,7 +276,7 @@ var wide = { "title": config.label.about, "hideFooter": true }); - + // TODO: remove $("#dialogAbout").dialog("open"); }); @@ -310,8 +310,8 @@ var wide = { if (goLintFound) { goLintFound = []; - } - + } + if ('run' === data.nextCmd) { var request = newWideRequest(); request.executable = data.executable; @@ -321,8 +321,7 @@ var wide = { url: '/run', data: JSON.stringify(request), dataType: "json", - beforeSend: function (data) { - $('.bottom-window-group .output').text(''); + beforeSend: function (data) { }, success: function (data) { @@ -330,38 +329,51 @@ var wide = { }); } - // TODO: 重构成 switch-case - - if ('run' === data.cmd) { // 正在运行 - wide.fillOutput($('.bottom-window-group .output').text() + data.output); - wide.curProcessId = data.pid; - } else if ('run-done' === data.cmd) { // 运行结束 - wide.curProcessId = undefined; - // 运行结束后修改 [构建&运行] 图标状态为可用状态 - $(".toolbars .ico-stop").removeClass("ico-stop") - .addClass("ico-buildrun").attr("title", config.label.build_n_run); - } else if ('build' === data.cmd || 'go install' === data.cmd) { - wide.fillOutput(data.output); - - if (0 !== data.output.length) { // 说明编译有错误输出 - 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}); - } + switch (data.cmd) { + case 'run': // 正在运行 + wide.fillOutput($('.bottom-window-group .output').text() + data.output); + 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); - } - // 触发一次 gutter lint - CodeMirror.signal(wide.curEditor, "change", wide.curEditor); - } else if ('go get' === data.cmd || 'go install' === data.cmd) { - wide.fillOutput($('.bottom-window-group .output').text() + data.output); - } else if ('pre-build' === data.cmd) { - wide.fillOutput(data.output); + break; + case 'start-build': + wide.fillOutput(data.output); + + break; + case 'go install': + wide.fillOutput($('.bottom-window-group .output').text() + data.output); + + break; + case 'go get': + wide.fillOutput($('.bottom-window-group .output').text() + data.output); + + break; + case 'build': + wide.fillOutput($('.bottom-window-group .output').text() + data.output); + + 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); + } + + // 触发一次 gutter lint + CodeMirror.signal(wide.curEditor, "change", wide.curEditor); + + break; } }; outputWS.onclose = function (e) { @@ -449,7 +461,7 @@ var wide = { if ($(".menu li.save-all").hasClass("disabled")) { return false; } - + // TODO: 只保存未保存过的文件 for (var i = 0, ii = editors.data.length; i < ii; i++) { @@ -516,7 +528,7 @@ var wide = { // 构建. build: function () { wide.saveAllFiles(); - + var currentPath = editors.getCurrentPath(); if (!currentPath) { return false; @@ -542,7 +554,7 @@ var wide = { // 构建并运行. run: function () { wide.saveAllFiles(); - + var currentPath = editors.getCurrentPath(); if (!currentPath) { return false; @@ -603,7 +615,7 @@ var wide = { }, goinstall: function () { wide.saveAllFiles(); - + var currentPath = editors.getCurrentPath(); if (!currentPath) { return false;