From f288d76eb9402b9db4e028f8e8a880e3b6559a37 Mon Sep 17 00:00:00 2001 From: 88250 Date: Sun, 12 Apr 2015 08:15:28 +0800 Subject: [PATCH] Fix #227 --- file/files.go | 33 --------------------------------- static/js/editors.js | 2 +- static/js/tree.js | 17 +++++++++++++---- static/js/wide.js | 6 ++++-- views/index.html | 1 + 5 files changed, 19 insertions(+), 40 deletions(-) diff --git a/file/files.go b/file/files.go index 4d8900f..fa6fee8 100644 --- a/file/files.go +++ b/file/files.go @@ -187,7 +187,6 @@ func GetFileHandler(w http.ResponseWriter, r *http.Request) { data["msg"] = "Can't open a binary file :(" } else { data["content"] = content - data["mode"] = getEditorMode(extension) data["path"] = path } } @@ -264,9 +263,6 @@ func NewFileHandler(w http.ResponseWriter, r *http.Request) { } if "f" == fileType { - extension := filepath.Ext(path) - data["mode"] = getEditorMode(extension) - logger.Debugf("Created a file [%s] by user [%s]", path, wSession.Username) } else { logger.Debugf("Created a dir [%s] by user [%s]", path, wSession.Username) @@ -472,7 +468,6 @@ func walk(path string, node *Node, creatable, removable, isGOAPI bool) { ext := filepath.Ext(fpath) child.IconSkin = getIconSkin(ext) - child.Mode = getEditorMode(ext) } } @@ -549,34 +544,6 @@ func getIconSkin(filenameExtension string) string { } } -// getEditorMode gets editor mode with the specified filename extension. -// -// Refers to the CodeMirror document for modes. -func getEditorMode(filenameExtension string) string { - switch filenameExtension { - case ".go": - return "text/x-go" - case ".html": - return "text/html" - case ".md": - return "text/x-markdown" - case ".js": - return "text/javascript" - case ".json": - return "application/json" - case ".css": - return "text/css" - case ".xml": - return "application/xml" - case ".sh": - return "text/x-sh" - case ".sql": - return "text/x-sql" - default: - return "text/plain" - } -} - // createFile creates file on the specified path. // // fileType: diff --git a/static/js/editors.js b/static/js/editors.js index 42cf247..1572fa4 100644 --- a/static/js/editors.js +++ b/static/js/editors.js @@ -192,7 +192,7 @@ var editors = { 'find', 'find-next', 'find-previous', 'replace', 'replace-all', 'format', 'autocomplete', 'jump-to-decl', 'expr-info', 'find-usages', 'toggle-comment', 'edit']); - + // remove selected tree node tree.fileTree.cancelSelectedNode(); wide.curNode = undefined; diff --git a/static/js/tree.js b/static/js/tree.js index c4eaa4a..2586ec7 100644 --- a/static/js/tree.js +++ b/static/js/tree.js @@ -186,7 +186,7 @@ var tree = { return false; } - + var dir = wide.curNode.getParentNode(); tree.fileTree.reAsyncChildNodes(dir, "refresh"); } @@ -376,7 +376,7 @@ var tree = { } } - if (!tree.isDir()) { // 如果单击了文件 + if (!tree.isDir()) { var request = newWideRequest(); request.path = treeNode.path; @@ -393,6 +393,15 @@ var tree = { return false; } + if (!data.mode) { + var mode = CodeMirror.findModeByFileName(treeNode.path); + data.mode = mode.mime; + } + + if (!data.mode) { + console.error("Can't find mode by file name [" + treeNode.path + "]"); + } + if ("img" === data.mode) { // 是图片文件的话新建 tab 打开 // 最好是开 tab,但这个最终取决于浏览器设置 var w = window.open(config.context + data.path); @@ -512,12 +521,12 @@ var tree = { // update tree node var suffixIndex = name.lastIndexOf('.'); var suffix = name.substr(suffixIndex + 1); - + var iconSkin = 'ico-ztree-dir '; if ('f' === wide.curNode.type) { iconSkin = wide.getClassBySuffix(suffix); } - + wide.curNode.name = name; wide.curNode.title = request.newPath; wide.curNode.path = request.newPath; diff --git a/static/js/wide.js b/static/js/wide.js index 68a24af..c33d204 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -181,6 +181,8 @@ var wide = { return false; } + var mode = CodeMirror.findModeByFileName(name); + $("#dialogNewFilePrompt").dialog("close"); var iconSkin = wide.getClassBySuffix(name.split(".")[1]); @@ -188,7 +190,7 @@ var wide = { "name": name, "iconSkin": iconSkin, "path": request.path, - "mode": data.mode, + "mode": mode, "removable": true, "creatable": true }]); @@ -374,7 +376,7 @@ var wide = { }, "ok": function () { $("#dialogGitClonePrompt").dialog("close"); - + var request = newWideRequest(); request.path = wide.curNode.path; request.repository = $("#dialogGitClonePrompt > input").val(); diff --git a/views/index.html b/views/index.html index d485142..3560736 100644 --- a/views/index.html +++ b/views/index.html @@ -649,6 +649,7 @@ +