OLD | NEW |
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 // 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 /** | 10 /** |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 | 489 |
490 this.copyManager_ = new FileCopyManager(); | 490 this.copyManager_ = new FileCopyManager(); |
491 this.copyManager_.addEventListener('copy-progress', | 491 this.copyManager_.addEventListener('copy-progress', |
492 this.onCopyProgress_.bind(this)); | 492 this.onCopyProgress_.bind(this)); |
493 | 493 |
494 window.addEventListener('popstate', this.onPopState_.bind(this)); | 494 window.addEventListener('popstate', this.onPopState_.bind(this)); |
495 window.addEventListener('unload', this.onUnload_.bind(this)); | 495 window.addEventListener('unload', this.onUnload_.bind(this)); |
496 | 496 |
497 this.directoryModel_.addEventListener('directory-changed', | 497 this.directoryModel_.addEventListener('directory-changed', |
498 this.onDirectoryChanged_.bind(this)); | 498 this.onDirectoryChanged_.bind(this)); |
| 499 this.directoryModel_.addEventListener('scan-started', |
| 500 this.showSpinner_.bind(this, true)); |
| 501 this.directoryModel_.addEventListener('scan-completed', |
| 502 this.showSpinner_.bind(this, false)); |
499 this.addEventListener('selection-summarized', | 503 this.addEventListener('selection-summarized', |
500 this.onSelectionSummarized_.bind(this)); | 504 this.onSelectionSummarized_.bind(this)); |
501 | 505 |
502 // The list of archives requested to mount. We will show contents once | 506 // The list of archives requested to mount. We will show contents once |
503 // archive is mounted, but only for mounts from within this filebrowser tab. | 507 // archive is mounted, but only for mounts from within this filebrowser tab. |
504 this.mountRequests_ = []; | 508 this.mountRequests_ = []; |
505 this.unmountRequests_ = []; | 509 this.unmountRequests_ = []; |
506 chrome.fileBrowserPrivate.onMountCompleted.addListener( | 510 chrome.fileBrowserPrivate.onMountCompleted.addListener( |
507 this.onMountCompleted_.bind(this)); | 511 this.onMountCompleted_.bind(this)); |
508 | 512 |
509 chrome.fileBrowserPrivate.onFileChanged.addListener( | 513 chrome.fileBrowserPrivate.onFileChanged.addListener( |
510 this.onFileChanged_.bind(this)); | 514 this.onFileChanged_.bind(this)); |
511 | 515 |
512 var self = this; | 516 var self = this; |
513 | 517 |
514 // The list of callbacks to be invoked during the directory rescan after | 518 // The list of callbacks to be invoked during the directory rescan after |
515 // all paste tasks are complete. | 519 // all paste tasks are complete. |
516 this.pasteSuccessCallbacks_ = []; | 520 this.pasteSuccessCallbacks_ = []; |
517 | 521 |
518 this.setupCurrentDirectory_(); | 522 this.setupCurrentDirectory_(); |
519 | 523 |
520 this.summarizeSelection_(); | 524 this.summarizeSelection_(); |
521 | 525 |
522 this.directoryModel_.fileList.sort('cachedMtime_', 'desc'); | 526 var sortField = 'cachedMtime_'; |
| 527 var sortDirection = 'desc'; |
| 528 if (FileManager.DialogType.isModal(this.dialogType_)) { |
| 529 sortField = |
| 530 window.localStorage['sort-field-' + this.dialogType_] || |
| 531 sortField; |
| 532 sortDirection = |
| 533 window.localStorage['sort-direction-' + this.dialogType_] || |
| 534 sortDirection; |
| 535 } |
| 536 this.directoryModel_.fileList.sort(sortField, sortDirection); |
523 | 537 |
524 this.refocus(); | 538 this.refocus(); |
525 | 539 |
526 this.createMetadataProvider_(); | 540 this.createMetadataProvider_(); |
527 | 541 |
528 this.table_.list.endBatchUpdates(); | 542 this.table_.list.endBatchUpdates(); |
529 this.grid_.endBatchUpdates(); | 543 this.grid_.endBatchUpdates(); |
530 | 544 |
531 metrics.recordInterval('Load.DOM'); | 545 metrics.recordInterval('Load.DOM'); |
532 metrics.recordInterval('Load.Total'); | 546 metrics.recordInterval('Load.Total'); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 this.previewPanel_ = this.dialogDom_.querySelector('.preview-panel'); | 587 this.previewPanel_ = this.dialogDom_.querySelector('.preview-panel'); |
574 this.previewFilename_ = this.dialogDom_.querySelector('.preview-filename'); | 588 this.previewFilename_ = this.dialogDom_.querySelector('.preview-filename'); |
575 this.previewSummary_ = this.dialogDom_.querySelector('.preview-summary'); | 589 this.previewSummary_ = this.dialogDom_.querySelector('.preview-summary'); |
576 this.filenameInput_ = this.dialogDom_.querySelector('.filename-input'); | 590 this.filenameInput_ = this.dialogDom_.querySelector('.filename-input'); |
577 this.taskItems_ = this.dialogDom_.querySelector('.tasks'); | 591 this.taskItems_ = this.dialogDom_.querySelector('.tasks'); |
578 this.okButton_ = this.dialogDom_.querySelector('.ok'); | 592 this.okButton_ = this.dialogDom_.querySelector('.ok'); |
579 this.cancelButton_ = this.dialogDom_.querySelector('.cancel'); | 593 this.cancelButton_ = this.dialogDom_.querySelector('.cancel'); |
580 this.deleteButton_ = this.dialogDom_.querySelector('.delete-button'); | 594 this.deleteButton_ = this.dialogDom_.querySelector('.delete-button'); |
581 this.table_ = this.dialogDom_.querySelector('.detail-table'); | 595 this.table_ = this.dialogDom_.querySelector('.detail-table'); |
582 this.grid_ = this.dialogDom_.querySelector('.thumbnail-grid'); | 596 this.grid_ = this.dialogDom_.querySelector('.thumbnail-grid'); |
| 597 this.spinner_ = this.dialogDom_.querySelector('.spinner'); |
| 598 this.showSpinner_(false); |
583 | 599 |
584 cr.ui.Table.decorate(this.table_); | 600 cr.ui.Table.decorate(this.table_); |
585 cr.ui.Grid.decorate(this.grid_); | 601 cr.ui.Grid.decorate(this.grid_); |
586 | 602 |
587 this.downloadsWarning_ = | 603 this.downloadsWarning_ = |
588 this.dialogDom_.querySelector('.downloads-warning'); | 604 this.dialogDom_.querySelector('.downloads-warning'); |
589 var html = util.htmlUnescape(str('DOWNLOADS_DIRECTORY_WARNING')); | 605 var html = util.htmlUnescape(str('DOWNLOADS_DIRECTORY_WARNING')); |
590 this.downloadsWarning_.lastElementChild.innerHTML = html; | 606 this.downloadsWarning_.lastElementChild.innerHTML = html; |
591 var link = this.downloadsWarning_.querySelector('a'); | 607 var link = this.downloadsWarning_.querySelector('a'); |
592 link.addEventListener('click', this.onDownloadsWarningClick_.bind(this)); | 608 link.addEventListener('click', this.onDownloadsWarningClick_.bind(this)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 }); | 682 }); |
667 dataModel.setCompareFunction('cachedMtime_', | 683 dataModel.setCompareFunction('cachedMtime_', |
668 this.compareMtime_.bind(this)); | 684 this.compareMtime_.bind(this)); |
669 dataModel.setCompareFunction('cachedSize_', | 685 dataModel.setCompareFunction('cachedSize_', |
670 this.compareSize_.bind(this)); | 686 this.compareSize_.bind(this)); |
671 dataModel.setCompareFunction('type', | 687 dataModel.setCompareFunction('type', |
672 this.compareType_.bind(this)); | 688 this.compareType_.bind(this)); |
673 | 689 |
674 dataModel.addEventListener('splice', | 690 dataModel.addEventListener('splice', |
675 this.onDataModelSplice_.bind(this)); | 691 this.onDataModelSplice_.bind(this)); |
| 692 dataModel.addEventListener('permuted', |
| 693 this.onDataModelPermuted_.bind(this)); |
676 | 694 |
677 this.directoryModel_.fileListSelection.addEventListener( | 695 this.directoryModel_.fileListSelection.addEventListener( |
678 'change', this.onSelectionChanged_.bind(this)); | 696 'change', this.onSelectionChanged_.bind(this)); |
679 | 697 |
680 this.directoryModel_.autoSelectIndex = | 698 this.directoryModel_.autoSelectIndex = |
681 this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE ? -1 : 0; | 699 this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE ? -1 : 0; |
682 | 700 |
683 // TODO(serya): temporary solution. | 701 // TODO(serya): temporary solution. |
684 this.directoryModel_.cacheEntryDate = cacheEntryDate; | 702 this.directoryModel_.cacheEntryDate = cacheEntryDate; |
685 this.directoryModel_.cacheEntrySize = cacheEntrySize; | 703 this.directoryModel_.cacheEntrySize = cacheEntrySize; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 if (successCallback) | 808 if (successCallback) |
791 setTimeout(function() { successCallback(entry) }, 0); | 809 setTimeout(function() { successCallback(entry) }, 0); |
792 }; | 810 }; |
793 | 811 |
794 FileManager.prototype.onDataModelSplice_ = function(event) { | 812 FileManager.prototype.onDataModelSplice_ = function(event) { |
795 var checkbox = this.document_.querySelector('#select-all-checkbox'); | 813 var checkbox = this.document_.querySelector('#select-all-checkbox'); |
796 if (checkbox) | 814 if (checkbox) |
797 this.updateSelectAllCheckboxState_(checkbox); | 815 this.updateSelectAllCheckboxState_(checkbox); |
798 }; | 816 }; |
799 | 817 |
| 818 FileManager.prototype.onDataModelPermuted_ = function(event) { |
| 819 if (FileManager.DialogType.isModal(this.dialogType_)) { |
| 820 var sortStatus = this.directoryModel_.fileList.sortStatus; |
| 821 window.localStorage['sort-field-' + this.dialogType_] = sortStatus.field; |
| 822 window.localStorage['sort-direction-' + this.dialogType_] = |
| 823 sortStatus.direction; |
| 824 } |
| 825 }; |
| 826 |
800 /** | 827 /** |
801 * Get the file type of the entry, caching the result. | 828 * Get the file type of the entry, caching the result. |
802 * | 829 * |
803 * When this method completes, the entry object will get a | 830 * When this method completes, the entry object will get a |
804 * 'cachedIconType_' property (if it doesn't already have one) containing the | 831 * 'cachedIconType_' property (if it doesn't already have one) containing the |
805 * icon type of the file as a string. | 832 * icon type of the file as a string. |
806 * | 833 * |
807 * @param {Entry} entry An HTML5 Entry object. | 834 * @param {Entry} entry An HTML5 Entry object. |
808 * @param {function(Entry)} successCallback The function to invoke once the | 835 * @param {function(Entry)} successCallback The function to invoke once the |
809 * file size is known. | 836 * file size is known. |
(...skipping 2320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3130 FileManager.prototype.onToggleSidebar_ = function(event) { | 3157 FileManager.prototype.onToggleSidebar_ = function(event) { |
3131 if (this.dialogContainer_.hasAttribute('sidebar')) { | 3158 if (this.dialogContainer_.hasAttribute('sidebar')) { |
3132 this.dialogContainer_.removeAttribute('sidebar'); | 3159 this.dialogContainer_.removeAttribute('sidebar'); |
3133 } else { | 3160 } else { |
3134 this.dialogContainer_.setAttribute('sidebar', 'sidebar'); | 3161 this.dialogContainer_.setAttribute('sidebar', 'sidebar'); |
3135 } | 3162 } |
3136 // TODO(dgozman): make table header css-resizable. | 3163 // TODO(dgozman): make table header css-resizable. |
3137 setTimeout(this.onResize_.bind(this), 300); | 3164 setTimeout(this.onResize_.bind(this), 300); |
3138 }; | 3165 }; |
3139 | 3166 |
| 3167 FileManager.prototype.showSpinner_ = function(on) { |
| 3168 this.spinner_.style.display = on ? '' : 'none'; |
| 3169 }; |
| 3170 |
3140 FileManager.prototype.onNewFolderCommand_ = function(event) { | 3171 FileManager.prototype.onNewFolderCommand_ = function(event) { |
3141 var self = this; | 3172 var self = this; |
3142 | 3173 |
3143 function onNameSelected(name) { | 3174 function onNameSelected(name) { |
3144 var valid = self.validateFileName_(name, function() { | 3175 var valid = self.validateFileName_(name, function() { |
3145 promptForName(name); | 3176 promptForName(name); |
3146 }); | 3177 }); |
3147 | 3178 |
3148 if (!valid) { | 3179 if (!valid) { |
3149 // Validation failed. User will be prompted for a new name after they | 3180 // Validation failed. User will be prompted for a new name after they |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3562 }); | 3593 }); |
3563 }, onError); | 3594 }, onError); |
3564 | 3595 |
3565 function onError(err) { | 3596 function onError(err) { |
3566 console.log('Error while checking free space: ' + err); | 3597 console.log('Error while checking free space: ' + err); |
3567 setTimeout(doCheck, 1000 * 60); | 3598 setTimeout(doCheck, 1000 * 60); |
3568 } | 3599 } |
3569 } | 3600 } |
3570 } | 3601 } |
3571 })(); | 3602 })(); |
OLD | NEW |