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

Unified Diff: chrome/browser/resources/file_manager/js/file_manager.js

Issue 7635029: File Manager: sort by date by default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add missing ) Created 9 years, 4 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/file_manager/js/file_manager.js
diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js
index 17b99392f888811f1fbb696dea462d4f7aae68d7..90cc03365f8f7edb72719a9c1963799410da1c2c 100644
--- a/chrome/browser/resources/file_manager/js/file_manager.js
+++ b/chrome/browser/resources/file_manager/js/file_manager.js
@@ -640,7 +640,11 @@ FileManager.prototype = {
this.dataModel_.setCompareFunction('name', function(a, b) {
return collator.compare(a.name, b.name);
});
- this.dataModel_.sort('name');
+ this.dataModel_.setCompareFunction('cachedMtime_',
+ this.compareMtime_.bind(this));
+ this.dataModel_.setCompareFunction('cachedSize_',
+ this.compareSize_.bind(this));
+ this.dataModel_.sort('cachedMtime_');
this.dataModel_.prepareSort = this.prepareSort_.bind(this);
if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE ||
@@ -662,6 +666,32 @@ FileManager.prototype = {
this.textSearchState_ = {text: '', date: new Date()};
};
+ /**
+ * Compare by mtime first, then by name.
+ */
+ FileManager.prototype.compareMtime_ = function(a, b) {
+ if (a.cachedMtime_ > b.cachedMtime)
+ return 1;
+
+ if (a.cachedMtime_ < b.cachedMtime)
+ return -1;
+
+ return this.collator_.compare(a.name, b.name);
+ };
+
+ /**
+ * Compare by size first, then by name.
+ */
+ FileManager.prototype.compareSize_ = function(a, b) {
+ if (a.cachedSize_ > b.cachedSize)
+ return 1;
+
+ if (a.cachedSize_ < b.cachedSize)
+ return -1;
+
+ return this.collator_.compare(a.name, b.name);
+ };
+
FileManager.prototype.refocus = function() {
this.document_.querySelector('[tabindex="0"]').focus();
};
@@ -1215,7 +1245,9 @@ FileManager.prototype = {
FileManager.prototype.prepareSort_ = function(field, callback) {
var cacheFunction;
- if (field == 'cachedMtime_') {
+ if (field == 'name' || field == 'cachedMtime_') {
+ // Mtime is the tie-breaker for a name sort, so we need to resolve
+ // it for both mtime and name sorts.
cacheFunction = cacheEntryDate;
} else if (field == 'cachedSize_') {
cacheFunction = cacheEntrySize;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698