Chromium Code Reviews| 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 var MAX_DRAG_THUMBAIL_COUNT = 4; | 5 var MAX_DRAG_THUMBAIL_COUNT = 4; |
| 6 | 6 |
| 7 function FileTransferController(fileList, | 7 function FileTransferController(fileList, |
| 8 fileListSelection, | 8 fileListSelection, |
| 9 dragNodeConstructor, | 9 dragNodeConstructor, |
| 10 copyManager, | 10 copyManager, |
| 11 directoryModel) { | 11 directoryModel, |
| 12 commands) { | |
| 12 this.fileList_ = fileList; | 13 this.fileList_ = fileList; |
| 13 this.fileListSelection_ = fileListSelection; | 14 this.fileListSelection_ = fileListSelection; |
| 14 this.dragNodeConstructor_ = dragNodeConstructor; | 15 this.dragNodeConstructor_ = dragNodeConstructor; |
| 15 this.copyManager_ = copyManager; | 16 this.copyManager_ = copyManager; |
| 16 this.directoryModel_ = directoryModel; | 17 this.directoryModel_ = directoryModel; |
| 18 this.commands_ = commands; | |
| 17 | 19 |
| 18 this.fileListSelection_.addEventListener('change', | 20 this.fileListSelection_.addEventListener('change', |
| 19 this.onSelectionChanged_.bind(this)); | 21 this.onSelectionChanged_.bind(this)); |
| 20 | 22 |
| 21 /** | 23 /** |
| 22 * DOM elements to represent selected files in drag operation. | 24 * DOM elements to represent selected files in drag operation. |
| 23 * @type {Array.<Element>} | 25 * @type {Array.<Element>} |
| 24 */ | 26 */ |
| 25 this.dragNodes_ = []; | 27 this.dragNodes_ = []; |
| 26 | 28 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 * Attach handlers of copy, cut and paste operations to the document. | 62 * Attach handlers of copy, cut and paste operations to the document. |
| 61 * @param {HTMLDocument} doc Command dispatcher. | 63 * @param {HTMLDocument} doc Command dispatcher. |
| 62 */ | 64 */ |
| 63 attachCopyPasteHandlers: function(doc) { | 65 attachCopyPasteHandlers: function(doc) { |
| 64 this.document_ = doc; | 66 this.document_ = doc; |
| 65 doc.addEventListener('beforecopy', this.onBeforeCopy_.bind(this)); | 67 doc.addEventListener('beforecopy', this.onBeforeCopy_.bind(this)); |
| 66 doc.addEventListener('copy', this.onCopy_.bind(this)); | 68 doc.addEventListener('copy', this.onCopy_.bind(this)); |
| 67 doc.addEventListener('beforecut', this.onBeforeCut_.bind(this)); | 69 doc.addEventListener('beforecut', this.onBeforeCut_.bind(this)); |
| 68 doc.addEventListener('cut', this.onCut_.bind(this)); | 70 doc.addEventListener('cut', this.onCut_.bind(this)); |
| 69 doc.addEventListener('beforepaste', this.onBeforePaste_.bind(this)); | 71 doc.addEventListener('beforepaste', this.onBeforePaste_.bind(this)); |
| 70 doc.addEventListener('paste', this.onPaste_.bind(this)); | 72 doc.addEventListener('paste', this.onPaste_.bind(this)); |
|
SeRya
2012/04/25 09:57:03
My suggestion is:
this.copyCommand_ = doc.querySe
| |
| 71 }, | 73 }, |
| 72 | 74 |
| 73 /** | 75 /** |
| 74 * Write the current selection to system clipboard. | 76 * Write the current selection to system clipboard. |
| 75 * | 77 * |
| 76 * @param {Clipboard} clipboard Clipboard from the event. | 78 * @param {Clipboard} clipboard Clipboard from the event. |
| 77 * @param {string} effectAllowed Value must be valid for the | 79 * @param {string} effectAllowed Value must be valid for the |
| 78 * |dataTransfer.effectAllowed| property ('move', 'copy', 'copyMove'). | 80 * |dataTransfer.effectAllowed| property ('move', 'copy', 'copyMove'). |
| 79 */ | 81 */ |
| 80 cutOrCopy: function(dataTransfer, effectAllowed) { | 82 cutOrCopy: function(dataTransfer, effectAllowed) { |
| 81 var directories = []; | 83 var directories = []; |
| 82 var files = []; | 84 var files = []; |
| 83 var entries = this.selectedEntries_; | 85 var entries = this.selectedEntries_; |
| 84 for (var i = 0; i < entries.length; i++) { | 86 for (var i = 0; i < entries.length; i++) { |
| 85 (entries[i].isDirectory ? directories : files).push(entries[i].fullPath); | 87 (entries[i].isDirectory ? directories : files).push(entries[i].fullPath); |
| 86 } | 88 } |
| 87 | 89 |
| 88 // Tag to check it's filemanager data. | 90 // Tag to check it's filemanager data. |
| 89 dataTransfer.setData('fs/tag', 'filemanager-data'); | 91 dataTransfer.setData('fs/tag', 'filemanager-data'); |
| 90 | 92 |
| 91 dataTransfer.setData('fs/isOnGData', this.isOnGData); | 93 dataTransfer.setData('fs/isOnGData', this.isOnGData); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 | 249 |
| 248 onBeforeCopy_: function(event) { | 250 onBeforeCopy_: function(event) { |
| 249 if (!this.isDocumentWideEvent_(event)) | 251 if (!this.isDocumentWideEvent_(event)) |
| 250 return; | 252 return; |
| 251 | 253 |
| 252 // queryCommandEnabled returns true if event.returnValue is false. | 254 // queryCommandEnabled returns true if event.returnValue is false. |
| 253 event.returnValue = !this.canCopyOrDrag_(); | 255 event.returnValue = !this.canCopyOrDrag_(); |
| 254 }, | 256 }, |
| 255 | 257 |
| 256 canCopyOrDrag_: function() { | 258 canCopyOrDrag_: function() { |
| 259 if (this.isOnGData && | |
| 260 this.directoryModel_.offline && | |
| 261 !this.allGDataFilesAvailable) | |
| 262 return false; | |
| 257 return this.selectedEntries_.length > 0; | 263 return this.selectedEntries_.length > 0; |
| 258 }, | 264 }, |
| 259 | 265 |
| 260 onCut_: function(event) { | 266 onCut_: function(event) { |
| 261 if (!this.isDocumentWideEvent_(event) || | 267 if (!this.isDocumentWideEvent_(event) || |
| 262 !this.canCutOrDrag_()) { | 268 !this.canCutOrDrag_()) { |
| 263 return; | 269 return; |
| 264 } | 270 } |
| 265 event.preventDefault(); | 271 event.preventDefault(); |
| 266 this.cutOrCopy(event.clipboardData, 'move'); | 272 this.cutOrCopy(event.clipboardData, 'move'); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 // asynchronous operations. | 370 // asynchronous operations. |
| 365 if (!this.isOnGData && entries[i].isFile) | 371 if (!this.isOnGData && entries[i].isFile) |
| 366 entries[i].file(function(file) { files.push(file); }); | 372 entries[i].file(function(file) { files.push(file); }); |
| 367 | 373 |
| 368 // Items to drag are created in advance. Images must be loaded | 374 // Items to drag are created in advance. Images must be loaded |
| 369 // at the time the 'dragstart' event comes. Otherwise draggable | 375 // at the time the 'dragstart' event comes. Otherwise draggable |
| 370 // image will be rendered without IMG tags. | 376 // image will be rendered without IMG tags. |
| 371 if (dragNodes.length < MAX_DRAG_THUMBAIL_COUNT) | 377 if (dragNodes.length < MAX_DRAG_THUMBAIL_COUNT) |
| 372 dragNodes.push(new this.dragNodeConstructor_(entries[i])); | 378 dragNodes.push(new this.dragNodeConstructor_(entries[i])); |
| 373 } | 379 } |
| 380 | |
| 381 if (this.isOnGData) { | |
| 382 this.allGDataFilesAvailable = false; | |
| 383 var urls = entries.map(function(e) { return e.toURL() }); | |
| 384 FileType.checkOfflineAvailability(entries, urls, function(result) { | |
| 385 this.allGDataFilesAvailable = result; | |
| 386 // |Copy| is the only menu item affected by allGDataFilesAvailable. | |
| 387 // It could be open right now, update its UI. | |
| 388 this.commands_['copy'].disabled = !this.canCopyOrDrag_(); | |
| 389 }.bind(this)); | |
| 390 } | |
| 374 }, | 391 }, |
| 375 | 392 |
| 376 get currentDirectory() { | 393 get currentDirectory() { |
| 377 return this.directoryModel_.currentEntry; | 394 return this.directoryModel_.currentEntry; |
| 378 }, | 395 }, |
| 379 | 396 |
| 380 get readonly() { | 397 get readonly() { |
| 381 return this.directoryModel_.readonly; | 398 return this.directoryModel_.readonly; |
| 382 }, | 399 }, |
| 383 | 400 |
| 384 get isOnGData() { | 401 get isOnGData() { |
| 385 return this.directoryModel_.rootType == DirectoryModel.RootType.GDATA; | 402 return this.directoryModel_.isOnGData; |
| 386 }, | 403 }, |
| 387 | 404 |
| 388 notify_: function(eventName) { | 405 notify_: function(eventName) { |
| 389 var self = this; | 406 var self = this; |
| 390 // Set timeout to avoid recursive events. | 407 // Set timeout to avoid recursive events. |
| 391 setTimeout(function() { | 408 setTimeout(function() { |
| 392 cr.dispatchSimpleEvent(self, eventName); | 409 cr.dispatchSimpleEvent(self, eventName); |
| 393 }, 0); | 410 }, 0); |
| 394 }, | 411 }, |
| 395 | 412 |
| 396 /** | 413 /** |
| 397 * @type {Array.<Entry>} | 414 * @type {Array.<Entry>} |
| 398 */ | 415 */ |
| 399 get selectedEntries_() { | 416 get selectedEntries_() { |
| 400 var list = this.fileList_; | 417 var list = this.fileList_; |
| 401 return this.fileListSelection_.selectedIndexes.map(function(index) { | 418 return this.fileListSelection_.selectedIndexes.map(function(index) { |
| 402 return list.item(index); | 419 return list.item(index); |
| 403 }); | 420 }); |
| 404 } | 421 } |
| 405 }; | 422 }; |
| 406 | 423 |
| OLD | NEW |