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 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 this.copyManager_.addEventListener('copy-progress', | 535 this.copyManager_.addEventListener('copy-progress', |
536 this.onCopyProgress_.bind(this)); | 536 this.onCopyProgress_.bind(this)); |
537 this.copyManager_.addEventListener('copy-operation-complete', | 537 this.copyManager_.addEventListener('copy-operation-complete', |
538 this.onCopyManagerOperationComplete_.bind(this)); | 538 this.onCopyManagerOperationComplete_.bind(this)); |
539 | 539 |
540 var controller = this.fileTransferController_ = new FileTransferController( | 540 var controller = this.fileTransferController_ = new FileTransferController( |
541 this.directoryModel_.fileList, | 541 this.directoryModel_.fileList, |
542 this.directoryModel_.fileListSelection, | 542 this.directoryModel_.fileListSelection, |
543 GridItem.bind(null, this), | 543 GridItem.bind(null, this), |
544 this.copyManager_, | 544 this.copyManager_, |
545 this.directoryModel_); | 545 this.directoryModel_, |
| 546 this.commands_); |
546 controller.attachDragSource(this.table_.list); | 547 controller.attachDragSource(this.table_.list); |
547 controller.attachDropTarget(this.table_.list); | 548 controller.attachDropTarget(this.table_.list); |
548 controller.attachDragSource(this.grid_); | 549 controller.attachDragSource(this.grid_); |
549 controller.attachDropTarget(this.grid_); | 550 controller.attachDropTarget(this.grid_); |
550 controller.attachCopyPasteHandlers(this.document_); | 551 controller.attachCopyPasteHandlers(this.document_); |
551 controller.addEventListener('selection-copied', | 552 controller.addEventListener('selection-copied', |
552 this.blinkSelection.bind(this)); | 553 this.blinkSelection.bind(this)); |
553 controller.addEventListener('selection-cut', | 554 controller.addEventListener('selection-cut', |
554 this.blinkSelection.bind(this)); | 555 this.blinkSelection.bind(this)); |
555 }; | 556 }; |
(...skipping 1343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1899 if (!this.isOnGData()) | 1900 if (!this.isOnGData()) |
1900 return; | 1901 return; |
1901 | 1902 |
1902 cacheGDataProps(entry, function(entry) { | 1903 cacheGDataProps(entry, function(entry) { |
1903 if (!entry.gdata_) | 1904 if (!entry.gdata_) |
1904 return; | 1905 return; |
1905 | 1906 |
1906 if (entry.gdata_.isHosted) { | 1907 if (entry.gdata_.isHosted) { |
1907 listItem.classList.add('gdata-hosted'); | 1908 listItem.classList.add('gdata-hosted'); |
1908 } | 1909 } |
1909 if (entry.isDirectory || FileManager.isAvaliableOffline_(entry.gdata_)) { | 1910 if (entry.isDirectory || FileType.isAvaliableOffline_(entry.gdata_)) { |
1910 listItem.classList.add('gdata-present'); | 1911 listItem.classList.add('gdata-present'); |
1911 } | 1912 } |
1912 }.bind(this)); | 1913 }.bind(this)); |
1913 }; | 1914 }; |
1914 | 1915 |
1915 /** | 1916 /** |
1916 * Render the Name column of the detail table. | 1917 * Render the Name column of the detail table. |
1917 * | 1918 * |
1918 * Invoked by cr.ui.Table when a file needs to be rendered. | 1919 * Invoked by cr.ui.Table when a file needs to be rendered. |
1919 * | 1920 * |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2031 }; | 2032 }; |
2032 | 2033 |
2033 FileManager.prototype.updateDate_ = function(div, entry) { | 2034 FileManager.prototype.updateDate_ = function(div, entry) { |
2034 div.textContent = '...'; | 2035 div.textContent = '...'; |
2035 this.displayDateInDiv_( | 2036 this.displayDateInDiv_( |
2036 div, this.metadataCache_.getCached(entry, 'filesystem')); | 2037 div, this.metadataCache_.getCached(entry, 'filesystem')); |
2037 }; | 2038 }; |
2038 | 2039 |
2039 FileManager.prototype.displayDateInDiv_ = function(div, filesystemProps) { | 2040 FileManager.prototype.displayDateInDiv_ = function(div, filesystemProps) { |
2040 if (!filesystemProps) return; | 2041 if (!filesystemProps) return; |
2041 if (this.directoryModel_.isSystemDirectoy && | 2042 if (this.directoryModel_.isSystemDirectory && |
2042 filesystemProps.modificationTime.getTime() == 0) { | 2043 filesystemProps.modificationTime.getTime() == 0) { |
2043 // Mount points for FAT volumes have this time associated with them. | 2044 // Mount points for FAT volumes have this time associated with them. |
2044 // We'd rather display nothing than this bogus date. | 2045 // We'd rather display nothing than this bogus date. |
2045 div.textContent = ''; | 2046 div.textContent = ''; |
2046 } else { | 2047 } else { |
2047 div.textContent = | 2048 div.textContent = |
2048 this.shortDateFormatter_.format(filesystemProps.modificationTime); | 2049 this.shortDateFormatter_.format(filesystemProps.modificationTime); |
2049 } | 2050 } |
2050 }; | 2051 }; |
2051 | 2052 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2144 */ | 2145 */ |
2145 FileManager.prototype.summarizeSelection_ = function() { | 2146 FileManager.prototype.summarizeSelection_ = function() { |
2146 var selection = this.selection = { | 2147 var selection = this.selection = { |
2147 entries: [], | 2148 entries: [], |
2148 urls: [], | 2149 urls: [], |
2149 totalCount: 0, | 2150 totalCount: 0, |
2150 fileCount: 0, | 2151 fileCount: 0, |
2151 directoryCount: 0, | 2152 directoryCount: 0, |
2152 bytes: 0, | 2153 bytes: 0, |
2153 showBytes: false, | 2154 showBytes: false, |
| 2155 allGDataFilesPresent: false, |
2154 iconType: null, | 2156 iconType: null, |
2155 indexes: this.currentList_.selectionModel.selectedIndexes | 2157 indexes: this.currentList_.selectionModel.selectedIndexes |
2156 }; | 2158 }; |
2157 | 2159 |
2158 if (!selection.indexes.length) { | 2160 if (!selection.indexes.length) { |
2159 this.updateCommonActionButtons_(); | 2161 this.updateCommonActionButtons_(); |
2160 this.updatePreviewPanelVisibility_(); | 2162 this.updatePreviewPanelVisibility_(); |
2161 cr.dispatchSimpleEvent(this, 'selection-summarized'); | 2163 cr.dispatchSimpleEvent(this, 'selection-summarized'); |
2162 return; | 2164 return; |
2163 } | 2165 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2258 } | 2260 } |
2259 | 2261 |
2260 if (entry.isFile) { | 2262 if (entry.isFile) { |
2261 selection.bytes += filesystem.size; | 2263 selection.bytes += filesystem.size; |
2262 selection.showBytes |= filesystem.fileType.type != 'hosted'; | 2264 selection.showBytes |= filesystem.fileType.type != 'hosted'; |
2263 } | 2265 } |
2264 } | 2266 } |
2265 | 2267 |
2266 this.dispatchEvent(new cr.Event('selection-summarized')); | 2268 this.dispatchEvent(new cr.Event('selection-summarized')); |
2267 }.bind(this)); | 2269 }.bind(this)); |
| 2270 |
| 2271 if (this.isOnGData()) { |
| 2272 FileType.checkOfflineAvailability( |
| 2273 selection.entries, selection.urls, function(result) { |
| 2274 selection.allGDataFilesPresent = result; |
| 2275 this.updateOkButton_(); |
| 2276 }.bind(this)); |
| 2277 } |
2268 }; | 2278 }; |
2269 | 2279 |
2270 /** | 2280 /** |
2271 * Initialize a thumbnail in the bottom pannel to pop up on mouse over. | 2281 * Initialize a thumbnail in the bottom pannel to pop up on mouse over. |
2272 * Image's assumed to be just loaded and not inserted into the DOM. | 2282 * Image's assumed to be just loaded and not inserted into the DOM. |
2273 * | 2283 * |
2274 * @param {HTMLElement} box Element what's going to contain the image. | 2284 * @param {HTMLElement} box Element what's going to contain the image. |
2275 * @param {HTMLElement} img Loaded image. | 2285 * @param {HTMLElement} img Loaded image. |
2276 */ | 2286 */ |
2277 FileManager.prototype.initThumbnailZoom_ = function(box, img, transform) { | 2287 FileManager.prototype.initThumbnailZoom_ = function(box, img, transform) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2379 self.onResize_(); | 2389 self.onResize_(); |
2380 } | 2390 } |
2381 | 2391 |
2382 function setVisibility(visibility) { | 2392 function setVisibility(visibility) { |
2383 panel.setAttribute('visibility', visibility); | 2393 panel.setAttribute('visibility', visibility); |
2384 } | 2394 } |
2385 }; | 2395 }; |
2386 | 2396 |
2387 | 2397 |
2388 FileManager.prototype.isOnGData = function() { | 2398 FileManager.prototype.isOnGData = function() { |
2389 return this.directoryModel_ && | 2399 return this.directoryModel_.isOnGData; |
2390 this.directoryModel_.rootPath == '/' + DirectoryModel.GDATA_DIRECTORY; | |
2391 }; | 2400 }; |
2392 | 2401 |
2393 FileManager.prototype.getMetadataProvider = function() { | 2402 FileManager.prototype.getMetadataProvider = function() { |
2394 return this.metadataProvider_; | 2403 return this.metadataProvider_; |
2395 }; | 2404 }; |
2396 | 2405 |
2397 /** | 2406 /** |
2398 * Callback called when tasks for selected files are determined. | 2407 * Callback called when tasks for selected files are determined. |
2399 * @param {Object} selection Selection is passed here, since this.selection | 2408 * @param {Object} selection Selection is passed here, since this.selection |
2400 * can change before tasks were found, and we should be accurate. | 2409 * can change before tasks were found, and we should be accurate. |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2567 // For internal tasks we do not listen to the event to avoid | 2576 // For internal tasks we do not listen to the event to avoid |
2568 // handling the same task instance from multiple tabs. | 2577 // handling the same task instance from multiple tabs. |
2569 // So, we manually execute the task. | 2578 // So, we manually execute the task. |
2570 this.onFileTaskExecute_(task_parts[1], urls); | 2579 this.onFileTaskExecute_(task_parts[1], urls); |
2571 } | 2580 } |
2572 }.bind(this)); | 2581 }.bind(this)); |
2573 }; | 2582 }; |
2574 | 2583 |
2575 FileManager.prototype.executeIfAvailable_ = function(urls, callback) { | 2584 FileManager.prototype.executeIfAvailable_ = function(urls, callback) { |
2576 if (this.isOnGDataOffline()) { | 2585 if (this.isOnGDataOffline()) { |
2577 chrome.fileBrowserPrivate.getGDataFileProperties(urls, function(props) { | 2586 FileType.checkOfflineAvailability( |
2578 for (var i = 0; i != props.length; i++) { | 2587 null /* entries */, urls, function(result) { |
2579 if (!FileManager.isAvaliableOffline_(props[i])) { | 2588 if (!result) { |
2580 this.alert.showHtml( | 2589 this.alert.showHtml( |
2581 str('OFFLINE_HEADER'), | 2590 str('OFFLINE_HEADER'), |
2582 strf( | 2591 strf( |
2583 urls.length == 1 ? | 2592 urls.length == 1 ? |
2584 'OFFLINE_MESSAGE' : | 2593 'OFFLINE_MESSAGE' : |
2585 'OFFLINE_MESSAGE_PLURAL', | 2594 'OFFLINE_MESSAGE_PLURAL', |
2586 str('OFFLINE_COLUMN_LABEL'))); | 2595 str('OFFLINE_COLUMN_LABEL'))); |
2587 return; | 2596 return; |
2588 } | |
2589 } | 2597 } |
2590 callback(urls); | 2598 callback(urls); |
2591 }.bind(this)); | 2599 }.bind(this)); |
2592 } else { | 2600 } else { |
2593 callback(urls); | 2601 callback(urls); |
2594 } | 2602 } |
2595 }; | 2603 }; |
2596 | 2604 |
2597 FileManager.isAvaliableOffline_ = function(gdata) { | |
2598 return gdata.isPresent && !gdata.isHosted; | |
2599 }; | |
2600 | |
2601 FileManager.prototype.isOffline = function() { | 2605 FileManager.prototype.isOffline = function() { |
2602 return !navigator.onLine; | 2606 return !navigator.onLine; |
2603 }; | 2607 }; |
2604 | 2608 |
2605 FileManager.prototype.onOnlineOffline_ = function() { | 2609 FileManager.prototype.onOnlineOffline_ = function() { |
2606 if (this.isOffline()) { | 2610 if (this.isOffline()) { |
2607 console.log('OFFLINE'); | 2611 console.log('OFFLINE'); |
2608 this.dialogContainer_.setAttribute('offline', true); | 2612 this.dialogContainer_.setAttribute('offline', true); |
2609 } else { | 2613 } else { |
2610 console.log('ONLINE'); | 2614 console.log('ONLINE'); |
2611 this.dialogContainer_.removeAttribute('offline'); | 2615 this.dialogContainer_.removeAttribute('offline'); |
2612 } | 2616 } |
2613 this.directoryModel_.offline = this.isOffline(); | 2617 this.directoryModel_.offline = this.isOffline(); |
| 2618 this.updateOkButton_(); |
2614 }; | 2619 }; |
2615 | 2620 |
2616 FileManager.prototype.isOnGDataOffline = function() { | 2621 FileManager.prototype.isOnGDataOffline = function() { |
2617 return this.isOnGData() && this.isOffline(); | 2622 return this.isOnGData() && this.isOffline(); |
2618 }; | 2623 }; |
2619 | 2624 |
2620 FileManager.prototype.isOnReadonlyDirectory = function() { | 2625 FileManager.prototype.isOnReadonlyDirectory = function() { |
2621 return this.directoryModel_.readonly; | 2626 return this.directoryModel_.readonly; |
2622 }; | 2627 }; |
2623 | 2628 |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3281 if (listItem) | 3286 if (listItem) |
3282 listItem.querySelector('input[type="checkbox"]').checked = true; | 3287 listItem.querySelector('input[type="checkbox"]').checked = true; |
3283 } | 3288 } |
3284 } | 3289 } |
3285 var selectAllCheckbox = | 3290 var selectAllCheckbox = |
3286 this.document_.getElementById('select-all-checkbox'); | 3291 this.document_.getElementById('select-all-checkbox'); |
3287 if (selectAllCheckbox) | 3292 if (selectAllCheckbox) |
3288 this.updateSelectAllCheckboxState_(selectAllCheckbox); | 3293 this.updateSelectAllCheckboxState_(selectAllCheckbox); |
3289 }; | 3294 }; |
3290 | 3295 |
| 3296 /** |
| 3297 * Check if all the files in the current selection are available. The only |
| 3298 * case when files might be not available is when the selection contains |
| 3299 * uncached GData files and the browser is offline. |
| 3300 * @return {boolean} True if all files in the current selection are available
. |
| 3301 */ |
| 3302 FileManager.prototype.isSelectionAvailable = function() { |
| 3303 return !this.isOnGDataOffline() || this.selection.allGDataFilesPresent; |
| 3304 }; |
| 3305 |
3291 FileManager.prototype.updateOkButton_ = function(event) { | 3306 FileManager.prototype.updateOkButton_ = function(event) { |
3292 var selectable; | 3307 var selectable; |
3293 | 3308 |
3294 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { | 3309 if (!this.selection) { |
| 3310 selectable = false; |
| 3311 } else if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { |
3295 selectable = this.selection.directoryCount == 1 && | 3312 selectable = this.selection.directoryCount == 1 && |
3296 this.selection.fileCount == 0; | 3313 this.selection.fileCount == 0; |
3297 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { | 3314 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { |
3298 selectable = (this.selection.directoryCount == 0 && | 3315 selectable = (this.isSelectionAvailable() && |
| 3316 this.selection.directoryCount == 0 && |
3299 this.selection.fileCount == 1); | 3317 this.selection.fileCount == 1); |
3300 } else if (this.dialogType_ == | 3318 } else if (this.dialogType_ == |
3301 FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { | 3319 FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { |
3302 selectable = (this.selection.directoryCount == 0 && | 3320 selectable = (this.isSelectionAvailable() && |
| 3321 this.selection.directoryCount == 0 && |
3303 this.selection.fileCount >= 1); | 3322 this.selection.fileCount >= 1); |
3304 } else if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { | 3323 } else if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { |
3305 if (this.isOnReadonlyDirectory()) { | 3324 if (this.isOnReadonlyDirectory()) { |
3306 selectable = false; | 3325 selectable = false; |
3307 } else { | 3326 } else { |
3308 selectable = !!this.filenameInput_.value; | 3327 selectable = !!this.filenameInput_.value; |
3309 } | 3328 } |
3310 } else if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { | 3329 } else if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { |
3311 // No "select" buttons on the full page UI. | 3330 // No "select" buttons on the full page UI. |
3312 selectable = true; | 3331 selectable = true; |
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4323 | 4342 |
4324 handleSplitterDragEnd: function(e) { | 4343 handleSplitterDragEnd: function(e) { |
4325 Splitter.prototype.handleSplitterDragEnd.apply(this, arguments); | 4344 Splitter.prototype.handleSplitterDragEnd.apply(this, arguments); |
4326 this.ownerDocument.documentElement.classList.remove('col-resize'); | 4345 this.ownerDocument.documentElement.classList.remove('col-resize'); |
4327 } | 4346 } |
4328 }; | 4347 }; |
4329 | 4348 |
4330 customSplitter.decorate(splitterElement); | 4349 customSplitter.decorate(splitterElement); |
4331 }; | 4350 }; |
4332 })(); | 4351 })(); |
OLD | NEW |