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, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 list.style.webkitUserDrag = 'element'; | 45 list.style.webkitUserDrag = 'element'; |
46 list.addEventListener('dragstart', this.onDragStart_.bind(this, list)); | 46 list.addEventListener('dragstart', this.onDragStart_.bind(this, list)); |
47 list.addEventListener('dragend', this.onDragEnd_.bind(this, list)); | 47 list.addEventListener('dragend', this.onDragEnd_.bind(this, list)); |
48 list.addEventListener('drag', this.onDrag_.bind(this, list)); | 48 list.addEventListener('drag', this.onDrag_.bind(this, list)); |
49 }, | 49 }, |
50 | 50 |
51 /** | 51 /** |
52 * @param {cr.ui.List} list List itself and its directory items will could | 52 * @param {cr.ui.List} list List itself and its directory items will could |
53 * be drop target. | 53 * be drop target. |
54 */ | 54 */ |
55 attachDropTarget: function(list) { | 55 attachDropTarget: function(list, opt_onlyIntoDirectories) { |
Vladislav Kaznacheev
2012/04/25 08:43:11
Please comment on the second parameter (here or in
SeRya
2012/04/25 10:15:16
Done.
| |
56 list.addEventListener('dragover', this.onDragOver_.bind(this, list)); | 56 list.addEventListener('dragover', this.onDragOver_.bind(this, list)); |
57 list.addEventListener('dragenter', this.onDragEnter_.bind(this, list)); | 57 list.addEventListener('dragenter', this.onDragEnter_.bind(this, list)); |
58 list.addEventListener('dragleave', this.onDragLeave_.bind(this, list)); | 58 list.addEventListener('dragleave', this.onDragLeave_.bind(this, list)); |
59 list.addEventListener('drop', this.onDrop_.bind(this, list)); | 59 list.addEventListener('drop', this.onDrop_.bind(this, list, |
60 !!opt_onlyIntoDirectories)); | |
60 }, | 61 }, |
61 | 62 |
62 /** | 63 /** |
63 * Attach handlers of copy, cut and paste operations to the document. | 64 * Attach handlers of copy, cut and paste operations to the document. |
64 * @param {HTMLDocument} doc Command dispatcher. | 65 * @param {HTMLDocument} doc Command dispatcher. |
65 */ | 66 */ |
66 attachCopyPasteHandlers: function(doc) { | 67 attachCopyPasteHandlers: function(doc) { |
67 this.document_ = doc; | 68 this.document_ = doc; |
68 doc.addEventListener('beforecopy', this.onBeforeCopy_.bind(this)); | 69 doc.addEventListener('beforecopy', this.onBeforeCopy_.bind(this)); |
69 doc.addEventListener('copy', this.onCopy_.bind(this)); | 70 doc.addEventListener('copy', this.onCopy_.bind(this)); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 | 186 |
186 this.setDropTarget_(item && list.isItem(item) ? item : null, | 187 this.setDropTarget_(item && list.isItem(item) ? item : null, |
187 event.dataTransfer); | 188 event.dataTransfer); |
188 }, | 189 }, |
189 | 190 |
190 onDragLeave_: function(event) { | 191 onDragLeave_: function(event) { |
191 if (this.dragEnterCount_-- == 0) | 192 if (this.dragEnterCount_-- == 0) |
192 this.setDropTarget_(null); | 193 this.setDropTarget_(null); |
193 }, | 194 }, |
194 | 195 |
195 onDrop_: function(list, event) { | 196 onDrop_: function(list, onlyIntoDirectories, event) { |
196 console.log('drop: ', event.dataTransfer.dropEffect); | 197 console.log('drop: ', event.dataTransfer.dropEffect); |
197 var item = list.getListItemAncestor(event.target); | 198 var item = list.getListItemAncestor(event.target); |
198 var dropTarget = item && list.isItem(item) ? | 199 var dropTarget = item && list.isItem(item) ? |
199 this.fileList_.item(item.listIndex) : null; | 200 list.dataModel.item(item.listIndex) : null; |
200 if (dropTarget && !dropTarget.isDirectory) | 201 if (dropTarget && !dropTarget.isDirectory) |
201 dropTarget = null; | 202 dropTarget = null; |
203 if (onlyIntoDirectories && !dropTarget) | |
204 return; | |
202 if (!this.canPasteOrDrop_(event.dataTransfer, dropTarget)) | 205 if (!this.canPasteOrDrop_(event.dataTransfer, dropTarget)) |
203 return; | 206 return; |
204 event.preventDefault(); | 207 event.preventDefault(); |
205 this.paste(event.dataTransfer, dropTarget); | 208 this.paste(event.dataTransfer, dropTarget); |
206 if (this.dropTarget_) { | 209 if (this.dropTarget_) { |
207 var target = this.dropTarget_; | 210 var target = this.dropTarget_; |
208 this.setDropTarget_(null); | 211 this.setDropTarget_(null); |
209 } | 212 } |
210 }, | 213 }, |
211 | 214 |
212 setDropTarget_: function(listItem, opt_dataTransfer) { | 215 setDropTarget_: function(listItem, opt_dataTransfer) { |
213 if (this.dropTarget_ == listItem) | 216 if (this.dropTarget_ == listItem) |
214 return; | 217 return; |
215 | 218 |
216 if (listItem) { | 219 if (listItem) { |
217 var entry = this.fileList_.item(listItem.listIndex); | 220 var list = listItem.parentElement; |
221 var entry = list.dataModel.item(listItem.listIndex); | |
218 if (entry.isDirectory && | 222 if (entry.isDirectory && |
219 (!opt_dataTransfer || | 223 (!opt_dataTransfer || |
220 this.canPasteOrDrop_(opt_dataTransfer, entry))) { | 224 this.canPasteOrDrop_(opt_dataTransfer, entry))) { |
221 listItem.classList.add('accepts'); | 225 listItem.classList.add('accepts'); |
222 } | 226 } |
223 } else { | 227 } else { |
224 this.dragEnterCount_ = 0; | 228 this.dragEnterCount_ = 0; |
225 } | 229 } |
226 if (this.dropTarget_ && this.dropTarget_.classList.contains('accepts')) { | 230 if (this.dropTarget_ && this.dropTarget_.classList.contains('accepts')) { |
227 var oldDropTarget = this.dropTarget_; | 231 var oldDropTarget = this.dropTarget_; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 }, | 305 }, |
302 | 306 |
303 onBeforePaste_: function(event) { | 307 onBeforePaste_: function(event) { |
304 if (!this.isDocumentWideEvent_(event)) | 308 if (!this.isDocumentWideEvent_(event)) |
305 return; | 309 return; |
306 // queryCommandEnabled returns true if event.returnValue is false. | 310 // queryCommandEnabled returns true if event.returnValue is false. |
307 event.returnValue = !this.canPasteOrDrop_(event.clipboardData); | 311 event.returnValue = !this.canPasteOrDrop_(event.clipboardData); |
308 }, | 312 }, |
309 | 313 |
310 canPasteOrDrop_: function(dataTransfer, opt_entry) { | 314 canPasteOrDrop_: function(dataTransfer, opt_entry) { |
311 if (this.readonly) | 315 if (!opt_entry && this.readonly) |
312 return false; // assure destination entry is in the current directory. | 316 return false; // assure destination entry is in the current directory. |
317 if (opt_entry && this.directoryModel_.isPathReadOnly(opt_entry.fullPath)) | |
318 return; | |
Vladislav Kaznacheev
2012/04/25 08:43:11
return false?
SeRya
2012/04/25 10:15:16
Done.
| |
313 | 319 |
314 if (!dataTransfer.types || dataTransfer.types.indexOf('fs/tag') == -1) | 320 if (!dataTransfer.types || dataTransfer.types.indexOf('fs/tag') == -1) |
315 return false; // Unsupported type of content. | 321 return false; // Unsupported type of content. |
316 if (dataTransfer.getData('fs/tag') == '') { | 322 if (dataTransfer.getData('fs/tag') == '') { |
317 // Data protected. Other checks are not possible but it makes sense to | 323 // Data protected. Other checks are not possible but it makes sense to |
318 // let the user try. | 324 // let the user try. |
319 return true; | 325 return true; |
320 } | 326 } |
321 | 327 |
322 var directories = dataTransfer.getData('fs/directories').split('\n'). | 328 var directories = dataTransfer.getData('fs/directories').split('\n'). |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 * @type {Array.<Entry>} | 406 * @type {Array.<Entry>} |
401 */ | 407 */ |
402 get selectedEntries_() { | 408 get selectedEntries_() { |
403 var list = this.fileList_; | 409 var list = this.fileList_; |
404 return this.fileListSelection_.selectedIndexes.map(function(index) { | 410 return this.fileListSelection_.selectedIndexes.map(function(index) { |
405 return list.item(index); | 411 return list.item(index); |
406 }); | 412 }); |
407 } | 413 } |
408 }; | 414 }; |
409 | 415 |
OLD | NEW |