added ability to copy files

This commit is contained in:
coderaiser 2013-03-14 10:42:43 -04:00
parent b0a75540b7
commit fbae7813e4
6 changed files with 73 additions and 31 deletions

View file

@ -30,7 +30,9 @@ would be on top.
* Added update of size on file changing in editor.
* Removed cache control of fs resour
* Removed cache control of fs resour.
* Added ability to copy files.
2012.03.01, Version 0.1.9

View file

@ -2,7 +2,7 @@
"api_url" : "/api/v1",
"appcache" : false,
"minification" : {
"js" : true,
"js" : false,
"css" : true,
"html" : true,
"img" : true

View file

@ -282,7 +282,7 @@ var Util, DOM, CloudFunc, $, KeyBinding, CloudCommander;
DOM.renameCurrent, /* f2 */
CloudCmd.Viewer, /* f3 */
CloudCmd.Editor, /* f4 */
null, /* f5 */
DOM.copyCurrent, /* f5 */
DOM.moveCurrent, /* f6 */
DOM.promptNewFolder, /* f7 */
DOM.promptDeleteCurrent,/* f8 */

View file

@ -67,6 +67,15 @@ var CloudCommander, Util,
});
};
this.cp = function(pData, pCallBack){
sendRequest({
method : 'PUT',
url : '/cp',
data : pData,
callback : pCallBack
});
};
this.mv = function(pData, pCallBack){
sendRequest({
method : 'PUT',
@ -1473,6 +1482,33 @@ var CloudCommander, Util,
}
};
/**
* move current file
*
* @pCurrent
*/
DOM.copyCurrent = function(pCurrentFile){
if( !DOM.isCurrentFile(pCurrentFile) )
pCurrentFile = null;
var lCurrent = pCurrentFile || DOM.getCurrentFile(),
lName = DOM.getCurrentName(lCurrent),
lFromPath = DOM.getCurrentPath(),
lToPath = DOM.getNotCurrentDirPath() + lName,
lTo = prompt( 'Copy file "' + lName + '" to', lToPath );
if( lTo && !Util.strCmp(lFromPath, lToPath) ){
var lFiles = {
from : lFromPath,
to : lToPath
};
DOM.RESTfull.cp(lFiles, function(){
});
}
};
/**
* unified way to scrollIntoViewIfNeeded
* (native suporte by webkit only)

View file

@ -34,7 +34,7 @@ var CloudCommander, Util, DOM;
F2 : 113,
F3 : 114,
F4 : 115,
F5 : 116,
F6 : 117,
F7 : 118,
F10 : 121,
@ -93,26 +93,22 @@ var CloudCommander, Util, DOM;
* наоборот
*/
else if(lKeyCode === KEY.TAB){
console.log('Tab pressed');
Util.tryCatchLog(function(){
/* changing parent panel of curent-file */
var lPanel = DOM.getPanel(),
lId = lPanel.id;
lTabPanel[lId] = lCurrentFile;
lPanel = DOM.getPanel({active:false});
/* changing parent panel of curent-file */
var lPanel = DOM.getPanel(),
lId = lPanel.id;
if(lTabPanel[lId])
DOM.setCurrentFile(lTabPanel[lId]);
else{
var lFirstFileOnList = DOM.getByTag('li', lPanel)[2];
DOM.setCurrentFile(lFirstFileOnList);
}
});
lTabPanel[lId] = lCurrentFile;
lPanel = DOM.getPanel({active:false});
lId = lPanel.id;
if(lTabPanel[lId])
DOM.setCurrentFile(lTabPanel[lId]);
else{
var lFirstFileOnList = DOM.getByTag('li', lPanel)[2];
DOM.setCurrentFile(lFirstFileOnList);
}
DOM.preventDefault(pEvent);//запрет на дальнейшее действие
}
@ -153,8 +149,14 @@ var CloudCommander, Util, DOM;
DOM.preventDefault(pEvent);
break;
case KEY.F5:
DOM.copyCurrent(lCurrentFile);
DOM.preventDefault(pEvent);
break;
case KEY.F6:
DOM.moveCurrent();
DOM.moveCurrent(lCurrentFile);
DOM.preventDefault(pEvent);
break;
case KEY.F7:

View file

@ -132,7 +132,6 @@
var lWriteStream = fs.createWriteStream(p.name);
lWriteStream.on('error', function(pError){
console.log(pError);
main.sendError(pParams, pError);
});
@ -243,13 +242,14 @@
main.sendError(pParams, pError);
});
else
main.sendError(pParams, p.data);
main.sendError(pParams, p.data);
break;
case 'cp':
if(lFiles){
var lReadStream = fs.createReadStream(lFiles.from),
lWriteStream = fs.createWriteStream(lFiles.to),
if( Util.checkObjTrue(lFiles, ['from', 'to']) ){
var l = lFiles,
lReadStream = fs.createReadStream(l.from),
lWriteStream = fs.createWriteStream(l.to),
lError = function(pError){
main.sendError(pParams, pError);
};
@ -258,12 +258,14 @@
lWriteStream.on('error', lError);
lReadStream.on('error', lError);
lWriteStream.on('end', function(){
main.sendResponse(pParams, 'copied: ' + p.name);
lReadStream.on('end', function(){
main.sendResponse(pParams, 'copied to: ' + l.to);
});
lReadStream.pipe(lWriteStream);
}
else
main.sendError(pParams, p.data);
break;
default:
send(pParams);