Fix #227
This commit is contained in:
parent
9bc8addfbf
commit
f288d76eb9
|
@ -187,7 +187,6 @@ func GetFileHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data["msg"] = "Can't open a binary file :("
|
data["msg"] = "Can't open a binary file :("
|
||||||
} else {
|
} else {
|
||||||
data["content"] = content
|
data["content"] = content
|
||||||
data["mode"] = getEditorMode(extension)
|
|
||||||
data["path"] = path
|
data["path"] = path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -264,9 +263,6 @@ func NewFileHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if "f" == fileType {
|
if "f" == fileType {
|
||||||
extension := filepath.Ext(path)
|
|
||||||
data["mode"] = getEditorMode(extension)
|
|
||||||
|
|
||||||
logger.Debugf("Created a file [%s] by user [%s]", path, wSession.Username)
|
logger.Debugf("Created a file [%s] by user [%s]", path, wSession.Username)
|
||||||
} else {
|
} else {
|
||||||
logger.Debugf("Created a dir [%s] by user [%s]", path, wSession.Username)
|
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)
|
ext := filepath.Ext(fpath)
|
||||||
|
|
||||||
child.IconSkin = getIconSkin(ext)
|
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.
|
// createFile creates file on the specified path.
|
||||||
//
|
//
|
||||||
// fileType:
|
// fileType:
|
||||||
|
|
|
@ -376,7 +376,7 @@ var tree = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tree.isDir()) { // 如果单击了文件
|
if (!tree.isDir()) {
|
||||||
var request = newWideRequest();
|
var request = newWideRequest();
|
||||||
request.path = treeNode.path;
|
request.path = treeNode.path;
|
||||||
|
|
||||||
|
@ -393,6 +393,15 @@ var tree = {
|
||||||
return false;
|
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 打开
|
if ("img" === data.mode) { // 是图片文件的话新建 tab 打开
|
||||||
// 最好是开 tab,但这个最终取决于浏览器设置
|
// 最好是开 tab,但这个最终取决于浏览器设置
|
||||||
var w = window.open(config.context + data.path);
|
var w = window.open(config.context + data.path);
|
||||||
|
|
|
@ -181,6 +181,8 @@ var wide = {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mode = CodeMirror.findModeByFileName(name);
|
||||||
|
|
||||||
$("#dialogNewFilePrompt").dialog("close");
|
$("#dialogNewFilePrompt").dialog("close");
|
||||||
var iconSkin = wide.getClassBySuffix(name.split(".")[1]);
|
var iconSkin = wide.getClassBySuffix(name.split(".")[1]);
|
||||||
|
|
||||||
|
@ -188,7 +190,7 @@ var wide = {
|
||||||
"name": name,
|
"name": name,
|
||||||
"iconSkin": iconSkin,
|
"iconSkin": iconSkin,
|
||||||
"path": request.path,
|
"path": request.path,
|
||||||
"mode": data.mode,
|
"mode": mode,
|
||||||
"removable": true,
|
"removable": true,
|
||||||
"creatable": true
|
"creatable": true
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -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}}/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/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/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/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/htmlmixed/htmlmixed.js"></script>
|
||||||
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/mode/javascript/javascript.js"></script>
|
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/mode/javascript/javascript.js"></script>
|
||||||
|
|
Loading…
Reference in New Issue