From 2bb20f9c80416c5ea5cbc3c3f8451a25f167af41 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 5 Mar 2013 15:38:04 -0500 Subject: [PATCH] added ability to move files --- ChangeLog | 2 ++ lib/client.js | 11 ++++----- lib/client/dom.js | 50 ++++++++++++++++++++++++++++++++++++---- lib/client/keyBinding.js | 8 ++++++- lib/client/menu.js | 2 +- 5 files changed, 60 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index d510c959..55c9b020 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,8 @@ and get them out to file system. * Fixed bug with multiple click events on f3 and f4 buttons. +* Added ability to move files. + 2012.03.01, Version 0.1.9 diff --git a/lib/client.js b/lib/client.js index 75fdb130..e678e0d3 100644 --- a/lib/client.js +++ b/lib/client.js @@ -123,11 +123,8 @@ CloudCmd._editFileName = function(pParent){ * backs */ DOM.addOneTimeListener('click', function(){ - var lA = DOM.getCurrentLink(pParent); - if (lA && lA.textContent !== '..') - lA.contentEditable = false; - - KeyBinding && KeyBinding.set(); + //lA.contentEditable = false; + //KeyBinding && KeyBinding.set(); }); } }; @@ -282,11 +279,11 @@ function initKeysPanel(pCallBack){ lFuncs =[ null, null, /* f1 */ - DOM.renameCurrentFile, /* f2 */ + DOM.renameCurrent, /* f2 */ CloudCmd.Viewer, /* f3 */ CloudCmd.Editor, /* f4 */ null, /* f5 */ - null, /* f6 */ + DOM.moveCurrent, /* f6 */ DOM.promptNewFolder, /* f7 */ DOM.promptDeleteCurrent,/* f8 */ ]; diff --git a/lib/client/dom.js b/lib/client/dom.js index d4b98424..87430d0d 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -931,6 +931,20 @@ var CloudCommander, Util, return lRet; }; + /** + * get current direcotory path + */ + DOM.getNotCurrentDirPath = function(){ + var lPanel = DOM.getPanel(true), + lPath = DOM.getByClass('path', lPanel)[0], + lRet; + + if(lPath) + lRet = lPath.textContent; + + return lRet; + }; + /** * unified way to get current file * @@ -1171,7 +1185,7 @@ var CloudCommander, Util, return lRet; }; - /** + /** * get link from current (or param) file * * @param pCurrentFile - current file by default @@ -1180,7 +1194,7 @@ var CloudCommander, Util, var lCurrent = pCurrentFile || DOM.getCurrentFile(), lPath = DOM.getCurrentLink( lCurrent ).href; - lPath = decodeURI(lPath); + lPath = decodeURI(lPath); /* убираем адрес хоста*/ lPath = Util.removeStr( lPath, [CloudCommander.HOST, CloudFunc.FS] ); @@ -1387,14 +1401,15 @@ var CloudCommander, Util, * * @pCurrent */ - DOM.renameCurrentFile = function(pCurrentFile){ + DOM.renameCurrent = function(pCurrentFile){ if( !DOM.isCurrentFile(pCurrentFile) ) pCurrentFile = null; var lCurrent = pCurrentFile || DOM.getCurrentFile(), lFrom = DOM.getCurrentName(lCurrent), - lTo = prompt("Rename", lFrom) || lFrom, + lTo = prompt('Rename', lFrom) || lFrom, lDirPath = DOM.getCurrentDirPath(); + if( !Util.strCmp(lFrom, lTo) ){ var lFiles = { from : lDirPath + lFrom, @@ -1407,6 +1422,33 @@ var CloudCommander, Util, } }; + /** + * move current file + * + * @pCurrent + */ + DOM.moveCurrent = 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( 'Rename/Move file "' + lName + '"', lToPath ); + + if( lTo && !Util.strCmp(lFromPath, lToPath) ){ + var lFiles = { + from : lFromPath, + to : lToPath + }; + + DOM.RESTfull.mv(lFiles, function(){ + CloudCommander.refresh(); + }); + } + }; + /** * unified way to scrollIntoViewIfNeeded * (native suporte by webkit only) diff --git a/lib/client/keyBinding.js b/lib/client/keyBinding.js index 3b1504b8..783d697e 100644 --- a/lib/client/keyBinding.js +++ b/lib/client/keyBinding.js @@ -34,6 +34,8 @@ var CloudCommander, Util, DOM; F2 : 113, F3 : 114, F4 : 115, + + F6 : 117, F7 : 118, F10 : 121, @@ -127,7 +129,7 @@ var CloudCommander, Util, DOM; break; case KEY.F2: - DOM.renameCurrentFile(lCurrentFile); + DOM.renameCurrent(lCurrentFile); break; case KEY.F3: @@ -143,6 +145,10 @@ var CloudCommander, Util, DOM; DOM.preventDefault(pEvent); break; + case KEY.F6: + DOM.moveCurrent(); + break; + case KEY.F7: DOM.promptNewFolder(); break; diff --git a/lib/client/menu.js b/lib/client/menu.js index b622a5e1..4744f25a 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -156,7 +156,7 @@ var CloudCommander, Util, DOM, CloudFunc, $; 'View' : Util.retExec(showEditor, true), 'Edit' : Util.retExec(showEditor, false), 'Rename' : function(){ - setTimeout( Util.retExec(DOM.renameCurrentFile), 100); + setTimeout( Util.retExec(DOM.renameCurrent), 100); }, 'Delete' : Util.retExec(DOM.promptDeleteCurrent) };