This commit is contained in:
Liang Ding 2014-12-07 11:29:45 +08:00
parent 6e7bfa5040
commit 65f9b77fb5
4 changed files with 34 additions and 34 deletions

View File

@ -384,7 +384,7 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) {
offset := getCursorOffset(code, line, ch)
// glog.Infof("offset [%d]", offset)
idestub := util.Go.GetExecutableInGOBIN("ide_stub")
ideStub := util.Go.GetExecutableInGOBIN("ide_stub")
argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-use", "."}
cmd := exec.Command(ideStub, argv...)
cmd.Dir = curDir

View File

@ -127,10 +127,10 @@ type Handler interface {
Handle(event *Event)
}
// Type of handler function.
type handleFunc func(event *Event)
// HandleFunc represents a handler function.
type HandleFunc func(event *Event)
// Default implementation of event handling.
func (fn handleFunc) Handle(event *Event) {
func (fn HandleFunc) Handle(event *Event) {
fn(event)
}

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// File tree manipulations.
// Package file includes file related manipulations.
package file
import (
@ -31,19 +31,19 @@ import (
"github.com/golang/glog"
)
// File node, used to construct the file tree.
type FileNode struct {
Name string `json:"name"`
Path string `json:"path"`
IconSkin string `json:"iconSkin"` // Value should be end with a space
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"`
FileNodes []*FileNode `json:"children"`
// Node represents a file node in file tree.
type Node struct {
Name string `json:"name"`
Path string `json:"path"`
IconSkin string `json:"iconSkin"` // Value should be end with a space
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"`
Children []*Node `json:"children"`
}
// Source code snippet, used to as the result of "Find Usages", "Search".
// Snippet represents a source code snippet, used to as the result of "Find Usages", "Search".
type Snippet struct {
Path string `json:"path"` // file path
Line int `json:"line"` // line number
@ -51,14 +51,14 @@ type Snippet struct {
Contents []string `json:"contents"` // lines nearby
}
var apiNode *FileNode
var apiNode *Node
// initAPINode builds the Go API file node.
func initAPINode() {
apiPath := util.Go.GetAPIPath()
apiNode = &FileNode{Name: "Go API", Path: apiPath, IconSkin: "ico-ztree-dir-api ", Type: "d",
Creatable: false, Removable: false, FileNodes: []*FileNode{}}
apiNode = &Node{Name: "Go API", Path: apiPath, IconSkin: "ico-ztree-dir-api ", Type: "d",
Creatable: false, Removable: false, Children: []*Node{}}
walk(apiPath, apiNode, false, false)
}
@ -82,7 +82,7 @@ func GetFiles(w http.ResponseWriter, r *http.Request) {
userWorkspace := conf.Wide.GetUserWorkspace(username)
workspaces := filepath.SplitList(userWorkspace)
root := FileNode{Name: "root", Path: "", IconSkin: "ico-ztree-dir ", Type: "d", FileNodes: []*FileNode{}}
root := Node{Name: "root", Path: "", IconSkin: "ico-ztree-dir ", Type: "d", Children: []*Node{}}
if nil == apiNode { // lazy init
initAPINode()
@ -92,18 +92,18 @@ func GetFiles(w http.ResponseWriter, r *http.Request) {
for _, workspace := range workspaces {
workspacePath := workspace + conf.PathSeparator + "src"
workspaceNode := FileNode{Name: workspace[strings.LastIndex(workspace, conf.PathSeparator)+1:],
workspaceNode := Node{Name: workspace[strings.LastIndex(workspace, conf.PathSeparator)+1:],
Path: workspacePath, IconSkin: "ico-ztree-dir-workspace ", Type: "d",
Creatable: true, Removable: false, FileNodes: []*FileNode{}}
Creatable: true, Removable: false, Children: []*Node{}}
walk(workspacePath, &workspaceNode, true, true)
// add workspace node
root.FileNodes = append(root.FileNodes, &workspaceNode)
root.Children = append(root.Children, &workspaceNode)
}
// add Go API node
root.FileNodes = append(root.FileNodes, apiNode)
root.Children = append(root.Children, apiNode)
data["root"] = root
}
@ -113,12 +113,12 @@ 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{}}
node := Node{Name: "root", Path: path, IconSkin: "ico-ztree-dir ", Type: "d", Children: []*Node{}}
walk(path, &node, true, true)
w.Header().Set("Content-Type", "application/json")
data, err := json.Marshal(node.FileNodes)
data, err := json.Marshal(node.Children)
if err != nil {
glog.Error(err)
return
@ -417,7 +417,7 @@ func SearchText(w http.ResponseWriter, r *http.Request) {
}
// walk traverses the specified path to build a file tree.
func walk(path string, node *FileNode, creatable, removable bool) {
func walk(path string, node *Node, creatable, removable bool) {
files := listFiles(path)
for _, filename := range files {
@ -425,8 +425,8 @@ func walk(path string, node *FileNode, creatable, removable bool) {
fio, _ := os.Lstat(fpath)
child := FileNode{Name: filename, Path: fpath, Removable: removable, FileNodes: []*FileNode{}}
node.FileNodes = append(node.FileNodes, &child)
child := Node{Name: filename, Path: fpath, Removable: removable, Children: []*Node{}}
node.Children = append(node.Children, &child)
if nil == fio {
glog.Warningf("Path [%s] is nil", fpath)

View File

@ -10,14 +10,14 @@ import (
"github.com/b3log/wide/util"
)
type FileInfo struct {
type fileInfo struct {
Name string `json:"name"`
Type string `json:"type"`
Error string `json:"error,omitempty"`
}
func handleUpload(p *multipart.Part, dir string) (fi *FileInfo) {
fi = &FileInfo{
func handleUpload(p *multipart.Part, dir string) (fi *fileInfo) {
fi = &fileInfo{
Name: p.FileName(),
Type: p.Header.Get("Content-Type"),
}
@ -32,8 +32,8 @@ func handleUpload(p *multipart.Part, dir string) (fi *FileInfo) {
return
}
func handleUploads(r *http.Request, dir string) (fileInfos []*FileInfo) {
fileInfos = make([]*FileInfo, 0)
func handleUploads(r *http.Request, dir string) (fileInfos []*fileInfo) {
fileInfos = make([]*fileInfo, 0)
mr, err := r.MultipartReader()
part, err := mr.NextPart()