This commit is contained in:
parent
6ae2ce8960
commit
338f16b262
|
@ -23,8 +23,10 @@ type FileNode struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
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
|
||||||
Type string `json:"type"` // "f": file, "d": directory
|
Type string `json:"type"` // "f": file, "d": directory
|
||||||
|
Creatable bool `json:"creatable"` // whether can create file in this file node
|
||||||
|
Removable bool `json:"removable"` // whether can remove this file node
|
||||||
Mode string `json:"mode"`
|
Mode string `json:"mode"`
|
||||||
FileNodes []*FileNode `json:"children"`
|
FileNodes []*FileNode `json:"children"`
|
||||||
}
|
}
|
||||||
|
@ -58,7 +60,8 @@ func GetFiles(w http.ResponseWriter, r *http.Request) {
|
||||||
workspacePath := workspace + conf.PathSeparator + "src"
|
workspacePath := workspace + conf.PathSeparator + "src"
|
||||||
|
|
||||||
workspaceNode := FileNode{Name: workspace[strings.LastIndex(workspace, conf.PathSeparator)+1:],
|
workspaceNode := FileNode{Name: workspace[strings.LastIndex(workspace, conf.PathSeparator)+1:],
|
||||||
Title: workspace, Path: workspacePath, IconSkin: "ico-ztree-dir-workspace ", Type: "d", FileNodes: []*FileNode{}}
|
Title: workspace, Path: workspacePath, IconSkin: "ico-ztree-dir-workspace ", Type: "d",
|
||||||
|
Creatable: true, Removable: false, FileNodes: []*FileNode{}}
|
||||||
|
|
||||||
walk(workspacePath, &workspaceNode)
|
walk(workspacePath, &workspaceNode)
|
||||||
|
|
||||||
|
@ -68,12 +71,11 @@ func GetFiles(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// construct Go API node
|
// construct Go API node
|
||||||
apiPath := runtime.GOROOT() + conf.PathSeparator + "src" + conf.PathSeparator + "pkg"
|
apiPath := runtime.GOROOT() + conf.PathSeparator + "src" + conf.PathSeparator + "pkg"
|
||||||
apiNode := FileNode{Name: "Go API", Title: apiPath, Path: apiPath, FileNodes: []*FileNode{}}
|
apiNode := FileNode{Name: "Go API", Title: apiPath, Path: apiPath, IconSkin: "ico-ztree-dir-api ", Type: "d",
|
||||||
|
Creatable: true, Removable: false, FileNodes: []*FileNode{}}
|
||||||
|
|
||||||
goapiBuildOKSignal := make(chan bool)
|
goapiBuildOKSignal := make(chan bool)
|
||||||
go func() {
|
go func() {
|
||||||
apiNode.Type = "d"
|
|
||||||
apiNode.IconSkin = "ico-ztree-dir-api "
|
|
||||||
|
|
||||||
walk(apiPath, &apiNode)
|
walk(apiPath, &apiNode)
|
||||||
|
|
||||||
|
@ -269,7 +271,7 @@ func walk(path string, node *FileNode) {
|
||||||
|
|
||||||
fio, _ := os.Lstat(fpath)
|
fio, _ := os.Lstat(fpath)
|
||||||
|
|
||||||
child := FileNode{Name: filename, Title: fpath, Path: fpath, FileNodes: []*FileNode{}}
|
child := FileNode{Name: filename, Title: fpath, Path: fpath, Removable: true, FileNodes: []*FileNode{}}
|
||||||
node.FileNodes = append(node.FileNodes, &child)
|
node.FileNodes = append(node.FileNodes, &child)
|
||||||
|
|
||||||
if nil == fio {
|
if nil == fio {
|
||||||
|
@ -280,11 +282,13 @@ func walk(path string, node *FileNode) {
|
||||||
|
|
||||||
if fio.IsDir() {
|
if fio.IsDir() {
|
||||||
child.Type = "d"
|
child.Type = "d"
|
||||||
|
child.Creatable = true
|
||||||
child.IconSkin = "ico-ztree-dir "
|
child.IconSkin = "ico-ztree-dir "
|
||||||
|
|
||||||
walk(fpath, &child)
|
walk(fpath, &child)
|
||||||
} else {
|
} else {
|
||||||
child.Type = "f"
|
child.Type = "f"
|
||||||
|
child.Creatable = false
|
||||||
ext := filepath.Ext(fpath)
|
ext := filepath.Ext(fpath)
|
||||||
|
|
||||||
child.IconSkin = getIconSkin(ext)
|
child.IconSkin = getIconSkin(ext)
|
||||||
|
|
Loading…
Reference in New Issue