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 /** | 5 /** |
6 * FileManager constructor. | 6 * FileManager constructor. |
7 * | 7 * |
8 * FileManager objects encapsulate the functionality of the file selector | 8 * FileManager objects encapsulate the functionality of the file selector |
9 * dialogs, as well as the full screen file manager application (though the | 9 * dialogs, as well as the full screen file manager application (though the |
10 * latter is not yet implemented). | 10 * latter is not yet implemented). |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 fileManager.volumeManager_); | 203 fileManager.volumeManager_); |
204 this.metadataCache_ = fileManager.metadataCache_; | 204 this.metadataCache_ = fileManager.metadataCache_; |
205 | 205 |
206 this.filesystemChangeHandler_ = | 206 this.filesystemChangeHandler_ = |
207 fileManager.updateMetadataInUI_.bind(fileManager, 'filesystem'); | 207 fileManager.updateMetadataInUI_.bind(fileManager, 'filesystem'); |
208 this.thumbnailChangeHandler_ = | 208 this.thumbnailChangeHandler_ = |
209 fileManager.updateMetadataInUI_.bind(fileManager, 'thumbnail'); | 209 fileManager.updateMetadataInUI_.bind(fileManager, 'thumbnail'); |
210 this.gdataChangeHandler_ = | 210 this.gdataChangeHandler_ = |
211 fileManager.updateMetadataInUI_.bind(fileManager, 'gdata'); | 211 fileManager.updateMetadataInUI_.bind(fileManager, 'gdata'); |
212 | 212 |
| 213 var dm = fileManager.directoryModel_; |
| 214 this.internalChangeHandler_ = dm.rescan.bind(dm); |
| 215 |
213 this.filesystemObserverId_ = null; | 216 this.filesystemObserverId_ = null; |
214 this.thumbnailObserverId_ = null; | 217 this.thumbnailObserverId_ = null; |
215 this.gdataObserverId_ = null; | 218 this.gdataObserverId_ = null; |
| 219 this.internalObserverId_ = null; |
216 | 220 |
217 // Holds the directories known to contain files with stale metadata | 221 // Holds the directories known to contain files with stale metadata |
218 // as URL to bool map. | 222 // as URL to bool map. |
219 this.directoriesWithStaleMetadata_ = {}; | 223 this.directoriesWithStaleMetadata_ = {}; |
220 }; | 224 }; |
221 | 225 |
222 FileManager.MetadataFileWatcher.prototype.__proto__ = FileWatcher.prototype; | 226 FileManager.MetadataFileWatcher.prototype.__proto__ = FileWatcher.prototype; |
223 | 227 |
224 /** | 228 /** |
225 * Changed metadata observers for the new directory. | 229 * Changed metadata observers for the new directory. |
226 * @override | 230 * @override |
227 * @param {DirectoryEntryi?} entry New watched directory entry. | 231 * @param {DirectoryEntryi?} entry New watched directory entry. |
228 * @override | 232 * @override |
229 */ | 233 */ |
230 FileManager.MetadataFileWatcher.prototype.changeWatchedEntry = | 234 FileManager.MetadataFileWatcher.prototype.changeWatchedEntry = function( |
231 function(entry) { | 235 entry) { |
232 FileWatcher.prototype.changeWatchedEntry.call(this, entry); | 236 FileWatcher.prototype.changeWatchedEntry.call(this, entry); |
233 | 237 |
234 if (this.filesystemObserverId_) | 238 if (this.filesystemObserverId_) |
235 this.metadataCache_.removeObserver(this.filesystemObserverId_); | 239 this.metadataCache_.removeObserver(this.filesystemObserverId_); |
236 if (this.thumbnailObserverId_) | 240 if (this.thumbnailObserverId_) |
237 this.metadataCache_.removeObserver(this.thumbnailObserverId_); | 241 this.metadataCache_.removeObserver(this.thumbnailObserverId_); |
238 if (this.gdataObserverId_) | 242 if (this.gdataObserverId_) |
239 this.metadataCache_.removeObserver(this.gdataObserverId_); | 243 this.metadataCache_.removeObserver(this.gdataObserverId_); |
240 this.filesystemObserverId_ = null; | 244 this.filesystemObserverId_ = null; |
241 this.gdataObserverId_ = null; | 245 this.gdataObserverId_ = null; |
| 246 this.internalObserverId_ = null; |
242 if (!entry) | 247 if (!entry) |
243 return; | 248 return; |
244 | 249 |
245 this.filesystemObserverId_ = this.metadataCache_.addObserver( | 250 this.filesystemObserverId_ = this.metadataCache_.addObserver( |
246 entry, | 251 entry, |
247 MetadataCache.CHILDREN, | 252 MetadataCache.CHILDREN, |
248 'filesystem', | 253 'filesystem', |
249 this.filesystemChangeHandler_); | 254 this.filesystemChangeHandler_); |
250 | 255 |
251 this.thumbnailObserverId_ = this.metadataCache_.addObserver( | 256 this.thumbnailObserverId_ = this.metadataCache_.addObserver( |
252 entry, | 257 entry, |
253 MetadataCache.CHILDREN, | 258 MetadataCache.CHILDREN, |
254 'thumbnail', | 259 'thumbnail', |
255 this.thumbnailChangeHandler_); | 260 this.thumbnailChangeHandler_); |
256 | 261 |
257 if (PathUtil.getRootType(entry.fullPath) === RootType.GDATA) { | 262 if (PathUtil.getRootType(entry.fullPath) === RootType.GDATA) { |
258 this.gdataObserverId_ = this.metadataCache_.addObserver( | 263 this.gdataObserverId_ = this.metadataCache_.addObserver( |
259 entry, | 264 entry, |
260 MetadataCache.CHILDREN, | 265 MetadataCache.CHILDREN, |
261 'gdata', | 266 'gdata', |
262 this.gdataChangeHandler_); | 267 this.gdataChangeHandler_); |
263 } | 268 } |
| 269 |
| 270 this.internalObserverId_ = this.metadataCache_.addObserver( |
| 271 entry, |
| 272 MetadataCache.CHILDREN, |
| 273 'internal', |
| 274 this.internalChangeHandler_); |
264 }; | 275 }; |
265 | 276 |
266 /** | 277 /** |
267 * @override | 278 * @override |
268 */ | 279 */ |
269 FileManager.MetadataFileWatcher.prototype.onFileInWatchedDirectoryChanged = | 280 FileManager.MetadataFileWatcher.prototype.onFileInWatchedDirectoryChanged = |
270 function() { | 281 function() { |
271 FileWatcher.prototype.onFileInWatchedDirectoryChanged.apply(this); | 282 FileWatcher.prototype.onFileInWatchedDirectoryChanged.apply(this); |
272 delete this.directoriesWithStaleMetadata_[ | 283 delete this.directoriesWithStaleMetadata_[ |
273 this.getWatchedDirectoryEntry().toURL()]; | 284 this.getWatchedDirectoryEntry().toURL()]; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 }; | 476 }; |
466 | 477 |
467 FileManager.prototype.initDataTransferOperations_ = function() { | 478 FileManager.prototype.initDataTransferOperations_ = function() { |
468 this.copyManager_ = new FileCopyManagerWrapper.getInstance( | 479 this.copyManager_ = new FileCopyManagerWrapper.getInstance( |
469 this.filesystem_.root); | 480 this.filesystem_.root); |
470 this.copyManager_.addEventListener('copy-progress', | 481 this.copyManager_.addEventListener('copy-progress', |
471 this.onCopyProgress_.bind(this)); | 482 this.onCopyProgress_.bind(this)); |
472 this.copyManager_.addEventListener('copy-operation-complete', | 483 this.copyManager_.addEventListener('copy-operation-complete', |
473 this.onCopyManagerOperationComplete_.bind(this)); | 484 this.onCopyManagerOperationComplete_.bind(this)); |
474 | 485 |
475 this.butterBar_ = new ButterBar(this.dialogDom_, this.copyManager_); | 486 this.butterBar_ = new ButterBar(this.dialogDom_, this.copyManager_, |
| 487 this.metadataCache_); |
476 | 488 |
477 var controller = this.fileTransferController_ = new FileTransferController( | 489 var controller = this.fileTransferController_ = new FileTransferController( |
478 GridItem.bind(null, this, false /* no checkbox */), | 490 GridItem.bind(null, this, false /* no checkbox */), |
479 this.copyManager_, | 491 this.copyManager_, |
480 this.directoryModel_); | 492 this.directoryModel_); |
481 controller.attachDragSource(this.table_.list); | 493 controller.attachDragSource(this.table_.list); |
482 controller.attachDropTarget(this.table_.list); | 494 controller.attachDropTarget(this.table_.list); |
483 controller.attachDragSource(this.grid_); | 495 controller.attachDragSource(this.grid_); |
484 controller.attachDropTarget(this.grid_); | 496 controller.attachDropTarget(this.grid_); |
485 controller.attachDropTarget(this.rootsList_, true); | 497 controller.attachDropTarget(this.rootsList_, true); |
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1277 return; | 1289 return; |
1278 | 1290 |
1279 case 'rename': | 1291 case 'rename': |
1280 this.initiateRename_(); | 1292 this.initiateRename_(); |
1281 return; | 1293 return; |
1282 | 1294 |
1283 case 'delete': | 1295 case 'delete': |
1284 if (this.isRenamingInProgress()) | 1296 if (this.isRenamingInProgress()) |
1285 document.execCommand('delete'); | 1297 document.execCommand('delete'); |
1286 else | 1298 else |
1287 this.deleteEntries(this.selection.entries); | 1299 this.deleteSelection(); |
1288 | 1300 |
1289 return; | 1301 return; |
1290 | 1302 |
1291 case 'newfolder': | 1303 case 'newfolder': |
1292 this.onNewFolderCommand_(event); | 1304 this.onNewFolderCommand_(event); |
1293 return; | 1305 return; |
1294 | 1306 |
1295 case 'unmount': | 1307 case 'unmount': |
1296 this.unmountVolume_(this.directoryModel_.getCurrentRootPath()); | 1308 this.unmountVolume_(this.directoryModel_.getCurrentRootPath()); |
1297 return; | 1309 return; |
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2630 }; | 2642 }; |
2631 | 2643 |
2632 /** | 2644 /** |
2633 * Return URL of the current directory or null. | 2645 * Return URL of the current directory or null. |
2634 */ | 2646 */ |
2635 FileManager.prototype.getCurrentDirectoryURL = function() { | 2647 FileManager.prototype.getCurrentDirectoryURL = function() { |
2636 return this.directoryModel_ && | 2648 return this.directoryModel_ && |
2637 this.directoryModel_.getCurrentDirEntry().toURL(); | 2649 this.directoryModel_.getCurrentDirEntry().toURL(); |
2638 }; | 2650 }; |
2639 | 2651 |
2640 FileManager.prototype.deleteEntries = function(entries, force, opt_callback) { | 2652 FileManager.prototype.deleteSelection = function(entries) { |
2641 if (!force) { | 2653 this.butterBar_.initiateDelete(this.selection.entries); |
2642 var self = this; | |
2643 var msg; | |
2644 if (entries.length == 1) { | |
2645 msg = strf('CONFIRM_DELETE_ONE', entries[0].name); | |
2646 } else { | |
2647 msg = strf('CONFIRM_DELETE_SOME', entries.length); | |
2648 } | |
2649 | |
2650 this.confirm.show(msg, this.deleteEntries.bind( | |
2651 this, entries, true, opt_callback)); | |
2652 return; | |
2653 } | |
2654 | |
2655 this.directoryModel_.deleteEntries(entries, opt_callback); | |
2656 }; | 2654 }; |
2657 | 2655 |
2658 FileManager.prototype.onDeleteButtonClick_ = function(event) { | 2656 FileManager.prototype.onDeleteButtonClick_ = function(event) { |
2659 this.deleteEntries(this.selection.entries); | 2657 this.deleteSelection(); |
2660 event.preventDefault(); | 2658 event.preventDefault(); |
2661 event.stopPropagation(); | 2659 event.stopPropagation(); |
2662 }; | 2660 }; |
2663 | 2661 |
2664 FileManager.prototype.onDeleteButtonKeyPress_ = function(event) { | 2662 FileManager.prototype.onDeleteButtonKeyPress_ = function(event) { |
2665 switch (util.getKeyModifiers(event) + event.keyCode) { | 2663 switch (util.getKeyModifiers(event) + event.keyCode) { |
2666 case '13': // Enter | 2664 case '13': // Enter |
2667 case '32': // Space | 2665 case '32': // Space |
2668 this.deleteEntries(this.selection.entries); | 2666 this.deleteSelection(); |
2669 event.preventDefault(); | 2667 event.preventDefault(); |
2670 event.stopPropagation(); | 2668 event.stopPropagation(); |
2671 break; | 2669 break; |
2672 } | 2670 } |
2673 }; | 2671 }; |
2674 | 2672 |
2675 FileManager.prototype.blinkSelection = function() { | 2673 FileManager.prototype.blinkSelection = function() { |
2676 if (!this.selection || this.selection.totalCount == 0) | 2674 if (!this.selection || this.selection.totalCount == 0) |
2677 return; | 2675 return; |
2678 | 2676 |
(...skipping 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4231 this.dialogDom_.querySelector('#default-action-separator'); | 4229 this.dialogDom_.querySelector('#default-action-separator'); |
4232 | 4230 |
4233 // TODO(dzvorygin): Here we use this hack, since 'hidden' is standard | 4231 // TODO(dzvorygin): Here we use this hack, since 'hidden' is standard |
4234 // attribute and we can't use it's setter as usual. | 4232 // attribute and we can't use it's setter as usual. |
4235 this.openWithCommand_.__lookupSetter__('hidden'). | 4233 this.openWithCommand_.__lookupSetter__('hidden'). |
4236 call(this.openWithCommand_, !(defaultItem && isMultiple)); | 4234 call(this.openWithCommand_, !(defaultItem && isMultiple)); |
4237 this.defaultActionMenuItem_.hidden = !defaultItem; | 4235 this.defaultActionMenuItem_.hidden = !defaultItem; |
4238 defaultActionSeparator.hidden = !defaultItem; | 4236 defaultActionSeparator.hidden = !defaultItem; |
4239 }; | 4237 }; |
4240 })(); | 4238 })(); |
OLD | NEW |