This commit is contained in:
Liang Ding 2014-10-27 23:02:15 +08:00
parent e6408edf54
commit 292781fe76
15 changed files with 217 additions and 443 deletions

View File

@ -0,0 +1,16 @@
package test
import (
"testing"
)
func Test_Division_1(t *testing.T) {
if i, e := Division(6, 2); i != 3 || e != nil { //try a unit test on function
t.Error("除法函数测试没通过") // 如果不是如预期的那么就报错
} else {
t.Log("第一个测试通过了") //记录一些你期望记录的信息
}
}
func Test_Division_2(t *testing.T) {
}

View File

@ -0,0 +1,17 @@
package test
import (
"testing"
)
func Test_Division_3(t *testing.T) {
if i, e := Division(6, 2); i != 3 || e != nil { //try a unit test on function
t.Error("除法函数测试没通过") // 如果不是如预期的那么就报错
} else {
t.Log("第一个测试通过了") //记录一些你期望记录的信息
}
}
func Test_Division_4(t *testing.T) {
t.Error("就是不通过")
}

View File

@ -0,0 +1,13 @@
package test
import (
"errors"
)
func Division(a, b float64) (float64, error) {
if b == 0 {
return 0, errors.New("除数不能为0")
}
return a / b, nil
}

View File

@ -1,411 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>
{{.i18n.wide}}
</title>
<link rel="stylesheet" href="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/codemirror.css">
<link rel="stylesheet" href="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/hint/show-hint.css">
<link rel="stylesheet" href="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/lint/lint.css">
<link rel="stylesheet" href="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/fold/foldgutter.css">
<link rel="stylesheet" href="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/theme/wide.css">
<link rel="stylesheet" href="{{.conf.StaticServer}}/static/js/lib/ztree/zTreeStyle.css">
<link rel="stylesheet" href="{{.conf.StaticServer}}/static/css/dialog.css?{{.conf.StaticResourceVersion}}">
<link rel="stylesheet" href="{{.conf.StaticServer}}/static/css/base.css?{{.conf.StaticResourceVersion}}">
<link rel="stylesheet" href="{{.conf.StaticServer}}/static/css/wide.css?{{.conf.StaticResourceVersion}}">
<link rel="stylesheet" href="{{.conf.StaticServer}}/static/css/side.css?{{.conf.StaticResourceVersion}}">
<link rel="stylesheet" href="{{.conf.StaticServer}}/static/css/start.css?{{.conf.StaticResourceVersion}}">
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
</head>
<body>
<!-- 主菜单 -->
<div class="menu fn-clear">
<ul class="fn-cleaer">
<li>
<span>
{{.i18n.file}}
</span>
<div class="frame">
<ul>
<li class="save-all disabled" onclick="wide.saveAllFiles()">
<span>
{{.i18n.save_all_files}}
</span>
</li>
<li class="close-all disabled" onclick="wide.closeAllFiles()">
<span>
{{.i18n.close_all_files}}
</span>
</li>
<li class="hr">
</li>
<li onclick="wide.exit()">
<span>
{{.i18n.exit}}
</span>
</li>
</ul>
</div>
</li>
<li>
<span>
{{.i18n.run}}
</span>
<div class="frame">
<ul>
<li class="run disabled" onclick="wide.run()">
<span>
{{.i18n.build_n_run}}
</span>
</li>
<li class="hr">
</li>
<li class="go-get disabled" onclick="wide.goget()">
<span>
{{.i18n.goget}}
</span>
</li>
<li class="go-install disabled" onclick="wide.goinstall()">
<span>
{{.i18n.goinstall}}
</span>
</li>
</ul>
</div>
</li>
<!--
<li>
<span>{{.i18n.debug}}</span>
<div class="frame">
<ul>
<li>
<span>{{.i18n.debug}}</span>
</li>
</ul>
</div>
</li>
-->
<li>
<span>
{{.i18n.help}}
</span>
<div class="frame">
<ul>
<li onclick="window.open('https://www.gitbook.io/book/88250/wide-user-guide')">
<span>
{{.i18n.wide_doc}}
</span>
</li>
<li onclick="window.open('https://github.com/b3log/wide/issues/new')">
{{.i18n.report_issues}}
</li>
<li class="hr">
</li>
<li onclick="editors.openStartPage()">
<span>
{{.i18n.start_page}}
</span>
</li>
<li onclick="wide.openAbout()">
<span>
{{.i18n.about}}
</span>
</li>
</ul>
</div>
</li>
</ul>
</div>
<div class="content">
<div class="side">
<span title="{{.i18n.min}}" class="font-ico ico-min">
</span>
<div class="tabs">
<div class="current" data-index="filreTree">
<span title="{{.i18n.file}}">
{{.i18n.file}}
</span>
</div>
</div>
<div class="tabs-panel">
<div data-index="filreTree">
<ul id="files" tabindex="-1" class="ztree">
</ul>
<!-- 目录右键菜单 -->
<div id="dirRMenu" class="frame">
<ul>
<li onclick="tree.newFile();">
{{.i18n.create_file}}
</li>
<li onclick="tree.newDir();">
{{.i18n.create_dir}}
</li>
<li onclick="tree.removeIt();">
{{.i18n.delete}}
</li>
</ul>
</div>
<!-- 文件右键菜单 -->
<div id="fileRMenu" class="frame">
<ul>
<li onclick="tree.removeIt();">
{{.i18n.delete}}
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="edit-panel">
<div class="toolbars fn-none">
<span onclick="wide.run()" class="font-ico ico-buildrun" title="{{.i18n.build_n_run}}">
</span>
<span onclick="wide.saveFile()" title="{{.i18n.save}}" class="font-ico ico-save">
</span>
<span onclick="wide.fmt(editors.getCurrentPath(), wide.curEditor)" class="ico-format font-ico" title="{{.i18n.format}}">
</span>
<span class="font-ico ico-max" onclick="windows.maxEditor()" title="{{.i18n.max_editor}}">
</span>
</div>
<div class="tabs">
</div>
<div class="tabs-panel">
</div>
</div>
<div class="bottom-window-group">
<span title="{{.i18n.min}}" class="font-ico ico-min">
</span>
<div class="tabs">
<div class="current" data-index="output">
<span title="{{.i18n.output}}">
{{.i18n.output}}
</span>
</div>
<div data-index="search">
<span title="{{.i18n.search}}">
{{.i18n.search}}
</span>
</div>
<div data-index="notification">
<span title="{{.i18n.notification}}">
{{.i18n.notification}}
</span>
</div>
</div>
<div class="tabs-panel">
<div data-index="output">
<textarea class="output">
</textarea>
</div>
<div class="fn-none" data-index="search">
<div tabindex="-1" class="search">
<div class="tabs fn-none">
<div class="current" data-index="first">
<span class="first">
</span>
<span class="ico-close font-ico">
</span>
</div>
</div>
<div class="tabs-panel">
<div data-index="first">
</div>
</div>
</div>
</div>
<div class="fn-none" data-index="notification">
<div tabindex="-1" class="notification">
<table cellpadding="0" cellspacing="0">
</table>
</div>
</div>
</div>
</div>
</div>
<div class="footer fn-clear">
<div class="fn-left">
<span title="{{.i18n.restore_side}}" class="font-ico ico-restore fn-none">
</span>
<span title="{{.i18n.resotre_bottom}}" class="font-ico ico-restore fn-none">
</span>
</div>
<div class="fn-right">
<span class="cursor">
</span>
<span class="notification-count" title="{{.i18n.unread_notification}}">
{{.i18n.notification}}!
</span>
</div>
</div>
<div id="dialogRemoveConfirm" class="fn-none">
{{.i18n.isDelete}}
<b>
</b>
?
</div>
<div id="dialogAlert" class="fn-none">
</div>
<div id="dialogNewFilePrompt" class="dialog-prompt fn-none">
<input/>
</div>
<div id="dialogNewDirPrompt" class="dialog-prompt fn-none">
<input/>
</div>
<div id="dialogGoLinePrompt" class="dialog-prompt fn-none">
<input/>
</div>
<div id="dialogSearchForm" class="dialog-form fn-none">
<input placeholder="{{.i18n.keyword}}" />
<input placeholder="{{.i18n.file_format}}" />
</div>
<script>
var config = {
"pathSeparator": {{.pathSeparator}},
"latestSessionContent": {{.latestSessionContent}},
"label": {
"restore_editor": "{{.i18n.restore_editor}}",
"max_editor": "{{.i18n.max_editor}}",
"delete": "{{.i18n.delete}}",
"cancel": "{{.i18n.cancel}}",
"goto_line": "{{.i18n.goto_line}}",
"goto": "{{.i18n.goto}}",
"create": "{{.i18n.create}}",
"create_file": "{{.i18n.create_file}}",
"create_dir": "{{.i18n.create_dir}}",
"tip": "{{.i18n.tip}}",
"confirm": "{{.i18n.confirm}}",
"build_n_run": "{{.i18n.build_n_run}}",
"stop": "{{.i18n.stop}}",
"usages": "{{.i18n.find_usages}}",
"search_text": "{{.i18n.search_text}}",
"search": "{{.i18n.search}}",
"initialise": "{{.i18n.initialise}}",
"confirm_save": "{{.i18n.confirm_save}}"
},
"channel": {
"editor": '{{.conf.EditorChannel}}',
"shell": '{{.conf.ShellChannel}}',
"output": '{{.conf.OutputChannel}}',
"session": '{{.conf.SessionChannel}}'
},
"wideSessionId": '{{.session.Id}}'
};
// 发往 Wide 的所有 AJAX 请求需要使用该函数创建请求参数.
function newWideRequest() {
var ret = {
sid: config.wideSessionId
}
return ret;
}
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/jquery-2.1.1.min.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/reconnecting-websocket.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/ztree/jquery.ztree.all-3.5.min.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/codemirror.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/lint/lint.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/lint/json-lint.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/selection/active-line.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/overwrite/codemirror-4.5/addon/hint/show-hint.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/hint/anyword-hint.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/display/rulers.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/edit/closebrackets.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/edit/matchbrackets.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/edit/closetag.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/search/searchcursor.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/search/match-highlighter.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/fold/foldcode.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/fold/foldgutter.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/fold/brace-fold.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/fold/xml-fold.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/fold/markdown-fold.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/addon/fold/comment-fold.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/mode/go/go.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/mode/xml/xml.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/mode/htmlmixed/htmlmixed.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/mode/javascript/javascript.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/mode/markdown/markdown.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/mode/css/css.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/mode/shell/shell.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-4.5/mode/sql/sql.js">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/lint/json-lint.js?{{.conf.StaticResourceVersion}}">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/lint/go-lint.js?{{.conf.StaticResourceVersion}}">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/tabs.js?{{.conf.StaticResourceVersion}}">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/dialog.js?{{.conf.StaticResourceVersion}}">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/editors.js?{{.conf.StaticResourceVersion}}">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/notification.js?{{.conf.StaticResourceVersion}}">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/tree.js?{{.conf.StaticResourceVersion}}">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/wide.js?{{.conf.StaticResourceVersion}}">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/session.js?{{.conf.StaticResourceVersion}}">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/menu.js?{{.conf.StaticResourceVersion}}">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/windows.js?{{.conf.StaticResourceVersion}}">
</script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/hotkeys.js?{{.conf.StaticResourceVersion}}">
</script>
</body>
</html>

View File

@ -86,13 +86,16 @@
"focus_notification": "Focus to Notification",
"start-build": "START [go build]",
"build-succ": "[go build] SUCCESS",
"build-failed": "[go build] Failed",
"build-failed": "[go build] ERROR",
"start-test": "START [go test]",
"test-succ": "[go test] SUCCESS",
"test-failed": "[go test] ERROR",
"start-install": "START [go install]",
"install-succ": "[go install] SUCCESS",
"install-failed": "[go install] Fialed",
"install-failed": "[go install] ERROR",
"start-get": "START [go get]",
"get-succ": "[go get] SUCCESS",
"get-failed": "[go get] Failed",
"get-failed": "[go get] ERROR",
"check_version": "Checking update",
"new_version_available": "new version available",
"go_env": "Go",
@ -101,5 +104,6 @@
"license": "License",
"credits": "Credits",
"uptodate": "it is up to date",
"test": "Test",
"colon": ": "
}

View File

@ -87,6 +87,9 @@
"start-build": "开始 [go build]",
"build-succ": "[go build] 成功",
"build-failed": "[go build] 失败",
"start-test": "开始 [go test]",
"test-succ": "[go test] 成功",
"test-failed": "[go test] 失败",
"start-install": "开始 [go install]",
"install-succ": "[go install] 成功",
"install-failed": "[go install] 失败",
@ -101,5 +104,6 @@
"license": "许可协议",
"credits": "致谢",
"uptodate": "已是最新版本",
"test": "测试",
"colon": ""
}

View File

@ -294,6 +294,7 @@ func main() {
http.HandleFunc("/build", handlerWrapper(output.BuildHandler))
http.HandleFunc("/run", handlerWrapper(output.RunHandler))
http.HandleFunc("/stop", handlerWrapper(output.StopHandler))
http.HandleFunc("/go/test", handlerWrapper(output.GoTestHandler))
http.HandleFunc("/go/get", handlerWrapper(output.GoGetHandler))
http.HandleFunc("/go/install", handlerWrapper(output.GoInstallHandler))
http.HandleFunc("/output/ws", handlerWrapper(output.WSHandler))

View File

@ -56,11 +56,9 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{"succ": true}
defer util.RetJSON(w, r, data)
decoder := json.NewDecoder(r.Body)
var args map[string]interface{}
if err := decoder.Decode(&args); err != nil {
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
glog.Error(err)
data["succ"] = false
@ -188,11 +186,9 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
username := httpSession.Values["username"].(string)
locale := conf.Wide.GetUser(username).Locale
decoder := json.NewDecoder(r.Body)
var args map[string]interface{}
if err := decoder.Decode(&args); err != nil {
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
glog.Error(err)
data["succ"] = false
@ -390,8 +386,8 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
}(rand.Int())
}
// go install.
func GoInstallHandler(w http.ResponseWriter, r *http.Request) {
// go test.
func GoTestHandler(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{"succ": true}
defer util.RetJSON(w, r, data)
@ -399,11 +395,9 @@ func GoInstallHandler(w http.ResponseWriter, r *http.Request) {
username := httpSession.Values["username"].(string)
locale := conf.Wide.GetUser(username).Locale
decoder := json.NewDecoder(r.Body)
var args map[string]interface{}
if err := decoder.Decode(&args); err != nil {
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
glog.Error(err)
data["succ"] = false
@ -415,8 +409,12 @@ func GoInstallHandler(w http.ResponseWriter, r *http.Request) {
filePath := args["file"].(string)
curDir := filePath[:strings.LastIndex(filePath, conf.PathSeparator)]
fout, err := os.Create(filePath)
cmd := exec.Command("go", "test", "-v")
cmd.Dir = curDir
setCmdEnv(cmd, username)
stdout, err := cmd.StdoutPipe()
if nil != err {
glog.Error(err)
data["succ"] = false
@ -424,17 +422,108 @@ func GoInstallHandler(w http.ResponseWriter, r *http.Request) {
return
}
code := args["code"].(string)
fout.WriteString(code)
if err := fout.Close(); nil != err {
stderr, err := cmd.StderrPipe()
if nil != err {
glog.Error(err)
data["succ"] = false
return
}
if !data["succ"].(bool) {
return
}
channelRet := map[string]interface{}{}
if nil != session.OutputWS[sid] {
// 在前端 output 中显示“开始 go test
channelRet["output"] = "<span class='start-test'>" + i18n.Get(locale, "start-test").(string) + "</span>\n"
channelRet["cmd"] = "start-test"
wsChannel := session.OutputWS[sid]
err := wsChannel.Conn.WriteJSON(&channelRet)
if nil != err {
glog.Error(err)
return
}
// 更新通道最近使用时间
wsChannel.Time = time.Now()
}
reader := bufio.NewReader(io.MultiReader(stdout, stderr))
if err := cmd.Start(); nil != err {
glog.Error(err)
data["succ"] = false
return
}
go func(runningId int) {
defer util.Recover()
glog.V(3).Infof("Session [%s] is running [go test] [runningId=%d]", sid, runningId)
channelRet := map[string]interface{}{}
channelRet["cmd"] = "go test"
// 一次性读取
buf, _ := ioutil.ReadAll(reader)
// 同步点,等待 go test 执行完成
cmd.Wait()
if !cmd.ProcessState.Success() {
glog.V(3).Infof("Session [%s] 's running [go test] [runningId=%d] has done (with error)", sid, runningId)
channelRet["output"] = "<span class='test-failed'>" + i18n.Get(locale, "test-failed").(string) + "</span>\n" + string(buf)
} else {
glog.V(3).Infof("Session [%s] 's running [go test] [runningId=%d] has done", sid, runningId)
channelRet["output"] = "<span class='test-succ'>" + i18n.Get(locale, "test-succ").(string) + "</span>\n" + string(buf)
}
if nil != session.OutputWS[sid] {
wsChannel := session.OutputWS[sid]
err := wsChannel.Conn.WriteJSON(&channelRet)
if nil != err {
glog.Error(err)
}
// 更新通道最近使用时间
wsChannel.Time = time.Now()
}
}(rand.Int())
}
// go install.
func GoInstallHandler(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{"succ": true}
defer util.RetJSON(w, r, data)
httpSession, _ := session.HTTPSession.Get(r, "wide-session")
username := httpSession.Values["username"].(string)
locale := conf.Wide.GetUser(username).Locale
var args map[string]interface{}
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
glog.Error(err)
data["succ"] = false
return
}
sid := args["sid"].(string)
filePath := args["file"].(string)
curDir := filePath[:strings.LastIndex(filePath, conf.PathSeparator)]
cmd := exec.Command("go", "install")
cmd.Dir = curDir
@ -577,11 +666,9 @@ func GoGetHandler(w http.ResponseWriter, r *http.Request) {
username := httpSession.Values["username"].(string)
locale := conf.Wide.GetUser(username).Locale
decoder := json.NewDecoder(r.Body)
var args map[string]interface{}
if err := decoder.Decode(&args); err != nil {
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
glog.Error(err)
data["succ"] = false

View File

@ -281,18 +281,21 @@
}
.bottom-window-group .output .start-build,
.bottom-window-group .output .start-test,
.bottom-window-group .output .start-install,
.bottom-window-group .output .start-get {
color: #999;
}
.bottom-window-group .output .build-succ,
.bottom-window-group .output .build-succ,
.bottom-window-group .output .test-succ,
.bottom-window-group .output .install-succ,
.bottom-window-group .output .get-succ {
color: rgb(0,153,0);
}
.bottom-window-group .output .build-failed,
.bottom-window-group .output .build-failed,
.bottom-window-group .output .test-failed,
.bottom-window-group .output .install-failed,
.bottom-window-group .output .get-failed {
color: red;

View File

@ -24,7 +24,7 @@ var editors = {
wide.curEditor.focus();
},
removeAfter: function (id, nextId) {
if (id === 'startPage') {
if (id === 'startPage') { // 当前关闭的 tab 是起始页
return false;
}
@ -35,6 +35,10 @@ var editors = {
break;
}
}
if (editors.data.length === 0) { // 起始页可能存在,所以用编辑器数据判断
menu.disabled(['save-all', 'close-all', 'build', 'run', 'go-test', 'go-get', 'go-install']);
$(".toolbars").hide();
}
if (!nextId) {
// 不存在打开的编辑器
@ -43,9 +47,6 @@ var editors = {
wide.curNode = undefined;
wide.curEditor = undefined;
menu.disabled(['save-all', 'close-all', 'run', 'go-get', 'go-install']);
$(".toolbars").hide();
return false;
}
@ -440,7 +441,7 @@ var editors = {
content: '<textarea id="editor' + id + '"></textarea>'
});
menu.undisabled(['save-all', 'close-all', 'run', 'go-get', 'go-install']);
menu.undisabled(['save-all', 'close-all', 'build', 'run', 'go-test', 'go-get', 'go-install']);
var rulers = [];
rulers.push({color: "#ccc", column: 120, lineStyle: "dashed"});

View File

@ -351,11 +351,13 @@ var wide = {
break;
case 'start-build':
case 'start-test':
case 'start-install':
case 'start-get':
wide.fillOutput(data.output);
break;
case 'go test':
case 'go install':
case 'go get':
wide.fillOutput($('.bottom-window-group .output > div').html() + data.output);
@ -541,6 +543,10 @@ var wide = {
if (!currentPath) {
return false;
}
if ($(".menu li.build").hasClass("disabled")) {
return false;
}
var request = newWideRequest();
request.file = currentPath;
@ -600,6 +606,36 @@ var wide = {
}
});
},
// 测试.
test: function () {
wide.saveAllFiles();
var currentPath = editors.getCurrentPath();
if (!currentPath) {
return false;
}
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) {
$('.bottom-window-group .output > div').text('');
wide.bottomWindowTab.setCurrent("output");
windows.flowBottom();
},
success: function (data) {
}
});
},
goget: function () {
wide.saveAllFiles();
@ -643,7 +679,6 @@ var wide = {
var request = newWideRequest();
request.file = currentPath;
request.code = wide.curEditor.getValue();
$.ajax({
type: 'POST',

View File

@ -46,13 +46,17 @@
<span>{{.i18n.run}}</span>
<div class="frame">
<ul>
<li class="run disabled" onclick="wide.build()">
<li class="build disabled" onclick="wide.build()">
<span>{{.i18n.build}}</span>
</li>
<li class="run disabled" onclick="wide.run()">
<span>{{.i18n.build_n_run}}</span>
</li>
<li class="hr"></li>
<li class="go-test disabled" onclick="wide.test()">
<span>{{.i18n.test}}</span>
</li>
<li class="hr"></li>
<li class="go-get disabled" onclick="wide.goget()">
<span>{{.i18n.goget}}</span>
</li>