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 LinkKind = cr.LinkKind; | 9 /** @const */ var LinkKind = cr.LinkKind; |
10 /** @const */ var ListItem = cr.ui.ListItem; | 10 /** @const */ var ListItem = cr.ui.ListItem; |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 not used. | 391 not used. |
392 * @param {boolean} commandDisabled Whether the menu item should be disabled | 392 * @param {boolean} commandDisabled Whether the menu item should be disabled |
393 no matter what bookmarks are selected. | 393 no matter what bookmarks are selected. |
394 */ | 394 */ |
395 function updateOpenCommand(e, command, singularId, pluralId, commandDisabled) { | 395 function updateOpenCommand(e, command, singularId, pluralId, commandDisabled) { |
396 if (singularId) { | 396 if (singularId) { |
397 // The command label reflects the selection which might not reflect | 397 // The command label reflects the selection which might not reflect |
398 // how many bookmarks will be opened. For example if you right click an | 398 // how many bookmarks will be opened. For example if you right click an |
399 // empty area in a folder with 1 bookmark the text should still say "all". | 399 // empty area in a folder with 1 bookmark the text should still say "all". |
400 var selectedNodes = getSelectedBookmarkNodes(e.target).filter(notNewNode); | 400 var selectedNodes = getSelectedBookmarkNodes(e.target).filter(notNewNode); |
401 var singular = selectedNodes.length == 1 && !bmm.isFolder(selectedNodes[0]); | 401 var singular = selectedNodes && selectedNodes.length == 1 && |
402 !bmm.isFolder(selectedNodes[0]); | |
402 command.label = loadTimeData.getString(singular ? singularId : pluralId); | 403 command.label = loadTimeData.getString(singular ? singularId : pluralId); |
403 } | 404 } |
404 | 405 |
405 if (commandDisabled) { | 406 if (commandDisabled) { |
406 command.disabled = true; | 407 command.disabled = true; |
407 e.canExecute = false; | 408 e.canExecute = false; |
408 return; | 409 return; |
409 } | 410 } |
410 | 411 |
411 getUrlsForOpenCommands(assertInstanceof(e.target, HTMLElement)).then( | 412 getUrlsForOpenCommands(assertInstanceof(e.target, HTMLElement)).then( |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 break; | 484 break; |
484 | 485 |
485 case 'sort-command': | 486 case 'sort-command': |
486 e.canExecute = !bmm.list.isSearch() && | 487 e.canExecute = !bmm.list.isSearch() && |
487 bmm.list.dataModel && bmm.list.dataModel.length > 1 && | 488 bmm.list.dataModel && bmm.list.dataModel.length > 1 && |
488 !isUnmodifiable(bmm.tree.getBookmarkNodeById(bmm.list.parentId)); | 489 !isUnmodifiable(bmm.tree.getBookmarkNodeById(bmm.list.parentId)); |
489 break; | 490 break; |
490 | 491 |
491 case 'undo-command': | 492 case 'undo-command': |
492 // If the search box is active, pass the undo command through | 493 // If the search box is active, pass the undo command through |
493 // (fixes http://crbug.com/278112). Otherwise, because | 494 // (fixes http://crbug.com/278112). Otherwise, because |
Bernhard Bauer
2015/04/15 10:11:57
(Read my comments bottom-up for context)
Here is
| |
494 // the global undo command has no visible UI, always enable it, and | 495 // the global undo command has no visible UI, always enable it, and |
495 // just make it a no-op if undo is not possible. | 496 // just make it a no-op if undo is not possible. |
496 e.canExecute = e.currentTarget.activeElement !== $('term'); | 497 e.canExecute = e.currentTarget.activeElement !== $('term'); |
497 break; | 498 break; |
498 | 499 |
499 default: | 500 default: |
500 canExecuteForList(e); | 501 canExecuteForList(e); |
501 if (!e.defaultPrevented) | 502 if (!e.defaultPrevented) |
502 canExecuteForTree(e); | 503 canExecuteForTree(e); |
503 break; | 504 break; |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
834 } | 835 } |
835 | 836 |
836 /** | 837 /** |
837 * Returns the selected bookmark nodes of the provided tree or list. | 838 * Returns the selected bookmark nodes of the provided tree or list. |
838 * If |opt_target| is not provided or null the active element is used. | 839 * If |opt_target| is not provided or null the active element is used. |
839 * Only call this if the list or the tree is focused. | 840 * Only call this if the list or the tree is focused. |
840 * @param {EventTarget=} opt_target The target list or tree. | 841 * @param {EventTarget=} opt_target The target list or tree. |
841 * @return {!Array} Array of bookmark nodes. | 842 * @return {!Array} Array of bookmark nodes. |
842 */ | 843 */ |
843 function getSelectedBookmarkNodes(opt_target) { | 844 function getSelectedBookmarkNodes(opt_target) { |
844 return (opt_target || document.activeElement) == bmm.tree ? | 845 if (opt_target) { |
Bernhard Bauer
2015/04/15 10:11:57
I don't really understand what's going on here. Yo
| |
845 bmm.tree.selectedFolders : bmm.list.selectedItems; | 846 return (opt_target == bmm.tree) ? bmm.tree.selectedFolders : |
847 bmm.list.selectedItems; | |
848 } else if (document.activeElement == bmm.tree || | |
849 document.activeElement == bmm.list) { | |
850 return (document.activeElement == bmm.tree) ? bmm.tree.selectedFolders : | |
851 bmm.list.selectedItems; | |
852 } | |
846 } | 853 } |
847 | 854 |
848 /** | 855 /** |
849 * @param {EventTarget=} opt_target The target list or tree. | 856 * @param {EventTarget=} opt_target The target list or tree. |
850 * @return {!Array<string>} An array of the selected bookmark IDs. | 857 * @return {!Array<string>} An array of the selected bookmark IDs. |
851 */ | 858 */ |
852 function getSelectedBookmarkIds(opt_target) { | 859 function getSelectedBookmarkIds(opt_target) { |
853 var selectedNodes = getSelectedBookmarkNodes(opt_target); | 860 var selectedNodes = getSelectedBookmarkNodes(opt_target); |
861 if (!selectedNodes || !selectedNodes.length) | |
862 return; | |
854 selectedNodes.sort(function(a, b) { return a.index - b.index }); | 863 selectedNodes.sort(function(a, b) { return a.index - b.index }); |
855 return selectedNodes.map(function(node) { | 864 return selectedNodes.map(function(node) { |
856 return node.id; | 865 return node.id; |
857 }); | 866 }); |
858 } | 867 } |
859 | 868 |
860 /** | 869 /** |
861 * @param {BookmarkTreeNode} node The node to test. | 870 * @param {BookmarkTreeNode} node The node to test. |
862 * @return {boolean} Whether the given node is unmodifiable. | 871 * @return {boolean} Whether the given node is unmodifiable. |
863 */ | 872 */ |
(...skipping 25 matching lines...) Expand all Loading... | |
889 chrome.bookmarkManagerPrivate.recordLaunch(); | 898 chrome.bookmarkManagerPrivate.recordLaunch(); |
890 }); | 899 }); |
891 } | 900 } |
892 | 901 |
893 /** | 902 /** |
894 * Opens an item in the list. | 903 * Opens an item in the list. |
895 */ | 904 */ |
896 function openItem() { | 905 function openItem() { |
897 var bookmarkNodes = getSelectedBookmarkNodes(); | 906 var bookmarkNodes = getSelectedBookmarkNodes(); |
898 // If we double clicked or pressed enter on a single folder, navigate to it. | 907 // If we double clicked or pressed enter on a single folder, navigate to it. |
899 if (bookmarkNodes.length == 1 && bmm.isFolder(bookmarkNodes[0])) | 908 if (bookmarkNodes && bookmarkNodes.length == 1 && |
909 bmm.isFolder(bookmarkNodes[0])) { | |
900 navigateTo(bookmarkNodes[0].id); | 910 navigateTo(bookmarkNodes[0].id); |
901 else | 911 } else { |
902 openBookmarks(LinkKind.FOREGROUND_TAB); | 912 openBookmarks(LinkKind.FOREGROUND_TAB); |
913 } | |
903 } | 914 } |
904 | 915 |
905 /** | 916 /** |
906 * Refreshes search results after delete or undo-delete. | 917 * Refreshes search results after delete or undo-delete. |
907 * This ensures children of deleted folders do not remain in results | 918 * This ensures children of deleted folders do not remain in results |
908 */ | 919 */ |
909 function updateSearchResults() { | 920 function updateSearchResults() { |
910 if (bmm.list.isSearch()) | 921 if (bmm.list.isSearch()) |
911 bmm.list.reload(); | 922 bmm.list.reload(); |
912 } | 923 } |
913 | 924 |
914 /** | 925 /** |
915 * Deletes the selected bookmarks. The bookmarks are saved in memory in case | 926 * Deletes the selected bookmarks. The bookmarks are saved in memory in case |
916 * the user needs to undo the deletion. | 927 * the user needs to undo the deletion. |
917 * @param {EventTarget=} opt_target The deleter of bookmarks. | 928 * @param {EventTarget=} opt_target The deleter of bookmarks. |
918 */ | 929 */ |
919 function deleteBookmarks(opt_target) { | 930 function deleteBookmarks(opt_target) { |
920 var selectedIds = getSelectedBookmarkIds(opt_target); | 931 var selectedIds = getSelectedBookmarkIds(opt_target); |
921 if (!selectedIds.length) | 932 if (!selectedIds || !selectedIds.length) |
922 return; | 933 return; |
923 | 934 |
924 var filteredIds = getFilteredSelectedBookmarkIds(opt_target); | 935 var filteredIds = getFilteredSelectedBookmarkIds(opt_target); |
925 lastDeleted = {nodes: [], target: opt_target || document.activeElement}; | 936 lastDeleted = {nodes: [], target: opt_target || document.activeElement}; |
926 | 937 |
927 function performDelete() { | 938 function performDelete() { |
928 // Only remove filtered ids. | 939 // Only remove filtered ids. |
929 chrome.bookmarkManagerPrivate.removeTrees(filteredIds); | 940 chrome.bookmarkManagerPrivate.removeTrees(filteredIds); |
930 $('undo-delete-command').canExecuteChange(); | 941 $('undo-delete-command').canExecuteChange(); |
931 $('undo-delete-from-folders-menu-command').canExecuteChange(); | 942 $('undo-delete-from-folders-menu-command').canExecuteChange(); |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1225 | 1236 |
1226 /** | 1237 /** |
1227 * @param {EventTarget=} opt_target A target to get bookmark IDs from. | 1238 * @param {EventTarget=} opt_target A target to get bookmark IDs from. |
1228 * @return {Array<string>} An array of bookmarks IDs. | 1239 * @return {Array<string>} An array of bookmarks IDs. |
1229 */ | 1240 */ |
1230 function getFilteredSelectedBookmarkIds(opt_target) { | 1241 function getFilteredSelectedBookmarkIds(opt_target) { |
1231 // Remove duplicates from filteredIds and return. | 1242 // Remove duplicates from filteredIds and return. |
1232 var filteredIds = []; | 1243 var filteredIds = []; |
1233 // Selected nodes to iterate through for matches. | 1244 // Selected nodes to iterate through for matches. |
1234 var nodes = getSelectedBookmarkNodes(opt_target); | 1245 var nodes = getSelectedBookmarkNodes(opt_target); |
1246 if (!nodes) | |
1247 return filteredIds; | |
1235 | 1248 |
1236 for (var i = 0; i < nodes.length; i++) | 1249 for (var i = 0; i < nodes.length; i++) |
1237 if (!hasSelectedAncestor(bmm.tree.getBookmarkNodeById(nodes[i].parentId))) | 1250 if (!hasSelectedAncestor(bmm.tree.getBookmarkNodeById(nodes[i].parentId))) |
1238 filteredIds.splice(0, 0, nodes[i].id); | 1251 filteredIds.splice(0, 0, nodes[i].id); |
1239 | 1252 |
1240 return filteredIds; | 1253 return filteredIds; |
1241 } | 1254 } |
1242 | 1255 |
1243 /** | 1256 /** |
1244 * Handler for the command event. This is used for context menu of list/tree | 1257 * Handler for the command event. This is used for context menu of list/tree |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1506 | 1519 |
1507 cr.ui.FocusOutlineManager.forDocument(document); | 1520 cr.ui.FocusOutlineManager.forDocument(document); |
1508 initializeSplitter(); | 1521 initializeSplitter(); |
1509 bmm.addBookmarkModelListeners(); | 1522 bmm.addBookmarkModelListeners(); |
1510 dnd.init(selectItemsAfterUserAction); | 1523 dnd.init(selectItemsAfterUserAction); |
1511 bmm.tree.reload(); | 1524 bmm.tree.reload(); |
1512 } | 1525 } |
1513 | 1526 |
1514 initializeBookmarkManager(); | 1527 initializeBookmarkManager(); |
1515 })(); | 1528 })(); |
OLD | NEW |