From b2faf20569b3f1706fb6cd65b60512f00eb16dc2 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 27 Aug 2014 09:31:35 -0400 Subject: [PATCH] feature(buffer) add --- html/fs/index.html | 1 + lib/client/buffer.js | 83 ++++++++++++++++++++++++++++++++++++++++++++ lib/client/dom.js | 1 + lib/client/key.js | 68 +++++------------------------------- 4 files changed, 93 insertions(+), 60 deletions(-) create mode 100644 lib/client/buffer.js diff --git a/html/fs/index.html b/html/fs/index.html index 08b7fc62..f35fdca4 100644 --- a/html/fs/index.html +++ b/html/fs/index.html @@ -52,6 +52,7 @@ client + 'load', client + 'notify', client + 'storage', + client + 'buffer', client + 'files', 'client', client + 'listeners', diff --git a/lib/client/buffer.js b/lib/client/buffer.js new file mode 100644 index 00000000..a2bc1726 --- /dev/null +++ b/lib/client/buffer.js @@ -0,0 +1,83 @@ +var Util, DOM; + +(function(Util, DOM) { + 'use strict'; + + DOM.Buffer = new BufferProto(); + + function BufferProto() { + var Storage = DOM.Storage, + Dialog = DOM.Dialog, + Info = DOM.CurrentInfo; + + function getNames() { + var name = Info.name, + names = DOM.getSelectedNames(), + n = names.length; + + return n ? names : [name]; + } + + this.copy = function() { + var Storage = DOM.Storage, + names = getNames(), + from = Info.dirPath; + + Storage.remove('move') + .set('copy', { + from : from, + names: names + }); + }; + + this.move = function() { + var Storage = DOM.Storage, + names = getNames(), + from = Info.dirPath; + + Storage.remove('copy') + .set('move', { + from : from, + names: names + }); + }; + + this.paste = function() { + var copy = Storage.get.bind(Storage, 'copy'), + move = Storage.get.bind(Storage, 'move'); + + 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'); + }); + }; + } +})(Util, DOM); diff --git a/lib/client/dom.js b/lib/client/dom.js index 81d8d861..b3ee1de3 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -1549,6 +1549,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; }, data); }; + this.moveFiles = function(data) { processFiles({ move: true diff --git a/lib/client/key.js b/lib/client/key.js index a3f714a8..9a4ad2ca 100644 --- a/lib/client/key.js +++ b/lib/client/key.js @@ -5,8 +5,7 @@ var CloudCmd, Util, DOM; var Info = DOM.CurrentInfo, Events = DOM.Events, - Storage = DOM.Storage, - Dialog = DOM.Dialog, + Buffer = DOM.Buffer, Chars = [], KEY = { @@ -171,10 +170,6 @@ 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, @@ -427,66 +422,19 @@ 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] - }); - } + + if (ctrl) + Buffer.copy(); 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] - }); - } + if (ctrl) + Buffer.move(); 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'); - }); - } + if (ctrl) + Buffer.paste(); break; /* чистим хранилище */