filemanager: add basic cut/paste

This commit is contained in:
Johannes Zellner
2021-01-30 23:23:34 +01:00
parent bd4423c9c6
commit 77cb64369b
3 changed files with 59 additions and 5 deletions

View File

@@ -70,7 +70,9 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
$scope.rootDirLabel = '';
$scope.title = '';
$scope.entries = [];
$scope.selected = [];
$scope.selected = []; // holds selected entries
$scope.clipboard = []; // holds cut or copied entries
$scope.clipboardCut = false; // if action is cut or copy
$scope.dropToBody = false;
$scope.sortAsc = true;
$scope.sortProperty = 'fileName';
@@ -118,6 +120,10 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
return filePath;
}
$scope.isSelected = function (entry) {
return $scope.selected.indexOf(entry) !== -1;
};
$scope.extractStatus = {
error: null,
busy: false,
@@ -330,6 +336,43 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
}
};
$scope.actionCut = function () {
$scope.clipboard = $scope.selected.slice();
$scope.clipboard.forEach(function (entry) {
entry.fullFilePath = sanitize($scope.cwd + '/' + entry.fileName);
});
$scope.clipboardCut = true;
};
$scope.actionCopy = function () {
$scope.clipboard = $scope.selected.slice();
$scope.clipboard.forEach(function (entry) {
entry.fullFilePath = sanitize($scope.cwd + '/' + entry.fileName);
});
$scope.clipboardCut = false;
};
$scope.actionPaste = function () {
if ($scope.clipboardCut) {
// move files
async.eachLimit($scope.clipboard, 5, function (entry, callback) {
var newFilePath = sanitize($scope.cwd + '/' + entry.fileName);
// TODO this will overwrite files in destination!
Client.filesRename($scope.id, $scope.type, entry.fullFilePath, newFilePath, callback);
}, function (error) {
if (error) return Client.error(error);
// clear clipboard
$scope.clipboard = [];
$scope.refresh();
});
} else {
// copy files
}
};
$scope.goDirectoryUp = function () {
$scope.changeDirectory($scope.cwd + '/..');
};
@@ -819,7 +862,7 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
}
});
$translate(['filemanager.list.menu.edit', 'filemanager.list.menu.rename', 'filemanager.list.menu.chown', 'filemanager.list.menu.extract', 'filemanager.list.menu.download', 'filemanager.list.menu.delete' ]).then(function (tr) {
$translate(['filemanager.list.menu.edit', 'filemanager.list.menu.cut', 'filemanager.list.menu.copy', 'filemanager.list.menu.paste', 'filemanager.list.menu.rename', 'filemanager.list.menu.chown', 'filemanager.list.menu.extract', 'filemanager.list.menu.download', 'filemanager.list.menu.delete' ]).then(function (tr) {
$scope.menuOptions = [
{
text: tr['filemanager.list.menu.edit'],
@@ -827,6 +870,17 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl
enabled: function () { return $scope.selected.length === 1; },
hasBottomDivider: true,
click: function ($itemScope, $event, entry) { $scope.open(entry); }
}, {
text: tr['filemanager.list.menu.cut'],
click: function ($itemScope, $event, entry) { $scope.actionCut(); }
}, {
text: tr['filemanager.list.menu.copy'],
click: function ($itemScope, $event, entry) { $scope.actionCopy(); }
}, {
text: tr['filemanager.list.menu.paste'],
hasBottomDivider: true,
enabled: function () { return $scope.clipboard.length; },
click: function ($itemScope, $event, entry) { $scope.actionPaste(); }
}, {
text: tr['filemanager.list.menu.rename'],
enabled: function () { return $scope.selected.length === 1; },