Commit e28c3b78 authored by Rachel Sugrono's avatar Rachel Sugrono Committed by Commit Bot

[quickview] Break the delete command handler into subroutines

Add subroutines to compose the Delete command handler, so the it is
easy for some special clients to access these subroutines, e.g. the
QuickView dialog.

Add an optional dialog argument to the deleteEntries_() subroutine.
The default argument is null which shows the default delete
confirm dialog, so no change in behavior.

For Quick View, the delete confirm dialog is provided by Quick View
when calling this helper.

No change in behavior, no new tests.

Bug: 803259
Change-Id: I4b2fe2d7cfd35a3c602bf7aa0b869b11a51bb691
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2026827Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Noel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736246}
parent cb1b403b
......@@ -963,23 +963,7 @@ CommandHandler.COMMANDS_['drive-sync-settings'] = new class extends Command {
CommandHandler.COMMANDS_['delete'] = new class extends Command {
execute(event, fileManager) {
const entries = CommandUtil.getCommandEntries(fileManager, event.target);
// Execute might be called without a call of canExecute method,
// e.g. called directly from code. Double check here not to delete
// undeletable entries.
if (!entries.every(CommandUtil.shouldShowMenuItemsForEntry.bind(
null, fileManager.volumeManager)) ||
this.containsReadOnlyEntry_(entries, fileManager)) {
return;
}
const message = entries.length === 1 ?
strf('GALLERY_CONFIRM_DELETE_ONE', entries[0].name) :
strf('GALLERY_CONFIRM_DELETE_SOME', entries.length);
fileManager.ui.deleteConfirmDialog.show(message, () => {
fileManager.fileOperationManager.deleteEntries(entries);
}, null, null);
this.deleteEntries_(entries, fileManager);
}
/** @override */
......@@ -994,10 +978,7 @@ CommandHandler.COMMANDS_['delete'] = new class extends Command {
return;
}
event.canExecute = entries.length > 0 &&
!this.containsReadOnlyEntry_(entries, fileManager) &&
!fileManager.directoryModel.isReadOnly() &&
CommandUtil.hasCapability(entries, 'canDelete');
event.canExecute = this.canDeleteEntries_(entries, fileManager);
// Hide if there isn't anything selected, meaning user clicked in an empty
// space in the file list.
......@@ -1005,6 +986,47 @@ CommandHandler.COMMANDS_['delete'] = new class extends Command {
event.command.setHidden(noEntries);
}
/**
* Delete the entries with an optional delete confirm dialog.
* @param {!Array<!Entry>} entries
* @param {!CommandHandlerDeps} fileManager
* @param {?FilesConfirmDialog} dialog An optional delete confirm dialog.
*/
deleteEntries_(entries, fileManager, dialog = null) {
// deleteEntries_ might be called without a call of canDeleteEntries_
// method, e.g. called directly from code. Double check here not to delete
// undeletable entries.
if (!entries.every(CommandUtil.shouldShowMenuItemsForEntry.bind(
null, fileManager.volumeManager)) ||
this.containsReadOnlyEntry_(entries, fileManager)) {
return;
}
const message = entries.length === 1 ?
strf('GALLERY_CONFIRM_DELETE_ONE', entries[0].name) :
strf('GALLERY_CONFIRM_DELETE_SOME', entries.length);
if (!dialog) {
dialog = fileManager.ui.deleteConfirmDialog;
}
dialog.show(message, () => {
fileManager.fileOperationManager.deleteEntries(entries);
}, null, null);
}
/**
* Checks if the entries are deletable.
* @param {!Array<!Entry>} entries
* @param {!CommandHandlerDeps} fileManager
*/
canDeleteEntries_(entries, fileManager) {
return entries.length > 0 &&
!this.containsReadOnlyEntry_(entries, fileManager) &&
!fileManager.directoryModel.isReadOnly() &&
CommandUtil.hasCapability(entries, 'canDelete');
}
/**
* Returns True if any entry belongs to a read-only volume or is
* forced to be read-only like MyFiles>Downloads.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment