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) offset := getCursorOffset(code, line, ch)
// glog.Infof("offset [%d]", offset) // 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", "."} argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-use", "."}
cmd := exec.Command(ideStub, argv...) cmd := exec.Command(ideStub, argv...)
cmd.Dir = curDir cmd.Dir = curDir

View File

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

View File

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

View File

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