Commit 2e601bd0 authored by Isabella Scalzi's avatar Isabella Scalzi Committed by Commit Bot

[quickview] Add |canDelete| property to |files-quick-view|

In preparation for adding a delete button to the Quick View toolbar add
property |canDelete| to |files-quick-view|, which indicates whether the
file shown can be deleted or not.

In a future CL, |shouldShowDeleteButton_| will then toggle the display
of the delete button in Quick View.

Test: Tests coming in future CL.
Bug: 803259
Change-Id: I880fd7f2065c11435a16ec923abca12277b0c824
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2040502
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739221}
parent be47c44f
......@@ -14,6 +14,12 @@ const FilesQuickView = Polymer({
// True if there is a file task that can open the file type.
hasTask: Boolean,
/**
* True if the entry shown in Quick View can be deleted.
* @type {boolean}
*/
canDelete: Boolean,
// URLs should be accessible from the <webview> since their content is
// rendered inside the <wevbiew>. Hint: use URL.createObjectURL.
contentUrl: String,
......@@ -75,6 +81,7 @@ const FilesQuickView = Polymer({
subtype: '',
filePath: '',
hasTask: false,
canDelete: false,
contentUrl: '',
videoPoster: '',
audioArtwork: '',
......@@ -148,6 +155,17 @@ const FilesQuickView = Polymer({
return hasTask && !isModal;
},
/**
* @param {boolean} canDelete
* @param {boolean} isModal
* @return {boolean}
*
* @private
*/
shouldShowDeleteButton_: function(canDelete, isModal) {
return canDelete && !isModal;
},
/**
* @param {!Event} event tap event.
*
......
......@@ -1047,6 +1047,20 @@ CommandHandler.COMMANDS_['delete'] = new class extends Command {
CommandUtil.hasCapability(entries, 'canDelete');
}
/**
* Returns True if entries can be deleted.
* @param {!Array<!Entry>} entries
* @param {!CommandHandlerDeps} fileManager
* @return {!Promise<!boolean>}
* @public
*/
canDeleteEntries(entries, fileManager) {
// Question: Now that we use this as a public method, in canDeleteEntries_
// should we now check for the condition
// !entries.every(CommandUtil.shouldShowMenuItemsForEntry?
return Promise.resolve(this.canDeleteEntries_(entries, fileManager));
}
/**
* Returns true if any entry belongs to a read-only volume or is
* forced to be read-only like MyFiles>Downloads.
......
......@@ -381,12 +381,15 @@ class QuickViewController {
return Promise
.all([
this.metadataModel_.get([entry], ['thumbnailUrl']),
this.taskController_.getEntryFileTasks(entry)
this.taskController_.getEntryFileTasks(entry),
CommandHandler.getCommand('delete').canDeleteEntries(
[entry], this.fileManager_)
])
.then(values => {
const items = (/**@type{Array<MetadataItem>}*/ (values[0]));
const tasks = (/**@type{!FileTasks}*/ (values[1]));
return this.onMetadataLoaded_(entry, items, tasks);
const canDelete = ((values[2]));
return this.onMetadataLoaded_(entry, items, tasks, canDelete);
})
.catch(error => {
if (error) {
......@@ -404,12 +407,19 @@ class QuickViewController {
* @param {!FileEntry} entry
* @param {Array<MetadataItem>} items
* @param {!FileTasks} fileTasks
* @param {boolean} canDelete
* @private
*/
onMetadataLoaded_(entry, items, fileTasks) {
onMetadataLoaded_(entry, items, fileTasks, canDelete) {
// Question: Now that canDelete is in the typedef of QuickViewParams,
// closure will complain unless I add canDelete to the params object
// that is returned by getQuickViewParameters. This means that I am passing
// canDelete into getQuickViewParameters_ unnecessarily. Is this okay, or
// is there another way to make it so that this does not happen?
const tasks = fileTasks.getTaskItems();
return this.getQuickViewParameters_(entry, items, tasks).then(params => {
return this.getQuickViewParameters_(entry, items, tasks, canDelete)
.then(params => {
if (this.quickViewModel_.getSelectedEntry() != entry) {
return; // Bail: there's no point drawing a stale selection.
}
......@@ -419,6 +429,7 @@ class QuickViewController {
subtype: params.subtype || '',
filePath: params.filePath || '',
hasTask: params.hasTask || false,
canDelete: params.canDelete || false,
contentUrl: params.contentUrl || '',
videoPoster: params.videoPoster || '',
audioArtwork: params.audioArtwork || '',
......@@ -436,11 +447,12 @@ class QuickViewController {
* @param {!FileEntry} entry
* @param {Array<MetadataItem>} items
* @param {!Array<!chrome.fileManagerPrivate.FileTask>} tasks
* @param {boolean} canDelete
* @return !Promise<!QuickViewParams>
*
* @private
*/
getQuickViewParameters_(entry, items, tasks) {
getQuickViewParameters_(entry, items, tasks, canDelete) {
const item = items[0];
const typeInfo = FileType.getType(entry);
const type = typeInfo.type;
......@@ -453,6 +465,7 @@ class QuickViewController {
subtype: typeInfo.subtype,
filePath: label,
hasTask: tasks.length > 0,
canDelete: canDelete,
};
const volumeInfo = this.volumeManager_.getVolumeInfo(entry);
......@@ -639,6 +652,7 @@ QuickViewController.UNSUPPORTED_IMAGE_SUBTYPES_ = [
* subtype: string,
* filePath: string,
* hasTask: boolean,
* canDelete: boolean,
* contentUrl: (string|undefined),
* videoPoster: (string|undefined),
* audioArtwork: (string|undefined),
......
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