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

Side by Side Diff: ui/file_manager/file_manager/foreground/js/directory_contents.js

Issue 419173002: Files.app: Make the sort for the search result stable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/file_manager/file_manager/foreground/js/file_manager.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * Scanner of the entries. 8 * Scanner of the entries.
9 * @constructor 9 * @constructor
10 */ 10 */
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 */ 394 */
395 FileFilter.prototype.filter = function(entry) { 395 FileFilter.prototype.filter = function(entry) {
396 for (var name in this.filters_) { 396 for (var name in this.filters_) {
397 if (!this.filters_[name](entry)) 397 if (!this.filters_[name](entry))
398 return false; 398 return false;
399 } 399 }
400 return true; 400 return true;
401 }; 401 };
402 402
403 /** 403 /**
404 * File list.
405 * @param {MetadataCache} metadataCache Metadata cache.
406 * @constructor
407 * @extends {cr.ui.ArrayDataModel}
408 */
409 function FileListModel(metadataCache) {
410 cr.ui.ArrayDataModel.call(this, []);
411
412 /**
413 * Metadata cache.
414 * @type {MetadataCache}
415 */
416 this.metadataCache_ = metadataCache;
417
418 /**
419 * Collator for sorting.
420 * @type {Intl.Collator}
421 */
422 this.collator_ = new Intl.Collator([], {numeric: true, sensitivity: 'base'});
423
424 // Initialize compare functions.
425 this.setCompareFunction('name', this.compareName_.bind(this));
426 this.setCompareFunction('modificationTime', this.compareMtime_.bind(this));
427 this.setCompareFunction('size', this.compareSize_.bind(this));
428 this.setCompareFunction('type', this.compareType_.bind(this));
429 }
430
431 FileListModel.prototype = {
432 __proto__: cr.ui.ArrayDataModel.prototype
433 };
434
435 /**
436 * Compare by mtime first, then by name.
437 * @param {Entry} a First entry.
438 * @param {Entry} b Second entry.
439 * @return {number} Compare result.
440 * @private
441 */
442 FileListModel.prototype.compareName_ = function(a, b) {
443 var result = this.collator_.compare(a.name, b.name);
444 return result !== 0 ? result : a.toURL().localeCompare(b.toURL());
445 };
446
447 /**
448 * Compare by mtime first, then by name.
449 * @param {Entry} a First entry.
450 * @param {Entry} b Second entry.
451 * @return {number} Compare result.
452 * @private
453 */
454 FileListModel.prototype.compareMtime_ = function(a, b) {
455 var aCachedFilesystem = this.metadataCache_.getCached(a, 'filesystem');
456 var aTime = aCachedFilesystem ? aCachedFilesystem.modificationTime : 0;
457
458 var bCachedFilesystem = this.metadataCache_.getCached(b, 'filesystem');
459 var bTime = bCachedFilesystem ? bCachedFilesystem.modificationTime : 0;
460
461 if (aTime > bTime)
462 return 1;
463
464 if (aTime < bTime)
465 return -1;
466
467 return this.compareName_(a, b);
468 };
469
470 /**
471 * Compare by size first, then by name.
472 * @param {Entry} a First entry.
473 * @param {Entry} b Second entry.
474 * @return {number} Compare result.
475 * @private
476 */
477 FileListModel.prototype.compareSize_ = function(a, b) {
478 var aCachedFilesystem = this.metadataCache_.getCached(a, 'filesystem');
479 var aSize = aCachedFilesystem ? aCachedFilesystem.size : 0;
480
481 var bCachedFilesystem = this.metadataCache_.getCached(b, 'filesystem');
482 var bSize = bCachedFilesystem ? bCachedFilesystem.size : 0;
483
484 return aSize !== bSize ? aSize - bSize : this.compareName_(a, b);
485 };
486
487 /**
488 * Compare by type first, then by subtype and then by name.
489 * @param {Entry} a First entry.
490 * @param {Entry} b Second entry.
491 * @return {number} Compare result.
492 * @private
493 */
494 FileListModel.prototype.compareType_ = function(a, b) {
495 // Directories precede files.
496 if (a.isDirectory !== b.isDirectory)
497 return Number(b.isDirectory) - Number(a.isDirectory);
498
499 var aType = FileType.typeToString(FileType.getType(a));
500 var bType = FileType.typeToString(FileType.getType(b));
501
502 var result = this.collator_.compare(aType, bType);
503 return result !== 0 ? result : this.compareName_(a, b);
504 };
505
506 /**
404 * A context of DirectoryContents. 507 * A context of DirectoryContents.
405 * TODO(yoshiki): remove this. crbug.com/224869. 508 * TODO(yoshiki): remove this. crbug.com/224869.
406 * 509 *
407 * @param {FileFilter} fileFilter The file-filter context. 510 * @param {FileFilter} fileFilter The file-filter context.
408 * @param {MetadataCache} metadataCache Metadata cache service. 511 * @param {MetadataCache} metadataCache Metadata cache service.
409 * @constructor 512 * @constructor
410 */ 513 */
411 function FileListContext(fileFilter, metadataCache) { 514 function FileListContext(fileFilter, metadataCache) {
412 /** 515 /**
413 * @type {cr.ui.ArrayDataModel} 516 * @type {FileListModel}
414 */ 517 */
415 this.fileList = new cr.ui.ArrayDataModel([]); 518 this.fileList = new FileListModel(metadataCache);
416 519
417 /** 520 /**
418 * @type {MetadataCache} 521 * @type {MetadataCache}
419 */ 522 */
420 this.metadataCache = metadataCache; 523 this.metadataCache = metadataCache;
421 524
422 /** 525 /**
423 * @type {FileFilter} 526 * @type {FileFilter}
424 */ 527 */
425 this.fileFilter = fileFilter; 528 this.fileFilter = fileFilter;
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 DirectoryContents.createForDriveMetadataSearch = function( 908 DirectoryContents.createForDriveMetadataSearch = function(
806 context, fakeDirectoryEntry, searchType) { 909 context, fakeDirectoryEntry, searchType) {
807 return new DirectoryContents( 910 return new DirectoryContents(
808 context, 911 context,
809 true, // Search 912 true, // Search
810 fakeDirectoryEntry, 913 fakeDirectoryEntry,
811 function() { 914 function() {
812 return new DriveMetadataSearchContentScanner(searchType); 915 return new DriveMetadataSearchContentScanner(searchType);
813 }); 916 });
814 }; 917 };
OLDNEW
« no previous file with comments | « no previous file | ui/file_manager/file_manager/foreground/js/file_manager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698