This commit is contained in:
Liang Ding 2014-11-25 14:20:45 +08:00
parent 2bf2272ac1
commit f892a7138d
8 changed files with 47 additions and 5 deletions

View File

@ -66,7 +66,7 @@ func initAPINode() {
// GetFiles handles request of constructing user workspace file tree. // GetFiles handles request of constructing user workspace file tree.
// //
// The Go API source code package also as a child node, // 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) { func GetFiles(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{"succ": true} data := map[string]interface{}{"succ": true}
defer util.RetJSON(w, r, data) defer util.RetJSON(w, r, data)
@ -103,6 +103,25 @@ func GetFiles(w http.ResponseWriter, r *http.Request) {
data["root"] = root 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. // GetFile handles request of opening file by editor.
func GetFile(w http.ResponseWriter, r *http.Request) { func GetFile(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{"succ": true} data := map[string]interface{}{"succ": true}

View File

@ -134,5 +134,6 @@
"locale": "Locale", "locale": "Locale",
"apply": "Apply", "apply": "Apply",
"clearOutput": "Clear Output", "clearOutput": "Clear Output",
"export": "Export" "export": "Export",
"refresh": "Refresh"
} }

View File

@ -134,5 +134,6 @@
"locale": "ロケール", "locale": "ロケール",
"apply": "適用する", "apply": "適用する",
"clearOutput": "空の出力", "clearOutput": "空の出力",
"export": "輸出" "export": "輸出",
"refresh": "リフレッシュ"
} }

View File

@ -134,5 +134,6 @@
"locale": "语言环境", "locale": "语言环境",
"apply": "应用", "apply": "应用",
"clearOutput": "清空输出", "clearOutput": "清空输出",
"export": "导出" "export": "导出",
"refresh": "刷新"
} }

View File

@ -134,5 +134,6 @@
"locale": "語言環境", "locale": "語言環境",
"apply": "應用", "apply": "應用",
"clearOutput": "清空輸出", "clearOutput": "清空輸出",
"export": "導出" "export": "導出",
"refresh": "刷新"
} }

View File

@ -273,6 +273,7 @@ func main() {
// file tree // file tree
http.HandleFunc("/files", handlerWrapper(file.GetFiles)) http.HandleFunc("/files", handlerWrapper(file.GetFiles))
http.HandleFunc("/file/refresh", handlerWrapper(file.RefreshDirectory))
http.HandleFunc("/file", handlerWrapper(file.GetFile)) http.HandleFunc("/file", handlerWrapper(file.GetFile))
http.HandleFunc("/file/save", handlerWrapper(file.SaveFile)) http.HandleFunc("/file/save", handlerWrapper(file.SaveFile))
http.HandleFunc("/file/new", handlerWrapper(file.NewFile)) http.HandleFunc("/file/new", handlerWrapper(file.NewFile))

View File

@ -179,6 +179,18 @@ var tree = {
$("#dirRMenu").hide(); $("#dirRMenu").hide();
$("#fileRMenu").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 () { init: function () {
$("#file").click(function () { $("#file").click(function () {
$(this).focus(); $(this).focus();
@ -205,6 +217,11 @@ var tree = {
showTitle: true, showTitle: true,
selectedMulti: false selectedMulti: false
}, },
async: {
enable: true,
url: "/file/refresh",
autoParam: ["path"]
},
callback: { callback: {
onDblClick: function (event, treeId, treeNode) { onDblClick: function (event, treeId, treeNode) {
if (treeNode) { if (treeNode) {

View File

@ -139,6 +139,7 @@
<li class="remove" onclick="tree.removeIt(this);">{{.i18n.delete}}</li> <li class="remove" onclick="tree.removeIt(this);">{{.i18n.delete}}</li>
<li class="rename" onclick="tree.rename(this);">{{.i18n.rename}}</li> <li class="rename" onclick="tree.rename(this);">{{.i18n.rename}}</li>
<li class="hr"></li> <li class="hr"></li>
<li class="refresh" onclick="tree.refresh(this);">{{.i18n.refresh}}</li>
<li class="export" onclick="tree.export(this);">{{.i18n.export}}</li> <li class="export" onclick="tree.export(this);">{{.i18n.export}}</li>
</ul> </ul>
</div> </div>