From 1ced1982cee42c95f8250c9a5e7d7c22ec2ea4af Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 16 Sep 2014 22:39:22 +0800 Subject: [PATCH] . --- editor/editors.go | 21 ++++++++++++++++++++- notification/notifications.go | 2 +- output/outputs.go | 4 +++- static/js/editor.js | 4 +++- static/js/wide.js | 2 +- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/editor/editors.go b/editor/editors.go index 675cde8..5138205 100644 --- a/editor/editors.go +++ b/editor/editors.go @@ -28,6 +28,7 @@ type snippet struct { Contents []string `json:"contents"` // 代码行 } +// 建立编辑器通道. func WSHandler(w http.ResponseWriter, r *http.Request) { session, _ := user.Session.Get(r, "wide-session") sid := session.Values["id"].(string) @@ -101,8 +102,26 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) { session, _ := user.Session.Get(r, "wide-session") username := session.Values["username"].(string) + path := args["path"].(string) + + fout, err := os.Create(path) + + if nil != err { + glog.Error(err) + http.Error(w, err.Error(), 500) + + return + } + code := args["code"].(string) - // TODO: 保存文件 + fout.WriteString(code) + + if err := fout.Close(); nil != err { + glog.Error(err) + http.Error(w, err.Error(), 500) + + return + } line := int(args["cursorLine"].(float64)) ch := int(args["cursorCh"].(float64)) diff --git a/notification/notifications.go b/notification/notifications.go index 4eb6629..4348ddc 100644 --- a/notification/notifications.go +++ b/notification/notifications.go @@ -78,7 +78,7 @@ func WSHandler(w http.ResponseWriter, r *http.Request) { ret := map[string]interface{}{"output": "Notification initialized", "cmd": "init-notification"} wsChan.Conn.WriteJSON(&ret) - glog.Infof("Open a new [Notification] with session [%s], %d", sid, len(notificationWSs)) + glog.V(4).Infof("Open a new [Notification] with session [%s], %d", sid, len(notificationWSs)) // 初始化用户事件队列 event.InitUserQueue(sid, event.HandleFunc(event2Notification)) diff --git a/output/outputs.go b/output/outputs.go index 779a69c..b1f7b18 100644 --- a/output/outputs.go +++ b/output/outputs.go @@ -249,10 +249,12 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { channelRet := map[string]interface{}{} channelRet["output"] = string(buf[:count]) channelRet["cmd"] = "build" - channelRet["nextCmd"] = "run" channelRet["executable"] = executable if 0 == count { // 说明构建成功,没有错误信息输出 + // 设置下一次执行命令(前端会根据这个发送请求) + channelRet["nextCmd"] = "run" + go func() { // 运行 go install,生成的库用于 gocode lib-path cmd := exec.Command("go", "install") cmd.Dir = curDir diff --git a/static/js/editor.js b/static/js/editor.js index 216d05d..9f5c572 100644 --- a/static/js/editor.js +++ b/static/js/editor.js @@ -78,7 +78,9 @@ var editors = { while (start && word.test(curLine.charAt(start - 1))) { --start; } + var request = { + path: $(".edit-header .current > span:eq(0)").attr("title"), code: editor.getValue(), cursorLine: cur.line, cursorCh: cur.ch @@ -269,7 +271,7 @@ var editors = { "Ctrl-S": function () { wide.saveFile(); }, - "Alt-Shift-F": function () { + "Shift-Alt-F": function () { wide.fmt(); }, "Alt-F7": "findUsages" diff --git a/static/js/wide.js b/static/js/wide.js index a6484a7..1bcd6d9 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -234,7 +234,7 @@ var wide = { break; default : - // TODO: XML/JSON 格式化处理 + // TODO: XML 格式化处理 break; } }