From 46ecea41c06027cbe517e1cbf4eb5695f1df5a57 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 27 Apr 2015 14:36:35 +0800 Subject: [PATCH] Sole node id --- file/files.go | 23 ++++++++++++++++------- static/js/editors.js | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/file/files.go b/file/files.go index a007c28..a807972 100644 --- a/file/files.go +++ b/file/files.go @@ -36,6 +36,7 @@ var logger = log.NewLogger(os.Stdout) // Node represents a file node in file tree. type Node struct { + Id string `json:"id"` Name string `json:"name"` Path string `json:"path"` IconSkin string `json:"iconSkin"` // Value should be end with a space @@ -97,10 +98,15 @@ func GetFilesHandler(w http.ResponseWriter, r *http.Request) { for _, workspace := range workspaces { workspacePath := workspace + conf.PathSeparator + "src" - workspaceNode := Node{Name: workspace[strings.LastIndex(workspace, conf.PathSeparator)+1:], - Path: filepath.ToSlash(workspacePath), /* jQuery data-index API can't accept "\", so we convert it to "/" */ - IconSkin: "ico-ztree-dir-workspace ", Type: "d", - Creatable: true, Removable: false, IsGoAPI: false, Children: []*Node{}} + workspaceNode := Node{ + Name: workspace[strings.LastIndex(workspace, conf.PathSeparator)+1:], + Path: workspacePath, + IconSkin: "ico-ztree-dir-workspace ", + Type: "d", + Creatable: true, + Removable: false, + IsGoAPI: false, + Children: []*Node{}} walk(workspacePath, &workspaceNode, true, true, false) @@ -447,9 +453,12 @@ func walk(path string, node *Node, creatable, removable, isGOAPI bool) { fio, _ := os.Lstat(fpath) - child := Node{Name: filename, - Path: filepath.ToSlash(fpath), /* jQuery data-index API can't accept "\", so we convert it to "/" */ - Removable: removable, IsGoAPI: isGOAPI, Children: []*Node{}} + child := Node{ + Name: filename, + Path: fpath, + Removable: removable, + IsGoAPI: isGOAPI, + Children: []*Node{}} node.Children = append(node.Children, &child) if nil == fio { diff --git a/static/js/editors.js b/static/js/editors.js index c86f1e1..7d796b2 100644 --- a/static/js/editors.js +++ b/static/js/editors.js @@ -745,7 +745,7 @@ var editors = { }, // 新建一个编辑器 Tab,如果已经存在 Tab 则切换到该 Tab. newEditor: function (data, cursor) { - var id = wide.curNode.path; + var id = wide.curNode.id; editors.tabs.add({ id: id,