diff --git a/file/files.go b/file/files.go index 86c13f6..7108632 100644 --- a/file/files.go +++ b/file/files.go @@ -66,7 +66,7 @@ func initAPINode() { // GetFiles handles request of constructing user workspace file tree. // // The Go API source code package also as a child node, -// so that users can easily view the Go API source code in filre tree. +// so that users can easily view the Go API source code in file tree. func GetFiles(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{"succ": true} defer util.RetJSON(w, r, data) @@ -103,6 +103,25 @@ func GetFiles(w http.ResponseWriter, r *http.Request) { data["root"] = root } +// RefreshDirectory handles request of refresh a directory of file tree. +func RefreshDirectory(w http.ResponseWriter, r *http.Request) { + r.ParseForm() + path := r.FormValue("path") + + node := FileNode{Name: "root", Path: path, IconSkin: "ico-ztree-dir ", Type: "d", FileNodes: []*FileNode{}} + + walk(path, &node, true, true) + + w.Header().Set("Content-Type", "application/json") + data, err := json.Marshal(node.FileNodes) + if err != nil { + glog.Error(err) + return + } + + w.Write(data) +} + // GetFile handles request of opening file by editor. func GetFile(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{"succ": true} diff --git a/i18n/en_US.json b/i18n/en_US.json index 251545a..7c7c1fe 100644 --- a/i18n/en_US.json +++ b/i18n/en_US.json @@ -134,5 +134,6 @@ "locale": "Locale", "apply": "Apply", "clearOutput": "Clear Output", - "export": "Export" + "export": "Export", + "refresh": "Refresh" } \ No newline at end of file diff --git a/i18n/ja_JP.json b/i18n/ja_JP.json index 338c342..4cf7a1a 100644 --- a/i18n/ja_JP.json +++ b/i18n/ja_JP.json @@ -134,5 +134,6 @@ "locale": "ロケール", "apply": "適用する", "clearOutput": "空の出力", - "export": "輸出" + "export": "輸出", + "refresh": "リフレッシュ" } diff --git a/i18n/zh_CN.json b/i18n/zh_CN.json index 2b02ea6..3cc1159 100644 --- a/i18n/zh_CN.json +++ b/i18n/zh_CN.json @@ -134,5 +134,6 @@ "locale": "语言环境", "apply": "应用", "clearOutput": "清空输出", - "export": "导出" + "export": "导出", + "refresh": "刷新" } \ No newline at end of file diff --git a/i18n/zh_TW.json b/i18n/zh_TW.json index a4519fc..860ed08 100644 --- a/i18n/zh_TW.json +++ b/i18n/zh_TW.json @@ -134,5 +134,6 @@ "locale": "語言環境", "apply": "應用", "clearOutput": "清空輸出", - "export": "導出" + "export": "導出", + "refresh": "刷新" } \ No newline at end of file diff --git a/main.go b/main.go index d2ba49e..74fc57e 100644 --- a/main.go +++ b/main.go @@ -273,6 +273,7 @@ func main() { // file tree http.HandleFunc("/files", handlerWrapper(file.GetFiles)) + http.HandleFunc("/file/refresh", handlerWrapper(file.RefreshDirectory)) http.HandleFunc("/file", handlerWrapper(file.GetFile)) http.HandleFunc("/file/save", handlerWrapper(file.SaveFile)) http.HandleFunc("/file/new", handlerWrapper(file.NewFile)) diff --git a/static/js/tree.js b/static/js/tree.js index 1bba33a..3f32b63 100644 --- a/static/js/tree.js +++ b/static/js/tree.js @@ -179,6 +179,18 @@ var tree = { $("#dirRMenu").hide(); $("#fileRMenu").hide(); }, + refresh: function (it) { + if (it) { + if ($(it).hasClass("disabled")) { + return false; + } + } + + tree.fileTree.reAsyncChildNodes(wide.curNode, "refresh"); + + $("#dirRMenu").hide(); + $("#fileRMenu").hide(); + }, init: function () { $("#file").click(function () { $(this).focus(); @@ -205,6 +217,11 @@ var tree = { showTitle: true, selectedMulti: false }, + async: { + enable: true, + url: "/file/refresh", + autoParam: ["path"] + }, callback: { onDblClick: function (event, treeId, treeNode) { if (treeNode) { diff --git a/views/index.html b/views/index.html index 0a0c82b..a96c7b4 100644 --- a/views/index.html +++ b/views/index.html @@ -139,6 +139,7 @@
  • {{.i18n.delete}}
  • {{.i18n.rename}}
  • +
  • {{.i18n.refresh}}
  • {{.i18n.export}}