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

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

Issue 10119007: [File Manager]Disable "Copy" command if selection contains dimmed GData files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed debugging code 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
« no previous file with comments | « chrome/browser/resources/file_manager/js/file_manager.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 function FileTransferController(fileList, 7 function FileTransferController(fileList,
8 fileListSelection, 8 fileListSelection,
9 dragNodeConstructor, 9 dragNodeConstructor,
10 copyManager, 10 copyManager,
11 directoryModel) { 11 directoryModel) {
12 this.fileList_ = fileList; 12 this.fileList_ = fileList;
13 this.fileListSelection_ = fileListSelection; 13 this.fileListSelection_ = fileListSelection;
14 this.dragNodeConstructor_ = dragNodeConstructor; 14 this.dragNodeConstructor_ = dragNodeConstructor;
15 this.copyManager_ = copyManager; 15 this.copyManager_ = copyManager;
16 this.directoryModel_ = directoryModel; 16 this.directoryModel_ = directoryModel;
17 17
18 this.fileListSelection_.addEventListener('change', 18 this.fileListSelection_.addEventListener('change',
19 this.onSelectionChanged_.bind(this)); 19 this.onSelectionChanged_.bind(this));
20 20
21 /** 21 /**
22 * DOM elements to represent selected files in drag operation. 22 * DOM elements to represent selected files in drag operation.
23 * @type {Array.<Element>} 23 * @type {Array.<Element>}
24 */ 24 */
25 this.dragNodes_ = []; 25 this.dragNodes_ = [];
26 26
27 /** 27 /**
28 * File objects for seletced files. 28 * File objects for selected files.
29 * @type {Array.<File>} 29 * @type {Array.<File>}
30 */ 30 */
31 this.files_ = []; 31 this.files_ = [];
32 32
33 } 33 }
34 34
35 FileTransferController.prototype = { 35 FileTransferController.prototype = {
36 __proto__: cr.EventTarget.prototype, 36 __proto__: cr.EventTarget.prototype,
37 37
38 /** 38 /**
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 }, 71 },
72 72
73 /** 73 /**
74 * Write the current selection to system clipboard. 74 * Write the current selection to system clipboard.
75 * 75 *
76 * @param {Clipboard} clipboard Clipboard from the event. 76 * @param {Clipboard} clipboard Clipboard from the event.
77 * @param {string} effectAllowed Value must be valid for the 77 * @param {string} effectAllowed Value must be valid for the
78 * |dataTransfer.effectAllowed| property ('move', 'copy', 'copyMove'). 78 * |dataTransfer.effectAllowed| property ('move', 'copy', 'copyMove').
79 */ 79 */
80 cutOrCopy: function(dataTransfer, effectAllowed) { 80 cutOrCopy: function(dataTransfer, effectAllowed) {
81 var directories = []; 81 var directories = [];
82 var files = []; 82 var files = [];
83 var entries = this.selectedEntries_; 83 var entries = this.selectedEntries_;
84 for (var i = 0; i < entries.length; i++) { 84 for (var i = 0; i < entries.length; i++) {
85 (entries[i].isDirectory ? directories : files).push(entries[i].fullPath); 85 (entries[i].isDirectory ? directories : files).push(entries[i].fullPath);
86 } 86 }
87 87
88 // Tag to check it's filemanager data. 88 // Tag to check it's filemanager data.
89 dataTransfer.setData('fs/tag', 'filemanager-data'); 89 dataTransfer.setData('fs/tag', 'filemanager-data');
90 90
91 dataTransfer.setData('fs/isOnGData', this.isOnGData); 91 dataTransfer.setData('fs/isOnGData', this.isOnGData);
92 dataTransfer.setData('fs/sourceDir', 92 dataTransfer.setData('fs/sourceDir',
93 this.currentDirectory.fullPath); 93 this.currentDirectory.fullPath);
94 dataTransfer.setData('fs/directories', directories.join('\n')); 94 dataTransfer.setData('fs/directories', directories.join('\n'));
95 dataTransfer.setData('fs/files', files.join('\n')); 95 dataTransfer.setData('fs/files', files.join('\n'));
96 dataTransfer.effectAllowed = effectAllowed; 96 dataTransfer.effectAllowed = effectAllowed;
97 dataTransfer.setData('fs/effectallowed', effectAllowed); 97 dataTransfer.setData('fs/effectallowed', effectAllowed);
98 98
99 for (var i = 0; i < this.files_.length; i++) { 99 for (var i = 0; i < this.files_.length; i++) {
100 dataTransfer.items.add(this.files_[i]); 100 dataTransfer.items.add(this.files_[i]);
101 } 101 }
102 }, 102 },
103 103
104 /** 104 /**
105 * Queue up a file copy operation based on the current system clipboard. 105 * Queue up a file copy operation based on the current system clipboard.
106 * @param {DataTransfer} dataTransfer System data transfer object. 106 * @param {DataTransfer} dataTransfer System data transfer object.
107 * @param {DirectoryEntry=} opt_destination Paste destination. 107 * @param {DirectoryEntry=} opt_destination Paste destination.
108 * @return {string} "move"|"copy"
108 */ 109 */
109 paste: function(dataTransfer, opt_destination) { 110 paste: function(dataTransfer, opt_destination) {
110 var destination = opt_destination || this.currentDirectory; 111 var destination = opt_destination || this.currentDirectory;
111 // effectAllowed set in copy/pase handlers stay uninitialized. DnD handlers 112 // effectAllowed set in copy/pase handlers stay uninitialized. DnD handlers
112 // work fine. 113 // work fine.
113 var effectAllowed = dataTransfer.effectAllowed != 'uninitialized' ? 114 var effectAllowed = dataTransfer.effectAllowed != 'uninitialized' ?
114 dataTransfer.effectAllowed : dataTransfer.getData('fs/effectallowed'); 115 dataTransfer.effectAllowed : dataTransfer.getData('fs/effectallowed');
115 116
116 var toMove = effectAllowed == 'move' || 117 var toMove = effectAllowed == 'move' ||
117 (effectAllowed == 'copyMove' && dataTransfer.dropEffect != 'copy'); 118 (effectAllowed == 'copyMove' && dataTransfer.dropEffect != 'copy');
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 248
248 onBeforeCopy_: function(event) { 249 onBeforeCopy_: function(event) {
249 if (!this.isDocumentWideEvent_(event)) 250 if (!this.isDocumentWideEvent_(event))
250 return; 251 return;
251 252
252 // queryCommandEnabled returns true if event.returnValue is false. 253 // queryCommandEnabled returns true if event.returnValue is false.
253 event.returnValue = !this.canCopyOrDrag_(); 254 event.returnValue = !this.canCopyOrDrag_();
254 }, 255 },
255 256
256 canCopyOrDrag_: function() { 257 canCopyOrDrag_: function() {
257 return this.selectedEntries_.length > 0; 258 return this.selectionAvailable_ && this.selectedEntries_.length > 0;
258 }, 259 },
259 260
260 onCut_: function(event) { 261 onCut_: function(event) {
261 if (!this.isDocumentWideEvent_(event) || 262 if (!this.isDocumentWideEvent_(event) ||
262 !this.canCutOrDrag_()) { 263 !this.canCutOrDrag_()) {
263 return; 264 return;
264 } 265 }
265 event.preventDefault(); 266 event.preventDefault();
266 this.cutOrCopy(event.clipboardData, 'move'); 267 this.cutOrCopy(event.clipboardData, 'move');
267 this.notify_('selection-cut'); 268 this.notify_('selection-cut');
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 }, 375 },
375 376
376 get currentDirectory() { 377 get currentDirectory() {
377 return this.directoryModel_.currentEntry; 378 return this.directoryModel_.currentEntry;
378 }, 379 },
379 380
380 get readonly() { 381 get readonly() {
381 return this.directoryModel_.readonly; 382 return this.directoryModel_.readonly;
382 }, 383 },
383 384
385 set selectionAvailable(available) {
386 this.selectionAvailable_ = available;
dgozman 2012/04/18 16:07:37 I don't like this 'set from outside to work proper
Vladislav Kaznacheev 2012/04/18 16:36:24 Yeah, I hate it myself. But asking the file manage
387 },
388
384 get isOnGData() { 389 get isOnGData() {
385 return this.directoryModel_.rootType == DirectoryModel.RootType.GDATA; 390 return this.directoryModel_.rootType == DirectoryModel.RootType.GDATA;
386 }, 391 },
387 392
388 notify_: function(eventName) { 393 notify_: function(eventName) {
389 var self = this; 394 var self = this;
390 // Set timeout to avoid recursive events. 395 // Set timeout to avoid recursive events.
391 setTimeout(function() { 396 setTimeout(function() {
392 cr.dispatchSimpleEvent(self, eventName); 397 cr.dispatchSimpleEvent(self, eventName);
393 }, 0); 398 }, 0);
394 }, 399 },
395 400
396 /** 401 /**
397 * @type {Array.<Entry>} 402 * @type {Array.<Entry>}
398 */ 403 */
399 get selectedEntries_() { 404 get selectedEntries_() {
400 var list = this.fileList_; 405 var list = this.fileList_;
401 return this.fileListSelection_.selectedIndexes.map(function(index) { 406 return this.fileListSelection_.selectedIndexes.map(function(index) {
402 return list.item(index); 407 return list.item(index);
403 }); 408 });
404 } 409 }
405 }; 410 };
406 411
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/js/file_manager.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698