Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: chrome/browser/resources/file_manager/js/file_transfer_controller.js

Issue 10184005: [File Manager] Properly enable/disable Copy and Open for GData files in the offline mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 * @param {HTMLDocument} doc Command dispatcher. 68 * @param {HTMLDocument} doc Command dispatcher.
69 */ 69 */
70 attachCopyPasteHandlers: function(doc) { 70 attachCopyPasteHandlers: function(doc) {
71 this.document_ = doc; 71 this.document_ = doc;
72 doc.addEventListener('beforecopy', this.onBeforeCopy_.bind(this)); 72 doc.addEventListener('beforecopy', this.onBeforeCopy_.bind(this));
73 doc.addEventListener('copy', this.onCopy_.bind(this)); 73 doc.addEventListener('copy', this.onCopy_.bind(this));
74 doc.addEventListener('beforecut', this.onBeforeCut_.bind(this)); 74 doc.addEventListener('beforecut', this.onBeforeCut_.bind(this));
75 doc.addEventListener('cut', this.onCut_.bind(this)); 75 doc.addEventListener('cut', this.onCut_.bind(this));
76 doc.addEventListener('beforepaste', this.onBeforePaste_.bind(this)); 76 doc.addEventListener('beforepaste', this.onBeforePaste_.bind(this));
77 doc.addEventListener('paste', this.onPaste_.bind(this)); 77 doc.addEventListener('paste', this.onPaste_.bind(this));
78 this.copyCommand_ = doc.querySelector('command#copy');
78 }, 79 },
79 80
80 /** 81 /**
81 * Write the current selection to system clipboard. 82 * Write the current selection to system clipboard.
82 * 83 *
83 * @param {Clipboard} clipboard Clipboard from the event. 84 * @param {Clipboard} clipboard Clipboard from the event.
84 * @param {string} effectAllowed Value must be valid for the 85 * @param {string} effectAllowed Value must be valid for the
85 * |dataTransfer.effectAllowed| property ('move', 'copy', 'copyMove'). 86 * |dataTransfer.effectAllowed| property ('move', 'copy', 'copyMove').
86 */ 87 */
87 cutOrCopy: function(dataTransfer, effectAllowed) { 88 cutOrCopy: function(dataTransfer, effectAllowed) {
88 var directories = []; 89 var directories = [];
89 var files = []; 90 var files = [];
90 var entries = this.selectedEntries_; 91 var entries = this.selectedEntries_;
91 for (var i = 0; i < entries.length; i++) { 92 for (var i = 0; i < entries.length; i++) {
92 (entries[i].isDirectory ? directories : files).push(entries[i].fullPath); 93 (entries[i].isDirectory ? directories : files).push(entries[i].fullPath);
93 } 94 }
94 95
95 // Tag to check it's filemanager data. 96 // Tag to check it's filemanager data.
96 dataTransfer.setData('fs/tag', 'filemanager-data'); 97 dataTransfer.setData('fs/tag', 'filemanager-data');
97 98
98 dataTransfer.setData('fs/isOnGData', this.isOnGData); 99 dataTransfer.setData('fs/isOnGData', this.isOnGData);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 258
258 onBeforeCopy_: function(event) { 259 onBeforeCopy_: function(event) {
259 if (!this.isDocumentWideEvent_(event)) 260 if (!this.isDocumentWideEvent_(event))
260 return; 261 return;
261 262
262 // queryCommandEnabled returns true if event.returnValue is false. 263 // queryCommandEnabled returns true if event.returnValue is false.
263 event.returnValue = !this.canCopyOrDrag_(); 264 event.returnValue = !this.canCopyOrDrag_();
264 }, 265 },
265 266
266 canCopyOrDrag_: function() { 267 canCopyOrDrag_: function() {
268 if (this.isOnGData && util.isOffline() && !this.allGDataFilesAvailable)
269 return false;
267 return this.selectedEntries_.length > 0; 270 return this.selectedEntries_.length > 0;
268 }, 271 },
269 272
270 onCut_: function(event) { 273 onCut_: function(event) {
271 if (!this.isDocumentWideEvent_(event) || 274 if (!this.isDocumentWideEvent_(event) ||
272 !this.canCutOrDrag_()) { 275 !this.canCutOrDrag_()) {
273 return; 276 return;
274 } 277 }
275 event.preventDefault(); 278 event.preventDefault();
276 this.cutOrCopy(event.clipboardData, 'move'); 279 this.cutOrCopy(event.clipboardData, 'move');
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 // asynchronous operations. 379 // asynchronous operations.
377 if (!this.isOnGData && entries[i].isFile) 380 if (!this.isOnGData && entries[i].isFile)
378 entries[i].file(function(file) { files.push(file); }); 381 entries[i].file(function(file) { files.push(file); });
379 382
380 // Items to drag are created in advance. Images must be loaded 383 // Items to drag are created in advance. Images must be loaded
381 // at the time the 'dragstart' event comes. Otherwise draggable 384 // at the time the 'dragstart' event comes. Otherwise draggable
382 // image will be rendered without IMG tags. 385 // image will be rendered without IMG tags.
383 if (dragNodes.length < MAX_DRAG_THUMBAIL_COUNT) 386 if (dragNodes.length < MAX_DRAG_THUMBAIL_COUNT)
384 dragNodes.push(new this.dragNodeConstructor_(entries[i])); 387 dragNodes.push(new this.dragNodeConstructor_(entries[i]));
385 } 388 }
389
390 if (this.isOnGData) {
391 this.allGDataFilesAvailable = false;
392 var urls = entries.map(function(e) { return e.toURL() });
393 this.directoryModel_.getMetadataCache().get(
394 urls, 'gdata', function(props) {
395 // We consider directories not available offline for the purposes of
396 // file transfer since we cannot afford to recursive traversal.
397 this.allGDataFilesAvailable =
398 entries.filter(function(e) {return e.isDirectory}).length == 0 &&
399 props.filter(function(p) {return !p.availableOffline}).length == 0;
400 // |Copy| is the only menu item affected by allGDataFilesAvailable.
401 // It could be open right now, update its UI.
402 this.copyCommand_.disabled = !this.canCopyOrDrag_();
403 }.bind(this));
404 }
386 }, 405 },
387 406
388 get currentDirectory() { 407 get currentDirectory() {
389 return this.directoryModel_.getCurrentDirEntry(); 408 return this.directoryModel_.getCurrentDirEntry();
390 }, 409 },
391 410
392 get readonly() { 411 get readonly() {
393 return this.directoryModel_.isReadOnly(); 412 return this.directoryModel_.isReadOnly();
394 }, 413 },
395 414
(...skipping 13 matching lines...) Expand all
409 * @type {Array.<Entry>} 428 * @type {Array.<Entry>}
410 */ 429 */
411 get selectedEntries_() { 430 get selectedEntries_() {
412 var list = this.fileList_; 431 var list = this.fileList_;
413 return this.fileListSelection_.selectedIndexes.map(function(index) { 432 return this.fileListSelection_.selectedIndexes.map(function(index) {
414 return list.item(index); 433 return list.item(index);
415 }); 434 });
416 } 435 }
417 }; 436 };
418 437
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/js/file_manager.js ('k') | chrome/browser/resources/file_manager/js/util.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698