| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 cr.define('bookmarks', function() { | 5 cr.define('bookmarks', function() { |
| 6 /** | 6 /** |
| 7 * @param {BookmarkElement} element | 7 * @param {BookmarkElement} element |
| 8 * @return {boolean} | 8 * @return {boolean} |
| 9 */ | 9 */ |
| 10 function isBookmarkItem(element) { | 10 function isBookmarkItem(element) { |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 var parentId = node.id; | 364 var parentId = node.id; |
| 365 | 365 |
| 366 if (position != DropPosition.ON) { | 366 if (position != DropPosition.ON) { |
| 367 var state = bookmarks.Store.getInstance().data; | 367 var state = bookmarks.Store.getInstance().data; |
| 368 | 368 |
| 369 // Drops between items in the normal list and the sidebar use the drop | 369 // Drops between items in the normal list and the sidebar use the drop |
| 370 // destination node's parent. | 370 // destination node's parent. |
| 371 parentId = assert(node.parentId); | 371 parentId = assert(node.parentId); |
| 372 index = state.nodes[parentId].children.indexOf(node.id); | 372 index = state.nodes[parentId].children.indexOf(node.id); |
| 373 | 373 |
| 374 // TODO(calamity): Handle dropping to an empty bookmark list. | |
| 375 if (position == DropPosition.BELOW) | 374 if (position == DropPosition.BELOW) |
| 376 index++; | 375 index++; |
| 377 } | 376 } |
| 378 | 377 |
| 379 return { | 378 return { |
| 380 index: index, | 379 index: index, |
| 381 parentId: parentId, | 380 parentId: parentId, |
| 382 }; | 381 }; |
| 383 }, | 382 }, |
| 384 | 383 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 396 | 395 |
| 397 /** | 396 /** |
| 398 * @private | 397 * @private |
| 399 * @param {Event} e | 398 * @param {Event} e |
| 400 */ | 399 */ |
| 401 onDragStart_: function(e) { | 400 onDragStart_: function(e) { |
| 402 var dragElement = getBookmarkElement(e.path); | 401 var dragElement = getBookmarkElement(e.path); |
| 403 if (!dragElement) | 402 if (!dragElement) |
| 404 return; | 403 return; |
| 405 | 404 |
| 405 var store = bookmarks.Store.getInstance(); |
| 406 var dragId = dragElement.itemId; |
| 407 |
| 406 // Determine the selected bookmarks. | 408 // Determine the selected bookmarks. |
| 407 var state = bookmarks.Store.getInstance().data; | 409 var state = store.data; |
| 408 var draggedNodes = Array.from(state.selection.items); | 410 var draggedNodes = Array.from(state.selection.items); |
| 409 | 411 |
| 412 // Change selection to the dragged node if the node is not part of the |
| 413 // existing selection. |
| 410 if (isBookmarkFolderNode(dragElement) || | 414 if (isBookmarkFolderNode(dragElement) || |
| 411 draggedNodes.indexOf(dragElement.itemId) == -1) { | 415 draggedNodes.indexOf(dragId) == -1) { |
| 412 // TODO(calamity): clear current selection. | 416 store.dispatch(bookmarks.actions.deselectItems()); |
| 413 draggedNodes = [dragElement.itemId]; | 417 if (!isBookmarkFolderNode(dragElement)) { |
| 418 store.dispatch( |
| 419 bookmarks.actions.selectItem(dragId, true, false, state)); |
| 420 } |
| 421 draggedNodes = [dragId]; |
| 414 } | 422 } |
| 415 | 423 |
| 416 e.preventDefault(); | 424 e.preventDefault(); |
| 417 | 425 |
| 418 // If we are dragging a single link, we can do the *Link* effect. | 426 // If we are dragging a single link, we can do the *Link* effect. |
| 419 // Otherwise, we only allow copy and move. | 427 // Otherwise, we only allow copy and move. |
| 420 if (e.dataTransfer) { | 428 if (e.dataTransfer) { |
| 421 e.dataTransfer.effectAllowed = | 429 e.dataTransfer.effectAllowed = |
| 422 draggedNodes.length == 1 && state.nodes[draggedNodes[0]].url ? | 430 draggedNodes.length == 1 && state.nodes[draggedNodes[0]].url ? |
| 423 'copyLink' : | 431 'copyLink' : |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 this.dropIndicator_.setTimeout = this.setTimeout_; | 635 this.dropIndicator_.setTimeout = this.setTimeout_; |
| 628 } | 636 } |
| 629 }; | 637 }; |
| 630 | 638 |
| 631 return { | 639 return { |
| 632 DNDManager: DNDManager, | 640 DNDManager: DNDManager, |
| 633 DragInfo: DragInfo, | 641 DragInfo: DragInfo, |
| 634 DropIndicator: DropIndicator, | 642 DropIndicator: DropIndicator, |
| 635 }; | 643 }; |
| 636 }); | 644 }); |
| OLD | NEW |