From 1915b56e33afc9256ab8a540b07d71e65af2ba2a Mon Sep 17 00:00:00 2001 From: Van Date: Wed, 3 Dec 2014 11:26:05 +0800 Subject: [PATCH] fixed# 179 --- static/js/tree.js | 68 +++++++++++++++++++++++++++++++++++++++++++++ static/js/wide.js | 71 ++++++----------------------------------------- views/index.html | 2 ++ 3 files changed, 79 insertions(+), 62 deletions(-) diff --git a/static/js/tree.js b/static/js/tree.js index 3d2aed1..54e4c54 100644 --- a/static/js/tree.js +++ b/static/js/tree.js @@ -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('' + wide.curNode.name); + break; + } + } + } + }); + } + }); } }; \ No newline at end of file diff --git a/static/js/wide.js b/static/js/wide.js index 674c778..aef5061 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -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; } diff --git a/views/index.html b/views/index.html index c0f7edd..71da6df 100644 --- a/views/index.html +++ b/views/index.html @@ -358,6 +358,8 @@ + +