Sole node id

This commit is contained in:
Liang Ding 2015-04-27 14:36:35 +08:00
parent f1b258ff7f
commit 46ecea41c0
2 changed files with 17 additions and 8 deletions

View File

@ -36,6 +36,7 @@ var logger = log.NewLogger(os.Stdout)
// Node represents a file node in file tree. // Node represents a file node in file tree.
type Node struct { type Node struct {
Id string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Path string `json:"path"` Path string `json:"path"`
IconSkin string `json:"iconSkin"` // Value should be end with a space 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 { for _, workspace := range workspaces {
workspacePath := workspace + conf.PathSeparator + "src" workspacePath := workspace + conf.PathSeparator + "src"
workspaceNode := Node{Name: workspace[strings.LastIndex(workspace, conf.PathSeparator)+1:], workspaceNode := Node{
Path: filepath.ToSlash(workspacePath), /* jQuery data-index API can't accept "\", so we convert it to "/" */ Name: workspace[strings.LastIndex(workspace, conf.PathSeparator)+1:],
IconSkin: "ico-ztree-dir-workspace ", Type: "d", Path: workspacePath,
Creatable: true, Removable: false, IsGoAPI: false, Children: []*Node{}} IconSkin: "ico-ztree-dir-workspace ",
Type: "d",
Creatable: true,
Removable: false,
IsGoAPI: false,
Children: []*Node{}}
walk(workspacePath, &workspaceNode, true, true, false) walk(workspacePath, &workspaceNode, true, true, false)
@ -447,9 +453,12 @@ func walk(path string, node *Node, creatable, removable, isGOAPI bool) {
fio, _ := os.Lstat(fpath) fio, _ := os.Lstat(fpath)
child := Node{Name: filename, child := Node{
Path: filepath.ToSlash(fpath), /* jQuery data-index API can't accept "\", so we convert it to "/" */ Name: filename,
Removable: removable, IsGoAPI: isGOAPI, Children: []*Node{}} Path: fpath,
Removable: removable,
IsGoAPI: isGOAPI,
Children: []*Node{}}
node.Children = append(node.Children, &child) node.Children = append(node.Children, &child)
if nil == fio { if nil == fio {

View File

@ -745,7 +745,7 @@ var editors = {
}, },
// 新建一个编辑器 Tab如果已经存在 Tab 则切换到该 Tab. // 新建一个编辑器 Tab如果已经存在 Tab 则切换到该 Tab.
newEditor: function (data, cursor) { newEditor: function (data, cursor) {
var id = wide.curNode.path; var id = wide.curNode.id;
editors.tabs.add({ editors.tabs.add({
id: id, id: id,