Index: ui/file_manager/gallery/js/gallery.js |
diff --git a/ui/file_manager/gallery/js/gallery.js b/ui/file_manager/gallery/js/gallery.js |
index 07891d48310e035c381ec49ede81b90dabd3a62b..fd85ae155ce62d325662199c8bb25cd0f68f9e0b 100644 |
--- a/ui/file_manager/gallery/js/gallery.js |
+++ b/ui/file_manager/gallery/js/gallery.js |
@@ -54,6 +54,7 @@ function Gallery(volumeManager) { |
this.selectedEntry_ = null; |
this.metadataCacheObserverId_ = null; |
this.onExternallyUnmountedBound_ = this.onExternallyUnmounted_.bind(this); |
+ this.initialized_ = false; |
this.dataModel_ = new GalleryDataModel( |
this.context_.metadataCache); |
@@ -340,6 +341,11 @@ Gallery.prototype.loadInternal_ = function(entries, selectedEntries) { |
return a.index - b.index; |
}); |
+ if (loadingList.length === 0) { |
+ this.dataModel_.splice(0, this.dataModel_.length); |
+ return; |
+ } |
+ |
// Load entries. |
// Use the self variable capture-by-closure because it is faster than bind. |
var self = this; |
@@ -359,6 +365,14 @@ Gallery.prototype.loadInternal_ = function(entries, selectedEntries) { |
if (chunk.length !== metadataList.length) |
return Promise.reject('Failed to load metadata.'); |
+ // Remove all the previous items if it's the first chunk. |
+ // Do it here because prevent a flicker between removing all the items |
+ // and adding new ones. |
+ if (firstChunk) { |
+ self.dataModel_.splice(0, self.dataModel_.length); |
+ self.updateThumbnails_(); // Remove the caches. |
+ } |
+ |
// Add items to the model. |
var items = []; |
chunk.forEach(function(chunkItem, index) { |
@@ -390,7 +404,7 @@ Gallery.prototype.loadInternal_ = function(entries, selectedEntries) { |
self.onSelection_(); |
// Init modes after the first chunk is loaded. |
- if (firstChunk) { |
+ if (firstChunk && !self.initialized_) { |
// Determine the initial mode. |
var shouldShowMosaic = selectedEntries.length > 1 || |
(self.context_.pageState && |
@@ -418,6 +432,7 @@ Gallery.prototype.loadInternal_ = function(entries, selectedEntries) { |
cr.dispatchSimpleEvent(self, 'loaded'); |
}); |
} |
+ self.initialized_ = true; |
} |
// Continue to load chunks. |
@@ -908,6 +923,17 @@ Gallery.prototype.debugMe = function() { |
var gallery = null; |
/** |
+ * (Re-)loads entries. |
+ */ |
+function reload() { |
+ initializePromise.then(function() { |
+ util.URLsToEntries(window.appState.urls, function(entries) { |
+ gallery.load(entries); |
+ }); |
+ }); |
+} |
+ |
+/** |
* Promise to initialize the load time data. |
* @type {!Promise} |
*/ |
@@ -937,27 +963,17 @@ var initializePromise = |
Promise.all([loadTimeDataPromise, volumeManagerPromise]). |
then(function(args) { |
var volumeManager = args[1]; |
- var gallery = new Gallery(volumeManager); |
- return gallery; |
+ gallery = new Gallery(volumeManager); |
}); |
// Loads entries. |
-initializePromise.then( |
- /** |
- * Loads entries. |
- * @param {!Gallery} gallery The gallery instance. |
- */ |
- function(gallery) { |
- util.URLsToEntries(window.appState.urls, function(entries) { |
- gallery.load(entries); |
- }); |
- }); |
+initializePromise.then(reload); |
/** |
* Enteres the debug mode. |
*/ |
window.debugMe = function() { |
- initializePromise.then(function(gallery) { |
+ initializePromise.then(function() { |
gallery.debugMe(); |
}); |
}; |