| 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 (function() { | 5 (function() { |
| 6 /** @const */ var BookmarkList = bmm.BookmarkList; | 6 /** @const */ var BookmarkList = bmm.BookmarkList; |
| 7 /** @const */ var BookmarkTree = bmm.BookmarkTree; | 7 /** @const */ var BookmarkTree = bmm.BookmarkTree; |
| 8 /** @const */ var Command = cr.ui.Command; | 8 /** @const */ var Command = cr.ui.Command; |
| 9 /** @const */ var CommandBinding = cr.ui.CommandBinding; | 9 /** @const */ var CommandBinding = cr.ui.CommandBinding; |
| 10 /** @const */ var LinkKind = cr.LinkKind; | 10 /** @const */ var LinkKind = cr.LinkKind; |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 switch (command.id) { | 448 switch (command.id) { |
| 449 case 'import-menu-command': | 449 case 'import-menu-command': |
| 450 e.canExecute = canEdit; | 450 e.canExecute = canEdit; |
| 451 break; | 451 break; |
| 452 case 'export-menu-command': | 452 case 'export-menu-command': |
| 453 // We can always execute the export-menu command. | 453 // We can always execute the export-menu command. |
| 454 e.canExecute = true; | 454 e.canExecute = true; |
| 455 break; | 455 break; |
| 456 case 'sort-command': | 456 case 'sort-command': |
| 457 e.canExecute = !list.isSearch() && | 457 e.canExecute = !list.isSearch() && |
| 458 list.dataModel && list.dataModel.length > 1; | 458 list.dataModel && list.dataModel.length > 1 && |
| 459 !isUnmodifiable(tree.getBookmarkNodeById(list.parentId)); |
| 459 break; | 460 break; |
| 460 case 'undo-command': | 461 case 'undo-command': |
| 461 // The global undo command has no visible UI, so always enable it, and | 462 // The global undo command has no visible UI, so always enable it, and |
| 462 // just make it a no-op if undo is not possible. | 463 // just make it a no-op if undo is not possible. |
| 463 e.canExecute = true; | 464 e.canExecute = true; |
| 464 break; | 465 break; |
| 465 default: | 466 default: |
| 466 canExecuteForList(e); | 467 canExecuteForList(e); |
| 467 break; | 468 break; |
| 468 } | 469 } |
| 469 } | 470 } |
| 470 | 471 |
| 471 /** | 472 /** |
| 472 * Helper function for handling canExecute for the list and the tree. | 473 * Helper function for handling canExecute for the list and the tree. |
| 473 * @param {!Event} e Can execute event object. | 474 * @param {!Event} e Can execute event object. |
| 474 * @param {boolean} isSearch Whether the user is trying to do a command on | 475 * @param {boolean} isSearch Whether the user is trying to do a command on |
| 475 * search. | 476 * search. |
| 476 */ | 477 */ |
| 477 function canExecuteShared(e, isSearch) { | 478 function canExecuteShared(e, isSearch) { |
| 478 var command = e.command; | 479 var command = e.command; |
| 479 var commandId = command.id; | 480 var commandId = command.id; |
| 480 switch (commandId) { | 481 switch (commandId) { |
| 481 case 'paste-from-organize-menu-command': | 482 case 'paste-from-organize-menu-command': |
| 482 case 'paste-from-context-menu-command': | 483 case 'paste-from-context-menu-command': |
| 483 updatePasteCommand(); | 484 updatePasteCommand(); |
| 484 break; | 485 break; |
| 485 | 486 |
| 486 case 'add-new-bookmark-command': | 487 case 'add-new-bookmark-command': |
| 487 case 'new-folder-command': | 488 case 'new-folder-command': |
| 488 e.canExecute = !isSearch && canEdit; | 489 var parentId = computeParentFolderForNewItem(); |
| 490 var unmodifiable = isUnmodifiable(tree.getBookmarkNodeById(parentId)); |
| 491 e.canExecute = !isSearch && canEdit && !unmodifiable; |
| 489 break; | 492 break; |
| 490 | 493 |
| 491 case 'open-in-new-tab-command': | 494 case 'open-in-new-tab-command': |
| 492 updateOpenCommand(e, command, 'open_in_new_tab', 'open_all', false); | 495 updateOpenCommand(e, command, 'open_in_new_tab', 'open_all', false); |
| 493 break; | 496 break; |
| 494 case 'open-in-background-tab-command': | 497 case 'open-in-background-tab-command': |
| 495 updateOpenCommand(e, command, '', '', false); | 498 updateOpenCommand(e, command, '', '', false); |
| 496 break; | 499 break; |
| 497 case 'open-in-new-window-command': | 500 case 'open-in-new-window-command': |
| 498 updateOpenCommand(e, command, | 501 updateOpenCommand(e, command, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 | 547 |
| 545 switch (commandId) { | 548 switch (commandId) { |
| 546 case 'rename-folder-command': | 549 case 'rename-folder-command': |
| 547 // Show rename if a single folder is selected. | 550 // Show rename if a single folder is selected. |
| 548 var items = list.selectedItems; | 551 var items = list.selectedItems; |
| 549 if (items.length != 1) { | 552 if (items.length != 1) { |
| 550 e.canExecute = false; | 553 e.canExecute = false; |
| 551 command.hidden = true; | 554 command.hidden = true; |
| 552 } else { | 555 } else { |
| 553 var isFolder = bmm.isFolder(items[0]); | 556 var isFolder = bmm.isFolder(items[0]); |
| 554 e.canExecute = isFolder && canEdit; | 557 e.canExecute = isFolder && canEdit && !hasUnmodifiable(items); |
| 555 command.hidden = !isFolder; | 558 command.hidden = !isFolder; |
| 556 } | 559 } |
| 557 break; | 560 break; |
| 558 | 561 |
| 559 case 'edit-command': | 562 case 'edit-command': |
| 560 // Show the edit command if not a folder. | 563 // Show the edit command if not a folder. |
| 561 var items = list.selectedItems; | 564 var items = list.selectedItems; |
| 562 if (items.length != 1) { | 565 if (items.length != 1) { |
| 563 e.canExecute = false; | 566 e.canExecute = false; |
| 564 command.hidden = false; | 567 command.hidden = false; |
| 565 } else { | 568 } else { |
| 566 var isFolder = bmm.isFolder(items[0]); | 569 var isFolder = bmm.isFolder(items[0]); |
| 567 e.canExecute = !isFolder && canEdit; | 570 e.canExecute = !isFolder && canEdit && !hasUnmodifiable(items); |
| 568 command.hidden = isFolder; | 571 command.hidden = isFolder; |
| 569 } | 572 } |
| 570 break; | 573 break; |
| 571 | 574 |
| 572 case 'show-in-folder-command': | 575 case 'show-in-folder-command': |
| 573 e.canExecute = isSearch() && hasSingleSelected(); | 576 e.canExecute = isSearch() && hasSingleSelected(); |
| 574 break; | 577 break; |
| 575 | 578 |
| 576 case 'delete-command': | 579 case 'delete-command': |
| 577 case 'cut-command': | 580 case 'cut-command': |
| 578 e.canExecute = canCopyItems() && canEdit; | 581 e.canExecute = canCopyItems() && canEdit && |
| 582 !hasUnmodifiable(list.selectedItems); |
| 579 break; | 583 break; |
| 580 | 584 |
| 581 case 'copy-command': | 585 case 'copy-command': |
| 582 e.canExecute = canCopyItems(); | 586 e.canExecute = canCopyItems(); |
| 583 break; | 587 break; |
| 584 | 588 |
| 585 case 'open-in-same-window-command': | 589 case 'open-in-same-window-command': |
| 586 e.canExecute = hasSelected(); | 590 e.canExecute = hasSelected(); |
| 587 break; | 591 break; |
| 588 | 592 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 613 return item == searchTreeItem; | 617 return item == searchTreeItem; |
| 614 } | 618 } |
| 615 | 619 |
| 616 function isTopLevelItem() { | 620 function isTopLevelItem() { |
| 617 return e.target.selectedItem.parentNode == tree; | 621 return e.target.selectedItem.parentNode == tree; |
| 618 } | 622 } |
| 619 | 623 |
| 620 switch (commandId) { | 624 switch (commandId) { |
| 621 case 'rename-folder-command': | 625 case 'rename-folder-command': |
| 622 command.hidden = false; | 626 command.hidden = false; |
| 623 e.canExecute = hasSelected() && !isTopLevelItem() && canEdit; | 627 e.canExecute = hasSelected() && !isTopLevelItem() && canEdit && |
| 628 !hasUnmodifiable(tree.selectedFolders); |
| 624 break; | 629 break; |
| 625 | 630 |
| 626 case 'edit-command': | 631 case 'edit-command': |
| 627 command.hidden = true; | 632 command.hidden = true; |
| 628 e.canExecute = false; | 633 e.canExecute = false; |
| 629 break; | 634 break; |
| 630 | 635 |
| 631 case 'delete-command': | 636 case 'delete-command': |
| 632 case 'cut-command': | 637 case 'cut-command': |
| 633 e.canExecute = hasSelected() && !isTopLevelItem() && canEdit; | 638 e.canExecute = hasSelected() && !isTopLevelItem() && canEdit && |
| 639 !hasUnmodifiable(tree.selectedFolders); |
| 634 break; | 640 break; |
| 635 | 641 |
| 636 case 'copy-command': | 642 case 'copy-command': |
| 637 e.canExecute = hasSelected() && !isTopLevelItem(); | 643 e.canExecute = hasSelected() && !isTopLevelItem(); |
| 638 break; | 644 break; |
| 639 | 645 |
| 640 default: | 646 default: |
| 641 canExecuteShared(e, isSearch()); | 647 canExecuteShared(e, isSearch()); |
| 642 } | 648 } |
| 643 } | 649 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 */ | 789 */ |
| 784 function getSelectedBookmarkIds() { | 790 function getSelectedBookmarkIds() { |
| 785 var selectedNodes = getSelectedBookmarkNodes(); | 791 var selectedNodes = getSelectedBookmarkNodes(); |
| 786 selectedNodes.sort(function(a, b) { return a.index - b.index }); | 792 selectedNodes.sort(function(a, b) { return a.index - b.index }); |
| 787 return selectedNodes.map(function(node) { | 793 return selectedNodes.map(function(node) { |
| 788 return node.id; | 794 return node.id; |
| 789 }); | 795 }); |
| 790 } | 796 } |
| 791 | 797 |
| 792 /** | 798 /** |
| 799 * @param {BookmarkTreeNode} node The node to test. |
| 800 * @return {boolean} Whether the given node is unmodifiable. |
| 801 */ |
| 802 function isUnmodifiable(node) { |
| 803 return node && node.unmodifiable; |
| 804 } |
| 805 |
| 806 /** |
| 807 * @param {BookmarkList} A list of BookmarkNodes. |
| 808 * @return {boolean} Whether any of the nodes is managed. |
| 809 */ |
| 810 function hasUnmodifiable(nodes) { |
| 811 return nodes.some(isUnmodifiable); |
| 812 } |
| 813 |
| 814 /** |
| 793 * Opens the selected bookmarks. | 815 * Opens the selected bookmarks. |
| 794 * @param {LinkKind} kind The kind of link we want to open. | 816 * @param {LinkKind} kind The kind of link we want to open. |
| 795 * @param {HTMLElement} opt_eventTarget The target of the user initiated event. | 817 * @param {HTMLElement} opt_eventTarget The target of the user initiated event. |
| 796 */ | 818 */ |
| 797 function openBookmarks(kind, opt_eventTarget) { | 819 function openBookmarks(kind, opt_eventTarget) { |
| 798 // If we have selected any folders, we need to find all the bookmarks one | 820 // If we have selected any folders, we need to find all the bookmarks one |
| 799 // level down. We use multiple async calls to getSubtree instead of getting | 821 // level down. We use multiple async calls to getSubtree instead of getting |
| 800 // the whole tree since we would like to minimize the amount of data sent. | 822 // the whole tree since we would like to minimize the amount of data sent. |
| 801 | 823 |
| 802 var urlsP = getUrlsForOpenCommands(opt_eventTarget); | 824 var urlsP = getUrlsForOpenCommands(opt_eventTarget); |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1355 | 1377 |
| 1356 cr.ui.FocusOutlineManager.forDocument(document); | 1378 cr.ui.FocusOutlineManager.forDocument(document); |
| 1357 initializeSplitter(); | 1379 initializeSplitter(); |
| 1358 bmm.addBookmarkModelListeners(); | 1380 bmm.addBookmarkModelListeners(); |
| 1359 dnd.init(selectItemsAfterUserAction); | 1381 dnd.init(selectItemsAfterUserAction); |
| 1360 tree.reload(); | 1382 tree.reload(); |
| 1361 } | 1383 } |
| 1362 | 1384 |
| 1363 initializeBookmarkManager(); | 1385 initializeBookmarkManager(); |
| 1364 })(); | 1386 })(); |
| OLD | NEW |