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.
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 {

View File

@ -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,