在树上添加 Ctrl+R 重命名快捷键

This commit is contained in:
Van 2014-12-03 11:40:41 +08:00
parent 1915b56e33
commit 02c1b0b5d6
2 changed files with 27 additions and 33 deletions

View File

@ -79,6 +79,13 @@ var hotkeys = {
shiftKey: false, shiftKey: false,
which: 81 which: 81
}, },
// Ctrl+R 重命名
rename: {
ctrlKey: true,
altKey: false,
shiftKey: false,
which: 82
},
// Shift+Alt+O 跳转到文件 // Shift+Alt+O 跳转到文件
goFile: { goFile: {
ctrlKey: false, ctrlKey: false,
@ -178,6 +185,14 @@ var hotkeys = {
return; return;
} }
if (event.ctrlKey === hotKeys.rename.ctrlKey
&& event.which === hotKeys.rename.which) { // Ctrl+R 重命名
if (wide.curNode.removable) {
$("#dialogRenamePrompt").dialog("open");
}
return;
}
switch (event.which) { switch (event.which) {
case 46: // 删除 case 46: // 删除
tree.removeIt(); tree.removeIt();

View File

@ -112,7 +112,6 @@ var tree = {
return false; return false;
} }
$("#dirRMenu").hide();
$("#dialogNewFilePrompt").dialog("open"); $("#dialogNewFilePrompt").dialog("open");
}, },
newDir: function (it) { newDir: function (it) {
@ -120,7 +119,6 @@ var tree = {
return false; return false;
} }
$("#dirRMenu").hide();
$("#dialogNewDirPrompt").dialog("open"); $("#dialogNewDirPrompt").dialog("open");
}, },
removeIt: function (it) { removeIt: function (it) {
@ -134,9 +132,6 @@ var tree = {
return false; return false;
} }
} }
$("#dirRMenu").hide();
$("#fileRMenu").hide();
$("#dialogRemoveConfirm").dialog("open"); $("#dialogRemoveConfirm").dialog("open");
}, },
rename: function (it) { rename: function (it) {
@ -145,9 +140,6 @@ var tree = {
return false; return false;
} }
} }
$("#dirRMenu").hide();
$("#fileRMenu").hide();
$("#dialogRenamePrompt").dialog("open"); $("#dialogRenamePrompt").dialog("open");
}, },
export: function (it) { export: function (it) {
@ -175,9 +167,6 @@ var tree = {
window.open('/file/zip?path=' + wide.curNode.path + '.zip'); window.open('/file/zip?path=' + wide.curNode.path + '.zip');
} }
}); });
$("#dirRMenu").hide();
$("#fileRMenu").hide();
}, },
refresh: function (it) { refresh: function (it) {
if (it) { if (it) {
@ -187,9 +176,6 @@ var tree = {
} }
tree.fileTree.reAsyncChildNodes(wide.curNode, "refresh"); tree.fileTree.reAsyncChildNodes(wide.curNode, "refresh");
$("#dirRMenu").hide();
$("#fileRMenu").hide();
}, },
import: function (it) { import: function (it) {
if (it) { if (it) {
@ -209,9 +195,6 @@ var tree = {
tree.fileTree.reAsyncChildNodes(wide.curNode, "refresh"); tree.fileTree.reAsyncChildNodes(wide.curNode, "refresh");
} }
}); });
$("#dirRMenu").hide();
$("#fileRMenu").hide();
}, },
init: function () { init: function () {
$("#file").click(function () { $("#file").click(function () {
@ -227,8 +210,8 @@ var tree = {
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
if (data.succ) { if (data.succ) {
var dirRMenu = $("#dirRMenu"); var $dirRMenu = $("#dirRMenu");
var fileRMenu = $("#fileRMenu"); var $fileRMenu = $("#fileRMenu");
var setting = { var setting = {
data: { data: {
key: { key: {
@ -257,37 +240,34 @@ var tree = {
if (!tree.isDir()) { // 如果右击了文件 if (!tree.isDir()) { // 如果右击了文件
if (wide.curNode.removable) { if (wide.curNode.removable) {
$("#fileRMenu .remove").removeClass("disabled"); $fileRMenu.find(".remove").removeClass("disabled");
} else { } else {
$("#fileRMenu .remove").addClass("disabled"); $fileRMenu.find(".remove").addClass("disabled");
} }
$("#fileRMenu").show(); $fileRMenu.css({
fileRMenu.css({
"top": event.clientY - 10 + "px", "top": event.clientY - 10 + "px",
"left": event.clientX + "px", "left": event.clientX + "px",
"display": "block" "display": "block"
}); }).show();
} else { // 右击了目录 } else { // 右击了目录
if (wide.curNode.removable) { if (wide.curNode.removable) {
$("#dirRMenu .remove, #dirRMenu .rename").removeClass("disabled"); $dirRMenu.find(".remove, .rename").removeClass("disabled");
} else { } else {
$("#dirRMenu .remove, #dirRMenu .rename").addClass("disabled"); $dirRMenu.find(".remove, .rename").addClass("disabled");
} }
if (wide.curNode.creatable) { if (wide.curNode.creatable) {
$("#dirRMenu .create").removeClass("disabled"); $dirRMenu.find(".create").removeClass("disabled");
} else { } else {
$("#dirRMenu .create").addClass("disabled"); $dirRMenu.find(".create").addClass("disabled");
} }
$("#dirRMenu").show(); $dirRMenu.css({
dirRMenu.css({
"top": event.clientY - 10 + "px", "top": event.clientY - 10 + "px",
"left": event.clientX + "px", "left": event.clientX + "px",
"display": "block" "display": "block"
}); }).show();
} }
$("#files").focus(); $("#files").focus();
} }
@ -476,7 +456,6 @@ var tree = {
var info = CodeMirror.findModeByExtension(name.substr(suffixIndex + 1)); var info = CodeMirror.findModeByExtension(name.substr(suffixIndex + 1));
if (info) { if (info) {
editors.data[i].editor.setOption("mode", info.mime); 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)"); var $currentSpan = $(".edit-panel .tabs > div[data-index=" + wide.curNode.tId + "] > span:eq(0)");