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 /** | 7 /** |
8 * TODO(olege): Fix style warnings. | 8 * TODO(olege): Fix style warnings. |
9 */ | 9 */ |
10 function FileTransferController(fileList, | 10 function FileTransferController(fileList, |
11 fileListSelection, | 11 fileListSelection, |
12 dragNodeConstructor, | 12 dragNodeConstructor, |
13 copyManager, | 13 copyManager, |
14 directoryModel) { | 14 directoryModel, |
15 metadataCache) { | |
15 this.fileList_ = fileList; | 16 this.fileList_ = fileList; |
16 this.fileListSelection_ = fileListSelection; | 17 this.fileListSelection_ = fileListSelection; |
17 this.dragNodeConstructor_ = dragNodeConstructor; | 18 this.dragNodeConstructor_ = dragNodeConstructor; |
18 this.copyManager_ = copyManager; | 19 this.copyManager_ = copyManager; |
19 this.directoryModel_ = directoryModel; | 20 this.directoryModel_ = directoryModel; |
21 this.metadataCache_ = metadataCache; | |
SeRya
2012/04/25 13:50:36
The parameter list tends to get huge. I't prefer a
| |
20 | 22 |
21 this.fileListSelection_.addEventListener('change', | 23 this.fileListSelection_.addEventListener('change', |
22 this.onSelectionChanged_.bind(this)); | 24 this.onSelectionChanged_.bind(this)); |
23 | 25 |
24 /** | 26 /** |
25 * DOM elements to represent selected files in drag operation. | 27 * DOM elements to represent selected files in drag operation. |
26 * @type {Array.<Element>} | 28 * @type {Array.<Element>} |
27 */ | 29 */ |
28 this.dragNodes_ = []; | 30 this.dragNodes_ = []; |
29 | 31 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 * @param {HTMLDocument} doc Command dispatcher. | 70 * @param {HTMLDocument} doc Command dispatcher. |
69 */ | 71 */ |
70 attachCopyPasteHandlers: function(doc) { | 72 attachCopyPasteHandlers: function(doc) { |
71 this.document_ = doc; | 73 this.document_ = doc; |
72 doc.addEventListener('beforecopy', this.onBeforeCopy_.bind(this)); | 74 doc.addEventListener('beforecopy', this.onBeforeCopy_.bind(this)); |
73 doc.addEventListener('copy', this.onCopy_.bind(this)); | 75 doc.addEventListener('copy', this.onCopy_.bind(this)); |
74 doc.addEventListener('beforecut', this.onBeforeCut_.bind(this)); | 76 doc.addEventListener('beforecut', this.onBeforeCut_.bind(this)); |
75 doc.addEventListener('cut', this.onCut_.bind(this)); | 77 doc.addEventListener('cut', this.onCut_.bind(this)); |
76 doc.addEventListener('beforepaste', this.onBeforePaste_.bind(this)); | 78 doc.addEventListener('beforepaste', this.onBeforePaste_.bind(this)); |
77 doc.addEventListener('paste', this.onPaste_.bind(this)); | 79 doc.addEventListener('paste', this.onPaste_.bind(this)); |
80 this.copyCommand_ = doc.querySelector('command#copy'); | |
78 }, | 81 }, |
79 | 82 |
80 /** | 83 /** |
81 * Write the current selection to system clipboard. | 84 * Write the current selection to system clipboard. |
82 * | 85 * |
83 * @param {Clipboard} clipboard Clipboard from the event. | 86 * @param {Clipboard} clipboard Clipboard from the event. |
84 * @param {string} effectAllowed Value must be valid for the | 87 * @param {string} effectAllowed Value must be valid for the |
85 * |dataTransfer.effectAllowed| property ('move', 'copy', 'copyMove'). | 88 * |dataTransfer.effectAllowed| property ('move', 'copy', 'copyMove'). |
86 */ | 89 */ |
87 cutOrCopy: function(dataTransfer, effectAllowed) { | 90 cutOrCopy: function(dataTransfer, effectAllowed) { |
88 var directories = []; | 91 var directories = []; |
89 var files = []; | 92 var files = []; |
90 var entries = this.selectedEntries_; | 93 var entries = this.selectedEntries_; |
91 for (var i = 0; i < entries.length; i++) { | 94 for (var i = 0; i < entries.length; i++) { |
92 (entries[i].isDirectory ? directories : files).push(entries[i].fullPath); | 95 (entries[i].isDirectory ? directories : files).push(entries[i].fullPath); |
93 } | 96 } |
94 | 97 |
95 // Tag to check it's filemanager data. | 98 // Tag to check it's filemanager data. |
96 dataTransfer.setData('fs/tag', 'filemanager-data'); | 99 dataTransfer.setData('fs/tag', 'filemanager-data'); |
97 | 100 |
98 dataTransfer.setData('fs/isOnGData', this.isOnGData); | 101 dataTransfer.setData('fs/isOnGData', this.isOnGData); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 | 260 |
258 onBeforeCopy_: function(event) { | 261 onBeforeCopy_: function(event) { |
259 if (!this.isDocumentWideEvent_(event)) | 262 if (!this.isDocumentWideEvent_(event)) |
260 return; | 263 return; |
261 | 264 |
262 // queryCommandEnabled returns true if event.returnValue is false. | 265 // queryCommandEnabled returns true if event.returnValue is false. |
263 event.returnValue = !this.canCopyOrDrag_(); | 266 event.returnValue = !this.canCopyOrDrag_(); |
264 }, | 267 }, |
265 | 268 |
266 canCopyOrDrag_: function() { | 269 canCopyOrDrag_: function() { |
270 if (this.isOnGData && util.isOffline() && !this.allGDataFilesAvailable) | |
271 return false; | |
267 return this.selectedEntries_.length > 0; | 272 return this.selectedEntries_.length > 0; |
268 }, | 273 }, |
269 | 274 |
270 onCut_: function(event) { | 275 onCut_: function(event) { |
271 if (!this.isDocumentWideEvent_(event) || | 276 if (!this.isDocumentWideEvent_(event) || |
272 !this.canCutOrDrag_()) { | 277 !this.canCutOrDrag_()) { |
273 return; | 278 return; |
274 } | 279 } |
275 event.preventDefault(); | 280 event.preventDefault(); |
276 this.cutOrCopy(event.clipboardData, 'move'); | 281 this.cutOrCopy(event.clipboardData, 'move'); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 // asynchronous operations. | 381 // asynchronous operations. |
377 if (!this.isOnGData && entries[i].isFile) | 382 if (!this.isOnGData && entries[i].isFile) |
378 entries[i].file(function(file) { files.push(file); }); | 383 entries[i].file(function(file) { files.push(file); }); |
379 | 384 |
380 // Items to drag are created in advance. Images must be loaded | 385 // Items to drag are created in advance. Images must be loaded |
381 // at the time the 'dragstart' event comes. Otherwise draggable | 386 // at the time the 'dragstart' event comes. Otherwise draggable |
382 // image will be rendered without IMG tags. | 387 // image will be rendered without IMG tags. |
383 if (dragNodes.length < MAX_DRAG_THUMBAIL_COUNT) | 388 if (dragNodes.length < MAX_DRAG_THUMBAIL_COUNT) |
384 dragNodes.push(new this.dragNodeConstructor_(entries[i])); | 389 dragNodes.push(new this.dragNodeConstructor_(entries[i])); |
385 } | 390 } |
391 | |
392 if (this.isOnGData) { | |
393 this.allGDataFilesAvailable = false; | |
394 var urls = entries.map(function(e) { return e.toURL() }); | |
395 this.metadataCache_.get(urls, 'gdata', function(props) { | |
396 // We consider directories not available offline for the purposes of | |
397 // file transfer since we cannot afford to recursive traversal. | |
398 this.allGDataFilesAvailable = | |
399 entries.filter(function(e) {return e.isDirectory}).length == 0 && | |
400 props.filter(function(p) {return !p.availableOffline}).length == 0; | |
401 // |Copy| is the only menu item affected by allGDataFilesAvailable. | |
402 // It could be open right now, update its UI. | |
403 this.copyCommand_.disabled = !this.canCopyOrDrag_(); | |
404 }.bind(this)); | |
405 } | |
386 }, | 406 }, |
387 | 407 |
388 get currentDirectory() { | 408 get currentDirectory() { |
389 return this.directoryModel_.getCurrentDirEntry(); | 409 return this.directoryModel_.getCurrentDirEntry(); |
390 }, | 410 }, |
391 | 411 |
392 get readonly() { | 412 get readonly() { |
393 return this.directoryModel_.isReadOnly(); | 413 return this.directoryModel_.isReadOnly(); |
394 }, | 414 }, |
395 | 415 |
(...skipping 13 matching lines...) Expand all Loading... | |
409 * @type {Array.<Entry>} | 429 * @type {Array.<Entry>} |
410 */ | 430 */ |
411 get selectedEntries_() { | 431 get selectedEntries_() { |
412 var list = this.fileList_; | 432 var list = this.fileList_; |
413 return this.fileListSelection_.selectedIndexes.map(function(index) { | 433 return this.fileListSelection_.selectedIndexes.map(function(index) { |
414 return list.item(index); | 434 return list.item(index); |
415 }); | 435 }); |
416 } | 436 } |
417 }; | 437 }; |
418 | 438 |
OLD | NEW |