feature(buffer) add

This commit is contained in:
coderaiser 2014-08-27 09:31:35 -04:00
parent 1f810293ff
commit b2faf20569
4 changed files with 93 additions and 60 deletions

View file

@ -52,6 +52,7 @@
client + 'load',
client + 'notify',
client + 'storage',
client + 'buffer',
client + 'files',
'client',
client + 'listeners',

83
lib/client/buffer.js Normal file
View file

@ -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);

View file

@ -1549,6 +1549,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
}, data);
};
this.moveFiles = function(data) {
processFiles({
move: true

View file

@ -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;
/* чистим хранилище */