fixed# 179

This commit is contained in:
Van 2014-12-03 11:26:05 +08:00
parent ea6b058cdf
commit 1915b56e33
3 changed files with 79 additions and 62 deletions

View File

@ -309,6 +309,7 @@ var tree = {
});
this._initSearch();
this._initRename();
},
openFile: function (treeNode, cursor) {
wide.curNode = treeNode;
@ -421,5 +422,72 @@ var tree = {
});
}
});
},
_initRename: function () {
$("#dialogRenamePrompt").dialog({
"modal": true,
"height": 52,
"width": 260,
"title": config.label.rename,
"okText": config.label.rename,
"cancelText": config.label.cancel,
"afterOpen": function () {
$("#dialogRenamePrompt").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled", true);
$("#dialogRenamePrompt > input").val(wide.curNode.name).select().focus();
},
"ok": function () {
var name = $("#dialogRenamePrompt > input").val(),
request = newWideRequest();
request.oldPath = wide.curNode.path;
request.newPath = wide.curNode.path.substring(0,
wide.curNode.path.lastIndexOf(config.pathSeparator))
+ config.pathSeparator + name;
$.ajax({
type: 'POST',
url: '/file/rename',
data: JSON.stringify(request),
dataType: "json",
success: function (data) {
if (!data.succ) {
$("#dialogRenamePrompt").dialog("close");
bottomGroup.tabs.setCurrent("notification");
windows.flowBottom();
$(".bottom-window-group .notification").focus();
return false;
}
$("#dialogRenamePrompt").dialog("close");
// update tree node
var suffixIndex = name.lastIndexOf('.'),
iconSkin = wide.getClassBySuffix(name.substr(suffixIndex + 1));
wide.curNode.name = name;
wide.curNode.title = request.newPath;
wide.curNode.path = request.newPath;
wide.curNode.iconSkin = iconSkin;
tree.fileTree.updateNode(wide.curNode);
// update open editor tab name
for (var i = 0, ii = editors.data.length; i < ii; i++) {
if (wide.curNode.tId === editors.data[i].id) {
var info = CodeMirror.findModeByExtension(name.substr(suffixIndex + 1));
if (info) {
editors.data[i].editor.setOption("mode", info.mime);
//CodeMirror.autoLoadMode(editors.data[i].editor, info.mode);
}
var $currentSpan = $(".edit-panel .tabs > div[data-index=" + wide.curNode.tId + "] > span:eq(0)");
$currentSpan.attr("title", request.newPath);
$currentSpan.html('<span class="' + iconSkin + 'ico"></span>' + wide.curNode.name);
break;
}
}
}
});
}
});
}
};

View File

@ -32,7 +32,6 @@ var wide = {
}
});
$("#dialogAlert").dialog({
"modal": true,
"height": 26,
@ -98,65 +97,6 @@ var wide = {
}
});
$("#dialogRenamePrompt").dialog({
"modal": true,
"height": 52,
"width": 260,
"title": config.label.rename,
"okText": config.label.rename,
"cancelText": config.label.cancel,
"afterOpen": function () {
var index = wide.curNode.name.lastIndexOf("."),
name = wide.curNode.name.substring(0, index);
if (index === -1) {
name = wide.curNode.name;
}
$("#dialogRenamePrompt").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled", true);
$("#dialogRenamePrompt > input").val(name).select().focus();
},
"ok": function () {
var name = $("#dialogRenamePrompt > input").val(),
request = newWideRequest();
request.oldPath = wide.curNode.path;
var pathIndex = wide.curNode.path.lastIndexOf(config.pathSeparator),
nameIndex = wide.curNode.name.lastIndexOf("."),
ext = wide.curNode.name.substring(nameIndex, wide.curNode.name.length);
request.newPath = wide.curNode.path.substring(0, pathIndex) + config.pathSeparator
+ name + ext;
$.ajax({
type: 'POST',
url: '/file/rename',
data: JSON.stringify(request),
dataType: "json",
success: function (data) {
if (!data.succ) {
$("#dialogRenamePrompt").dialog("close");
bottomGroup.tabs.setCurrent("notification");
windows.flowBottom();
$(".bottom-window-group .notification").focus();
return false;
}
$("#dialogRenamePrompt").dialog("close");
// update tree node
wide.curNode.name = name + ext;
wide.curNode.title = request.newPath;
wide.curNode.path = request.newPath;
tree.fileTree.updateNode(wide.curNode);
// update open editor tab name
var $currentSpan = $(".edit-panel .tabs > div[data-index=" + wide.curNode.tId + "] > span:eq(0)");
$currentSpan.attr("title", request.newPath);
$currentSpan.html($currentSpan.find("span").html() + wide.curNode.name);
}
});
}
});
$("#dialogNewFilePrompt").dialog({
"modal": true,
"height": 52,
@ -669,7 +609,8 @@ var wide = {
getClassBySuffix: function (suffix) {
var iconSkin = "ico-ztree-other ";
switch (suffix) {
case "html", "htm":
case "html":
case "htm":
iconSkin = "ico-ztree-html ";
break;
case "go":
@ -696,7 +637,13 @@ var wide = {
case "xml":
iconSkin = "ico-ztree-xml ";
break;
case "jpg", "jpeg", "bmp", "gif", "png", "svg", "ico":
case "jpg":
case "jpeg":
case "bmp":
case "gif":
case "png":
case "svg":
case "ico":
iconSkin = "ico-ztree-img ";
break;
}

View File

@ -358,6 +358,8 @@
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/addon/fold/xml-fold.js"></script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/addon/fold/markdown-fold.js"></script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/addon/fold/comment-fold.js"></script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/addon/mode/loadmode.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/xml/xml.js"></script>
<script type="text/javascript" src="{{.conf.StaticServer}}/static/js/lib/codemirror-{{.codeMirrorVer}}/mode/htmlmixed/htmlmixed.js"></script>