| 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 1971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1982 var url = urls[index]; | 1982 var url = urls[index]; |
| 1983 if (!(url in items)) continue; | 1983 if (!(url in items)) continue; |
| 1984 var listItem = items[url]; | 1984 var listItem = items[url]; |
| 1985 var entry = entries[url]; | 1985 var entry = entries[url]; |
| 1986 var props = properties[index]; | 1986 var props = properties[index]; |
| 1987 if (type == 'filesystem') { | 1987 if (type == 'filesystem') { |
| 1988 this.displayDateInDiv_(listItem.querySelector('.date'), props); | 1988 this.displayDateInDiv_(listItem.querySelector('.date'), props); |
| 1989 this.displaySizeInDiv_(listItem.querySelector('.size'), props); | 1989 this.displaySizeInDiv_(listItem.querySelector('.size'), props); |
| 1990 this.displayTypeInDiv_(listItem.querySelector('.type'), props); | 1990 this.displayTypeInDiv_(listItem.querySelector('.type'), props); |
| 1991 } else if (type == 'gdata') { | 1991 } else if (type == 'gdata') { |
| 1992 this.displayOfflineInDiv_(listItem.querySelector('.offline'), props); | 1992 var offline = listItem.querySelector('.offline'); |
| 1993 if (offline) // This column is only present in full page mode. |
| 1994 this.displayOfflineInDiv_(offline, props); |
| 1993 this.displayGDataStyleInItem_(listItem, entry, props); | 1995 this.displayGDataStyleInItem_(listItem, entry, props); |
| 1994 } | 1996 } |
| 1995 } | 1997 } |
| 1996 }; | 1998 }; |
| 1997 | 1999 |
| 1998 /** | 2000 /** |
| 1999 * Restore the item which is being renamed while refreshing the file list. Do | 2001 * Restore the item which is being renamed while refreshing the file list. Do |
| 2000 * nothing if no item is being renamed or such an item disappeared. | 2002 * nothing if no item is being renamed or such an item disappeared. |
| 2001 * | 2003 * |
| 2002 * While refreshing file list it gets repopulated with new file entries. | 2004 * While refreshing file list it gets repopulated with new file entries. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2034 */ | 2036 */ |
| 2035 FileManager.prototype.summarizeSelection_ = function() { | 2037 FileManager.prototype.summarizeSelection_ = function() { |
| 2036 var selection = this.selection = { | 2038 var selection = this.selection = { |
| 2037 entries: [], | 2039 entries: [], |
| 2038 urls: [], | 2040 urls: [], |
| 2039 totalCount: 0, | 2041 totalCount: 0, |
| 2040 fileCount: 0, | 2042 fileCount: 0, |
| 2041 directoryCount: 0, | 2043 directoryCount: 0, |
| 2042 bytes: 0, | 2044 bytes: 0, |
| 2043 showBytes: false, | 2045 showBytes: false, |
| 2046 allGDataFilesPresent: false, |
| 2044 iconType: null, | 2047 iconType: null, |
| 2045 indexes: this.currentList_.selectionModel.selectedIndexes | 2048 indexes: this.currentList_.selectionModel.selectedIndexes |
| 2046 }; | 2049 }; |
| 2047 | 2050 |
| 2048 if (!selection.indexes.length) { | 2051 if (!selection.indexes.length) { |
| 2049 this.updateCommonActionButtons_(); | 2052 this.updateCommonActionButtons_(); |
| 2050 this.updatePreviewPanelVisibility_(); | 2053 this.updatePreviewPanelVisibility_(); |
| 2051 cr.dispatchSimpleEvent(this, 'selection-summarized'); | 2054 cr.dispatchSimpleEvent(this, 'selection-summarized'); |
| 2052 return; | 2055 return; |
| 2053 } | 2056 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2148 } | 2151 } |
| 2149 | 2152 |
| 2150 if (entry.isFile) { | 2153 if (entry.isFile) { |
| 2151 selection.bytes += filesystem.size; | 2154 selection.bytes += filesystem.size; |
| 2152 selection.showBytes |= filesystem.fileType.type != 'hosted'; | 2155 selection.showBytes |= filesystem.fileType.type != 'hosted'; |
| 2153 } | 2156 } |
| 2154 } | 2157 } |
| 2155 | 2158 |
| 2156 this.dispatchEvent(new cr.Event('selection-summarized')); | 2159 this.dispatchEvent(new cr.Event('selection-summarized')); |
| 2157 }.bind(this)); | 2160 }.bind(this)); |
| 2161 |
| 2162 if (this.isOnGData()) { |
| 2163 this.metadataCache_.get(selection.urls, 'gdata', function(props) { |
| 2164 selection.allGDataFilesPresent = |
| 2165 props.filter(function(p) {return !p.availableOffline}).length == 0; |
| 2166 this.updateOkButton_(); |
| 2167 }.bind(this)); |
| 2168 } |
| 2158 }; | 2169 }; |
| 2159 | 2170 |
| 2160 /** | 2171 /** |
| 2172 * Check if all the files in the current selection are available. The only |
| 2173 * case when files might be not available is when the selection contains |
| 2174 * uncached GData files and the browser is offline. |
| 2175 * @return {boolean} True if all files in the current selection are |
| 2176 * available. |
| 2177 */ |
| 2178 FileManager.prototype.isSelectionAvailable = function() { |
| 2179 return !this.isOnGDataOffline() || this.selection.allGDataFilesPresent; |
| 2180 }; |
| 2181 |
| 2182 /** |
| 2161 * Initialize a thumbnail in the bottom pannel to pop up on mouse over. | 2183 * Initialize a thumbnail in the bottom pannel to pop up on mouse over. |
| 2162 * Image's assumed to be just loaded and not inserted into the DOM. | 2184 * Image's assumed to be just loaded and not inserted into the DOM. |
| 2163 * | 2185 * |
| 2164 * @param {HTMLElement} box Element what's going to contain the image. | 2186 * @param {HTMLElement} box Element what's going to contain the image. |
| 2165 * @param {HTMLElement} img Loaded image. | 2187 * @param {HTMLElement} img Loaded image. |
| 2166 */ | 2188 */ |
| 2167 FileManager.prototype.initThumbnailZoom_ = function(box, img, transform) { | 2189 FileManager.prototype.initThumbnailZoom_ = function(box, img, transform) { |
| 2168 var width = img.width; | 2190 var width = img.width; |
| 2169 var height = img.height; | 2191 var height = img.height; |
| 2170 var THUMBNAIL_SIZE = 45; | 2192 var THUMBNAIL_SIZE = 45; |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2459 // handling the same task instance from multiple tabs. | 2481 // handling the same task instance from multiple tabs. |
| 2460 // So, we manually execute the task. | 2482 // So, we manually execute the task. |
| 2461 this.onFileTaskExecute_(task_parts[1], urls); | 2483 this.onFileTaskExecute_(task_parts[1], urls); |
| 2462 } | 2484 } |
| 2463 }.bind(this)); | 2485 }.bind(this)); |
| 2464 }; | 2486 }; |
| 2465 | 2487 |
| 2466 FileManager.prototype.executeIfAvailable_ = function(urls, callback) { | 2488 FileManager.prototype.executeIfAvailable_ = function(urls, callback) { |
| 2467 if (this.isOnGDataOffline()) { | 2489 if (this.isOnGDataOffline()) { |
| 2468 this.metadataCache_.get(urls, 'gdata', function(props) { | 2490 this.metadataCache_.get(urls, 'gdata', function(props) { |
| 2469 for (var i = 0; i != props.length; i++) { | 2491 if (props.filter(function(p) {return !p.availableOffline}).length) { |
| 2470 if (!props[i].availableOffline) { | 2492 this.alert.showHtml( |
| 2471 this.alert.showHtml( | 2493 str('OFFLINE_HEADER'), |
| 2472 str('OFFLINE_HEADER'), | 2494 strf( |
| 2473 strf( | 2495 urls.length == 1 ? |
| 2474 urls.length == 1 ? | 2496 'OFFLINE_MESSAGE' : |
| 2475 'OFFLINE_MESSAGE' : | 2497 'OFFLINE_MESSAGE_PLURAL', |
| 2476 'OFFLINE_MESSAGE_PLURAL', | 2498 str('OFFLINE_COLUMN_LABEL'))); |
| 2477 str('OFFLINE_COLUMN_LABEL'))); | 2499 return; |
| 2478 return; | |
| 2479 } | |
| 2480 } | 2500 } |
| 2481 callback(urls); | 2501 callback(urls); |
| 2482 }.bind(this)); | 2502 }.bind(this)); |
| 2483 } else { | 2503 } else { |
| 2484 callback(urls); | 2504 callback(urls); |
| 2485 } | 2505 } |
| 2486 }; | 2506 }; |
| 2487 | 2507 |
| 2488 FileManager.prototype.isOffline = function() { | |
| 2489 return !navigator.onLine; | |
| 2490 }; | |
| 2491 | |
| 2492 FileManager.prototype.onOnlineOffline_ = function() { | 2508 FileManager.prototype.onOnlineOffline_ = function() { |
| 2493 if (this.isOffline()) { | 2509 if (util.isOffline()) { |
| 2494 console.log('OFFLINE'); | 2510 console.log('OFFLINE'); |
| 2495 this.dialogContainer_.setAttribute('offline', true); | 2511 this.dialogContainer_.setAttribute('offline', true); |
| 2496 } else { | 2512 } else { |
| 2497 console.log('ONLINE'); | 2513 console.log('ONLINE'); |
| 2498 this.dialogContainer_.removeAttribute('offline'); | 2514 this.dialogContainer_.removeAttribute('offline'); |
| 2499 } | 2515 } |
| 2500 }; | 2516 }; |
| 2501 | 2517 |
| 2502 FileManager.prototype.isOnGDataOffline = function() { | 2518 FileManager.prototype.isOnGDataOffline = function() { |
| 2503 return this.isOnGData() && this.isOffline(); | 2519 return this.isOnGData() && util.isOffline(); |
| 2504 }; | 2520 }; |
| 2505 | 2521 |
| 2506 FileManager.prototype.isOnReadonlyDirectory = function() { | 2522 FileManager.prototype.isOnReadonlyDirectory = function() { |
| 2507 return this.directoryModel_.isReadOnly(); | 2523 return this.directoryModel_.isReadOnly(); |
| 2508 }; | 2524 }; |
| 2509 | 2525 |
| 2510 /** | 2526 /** |
| 2511 * Event handler called when some volume was mounted or unmouted. | 2527 * Event handler called when some volume was mounted or unmouted. |
| 2512 */ | 2528 */ |
| 2513 FileManager.prototype.onMountCompleted_ = function(event) { | 2529 FileManager.prototype.onMountCompleted_ = function(event) { |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3069 strf('GDATA_OUT_OF_SPACE_MESSAGE', | 3085 strf('GDATA_OUT_OF_SPACE_MESSAGE', |
| 3070 util.bytesToSi(filesystem.size))); | 3086 util.bytesToSi(filesystem.size))); |
| 3071 }); | 3087 }); |
| 3072 } | 3088 } |
| 3073 // We don't have update events yet, so clear the cached data. | 3089 // We don't have update events yet, so clear the cached data. |
| 3074 self.metadataCache_.clear(entry, 'gdata'); | 3090 self.metadataCache_.clear(entry, 'gdata'); |
| 3075 checkbox.checked = props[0].isPinned; | 3091 checkbox.checked = props[0].isPinned; |
| 3076 } | 3092 } |
| 3077 var pin = checkbox.checked; | 3093 var pin = checkbox.checked; |
| 3078 this.metadataCache_.get(entry, 'gdata', function(gdata) { | 3094 this.metadataCache_.get(entry, 'gdata', function(gdata) { |
| 3079 if (self.isOffline() && pin && !gdata.present) { | 3095 if (util.isOffline() && pin && !gdata.present) { |
| 3080 // If we are offline, we cannot pin a file that is not already present. | 3096 // If we are offline, we cannot pin a file that is not already present. |
| 3081 checkbox.checked = false; // Revert the default action. | 3097 checkbox.checked = false; // Revert the default action. |
| 3082 self.alert.showHtml( | 3098 self.alert.showHtml( |
| 3083 str('OFFLINE_HEADER'), | 3099 str('OFFLINE_HEADER'), |
| 3084 strf('OFFLINE_MESSAGE', str('OFFLINE_COLUMN_LABEL'))); | 3100 strf('OFFLINE_MESSAGE', str('OFFLINE_COLUMN_LABEL'))); |
| 3085 return; | 3101 return; |
| 3086 } | 3102 } |
| 3087 chrome.fileBrowserPrivate.pinGDataFile([entry.toURL()], pin, callback); | 3103 chrome.fileBrowserPrivate.pinGDataFile([entry.toURL()], pin, callback); |
| 3088 }); | 3104 }); |
| 3089 event.preventDefault(); | 3105 event.preventDefault(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3182 this.updateSelectAllCheckboxState_(selectAllCheckbox); | 3198 this.updateSelectAllCheckboxState_(selectAllCheckbox); |
| 3183 }; | 3199 }; |
| 3184 | 3200 |
| 3185 FileManager.prototype.updateOkButton_ = function(event) { | 3201 FileManager.prototype.updateOkButton_ = function(event) { |
| 3186 var selectable; | 3202 var selectable; |
| 3187 | 3203 |
| 3188 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { | 3204 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { |
| 3189 selectable = this.selection.directoryCount == 1 && | 3205 selectable = this.selection.directoryCount == 1 && |
| 3190 this.selection.fileCount == 0; | 3206 this.selection.fileCount == 0; |
| 3191 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { | 3207 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { |
| 3192 selectable = (this.selection.directoryCount == 0 && | 3208 selectable = (this.isSelectionAvailable() && |
| 3209 this.selection.directoryCount == 0 && |
| 3193 this.selection.fileCount == 1); | 3210 this.selection.fileCount == 1); |
| 3194 } else if (this.dialogType_ == | 3211 } else if (this.dialogType_ == |
| 3195 FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { | 3212 FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { |
| 3196 selectable = (this.selection.directoryCount == 0 && | 3213 selectable = (this.isSelectionAvailable() && |
| 3214 this.selection.directoryCount == 0 && |
| 3197 this.selection.fileCount >= 1); | 3215 this.selection.fileCount >= 1); |
| 3198 } else if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { | 3216 } else if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { |
| 3199 if (this.isOnReadonlyDirectory()) { | 3217 if (this.isOnReadonlyDirectory()) { |
| 3200 selectable = false; | 3218 selectable = false; |
| 3201 } else { | 3219 } else { |
| 3202 selectable = !!this.filenameInput_.value; | 3220 selectable = !!this.filenameInput_.value; |
| 3203 } | 3221 } |
| 3204 } else if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { | 3222 } else if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { |
| 3205 // No "select" buttons on the full page UI. | 3223 // No "select" buttons on the full page UI. |
| 3206 selectable = true; | 3224 selectable = true; |
| (...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4226 | 4244 |
| 4227 handleSplitterDragEnd: function(e) { | 4245 handleSplitterDragEnd: function(e) { |
| 4228 Splitter.prototype.handleSplitterDragEnd.apply(this, arguments); | 4246 Splitter.prototype.handleSplitterDragEnd.apply(this, arguments); |
| 4229 this.ownerDocument.documentElement.classList.remove('col-resize'); | 4247 this.ownerDocument.documentElement.classList.remove('col-resize'); |
| 4230 } | 4248 } |
| 4231 }; | 4249 }; |
| 4232 | 4250 |
| 4233 customSplitter.decorate(splitterElement); | 4251 customSplitter.decorate(splitterElement); |
| 4234 }; | 4252 }; |
| 4235 })(); | 4253 })(); |
| OLD | NEW |