| 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * FileManager constructor. | 8 * FileManager constructor. |
| 9 * | 9 * |
| 10 * FileManager objects encapsulate the functionality of the file selector | 10 * FileManager objects encapsulate the functionality of the file selector |
| (...skipping 2604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2615 input.selectionStart = 0; | 2615 input.selectionStart = 0; |
| 2616 input.selectionEnd = selectionEnd; | 2616 input.selectionEnd = selectionEnd; |
| 2617 } | 2617 } |
| 2618 }, 0); | 2618 }, 0); |
| 2619 }; | 2619 }; |
| 2620 | 2620 |
| 2621 /** | 2621 /** |
| 2622 * @private | 2622 * @private |
| 2623 */ | 2623 */ |
| 2624 FileManager.prototype.onScanStarted_ = function() { | 2624 FileManager.prototype.onScanStarted_ = function() { |
| 2625 if (this.scanInProgress_ && !this.scanUpdatedAtLeastOnceOrCompleted_) { | 2625 if (this.scanInProgress_) { |
| 2626 this.table_.list.endBatchUpdates(); | 2626 this.table_.list.endBatchUpdates(); |
| 2627 this.grid_.endBatchUpdates(); | 2627 this.grid_.endBatchUpdates(); |
| 2628 } | 2628 } |
| 2629 | 2629 |
| 2630 this.updateCommands(); | 2630 this.updateCommands(); |
| 2631 this.table_.list.startBatchUpdates(); | 2631 this.table_.list.startBatchUpdates(); |
| 2632 this.grid_.startBatchUpdates(); | 2632 this.grid_.startBatchUpdates(); |
| 2633 this.scanInProgress_ = true; | 2633 this.scanInProgress_ = true; |
| 2634 | 2634 |
| 2635 this.scanUpdatedAtLeastOnceOrCompleted_ = false; | 2635 this.scanUpdatedAtLeastOnceOrCompleted_ = false; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2656 FileManager.prototype.onScanCompleted_ = function() { | 2656 FileManager.prototype.onScanCompleted_ = function() { |
| 2657 if (!this.scanInProgress_) { | 2657 if (!this.scanInProgress_) { |
| 2658 console.error('Scan-completed event recieved. But scan is not started.'); | 2658 console.error('Scan-completed event recieved. But scan is not started.'); |
| 2659 return; | 2659 return; |
| 2660 } | 2660 } |
| 2661 | 2661 |
| 2662 this.updateCommands(); | 2662 this.updateCommands(); |
| 2663 this.hideSpinnerLater_(); | 2663 this.hideSpinnerLater_(); |
| 2664 this.refreshCurrentDirectoryMetadata_(); | 2664 this.refreshCurrentDirectoryMetadata_(); |
| 2665 | 2665 |
| 2666 if (this.scanUpdatedTimer_) { |
| 2667 clearTimeout(this.scanUpdatedTimer_); |
| 2668 this.scanUpdatedTimer_ = null; |
| 2669 } |
| 2670 |
| 2666 // To avoid flickering postpone updating the ui by a small amount of time. | 2671 // To avoid flickering postpone updating the ui by a small amount of time. |
| 2667 // There is a high chance, that metadata will be received within 50 ms. | 2672 // There is a high chance, that metadata will be received within 50 ms. |
| 2668 this.scanCompletedTimer_ = setTimeout(function() { | 2673 this.scanCompletedTimer_ = setTimeout(function() { |
| 2669 // Check if batch updates are already finished by onScanUpdated_(). | 2674 // Check if batch updates are already finished by onScanUpdated_(). |
| 2670 if (this.scanUpdatedAtLeastOnceOrCompleted_) | 2675 if (!this.scanUpdatedAtLeastOnceOrCompleted_) { |
| 2671 return; | 2676 this.scanUpdatedAtLeastOnceOrCompleted_ = true; |
| 2672 this.scanUpdatedAtLeastOnceOrCompleted_ = true; | 2677 this.updateMiddleBarVisibility_(); |
| 2678 } |
| 2679 |
| 2673 this.scanInProgress_ = false; | 2680 this.scanInProgress_ = false; |
| 2674 if (this.scanUpdatedTimer_) { | |
| 2675 clearTimeout(this.scanUpdatedTimer_); | |
| 2676 this.scanUpdatedTimer_ = null; | |
| 2677 } | |
| 2678 this.table_.list.endBatchUpdates(); | 2681 this.table_.list.endBatchUpdates(); |
| 2679 this.grid_.endBatchUpdates(); | 2682 this.grid_.endBatchUpdates(); |
| 2680 this.updateMiddleBarVisibility_(); | |
| 2681 this.scanCompletedTimer_ = null; | 2683 this.scanCompletedTimer_ = null; |
| 2682 }.bind(this), 50); | 2684 }.bind(this), 50); |
| 2683 }; | 2685 }; |
| 2684 | 2686 |
| 2685 /** | 2687 /** |
| 2686 * @private | 2688 * @private |
| 2687 */ | 2689 */ |
| 2688 FileManager.prototype.onScanUpdated_ = function() { | 2690 FileManager.prototype.onScanUpdated_ = function() { |
| 2689 if (!this.scanInProgress_) { | 2691 if (!this.scanInProgress_) { |
| 2690 console.error('Scan-updated event recieved. But scan is not started.'); | 2692 console.error('Scan-updated event recieved. But scan is not started.'); |
| 2691 return; | 2693 return; |
| 2692 } | 2694 } |
| 2693 | 2695 |
| 2694 // We need to hide the spinner only once. | 2696 if (this.scanUpdatedTimer_ || this.scanCompletedTimer_) |
| 2695 if (this.scanUpdatedAtLeastOnceOrCompleted_ || this.scanUpdatedTimer_) | |
| 2696 return; | 2697 return; |
| 2697 | 2698 |
| 2698 // Show contents incrementally by finishing batch updated, but only after | 2699 // Show contents incrementally by finishing batch updated, but only after |
| 2699 // 200ms elapsed, to avoid flickering when it is not necessary. | 2700 // 200ms elapsed, to avoid flickering when it is not necessary. |
| 2700 this.scanUpdatedTimer_ = setTimeout(function() { | 2701 this.scanUpdatedTimer_ = setTimeout(function() { |
| 2701 // We need to hide the spinner only once. | 2702 // We need to hide the spinner only once. |
| 2702 if (this.scanUpdatedAtLeastOnceOrCompleted_) | 2703 if (!this.scanUpdatedAtLeastOnceOrCompleted_) { |
| 2703 return; | 2704 this.scanUpdatedAtLeastOnceOrCompleted_ = true; |
| 2704 if (this.scanCompletedTimer_) { | 2705 this.hideSpinnerLater_(); |
| 2705 clearTimeout(this.scanCompletedTimer_); | 2706 this.updateMiddleBarVisibility_(); |
| 2706 this.scanCompletedTimer_ = null; | |
| 2707 } | 2707 } |
| 2708 this.scanUpdatedAtLeastOnceOrCompleted_ = true; | 2708 |
| 2709 this.scanInProgress_ = false; | 2709 // Update the UI. |
| 2710 this.hideSpinnerLater_(); | 2710 if (this.scanInProgress_) { |
| 2711 this.table_.list.endBatchUpdates(); | 2711 this.table_.list.endBatchUpdates(); |
| 2712 this.grid_.endBatchUpdates(); | 2712 this.grid_.endBatchUpdates(); |
| 2713 this.updateMiddleBarVisibility_(); | 2713 this.table_.list.startBatchUpdates(); |
| 2714 this.grid_.startBatchUpdates(); |
| 2715 } |
| 2714 this.scanUpdatedTimer_ = null; | 2716 this.scanUpdatedTimer_ = null; |
| 2715 }.bind(this), 200); | 2717 }.bind(this), 200); |
| 2716 }; | 2718 }; |
| 2717 | 2719 |
| 2718 /** | 2720 /** |
| 2719 * @private | 2721 * @private |
| 2720 */ | 2722 */ |
| 2721 FileManager.prototype.onScanCancelled_ = function() { | 2723 FileManager.prototype.onScanCancelled_ = function() { |
| 2722 if (!this.scanInProgress_) { | 2724 if (!this.scanInProgress_) { |
| 2723 console.error('Scan-cancelled event recieved. But scan is not started.'); | 2725 console.error('Scan-cancelled event recieved. But scan is not started.'); |
| 2724 return; | 2726 return; |
| 2725 } | 2727 } |
| 2726 | 2728 |
| 2727 this.updateCommands(); | 2729 this.updateCommands(); |
| 2728 this.hideSpinnerLater_(); | 2730 this.hideSpinnerLater_(); |
| 2729 if (this.scanCompletedTimer_) { | 2731 if (this.scanCompletedTimer_) { |
| 2730 clearTimeout(this.scanCompletedTimer_); | 2732 clearTimeout(this.scanCompletedTimer_); |
| 2731 this.scanCompletedTimer_ = null; | 2733 this.scanCompletedTimer_ = null; |
| 2732 } | 2734 } |
| 2733 if (this.scanUpdatedTimer_) { | 2735 if (this.scanUpdatedTimer_) { |
| 2734 clearTimeout(this.scanUpdatedTimer_); | 2736 clearTimeout(this.scanUpdatedTimer_); |
| 2735 this.scanUpdatedTimer_ = null; | 2737 this.scanUpdatedTimer_ = null; |
| 2736 } | 2738 } |
| 2737 // Finish unfinished batch updates. | 2739 // Finish unfinished batch updates. |
| 2738 if (!this.scanUpdatedAtLeastOnceOrCompleted_) { | 2740 if (!this.scanUpdatedAtLeastOnceOrCompleted_) { |
| 2739 this.scanUpdatedAtLeastOnceOrCompleted_ = true; | 2741 this.scanUpdatedAtLeastOnceOrCompleted_ = true; |
| 2740 this.scanInProgress_ = false; | |
| 2741 this.table_.list.endBatchUpdates(); | |
| 2742 this.grid_.endBatchUpdates(); | |
| 2743 this.updateMiddleBarVisibility_(); | 2742 this.updateMiddleBarVisibility_(); |
| 2744 } | 2743 } |
| 2744 |
| 2745 this.scanInProgress_ = false; |
| 2746 this.table_.list.endBatchUpdates(); |
| 2747 this.grid_.endBatchUpdates(); |
| 2745 }; | 2748 }; |
| 2746 | 2749 |
| 2747 /** | 2750 /** |
| 2748 * @private | 2751 * @private |
| 2749 */ | 2752 */ |
| 2750 FileManager.prototype.cancelSpinnerTimeout_ = function() { | 2753 FileManager.prototype.cancelSpinnerTimeout_ = function() { |
| 2751 if (this.showSpinnerTimeout_) { | 2754 if (this.showSpinnerTimeout_) { |
| 2752 clearTimeout(this.showSpinnerTimeout_); | 2755 clearTimeout(this.showSpinnerTimeout_); |
| 2753 this.showSpinnerTimeout_ = null; | 2756 this.showSpinnerTimeout_ = null; |
| 2754 } | 2757 } |
| (...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3837 */ | 3840 */ |
| 3838 FileManager.prototype.setCtrlKeyPressed_ = function(flag) { | 3841 FileManager.prototype.setCtrlKeyPressed_ = function(flag) { |
| 3839 this.ctrlKeyPressed_ = flag; | 3842 this.ctrlKeyPressed_ = flag; |
| 3840 // Before the DOM is constructed, the key event can be handled. | 3843 // Before the DOM is constructed, the key event can be handled. |
| 3841 var cacheClearCommand = | 3844 var cacheClearCommand = |
| 3842 this.document_.querySelector('#drive-clear-local-cache'); | 3845 this.document_.querySelector('#drive-clear-local-cache'); |
| 3843 if (cacheClearCommand) | 3846 if (cacheClearCommand) |
| 3844 cacheClearCommand.canExecuteChange(); | 3847 cacheClearCommand.canExecuteChange(); |
| 3845 }; | 3848 }; |
| 3846 })(); | 3849 })(); |
| OLD | NEW |