OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Setting the src of an img to an empty string can crash the browser, so we | 5 // Setting the src of an img to an empty string can crash the browser, so we |
6 // use an empty 1x1 gif instead. | 6 // use an empty 1x1 gif instead. |
7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' | 7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' |
8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; | 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; |
9 | 9 |
10 var g_slideshow_data = null; | 10 var g_slideshow_data = null; |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 // Always sharing the data model between the detail/thumb views confuses | 633 // Always sharing the data model between the detail/thumb views confuses |
634 // them. Instead we maintain this bogus data model, and hook it up to the | 634 // them. Instead we maintain this bogus data model, and hook it up to the |
635 // view that is not in use. | 635 // view that is not in use. |
636 this.emptyDataModel_ = new cr.ui.ArrayDataModel([]); | 636 this.emptyDataModel_ = new cr.ui.ArrayDataModel([]); |
637 | 637 |
638 this.dataModel_ = new cr.ui.ArrayDataModel([]); | 638 this.dataModel_ = new cr.ui.ArrayDataModel([]); |
639 var collator = this.collator_; | 639 var collator = this.collator_; |
640 this.dataModel_.setCompareFunction('name', function(a, b) { | 640 this.dataModel_.setCompareFunction('name', function(a, b) { |
641 return collator.compare(a.name, b.name); | 641 return collator.compare(a.name, b.name); |
642 }); | 642 }); |
643 this.dataModel_.sort('name'); | 643 this.dataModel_.setCompareFunction('cachedMtime_', |
| 644 this.compareMtime_.bind(this)); |
| 645 this.dataModel_.setCompareFunction('cachedSize_', |
| 646 this.compareSize_.bind(this)); |
| 647 this.dataModel_.sort('cachedMtime_'); |
644 this.dataModel_.prepareSort = this.prepareSort_.bind(this); | 648 this.dataModel_.prepareSort = this.prepareSort_.bind(this); |
645 | 649 |
646 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE || | 650 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE || |
647 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FOLDER || | 651 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FOLDER || |
648 this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { | 652 this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { |
649 this.selectionModelClass_ = cr.ui.ListSingleSelectionModel; | 653 this.selectionModelClass_ = cr.ui.ListSingleSelectionModel; |
650 } else { | 654 } else { |
651 this.selectionModelClass_ = cr.ui.ListSelectionModel; | 655 this.selectionModelClass_ = cr.ui.ListSelectionModel; |
652 } | 656 } |
653 | 657 |
654 this.initTable_(); | 658 this.initTable_(); |
655 this.initGrid_(); | 659 this.initGrid_(); |
656 | 660 |
657 this.setListType(FileManager.ListType.DETAIL); | 661 this.setListType(FileManager.ListType.DETAIL); |
658 | 662 |
659 this.onResize_(); | 663 this.onResize_(); |
660 this.dialogDom_.style.opacity = '1'; | 664 this.dialogDom_.style.opacity = '1'; |
661 | 665 |
662 this.textSearchState_ = {text: '', date: new Date()}; | 666 this.textSearchState_ = {text: '', date: new Date()}; |
663 }; | 667 }; |
664 | 668 |
| 669 /** |
| 670 * Compare by mtime first, then by name. |
| 671 */ |
| 672 FileManager.prototype.compareMtime_ = function(a, b) { |
| 673 if (a.cachedMtime_ > b.cachedMtime) |
| 674 return 1; |
| 675 |
| 676 if (a.cachedMtime_ < b.cachedMtime) |
| 677 return -1; |
| 678 |
| 679 return this.collator_.compare(a.name, b.name); |
| 680 }; |
| 681 |
| 682 /** |
| 683 * Compare by size first, then by name. |
| 684 */ |
| 685 FileManager.prototype.compareSize_ = function(a, b) { |
| 686 if (a.cachedSize_ > b.cachedSize) |
| 687 return 1; |
| 688 |
| 689 if (a.cachedSize_ < b.cachedSize) |
| 690 return -1; |
| 691 |
| 692 return this.collator_.compare(a.name, b.name); |
| 693 }; |
| 694 |
665 FileManager.prototype.refocus = function() { | 695 FileManager.prototype.refocus = function() { |
666 this.document_.querySelector('[tabindex="0"]').focus(); | 696 this.document_.querySelector('[tabindex="0"]').focus(); |
667 }; | 697 }; |
668 | 698 |
669 FileManager.prototype.showButter = function(message, opt_options) { | 699 FileManager.prototype.showButter = function(message, opt_options) { |
670 var butter = this.document_.createElement('div'); | 700 var butter = this.document_.createElement('div'); |
671 butter.className = 'butter-bar'; | 701 butter.className = 'butter-bar'; |
672 butter.style.top = '-30px'; | 702 butter.style.top = '-30px'; |
673 this.dialogDom_.appendChild(butter); | 703 this.dialogDom_.appendChild(butter); |
674 | 704 |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 | 1238 |
1209 /** | 1239 /** |
1210 * Cache necessary data before a sort happens. | 1240 * Cache necessary data before a sort happens. |
1211 * | 1241 * |
1212 * This is called by the table code before a sort happens, so that we can | 1242 * This is called by the table code before a sort happens, so that we can |
1213 * go fetch data for the sort field that we may not have yet. | 1243 * go fetch data for the sort field that we may not have yet. |
1214 */ | 1244 */ |
1215 FileManager.prototype.prepareSort_ = function(field, callback) { | 1245 FileManager.prototype.prepareSort_ = function(field, callback) { |
1216 var cacheFunction; | 1246 var cacheFunction; |
1217 | 1247 |
1218 if (field == 'cachedMtime_') { | 1248 if (field == 'name' || field == 'cachedMtime_') { |
| 1249 // Mtime is the tie-breaker for a name sort, so we need to resolve |
| 1250 // it for both mtime and name sorts. |
1219 cacheFunction = cacheEntryDate; | 1251 cacheFunction = cacheEntryDate; |
1220 } else if (field == 'cachedSize_') { | 1252 } else if (field == 'cachedSize_') { |
1221 cacheFunction = cacheEntrySize; | 1253 cacheFunction = cacheEntrySize; |
1222 } else if (field == 'cachedIconType_') { | 1254 } else if (field == 'cachedIconType_') { |
1223 cacheFunction = cacheEntryIconType; | 1255 cacheFunction = cacheEntryIconType; |
1224 } else { | 1256 } else { |
1225 callback(); | 1257 callback(); |
1226 return; | 1258 return; |
1227 } | 1259 } |
1228 | 1260 |
(...skipping 1841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3070 | 3102 |
3071 if (msg) { | 3103 if (msg) { |
3072 console.log('no no no'); | 3104 console.log('no no no'); |
3073 this.alert.show(msg, onAccept); | 3105 this.alert.show(msg, onAccept); |
3074 return false; | 3106 return false; |
3075 } | 3107 } |
3076 | 3108 |
3077 return true; | 3109 return true; |
3078 }; | 3110 }; |
3079 })(); | 3111 })(); |
OLD | NEW |