From 96515d7338006a99b853c899708d7f6667bd43fd Mon Sep 17 00:00:00 2001 From: Julius Härtl Date: Tue, 11 May 2021 10:10:10 +0200 Subject: Allow apps to register a file action for multiselect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/files/js/app.js | 3 +++ apps/files/js/filelist.js | 33 +++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/apps/files/js/app.js b/apps/files/js/app.js index 8015f395b74..1a7049832ca 100644 --- a/apps/files/js/app.js +++ b/apps/files/js/app.js @@ -97,17 +97,20 @@ name: 'copyMove', displayName: t('files', 'Move or copy'), iconClass: 'icon-external', + order: 10, }, { name: 'download', displayName: t('files', 'Download'), iconClass: 'icon-download', + order: 10, }, OCA.Files.FileList.MultiSelectMenuActions.ToggleSelectionModeAction, { name: 'delete', displayName: t('files', 'Delete'), iconClass: 'icon-delete', + order: 99, }, ], sorting: { diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 11d0bc4511d..b981785db40 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -330,9 +330,7 @@ this.multiSelectMenuItems[i] = this.multiSelectMenuItems[i](this); } } - this.fileMultiSelectMenu = new OCA.Files.FileMultiSelectMenu(this.multiSelectMenuItems); - this.fileMultiSelectMenu.render(); - this.$el.find('.selectedActions').append(this.fileMultiSelectMenu.$el); + this._updateMultiSelectFileActions() } if (options.sorting) { @@ -516,7 +514,7 @@ multiSelectMenuClick: function (ev, action) { var actionFunction = _.find(this.multiSelectMenuItems, function (item) {return item.name === action;}).action; if (actionFunction) { - actionFunction(ev); + actionFunction(this.getSelectedFiles()); return; } switch (action) { @@ -1368,6 +1366,32 @@ }, + /** + * Register action for multiple selected files + * + * @param {OCA.Files.FileAction} fileAction object + * The callback of FileAction will be called with an array of files that are currently selected + */ + registerMultiSelectFileAction: function(fileAction) { + if (typeof this.multiSelectMenuItems === 'undefined') { + return; + } + this.multiSelectMenuItems.push(fileAction) + this._updateMultiSelectFileActions() + }, + + _updateMultiSelectFileActions: function() { + if (typeof this.multiSelectMenuItems === 'undefined') { + return; + } + this.fileMultiSelectMenu = new OCA.Files.FileMultiSelectMenu(this.multiSelectMenuItems.sort(function(a, b) { + return a.order > b.order + })); + this.fileMultiSelectMenu.render(); + this.$el.find('.selectedActions .filesSelectMenu').remove(); + this.$el.find('.selectedActions').append(this.fileMultiSelectMenu.$el); + }, + /** * Sets the files to be displayed in the list. * This operation will re-render the list and update the summary. @@ -3785,6 +3809,7 @@ return t('files', 'Select file range'); }, iconClass: 'icon-fullscreen', + order: 15, action: function() { fileList._onClickToggleSelectionMode(); }, -- cgit v1.2.3