From 047a4a3ab415d6c5f604fc16c856e57237b09b16 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 7 Jan 2019 10:25:13 +0100 Subject: [PATCH] Copy files to a shared folder instead of moving them --- www/common/proxy-manager.js | 13 +++++++++++-- www/drive/inner.js | 21 ++++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index f69340766..8bc59e48f 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -281,6 +281,10 @@ define([ var resolved = _resolvePaths(Env, data.paths); var newResolved = _resolvePath(Env, data.newPath); + // NOTE: we can only copy when moving from one drive to another. We don't want + // duplicates in the same drive + var copy = data.copy; + if (!newResolved.userObject.isFolder(newResolved.path)) { return void cb(); } nThen(function (waitFor) { @@ -305,6 +309,8 @@ define([ Array.prototype.push.apply(ownedPads, _owned); }); + if (copy) { return; } + if (resolved.main.length) { var rootPath = resolved.main[0].slice(); rootPath.pop(); @@ -338,6 +344,8 @@ define([ uoTo.copyFromOtherDrive(newResolved.path, obj.el, obj.data, obj.key); }); + if (copy) { return; } + // Remove the elements from the old location (without unpinning) uoFrom.delete(paths, waitFor()); } @@ -791,12 +799,13 @@ define([ } }, cb); }; - var moveInner = function (Env, paths, newPath, cb) { + var moveInner = function (Env, paths, newPath, cb, copy) { return void Env.sframeChan.query("Q_DRIVE_USEROBJECT", { cmd: "move", data: { paths: paths, - newPath: newPath + newPath: newPath, + copy: copy } }, cb); }; diff --git a/www/drive/inner.js b/www/drive/inner.js index 58067e6d9..03f0950b0 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -1208,18 +1208,14 @@ define([ } return manager.getTitle(file); }; - // manager.moveElements is able to move several paths to a new location, including - // the Trash or the "Unsorted files" folder - var moveElements = function (paths, newPath, force, cb) { + // moveElements is able to move several paths to a new location + var moveElements = function (paths, newPath, copy, cb) { if (!APP.editable) { return; } - var andThenMove = function () { - manager.move(paths, newPath, cb); - }; // Cancel drag&drop from TRASH to TRASH if (manager.isPathIn(newPath, [TRASH]) && paths.length && paths[0][0] === TRASH) { return; } - andThenMove(); + manager.move(paths, newPath, cb, copy); }; // Delete paths from the drive and/or shared folders (without moving them to the trash) var deletePaths = function (paths, pathsList) { @@ -1228,6 +1224,10 @@ define([ paths.forEach(function (p) { pathsList.push(p.path); }); } var hasOwned = pathsList.some(function (p) { + // NOTE: Owned pads in shared folders won't be removed from the server + // so we don't have to check, we can use the default message + if (manager.isInSharedFolder(p)) { return false; } + var el = manager.find(p); var data = manager.isSharedFolder(el) ? manager.getSharedFolderData(el) : manager.getFileData(el); @@ -1310,7 +1310,7 @@ define([ $('.cp-app-drive-element-droppable').removeClass('cp-app-drive-element-droppable'); var data = ev.dataTransfer.getData("text"); - // Don't the the normal drop handler for file upload + // Don't use the normal drop handler for file upload var fileDrop = ev.dataTransfer.files; if (fileDrop.length) { return void onFileDrop(fileDrop, ev); } @@ -1333,6 +1333,7 @@ define([ return void deletePaths(null, movedPaths); } + var copy = false; if (manager.isPathIn(newPath, [TRASH])) { // Filter the selection to remove shared folders. // Shared folders can't be moved to the trash! @@ -1347,10 +1348,12 @@ define([ } movedPaths = filteredPaths; + } else if (ev.ctrlKey || (ev.metaKey && APP.isMac)) { + copy = true; } if (movedPaths && movedPaths.length) { - moveElements(movedPaths, newPath, null, refresh); + moveElements(movedPaths, newPath, copy, refresh); } };