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({ ...@@ -14,6 +14,12 @@ const FilesQuickView = Polymer({
// True if there is a file task that can open the file type. // True if there is a file task that can open the file type.
hasTask: Boolean, 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 // URLs should be accessible from the <webview> since their content is
// rendered inside the <wevbiew>. Hint: use URL.createObjectURL. // rendered inside the <wevbiew>. Hint: use URL.createObjectURL.
contentUrl: String, contentUrl: String,
...@@ -75,6 +81,7 @@ const FilesQuickView = Polymer({ ...@@ -75,6 +81,7 @@ const FilesQuickView = Polymer({
subtype: '', subtype: '',
filePath: '', filePath: '',
hasTask: false, hasTask: false,
canDelete: false,
contentUrl: '', contentUrl: '',
videoPoster: '', videoPoster: '',
audioArtwork: '', audioArtwork: '',
...@@ -148,6 +155,17 @@ const FilesQuickView = Polymer({ ...@@ -148,6 +155,17 @@ const FilesQuickView = Polymer({
return hasTask && !isModal; return hasTask && !isModal;
}, },
/**
* @param {boolean} canDelete
* @param {boolean} isModal
* @return {boolean}
*
* @private
*/
shouldShowDeleteButton_: function(canDelete, isModal) {
return canDelete && !isModal;
},
/** /**
* @param {!Event} event tap event. * @param {!Event} event tap event.
* *
......
...@@ -1047,6 +1047,20 @@ CommandHandler.COMMANDS_['delete'] = new class extends Command { ...@@ -1047,6 +1047,20 @@ CommandHandler.COMMANDS_['delete'] = new class extends Command {
CommandUtil.hasCapability(entries, 'canDelete'); 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 * Returns true if any entry belongs to a read-only volume or is
* forced to be read-only like MyFiles>Downloads. * forced to be read-only like MyFiles>Downloads.
......
...@@ -381,12 +381,15 @@ class QuickViewController { ...@@ -381,12 +381,15 @@ class QuickViewController {
return Promise return Promise
.all([ .all([
this.metadataModel_.get([entry], ['thumbnailUrl']), this.metadataModel_.get([entry], ['thumbnailUrl']),
this.taskController_.getEntryFileTasks(entry) this.taskController_.getEntryFileTasks(entry),
CommandHandler.getCommand('delete').canDeleteEntries(
[entry], this.fileManager_)
]) ])
.then(values => { .then(values => {
const items = (/**@type{Array<MetadataItem>}*/ (values[0])); const items = (/**@type{Array<MetadataItem>}*/ (values[0]));
const tasks = (/**@type{!FileTasks}*/ (values[1])); 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 => { .catch(error => {
if (error) { if (error) {
...@@ -404,43 +407,52 @@ class QuickViewController { ...@@ -404,43 +407,52 @@ class QuickViewController {
* @param {!FileEntry} entry * @param {!FileEntry} entry
* @param {Array<MetadataItem>} items * @param {Array<MetadataItem>} items
* @param {!FileTasks} fileTasks * @param {!FileTasks} fileTasks
* @param {boolean} canDelete
* @private * @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(); const tasks = fileTasks.getTaskItems();
return this.getQuickViewParameters_(entry, items, tasks).then(params => { return this.getQuickViewParameters_(entry, items, tasks, canDelete)
if (this.quickViewModel_.getSelectedEntry() != entry) { .then(params => {
return; // Bail: there's no point drawing a stale selection. if (this.quickViewModel_.getSelectedEntry() != entry) {
} return; // Bail: there's no point drawing a stale selection.
}
this.quickView_.setProperties({ this.quickView_.setProperties({
type: params.type || '', type: params.type || '',
subtype: params.subtype || '', subtype: params.subtype || '',
filePath: params.filePath || '', filePath: params.filePath || '',
hasTask: params.hasTask || false, hasTask: params.hasTask || false,
contentUrl: params.contentUrl || '', canDelete: params.canDelete || false,
videoPoster: params.videoPoster || '', contentUrl: params.contentUrl || '',
audioArtwork: params.audioArtwork || '', videoPoster: params.videoPoster || '',
autoplay: params.autoplay || false, audioArtwork: params.audioArtwork || '',
browsable: params.browsable || false, autoplay: params.autoplay || false,
}); browsable: params.browsable || false,
});
if (params.hasTask) { if (params.hasTask) {
this.tasks_ = fileTasks; this.tasks_ = fileTasks;
} }
}); });
} }
/** /**
* @param {!FileEntry} entry * @param {!FileEntry} entry
* @param {Array<MetadataItem>} items * @param {Array<MetadataItem>} items
* @param {!Array<!chrome.fileManagerPrivate.FileTask>} tasks * @param {!Array<!chrome.fileManagerPrivate.FileTask>} tasks
* @param {boolean} canDelete
* @return !Promise<!QuickViewParams> * @return !Promise<!QuickViewParams>
* *
* @private * @private
*/ */
getQuickViewParameters_(entry, items, tasks) { getQuickViewParameters_(entry, items, tasks, canDelete) {
const item = items[0]; const item = items[0];
const typeInfo = FileType.getType(entry); const typeInfo = FileType.getType(entry);
const type = typeInfo.type; const type = typeInfo.type;
...@@ -453,6 +465,7 @@ class QuickViewController { ...@@ -453,6 +465,7 @@ class QuickViewController {
subtype: typeInfo.subtype, subtype: typeInfo.subtype,
filePath: label, filePath: label,
hasTask: tasks.length > 0, hasTask: tasks.length > 0,
canDelete: canDelete,
}; };
const volumeInfo = this.volumeManager_.getVolumeInfo(entry); const volumeInfo = this.volumeManager_.getVolumeInfo(entry);
...@@ -639,6 +652,7 @@ QuickViewController.UNSUPPORTED_IMAGE_SUBTYPES_ = [ ...@@ -639,6 +652,7 @@ QuickViewController.UNSUPPORTED_IMAGE_SUBTYPES_ = [
* subtype: string, * subtype: string,
* filePath: string, * filePath: string,
* hasTask: boolean, * hasTask: boolean,
* canDelete: boolean,
* contentUrl: (string|undefined), * contentUrl: (string|undefined),
* videoPoster: (string|undefined), * videoPoster: (string|undefined),
* audioArtwork: (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