File rename/remove bug fix

This commit is contained in:
Liang Ding 2015-10-02 21:39:36 +08:00
parent 54cfad611d
commit 59bb310fa0
3 changed files with 6 additions and 55 deletions

View File

@ -165,13 +165,13 @@ var session = {
switch (data.cmd) {
case 'create-file':
var dirNode = tree.fileTree.getNodeByTId(tree.getTIdByPath(data.dir)),
var node = tree.fileTree.getNodeByTId(tree.getTIdByPath(data.dir)),
name = data.path.replace(data.dir + '/', ''),
mode = CodeMirror.findModeByFileName(name),
iconSkin = wide.getClassBySuffix(name.split(".")[1]);
if (data.type && data.type === 'f') {
tree.fileTree.addNodes(dirNode, [{
tree.fileTree.addNodes(node, [{
"id": data.path,
"name": name,
"iconSkin": iconSkin,
@ -182,7 +182,7 @@ var session = {
}]);
} else {
tree.fileTree.addNodes(dirNode, [{
tree.fileTree.addNodes(node, [{
"id": data.path,
"name": name,
"iconSkin": "ico-ztree-dir ",
@ -196,8 +196,9 @@ var session = {
break;
case 'remove-file':
case 'rename-file':
var dirNode = tree.fileTree.getNodeByTId(tree.getTIdByPath(data.path));
tree.fileTree.removeNode(dirNode);
var node = tree.fileTree.getNodeByTId(tree.getTIdByPath(data.path));
tree.fileTree.removeNode(node);
break;
}
};

View File

@ -542,37 +542,6 @@ var tree = {
}
$("#dialogRenamePrompt").dialog("close");
// 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;
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.path === editors.data[i].id) {
var mode = CodeMirror.findModeByExtension(suffix);
if (mode) {
editors.data[i].editor.setOption("mode", mode.mime);
}
var $currentSpan = $('.edit-panel .tabs > div[data-index="' + wide.curNode.path + '"] > span:eq(0)');
$currentSpan.attr("title", request.newPath);
$currentSpan.html('<span class="' + iconSkin + 'ico"></span>' + wide.curNode.name);
break;
}
}
}
});
}

View File

@ -125,25 +125,6 @@ var wide = {
}
$("#dialogRemoveConfirm").dialog("close");
tree.fileTree.removeNode(wide.curNode);
if (!tree.isDir()) {
// 是文件的话,查看 editor 中是否被打开,如打开则移除
for (var i = 0, ii = editors.data.length; i < ii; i++) {
if (editors.data[i].id === wide.curNode.path) {
$('.edit-panel .tabs > div[data-index="' + wide.curNode.path + '"]').find(".ico-close").click();
break;
}
}
} else {
for (var i = 0, ii = editors.data.length; i < ii; i++) {
if (tree.isParents(editors.data[i].id, wide.curNode.path)) {
$('.edit-panel .tabs > div[data-index="' + editors.data[i].id + '"]').find(".ico-close").click();
i--;
ii--;
}
}
}
}
});
}