This commit is contained in:
88250 2015-04-12 08:15:28 +08:00
parent 9bc8addfbf
commit f288d76eb9
5 changed files with 19 additions and 40 deletions

View File

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

View File

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

View File

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

View File

@ -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();

View File

@ -649,6 +649,7 @@
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/addon/comment/comment.js"></script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/mode/meta.js"></script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/mode/go/go.js"></script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/mode/clike/clike.js"></script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/mode/xml/xml.js"></script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/mode/htmlmixed/htmlmixed.js"></script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/mode/javascript/javascript.js"></script>