From f56a17510186a7720977e468b38c58f605eea804 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 27 Aug 2014 07:59:15 -0400 Subject: [PATCH] feature(key) add copy, cut to buffer; paste from buffer --- HELP.md | 3 ++ lib/client/dom.js | 57 ++++++++++++++++++++------------- lib/client/key.js | 80 +++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 116 insertions(+), 24 deletions(-) diff --git a/HELP.md b/HELP.md index 2b66bb8d..4a798be8 100644 --- a/HELP.md +++ b/HELP.md @@ -111,6 +111,9 @@ Hot keys | `*` | select/unselect all | `+` | expand selection | `-` | shrink selection +| `Ctrl + с` | copy to buffer +| `Ctrl + x` | cut to buffer +| `Ctrl + v` | paste from buffer | `Ctrl + r` | refresh | `Ctrl + d` | clear local storage | `Alt + q` | disable key bindings diff --git a/lib/client/dom.js b/lib/client/dom.js index 8e2653bc..81d8d861 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -1464,16 +1464,16 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; * process files (copy or move) * @param operation */ - function processFiles(operation) { + function processFiles(operation, data) { var n, name, files, cmp, msg, opFunc, RESTful = DOM.RESTful, - from = CurrentInfo.dirPath, - to = DOM.getNotCurrentDirPath(), + from = '', + to = '', - names = Cmd.getSelectedNames(), + names = [], - length = names && names.length; + length = 0; if (operation.copy) { opFunc = RESTful.cp; @@ -1483,24 +1483,37 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; msg = 'Rename/Move '; } - if (!length) { - name = DOM.getCurrentName(); - names.push(name); - } else if (length === 1) { - name = names[0]; + if (data) { + from = data.from; + to = data.to; + names = data.names; + } else { + from = CurrentInfo.dirPath; + to = DOM.getNotCurrentDirPath(); + + names = Cmd.getSelectedNames(); + length = names && names.length; + + if (!length) { + name = DOM.getCurrentName(); + names.push(name); + } else if (length === 1) { + name = names[0]; + } + + if (length > 1) + msg += n + ' file(s)'; + else + msg += '"' + name + '"'; + + msg += ' to'; } - if (length > 1) - msg += n + ' file(s)'; - else - msg += '"' + name + '"'; - - msg += ' to'; - if (name === '..') { Dialog.alert('No files selected!'); } else { - to = Dialog.prompt(msg, to); + if (!data) + to = Dialog.prompt(msg, to); cmp = Util.strCmp(from, to); @@ -1530,16 +1543,16 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; } } - this.copyFiles = function() { + this.copyFiles = function(data) { processFiles({ copy: true - }); + }, data); }; - this.moveFiles = function() { + this.moveFiles = function(data) { processFiles({ move: true - }); + }, data); }; /** diff --git a/lib/client/key.js b/lib/client/key.js index de78738d..a3f714a8 100644 --- a/lib/client/key.js +++ b/lib/client/key.js @@ -1,9 +1,13 @@ var CloudCmd, Util, DOM; + (function(CloudCmd, Util, DOM) { 'use strict'; var Info = DOM.CurrentInfo, Events = DOM.Events, + Storage = DOM.Storage, + Dialog = DOM.Dialog, + Chars = [], KEY = { BACKSPACE : 8, @@ -26,6 +30,7 @@ var CloudCmd, Util, DOM; A : 65, + C : 67, D : 68, G : 71, @@ -36,6 +41,10 @@ var CloudCmd, Util, DOM; S : 83, T : 84, + V : 86, + + X : 88, + Z : 90, ASTERISK : 106, @@ -162,12 +171,16 @@ var CloudCmd, Util, DOM; function switchKey(event) { var i, obj, name, isSelected, isDir, prev, next, + names = [], + copy = Storage.get.bind(Storage, 'copy'), + move = Storage.get.bind(Storage, 'move'), + current = Info.element, panel = Info.panel, path = Info.path, keyCode = event.keyCode, shift = event.shiftKey, - lAlt = event.altKey, + alt = event.altKey, ctrl = event.ctrlKey; if (current) { @@ -413,6 +426,69 @@ var CloudCmd, Util, DOM; } break; + case Key.C: + if (ctrl) { + names = DOM.getSelectedNames(); + i = names.length; + + Storage.remove('move') + .set('copy', { + from : Info.dirPath, + names: i ? names : [Info.name] + }); + } + break; + + case Key.X: + if (ctrl) { + names = DOM.getSelectedNames(); + i = names.length; + + Storage.remove('cop') + .set('move', { + from : Info.dirPath, + names: i ? names : [Info.name] + }); + } + break; + + case Key.V: + if (ctrl) { + Util.exec.parallel([copy, move], function(error, cp, mv) { + var data = {}, + msg = 'Path is same!', + path = Info.dirPath; + + if (!error && !cp && !mv) + error = 'No files selected!'; + + if (error) { + DOM.Dialog.alert(error); + } else if (cp) { + data = Util.parseJSON(cp); + data.to = path; + + if (data.from === path) + Dialog.alert(msg); + else + DOM.copyFiles(data); + + } else if (mv) { + data = Util.parseJSON(mv); + data.to = path; + + if (data.from === path) + Dialog.alert(msg); + else + DOM.moveFiles(data); + } + + Storage.remove('copy') + .remove('move'); + }); + } + break; + /* чистим хранилище */ case Key.D: if (ctrl) { @@ -427,7 +503,7 @@ var CloudCmd, Util, DOM; /* убираем все обработчики нажатий клавиш */ case Key.Q: - if (lAlt) { + if (alt) { Util.log('+q pressed\n' + '+r reload key-handerl - removed' + '+s clear Storage key-handler - removed'+