Merge pull request #26941 from nextcloud/enh/register-multiselect-fileactions

Allow apps to register a file action for multiselect
This commit is contained in:
Roeland Jago Douma 2021-05-12 10:53:58 +02:00 committed by GitHub
commit 6c741724fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 4 deletions

View File

@ -97,17 +97,20 @@
name: 'copyMove', name: 'copyMove',
displayName: t('files', 'Move or copy'), displayName: t('files', 'Move or copy'),
iconClass: 'icon-external', iconClass: 'icon-external',
order: 10,
}, },
{ {
name: 'download', name: 'download',
displayName: t('files', 'Download'), displayName: t('files', 'Download'),
iconClass: 'icon-download', iconClass: 'icon-download',
order: 10,
}, },
OCA.Files.FileList.MultiSelectMenuActions.ToggleSelectionModeAction, OCA.Files.FileList.MultiSelectMenuActions.ToggleSelectionModeAction,
{ {
name: 'delete', name: 'delete',
displayName: t('files', 'Delete'), displayName: t('files', 'Delete'),
iconClass: 'icon-delete', iconClass: 'icon-delete',
order: 99,
}, },
], ],
sorting: { sorting: {

View File

@ -330,9 +330,7 @@
this.multiSelectMenuItems[i] = this.multiSelectMenuItems[i](this); this.multiSelectMenuItems[i] = this.multiSelectMenuItems[i](this);
} }
} }
this.fileMultiSelectMenu = new OCA.Files.FileMultiSelectMenu(this.multiSelectMenuItems); this._updateMultiSelectFileActions()
this.fileMultiSelectMenu.render();
this.$el.find('.selectedActions').append(this.fileMultiSelectMenu.$el);
} }
if (options.sorting) { if (options.sorting) {
@ -516,7 +514,7 @@
multiSelectMenuClick: function (ev, action) { multiSelectMenuClick: function (ev, action) {
var actionFunction = _.find(this.multiSelectMenuItems, function (item) {return item.name === action;}).action; var actionFunction = _.find(this.multiSelectMenuItems, function (item) {return item.name === action;}).action;
if (actionFunction) { if (actionFunction) {
actionFunction(ev); actionFunction(this.getSelectedFiles());
return; return;
} }
switch (action) { 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. * Sets the files to be displayed in the list.
* This operation will re-render the list and update the summary. * This operation will re-render the list and update the summary.
@ -3785,6 +3809,7 @@
return t('files', 'Select file range'); return t('files', 'Select file range');
}, },
iconClass: 'icon-fullscreen', iconClass: 'icon-fullscreen',
order: 15,
action: function() { action: function() {
fileList._onClickToggleSelectionMode(); fileList._onClickToggleSelectionMode();
}, },