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 // Setting the src of an img to an empty string can crash the browser, so we | 5 // Setting the src of an img to an empty string can crash the browser, so we |
6 // use an empty 1x1 gif instead. | 6 // use an empty 1x1 gif instead. |
7 | 7 |
8 /** | 8 /** |
9 * FileManager constructor. | 9 * FileManager constructor. |
10 * | 10 * |
(...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1270 this.table_.querySelector('.list').addEventListener( | 1270 this.table_.querySelector('.list').addEventListener( |
1271 'dblclick', this.onDetailDoubleClick_.bind(this)); | 1271 'dblclick', this.onDetailDoubleClick_.bind(this)); |
1272 | 1272 |
1273 cr.ui.contextMenuHandler.setContextMenu(this.table_.querySelector('.list'), | 1273 cr.ui.contextMenuHandler.setContextMenu(this.table_.querySelector('.list'), |
1274 this.fileContextMenu_); | 1274 this.fileContextMenu_); |
1275 | 1275 |
1276 this.table_.addEventListener('mousedown', | 1276 this.table_.addEventListener('mousedown', |
1277 this.onGridOrTableMouseDown_.bind(this)); | 1277 this.onGridOrTableMouseDown_.bind(this)); |
1278 }; | 1278 }; |
1279 | 1279 |
| 1280 FileManager.prototype.initButter_ = function() { |
| 1281 var self = this; |
| 1282 var progress = this.copyManager_.getProgress(); |
| 1283 |
| 1284 var options = {progress: progress.percentage, actions:{}}; |
| 1285 options.actions[str('CANCEL_LABEL')] = function cancelPaste() { |
| 1286 self.copyManager_.requestCancel(); |
| 1287 }; |
| 1288 this.showButter(strf('PASTE_ITEMS_REMAINING', progress.pendingItems), |
| 1289 options); |
| 1290 }; |
| 1291 |
1280 FileManager.prototype.onCopyProgress_ = function(event) { | 1292 FileManager.prototype.onCopyProgress_ = function(event) { |
1281 var status = this.copyManager_.getStatus(); | 1293 var progress = this.copyManager_.getProgress(); |
1282 | |
1283 // TODO(bshe): Need to figure out a way to get completed bytes in real | |
1284 // time. We currently use completedItems and totalItems to estimate the | |
1285 // progress. There are completeBytes and totalBytes ready to use. | |
1286 // However, the completedBytes is not in real time. It only updates | |
1287 // itself after each item finished. So if there is a large item to | |
1288 // copy, the progress bar will stop moving until it finishes and jump | |
1289 // a large portion of the bar. | |
1290 // There is case that when user copy a large file, we want to show an | |
1291 // 100% animated progress bar. So we use completedItems + 1 here. | |
1292 var progress = (status.completedItems + 1) / status.totalItems; | |
1293 | |
1294 // If the files we're copying is larger than 100MB or more than 25, | |
1295 // update the user on the current status with a progress bar and give | |
1296 // an option to cancel. The rule of thumb here is if the pasting | |
1297 // process is less than 500ms. We dont want to show progress bar. | |
1298 var shouldShow = status.totalItems > 0 && | |
1299 status.completedItems < status.totalItems && | |
1300 (status.totalBytes > 100000000 || status.totalItems > 25); | |
1301 | 1294 |
1302 if (event.reason == 'BEGIN') { | 1295 if (event.reason == 'BEGIN') { |
1303 if (shouldShow) { | |
1304 var self = this; | |
1305 var options = {timeout:0, progress: progress, actions:{}}; | |
1306 // We can't cancel the operation when pasting one file. | |
1307 if (status.totalItems > 1) { | |
1308 options.actions[str('CANCEL_LABEL')] = function cancelPaste() { | |
1309 self.copyManager_.requestCancel(); | |
1310 }; | |
1311 } | |
1312 this.showButter(strf('PASTE_ITEMS_REMAINING', status.pendingItems), | |
1313 options); | |
1314 } | |
1315 } | |
1316 else if (event.reason == 'PROGRESS') { | |
1317 if (shouldShow) { | |
1318 var options = {timeout:0, progress: progress}; | |
1319 this.updateButter(strf('PASTE_ITEMS_REMAINING', status.pendingItems), | |
1320 options); | |
1321 } | |
1322 } | |
1323 else if (event.reason == 'SUCCESS') { | |
1324 if (this.currentButter_) | 1296 if (this.currentButter_) |
1325 this.hideButter(); | 1297 this.hideButter(); |
1326 | 1298 |
| 1299 clearTimeout(this.butterTimeout_); |
| 1300 // If the copy process lasts more than 500 ms, we show a progress bar. |
| 1301 this.butterTimeout_ = setTimeout(this.initButter_.bind(this), 500); |
| 1302 return; |
| 1303 } |
| 1304 if (event.reason == 'PROGRESS') { |
| 1305 // Perform this check inside Progress event handler, avoid to log error |
| 1306 // message 'Unknown event reason: PROGRESS' in console. |
| 1307 if (this.currentButter_) { |
| 1308 var options = {progress: progress.percentage}; |
| 1309 this.updateButter(strf('PASTE_ITEMS_REMAINING', progress.pendingItems), |
| 1310 options); |
| 1311 } |
| 1312 return; |
| 1313 } |
| 1314 if (event.reason == 'SUCCESS') { |
| 1315 clearTimeout(this.butterTimeout_); |
| 1316 if (this.currentButter_) |
| 1317 this.hideButter(); |
| 1318 |
1327 this.updateCommands_(); | 1319 this.updateCommands_(); |
1328 self = this; | 1320 self = this; |
1329 var callback; | 1321 var callback; |
1330 while (callback = self.pasteSuccessCallbacks_.shift()) { | 1322 while (callback = self.pasteSuccessCallbacks_.shift()) { |
1331 try { | 1323 try { |
1332 callback(); | 1324 callback(); |
1333 } catch (ex) { | 1325 } catch (ex) { |
1334 console.error('Caught exception while inovking callback: ' + | 1326 console.error('Caught exception while inovking callback: ' + |
1335 callback, ex); | 1327 callback, ex); |
1336 } | 1328 } |
1337 } | 1329 } |
1338 // TODO(benchan): Currently, there is no FileWatcher emulation for | 1330 // TODO(benchan): Currently, there is no FileWatcher emulation for |
1339 // GDataFileSystem, so we need to manually trigger the directory rescan | 1331 // GDataFileSystem, so we need to manually trigger the directory rescan |
1340 // after paste operations complete. Remove this once we emulate file | 1332 // after paste operations complete. Remove this once we emulate file |
1341 // watching functionalities in GDataFileSystem. | 1333 // watching functionalities in GDataFileSystem. |
1342 if (this.isOnGData()) { | 1334 if (this.isOnGData()) { |
1343 this.directoryModel_.rescanLater(); | 1335 this.directoryModel_.rescanLater(); |
1344 } | 1336 } |
1345 } else if (event.reason == 'ERROR') { | 1337 } else if (event.reason == 'ERROR') { |
| 1338 clearTimeout(this.butterTimeout_); |
1346 switch (event.error.reason) { | 1339 switch (event.error.reason) { |
1347 case 'TARGET_EXISTS': | 1340 case 'TARGET_EXISTS': |
1348 var name = event.error.data.name; | 1341 var name = event.error.data.name; |
1349 if (event.error.data.isDirectory) | 1342 if (event.error.data.isDirectory) |
1350 name += '/'; | 1343 name += '/'; |
1351 this.showButterError(strf('PASTE_TARGET_EXISTS_ERROR', name)); | 1344 this.showButterError(strf('PASTE_TARGET_EXISTS_ERROR', name)); |
1352 break; | 1345 break; |
1353 | 1346 |
1354 case 'FILESYSTEM_ERROR': | 1347 case 'FILESYSTEM_ERROR': |
1355 this.showButterError( | 1348 this.showButterError( |
(...skipping 1634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2990 | 2983 |
2991 /** | 2984 /** |
2992 * Queue up a file copy operation based on the current system clipboard. | 2985 * Queue up a file copy operation based on the current system clipboard. |
2993 */ | 2986 */ |
2994 FileManager.prototype.pasteFromClipboard_ = function(event) { | 2987 FileManager.prototype.pasteFromClipboard_ = function(event) { |
2995 event.preventDefault(); | 2988 event.preventDefault(); |
2996 | 2989 |
2997 if (!event.clipboardData.getData('fs/isCut')) | 2990 if (!event.clipboardData.getData('fs/isCut')) |
2998 return; | 2991 return; |
2999 | 2992 |
3000 // Pass an empty string so that the butter bar remains invisible until | |
3001 // the first progress update. This prevents the flicker on short operations. | |
3002 this.showButter('', {timeout: 0}); | |
3003 | |
3004 var clipboard = { | 2993 var clipboard = { |
3005 isCut: event.clipboardData.getData('fs/isCut'), | 2994 isCut: event.clipboardData.getData('fs/isCut'), |
3006 sourceDir: event.clipboardData.getData('fs/sourceDir'), | 2995 sourceDir: event.clipboardData.getData('fs/sourceDir'), |
3007 sourceOnGData: event.clipboardData.getData('fs/sourceOnGData'), | 2996 sourceOnGData: event.clipboardData.getData('fs/sourceOnGData'), |
3008 directories: event.clipboardData.getData('fs/directories'), | 2997 directories: event.clipboardData.getData('fs/directories'), |
3009 files: event.clipboardData.getData('fs/files') | 2998 files: event.clipboardData.getData('fs/files') |
3010 }; | 2999 }; |
3011 | 3000 |
3012 // If both source and target are on GData, FileCopyManager uses | 3001 // If both source and target are on GData, FileCopyManager uses |
3013 // FileEntry.copyTo() / FileEntry.moveTo() to copy / move files. | 3002 // FileEntry.copyTo() / FileEntry.moveTo() to copy / move files. |
(...skipping 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4162 }); | 4151 }); |
4163 }, onError); | 4152 }, onError); |
4164 | 4153 |
4165 function onError(err) { | 4154 function onError(err) { |
4166 console.log('Error while checking free space: ' + err); | 4155 console.log('Error while checking free space: ' + err); |
4167 setTimeout(doCheck, 1000 * 60); | 4156 setTimeout(doCheck, 1000 * 60); |
4168 } | 4157 } |
4169 } | 4158 } |
4170 } | 4159 } |
4171 })(); | 4160 })(); |
OLD | NEW |