summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authoryoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-15 16:34:38 +0000
committeryoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-15 16:34:38 +0000
commitbb2a1c5bbb92d88e7542ca8937f4440da7b4e0b6 (patch)
tree026a6a15dd6f1e08f48cad7ba6c22d764a94c8ae /ui
parent524aa7da6af1a9fa4d4eadae5caa2b7b71ac8c0a (diff)
downloadchromium_src-bb2a1c5bbb92d88e7542ca8937f4440da7b4e0b6.zip
chromium_src-bb2a1c5bbb92d88e7542ca8937f4440da7b4e0b6.tar.gz
chromium_src-bb2a1c5bbb92d88e7542ca8937f4440da7b4e0b6.tar.bz2
Files.app: Not use URL in sorting
In URL, some non-alphanumeric characters are represented as "%xx" format and it makes the sort incorrect. This patch creates the utility functions to sort and use them in sorting. BUG=404061 TEST=manually tested Review URL: https://codereview.chromium.org/479503002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289914 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/file_manager/file_manager/common/js/util.js28
-rw-r--r--ui/file_manager/file_manager/foreground/js/directory_contents.js28
-rw-r--r--ui/file_manager/file_manager/foreground/js/directory_tree.js5
-rw-r--r--ui/file_manager/file_manager/foreground/js/folder_shortcuts_data_model.js5
4 files changed, 36 insertions, 30 deletions
diff --git a/ui/file_manager/file_manager/common/js/util.js b/ui/file_manager/file_manager/common/js/util.js
index 78a952a..25af534 100644
--- a/ui/file_manager/file_manager/common/js/util.js
+++ b/ui/file_manager/file_manager/common/js/util.js
@@ -1006,6 +1006,34 @@ util.isSameFileSystem = function(fileSystem1, fileSystem2) {
};
/**
+ * Collator for sorting.
+ * @type {Intl.Collator}
+ */
+util.collator = new Intl.Collator([], {usage: 'sort',
+ numeric: true,
+ sensitivity: 'base'});
+
+/**
+ * Compare by name. The 2 entries must be in same directory.
+ * @param {Entry} entry1 First entry.
+ * @param {Entry} entry2 Second entry.
+ * @return {number} Compare result.
+ */
+util.compareName = function(entry1, entry2) {
+ return util.collator.compare(entry1.name, entry2.name);
+};
+
+/**
+ * Compare by path.
+ * @param {Entry} entry1 First entry.
+ * @param {Entry} entry2 Second entry.
+ * @return {number} Compare result.
+ */
+util.comparePath = function(entry1, entry2) {
+ return util.collator.compare(entry1.fullPath, entry2.fullPath);
+};
+
+/**
* Checks if the child entry is a descendant of another entry. If the entries
* point to the same file or directory, then returns false.
*
diff --git a/ui/file_manager/file_manager/foreground/js/directory_contents.js b/ui/file_manager/file_manager/foreground/js/directory_contents.js
index b40d1ec..10ca762 100644
--- a/ui/file_manager/file_manager/foreground/js/directory_contents.js
+++ b/ui/file_manager/file_manager/foreground/js/directory_contents.js
@@ -415,14 +415,8 @@ function FileListModel(metadataCache) {
*/
this.metadataCache_ = metadataCache;
- /**
- * Collator for sorting.
- * @type {Intl.Collator}
- */
- this.collator_ = new Intl.Collator([], {numeric: true, sensitivity: 'base'});
-
// Initialize compare functions.
- this.setCompareFunction('name', this.compareName_.bind(this));
+ this.setCompareFunction('name', util.compareName);
this.setCompareFunction('modificationTime', this.compareMtime_.bind(this));
this.setCompareFunction('size', this.compareSize_.bind(this));
this.setCompareFunction('type', this.compareType_.bind(this));
@@ -439,18 +433,6 @@ FileListModel.prototype = {
* @return {number} Compare result.
* @private
*/
-FileListModel.prototype.compareName_ = function(a, b) {
- var result = this.collator_.compare(a.name, b.name);
- return result !== 0 ? result : a.toURL().localeCompare(b.toURL());
-};
-
-/**
- * Compare by mtime first, then by name.
- * @param {Entry} a First entry.
- * @param {Entry} b Second entry.
- * @return {number} Compare result.
- * @private
- */
FileListModel.prototype.compareMtime_ = function(a, b) {
var aCachedFilesystem = this.metadataCache_.getCached(a, 'filesystem');
var aTime = aCachedFilesystem ? aCachedFilesystem.modificationTime : 0;
@@ -464,7 +446,7 @@ FileListModel.prototype.compareMtime_ = function(a, b) {
if (aTime < bTime)
return -1;
- return this.compareName_(a, b);
+ return util.compareName(a, b);
};
/**
@@ -481,7 +463,7 @@ FileListModel.prototype.compareSize_ = function(a, b) {
var bCachedFilesystem = this.metadataCache_.getCached(b, 'filesystem');
var bSize = bCachedFilesystem ? bCachedFilesystem.size : 0;
- return aSize !== bSize ? aSize - bSize : this.compareName_(a, b);
+ return aSize !== bSize ? aSize - bSize : util.compareName(a, b);
};
/**
@@ -499,8 +481,8 @@ FileListModel.prototype.compareType_ = function(a, b) {
var aType = FileType.typeToString(FileType.getType(a));
var bType = FileType.typeToString(FileType.getType(b));
- var result = this.collator_.compare(aType, bType);
- return result !== 0 ? result : this.compareName_(a, b);
+ var result = util.collator.compare(aType, bType);
+ return result !== 0 ? result : util.compareName(a, b);
};
/**
diff --git a/ui/file_manager/file_manager/foreground/js/directory_tree.js b/ui/file_manager/file_manager/foreground/js/directory_tree.js
index 8fe829e..6c48f2a 100644
--- a/ui/file_manager/file_manager/foreground/js/directory_tree.js
+++ b/ui/file_manager/file_manager/foreground/js/directory_tree.js
@@ -279,9 +279,7 @@ DirectoryItem.prototype.updateSubDirectories = function(
}
var sortEntries = function(fileFilter, entries) {
- entries.sort(function(a, b) {
- return (a.name.toLowerCase() > b.name.toLowerCase()) ? 1 : -1;
- });
+ entries.sort(util.compareName);
return entries.filter(fileFilter.filter.bind(fileFilter));
};
@@ -514,6 +512,7 @@ VolumeItem.prototype.updateSubDirectories = function(recursive) {
for (var key in this.volumeInfo.fakeEntries)
entries.push(this.volumeInfo.fakeEntries[key]);
}
+ // This list is sorted by URL on purpose.
entries.sort(function(a, b) { return a.toURL() < b.toURL(); });
for (var i = 0; i < entries.length; i++) {
diff --git a/ui/file_manager/file_manager/foreground/js/folder_shortcuts_data_model.js b/ui/file_manager/file_manager/foreground/js/folder_shortcuts_data_model.js
index acf55f5..2e88232 100644
--- a/ui/file_manager/file_manager/foreground/js/folder_shortcuts_data_model.js
+++ b/ui/file_manager/file_manager/foreground/js/folder_shortcuts_data_model.js
@@ -275,10 +275,7 @@ FolderShortcutsDataModel.prototype = {
* Otherwise, returns 1.
*/
compare: function(a, b) {
- return a.toURL().localeCompare(
- b.toURL(),
- undefined, // locale parameter, use default locale.
- {usage: 'sort', numeric: true});
+ return util.comparePath(a, b);
},
/**