Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2297)

Unified Diff: chrome/browser/resources/file_manager/foreground/js/photo/gallery.js

Issue 109973002: Migrate from URLs to Entries in the Files App's gallery. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/file_manager/foreground/js/photo/gallery.js
diff --git a/chrome/browser/resources/file_manager/foreground/js/photo/gallery.js b/chrome/browser/resources/file_manager/foreground/js/photo/gallery.js
index 0e225c666c966933d09706ac9b46e77aa7bfa5c0..6eb73c50cb50b75781aae1ca6d98f4b1b8c5234b 100644
--- a/chrome/browser/resources/file_manager/foreground/js/photo/gallery.js
+++ b/chrome/browser/resources/file_manager/foreground/js/photo/gallery.js
@@ -43,6 +43,7 @@ function Gallery(context, volumeManager) {
this.context_ = context;
this.metadataCache_ = context.metadataCache;
this.volumeManager_ = volumeManager;
+ this.selectedEntry_ = null;
this.dataModel_ = new cr.ui.ArrayDataModel([]);
this.selectionModel_ = new cr.ui.ListSelectionModel();
@@ -62,12 +63,12 @@ Gallery.prototype.__proto__ = cr.EventTarget.prototype;
*
* @param {Object} context Gallery context.
* @param {VolumeManagerWrapper} volumeManager VolumeManager of the system.
- * @param {Array.<string>} urls Array of urls.
- * @param {Array.<string>} selectedUrls Array of selected urls.
+ * @param {Array.<Entry>} entries Array of entries.
+ * @param {Array.<Entry>} selectedEntries Array of selected entries.
*/
-Gallery.open = function(context, volumeManager, urls, selectedUrls) {
+Gallery.open = function(context, volumeManager, entries, selectedEntries) {
Gallery.instance = new Gallery(context, volumeManager);
- Gallery.instance.load(urls, selectedUrls);
+ Gallery.instance.load(entries, selectedEntries);
};
/**
@@ -131,9 +132,11 @@ Gallery.prototype.initListeners_ = function() {
* @private
*/
Gallery.prototype.onExternallyUnmounted_ = function(event) {
- if (!this.selectedItemFilesystemPath_)
+ if (!this.selectedEntry_)
return;
- if (this.selectedItemFilesystemPath_.indexOf(event.mountPath) == 0)
+
+ if (this.selectedEntry_.filesystem.root.toURL() ===
hirono 2013/12/09 06:53:50 Could you compare volume info instead of root URL?
mtomasz 2013/12/10 02:37:34 Done.
+ event.volumeInfo.filesystem.root.toURL())
this.onBack_();
};
@@ -269,24 +272,24 @@ Gallery.prototype.createToolbarButton_ = function(className, title) {
/**
* Load the content.
*
- * @param {Array.<string>} urls Array of urls.
- * @param {Array.<string>} selectedUrls Array of selected urls.
+ * @param {Array.<Entry>} entries Array of entries.
+ * @param {Array.<Entry>} selectedEntries Array of selected entries.
*/
-Gallery.prototype.load = function(urls, selectedUrls) {
+Gallery.prototype.load = function(entries, selectedEntries) {
var items = [];
- for (var index = 0; index < urls.length; ++index) {
- items.push(new Gallery.Item(urls[index]));
+ for (var index = 0; index < entries.length; ++index) {
+ items.push(new Gallery.Item(entries[index]));
}
this.dataModel_.push.apply(this.dataModel_, items);
this.selectionModel_.adjustLength(this.dataModel_.length);
- for (var i = 0; i != selectedUrls.length; i++) {
- var selectedIndex = urls.indexOf(selectedUrls[i]);
+ for (var i = 0; i != selectedEntries.length; i++) {
hirono 2013/12/09 06:53:50 !== is preferred.
mtomasz 2013/12/10 02:37:34 Done.
+ var selectedIndex = entries.indexOf(selectedEntries[i]);
if (selectedIndex >= 0)
this.selectionModel_.setIndexSelected(selectedIndex, true);
else
- console.error('Cannot select ' + selectedUrls[i]);
+ console.error('Cannot select ' + selectedEntries[i]);
}
if (this.selectionModel_.selectedIndexes.length == 0)
@@ -296,16 +299,16 @@ Gallery.prototype.load = function(urls, selectedUrls) {
// Mosaic view should show up if most of the selected files are images.
var imagesCount = 0;
- for (var i = 0; i != selectedUrls.length; i++) {
- if (FileType.getMediaType(selectedUrls[i]) == 'image')
+ for (var i = 0; i != selectedEntries.length; i++) {
hirono 2013/12/09 06:53:50 ditto.
mtomasz 2013/12/10 02:37:34 Done.
+ if (FileType.getMediaType(selectedEntries[i]) == 'image')
hirono 2013/12/09 06:53:50 ditto.
mtomasz 2013/12/10 02:37:34 Done.
imagesCount++;
}
- var mostlyImages = imagesCount > (selectedUrls.length / 2.0);
+ var mostlyImages = imagesCount > (selectedEntries.length / 2.0);
var forcedMosaic = (this.context_.pageState &&
this.context_.pageState.gallery == 'mosaic');
- var showMosaic = (mostlyImages && selectedUrls.length > 1) || forcedMosaic;
+ var showMosaic = (mostlyImages && selectedEntries.length > 1) || forcedMosaic;
if (mosaic && showMosaic) {
this.setCurrentMode_(this.mosaicMode_);
mosaic.init();
@@ -337,7 +340,7 @@ Gallery.prototype.back_ = function() {
util.toggleFullScreen(this.context_.appWindow,
false); // Leave the full screen mode.
}
- this.context_.onBack(this.getSelectedUrls());
+ this.context_.onBack(this.getSelectedEntries());
};
/**
@@ -485,13 +488,10 @@ Gallery.prototype.delete_ = function() {
if (!itemsToRemove.length)
return; // All deleted.
- var url = itemsToRemove.pop().getUrl();
- webkitResolveLocalFileSystemURL(url,
- function(entry) {
- entry.remove(deleteNext,
- util.flog('Error deleting ' + url, deleteNext));
- },
- util.flog('Error resolving ' + url, deleteNext));
+ var entry = itemsToRemove.pop().getEntry();
+ entry.remove(deleteNext, function() {
hirono 2013/12/09 06:53:50 Could you add the TODO comment? TODO(hirono): Use
mtomasz 2013/12/10 02:37:34 Done.
+ util.flog('Error deleting: ' + entry.fullPath, deleteNext);
+ });
}
// Prevent the Gallery from handling Esc and Enter.
@@ -533,11 +533,11 @@ Gallery.prototype.getSelectedItems = function() {
};
/**
- * @return {Array.<string>} Array of currently selected urls.
+ * @return {Array.<Entry>} Array of currently selected entries.
*/
-Gallery.prototype.getSelectedUrls = function() {
+Gallery.prototype.getSelectedEntries = function() {
return this.selectionModel_.selectedIndexes.map(function(index) {
- return this.dataModel_.item(index).getUrl();
+ return this.dataModel_.item(index).getEntry();
}.bind(this));
};
@@ -634,10 +634,9 @@ Gallery.prototype.updateSelectionAndState_ = function() {
var selectedItems = this.getSelectedItems();
if (selectedItems.length == 1) {
var item = selectedItems[0];
- path = util.extractFilePath(item.getUrl());
- var fullName = item.getFileName();
- window.top.document.title = fullName;
- displayName = ImageUtil.getFileNameFromFullName(fullName);
+ var entry = item.getEntry();
+ window.top.document.title = entry.name;
+ displayName = ImageUtil.getDisplayNameFromName(entry.name);
} else if (selectedItems.length > 1 && this.context_.curDirEntry) {
// If the Gallery was opened on search results the search query will not be
// recorded in the app state and the relaunch will just open the gallery
@@ -664,14 +663,7 @@ Gallery.prototype.updateSelectionAndState_ = function() {
var selectedIndex = this.selectionModel_.selectedIndex;
var selectedItem =
this.dataModel_.item(this.selectionModel_.selectedIndex);
-
- this.selectedItemFilesystemPath_ = null;
- webkitResolveLocalFileSystemURL(selectedItem.getUrl(),
- function(entry) {
- if (this.selectionModel_.selectedIndex != selectedIndex)
- return;
- this.selectedItemFilesystemPath_ = entry.fullPath;
- }.bind(this));
+ this.selectedEntry_ = selectedItem.getEntry();
}
};
@@ -703,7 +695,7 @@ Gallery.prototype.onFilenameEditBlur_ = function(event) {
}
var item = this.getSingleSelectedItem();
- var oldUrl = item.getUrl();
+ var oldEntry = item.getEntry();
var onFileExists = function() {
this.prompt_.show('GALLERY_FILE_EXISTS', 3000);
@@ -714,7 +706,7 @@ Gallery.prototype.onFilenameEditBlur_ = function(event) {
var onSuccess = function() {
var e = new Event('content');
hirono 2013/12/09 06:53:50 Please replace e with event.
mtomasz 2013/12/10 02:37:34 Done.
e.item = item;
- e.oldUrl = oldUrl;
+ e.oldEntry = oldEntry;
e.metadata = null; // Metadata unchanged.
this.dataModel_.dispatchEvent(e);
}.bind(this);
@@ -797,7 +789,7 @@ Gallery.prototype.toggleShare_ = function() {
* @private.
*/
Gallery.prototype.updateShareMenu_ = function() {
- var urls = this.getSelectedUrls();
+ var entries = this.getSelectedEntries();
function isShareAction(task) {
var taskParts = task.taskId.split('|');
@@ -824,7 +816,7 @@ Gallery.prototype.updateShareMenu_ = function() {
item.style.backgroundImage = 'url(' + task.iconUrl + ')';
item.addEventListener('click', function(taskId) {
this.toggleShare_(); // Hide the menu.
- this.executeWhenReady(api.executeTask.bind(api, taskId, urls));
+ this.executeWhenReady(api.executeTask.bind(api, taskId, entries));
}.bind(this, task.taskId));
}
@@ -835,10 +827,11 @@ Gallery.prototype.updateShareMenu_ = function() {
// Create or update the share menu with a list of sharing tasks and show
// or hide the share button.
- if (!urls.length)
+ // TODO(mtomasz): Pass Entries directly, instead of URLs.
+ if (!entries.length)
createShareMenu([]); // Empty list of tasks, since there is no selection.
else
- api.getFileTasks(urls, mimeTypes, createShareMenu);
+ api.getFileTasks(util.entriesToURLs(entries), mimeTypes, createShareMenu);
};
/**

Powered by Google App Engine
This is Rietveld 408576698