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

Side by Side Diff: chrome/browser/resources/bookmark_manager/js/main.js

Issue 308003013: Make the Bookmark Manager aware of managed bookmarks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 6 years, 6 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/bookmark_manager/js/bmm.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 (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
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 !bmm.isManaged(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 isManaged = bmm.isManaged(tree.getBookmarkNodeById(parentId));
491 e.canExecute = !isSearch && canEdit && !isManaged;
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
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 && !hasManaged(items);
arv (Not doing code reviews) 2014/06/03 14:31:39 Can't this just check if the list is managed since
Joao da Silva 2014/06/05 20:28:38 The isManaged check needs a BookmarkTreeNode, I'm
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 && !hasManaged(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 !hasManaged(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
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 !hasManaged(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 !hasManaged(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
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 {BookmarkList} A list of BookmarkNodes.
800 * @return {boolean} Whether any of the nodes is managed.
801 */
802 function hasManaged(nodes) {
803 return nodes.some(bmm.isManaged);
804 }
805
806 /**
793 * Opens the selected bookmarks. 807 * Opens the selected bookmarks.
794 * @param {LinkKind} kind The kind of link we want to open. 808 * @param {LinkKind} kind The kind of link we want to open.
795 * @param {HTMLElement} opt_eventTarget The target of the user initiated event. 809 * @param {HTMLElement} opt_eventTarget The target of the user initiated event.
796 */ 810 */
797 function openBookmarks(kind, opt_eventTarget) { 811 function openBookmarks(kind, opt_eventTarget) {
798 // If we have selected any folders, we need to find all the bookmarks one 812 // 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 813 // 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. 814 // the whole tree since we would like to minimize the amount of data sent.
801 815
802 var urlsP = getUrlsForOpenCommands(opt_eventTarget); 816 var urlsP = getUrlsForOpenCommands(opt_eventTarget);
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 1369
1356 cr.ui.FocusOutlineManager.forDocument(document); 1370 cr.ui.FocusOutlineManager.forDocument(document);
1357 initializeSplitter(); 1371 initializeSplitter();
1358 bmm.addBookmarkModelListeners(); 1372 bmm.addBookmarkModelListeners();
1359 dnd.init(selectItemsAfterUserAction); 1373 dnd.init(selectItemsAfterUserAction);
1360 tree.reload(); 1374 tree.reload();
1361 } 1375 }
1362 1376
1363 initializeBookmarkManager(); 1377 initializeBookmarkManager();
1364 })(); 1378 })();
OLDNEW
« no previous file with comments | « chrome/browser/resources/bookmark_manager/js/bmm.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698