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 // If directory files changes too often, don't rescan directory more than once | 7 // If directory files changes too often, don't rescan directory more than once |
8 // per specified interval | 8 // per specified interval |
9 var SIMULTANEOUS_RESCAN_INTERVAL = 500; | 9 var SIMULTANEOUS_RESCAN_INTERVAL = 500; |
10 // Used for operations that require almost instant rescan. | 10 // Used for operations that require almost instant rescan. |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 return index >= 0 && this.getFileList().item(index); | 277 return index >= 0 && this.getFileList().item(index); |
278 }; | 278 }; |
279 | 279 |
280 /** | 280 /** |
281 * @param {Entry} value The new lead entry. | 281 * @param {Entry} value The new lead entry. |
282 * @private | 282 * @private |
283 */ | 283 */ |
284 DirectoryModel.prototype.setLeadEntry_ = function(value) { | 284 DirectoryModel.prototype.setLeadEntry_ = function(value) { |
285 var fileList = this.getFileList(); | 285 var fileList = this.getFileList(); |
286 for (var i = 0; i < fileList.length; i++) { | 286 for (var i = 0; i < fileList.length; i++) { |
287 if (util.isSameEntry(fileList.item(i), value)) { | 287 if (util.isSameEntry(/** @type {Entry} */ (fileList.item(i)), value)) { |
288 this.fileListSelection_.leadIndex = i; | 288 this.fileListSelection_.leadIndex = i; |
289 return; | 289 return; |
290 } | 290 } |
291 } | 291 } |
292 }; | 292 }; |
293 | 293 |
294 /** | 294 /** |
295 * Schedule rescan with short delay. | 295 * Schedule rescan with short delay. |
296 * @param {boolean} refresh True to refresh metadata, or false to use cached | 296 * @param {boolean} refresh True to refresh metadata, or false to use cached |
297 * one. | 297 * one. |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 }; | 706 }; |
707 | 707 |
708 /** | 708 /** |
709 * @param {Entry} entry The entry to be searched. | 709 * @param {Entry} entry The entry to be searched. |
710 * @return {number} The index in the fileList, or -1 if not found. | 710 * @return {number} The index in the fileList, or -1 if not found. |
711 * @private | 711 * @private |
712 */ | 712 */ |
713 DirectoryModel.prototype.findIndexByEntry_ = function(entry) { | 713 DirectoryModel.prototype.findIndexByEntry_ = function(entry) { |
714 var fileList = this.getFileList(); | 714 var fileList = this.getFileList(); |
715 for (var i = 0; i < fileList.length; i++) { | 715 for (var i = 0; i < fileList.length; i++) { |
716 if (util.isSameEntry(fileList.item(i), entry)) | 716 if (util.isSameEntry(/** @type {Entry} */ (fileList.item(i)), entry)) |
717 return i; | 717 return i; |
718 } | 718 } |
719 return -1; | 719 return -1; |
720 }; | 720 }; |
721 | 721 |
722 /** | 722 /** |
723 * Called when rename is done successfully. | 723 * Called when rename is done successfully. |
724 * Note: conceptually, DirectoryModel should work without this, because entries | 724 * Note: conceptually, DirectoryModel should work without this, because entries |
725 * can be renamed by other systems anytime and Files.app should reflect it | 725 * can be renamed by other systems anytime and Files.app should reflect it |
726 * correctly. | 726 * correctly. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 this.currentDirContents_.getDirectoryEntry(); | 852 this.currentDirContents_.getDirectoryEntry(); |
853 this.clearAndScan_( | 853 this.clearAndScan_( |
854 newDirectoryContents, | 854 newDirectoryContents, |
855 function(result) { | 855 function(result) { |
856 // Calls the callback of the method when successful. | 856 // Calls the callback of the method when successful. |
857 if (result && opt_callback) | 857 if (result && opt_callback) |
858 opt_callback(); | 858 opt_callback(); |
859 | 859 |
860 // Notify that the current task of this.directoryChangeQueue_ | 860 // Notify that the current task of this.directoryChangeQueue_ |
861 // is completed. | 861 // is completed. |
862 setTimeout(queueTaskCallback); | 862 setTimeout(queueTaskCallback, 0); |
863 }); | 863 }); |
864 | 864 |
865 // For tests that open the dialog to empty directories, everything | 865 // For tests that open the dialog to empty directories, everything |
866 // is loaded at this point. | 866 // is loaded at this point. |
867 util.testSendMessage('directory-change-complete'); | 867 util.testSendMessage('directory-change-complete'); |
868 | 868 |
869 var event = new Event('directory-changed'); | 869 var event = new Event('directory-changed'); |
870 event.previousDirEntry = previousDirEntry; | 870 event.previousDirEntry = previousDirEntry; |
871 event.newDirEntry = dirEntry; | 871 event.newDirEntry = dirEntry; |
872 this.dispatchEvent(event); | 872 this.dispatchEvent(event); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 var fileList = this.getFileList(); | 950 var fileList = this.getFileList(); |
951 for (var i = 0; i < fileList.length; i++) { | 951 for (var i = 0; i < fileList.length; i++) { |
952 if (fileList.item(i).toURL() === entry.toURL()) { | 952 if (fileList.item(i).toURL() === entry.toURL()) { |
953 this.selectIndex(i); | 953 this.selectIndex(i); |
954 return; | 954 return; |
955 } | 955 } |
956 } | 956 } |
957 }; | 957 }; |
958 | 958 |
959 /** | 959 /** |
960 * @param {Array.<string>} entries Array of entries. | 960 * @param {Array.<Entry>} entries Array of entries. |
961 */ | 961 */ |
962 DirectoryModel.prototype.selectEntries = function(entries) { | 962 DirectoryModel.prototype.selectEntries = function(entries) { |
963 // URLs are needed here, since we are comparing Entries by URLs. | 963 // URLs are needed here, since we are comparing Entries by URLs. |
964 var urls = util.entriesToURLs(entries); | 964 var urls = util.entriesToURLs(entries); |
965 var fileList = this.getFileList(); | 965 var fileList = this.getFileList(); |
966 this.fileListSelection_.beginChange(); | 966 this.fileListSelection_.beginChange(); |
967 this.fileListSelection_.unselectAll(); | 967 this.fileListSelection_.unselectAll(); |
968 for (var i = 0; i < fileList.length; i++) { | 968 for (var i = 0; i < fileList.length; i++) { |
969 if (urls.indexOf(fileList.item(i).toURL()) >= 0) | 969 if (urls.indexOf(fileList.item(i).toURL()) >= 0) |
970 this.fileListSelection_.setIndexSelected(i, true); | 970 this.fileListSelection_.setIndexSelected(i, true); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 if (this.onSearchCompleted_) { | 1126 if (this.onSearchCompleted_) { |
1127 this.removeEventListener('scan-completed', this.onSearchCompleted_); | 1127 this.removeEventListener('scan-completed', this.onSearchCompleted_); |
1128 this.onSearchCompleted_ = null; | 1128 this.onSearchCompleted_ = null; |
1129 } | 1129 } |
1130 | 1130 |
1131 if (this.onClearSearch_) { | 1131 if (this.onClearSearch_) { |
1132 this.onClearSearch_(); | 1132 this.onClearSearch_(); |
1133 this.onClearSearch_ = null; | 1133 this.onClearSearch_ = null; |
1134 } | 1134 } |
1135 }; | 1135 }; |
OLD | NEW |