Chromium Code Reviews| 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 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 var bookmarkNodes = getSelectedBookmarkNodes(); | 817 var bookmarkNodes = getSelectedBookmarkNodes(); |
| 818 // If we double clicked or pressed enter on a single folder, navigate to it. | 818 // If we double clicked or pressed enter on a single folder, navigate to it. |
| 819 if (bookmarkNodes.length == 1 && bmm.isFolder(bookmarkNodes[0])) { | 819 if (bookmarkNodes.length == 1 && bmm.isFolder(bookmarkNodes[0])) { |
| 820 navigateTo(bookmarkNodes[0].id, updateHash); | 820 navigateTo(bookmarkNodes[0].id, updateHash); |
| 821 } else { | 821 } else { |
| 822 openBookmarks(LinkKind.FOREGROUND_TAB); | 822 openBookmarks(LinkKind.FOREGROUND_TAB); |
| 823 } | 823 } |
| 824 } | 824 } |
| 825 | 825 |
| 826 /** | 826 /** |
| 827 * Refreshes search results after delete or undo-delete. | |
| 828 * This ensures children of deleted folders do not remain in results | |
| 829 */ | |
| 830 function updateSearchResults() { | |
|
tfarina
2013/12/10 23:59:32
you need to get arv or dbeam to review the JS part
| |
| 831 if (list.isSearch()) { | |
| 832 // Refresh search results | |
| 833 navigateTo(tree.items[0].id, updateHash); | |
| 834 $('term').focus(); | |
|
arv (Not doing code reviews)
2013/12/11 16:41:38
This is not very nice. Why are we changing focus h
d.halman
2013/12/13 21:04:07
This was a somewhat hacky way to force search resu
| |
| 835 setSearch($('term').value); | |
| 836 } | |
| 837 } | |
| 838 | |
| 839 /** | |
| 827 * Deletes the selected bookmarks. The bookmarks are saved in memory in case | 840 * Deletes the selected bookmarks. The bookmarks are saved in memory in case |
| 828 * the user needs to undo the deletion. | 841 * the user needs to undo the deletion. |
| 829 */ | 842 */ |
| 830 function deleteBookmarks() { | 843 function deleteBookmarks() { |
| 831 var selectedIds = getSelectedBookmarkIds(); | 844 var selectedIds = getSelectedBookmarkIds(); |
| 832 lastDeletedNodes = []; | 845 lastDeletedNodes = []; |
| 833 | 846 |
| 834 function performDelete() { | 847 function performDelete() { |
| 835 chrome.bookmarkManagerPrivate.removeTrees(selectedIds); | 848 chrome.bookmarkManagerPrivate.removeTrees(selectedIds); |
| 836 $('undo-delete-command').canExecuteChange(); | 849 $('undo-delete-command').canExecuteChange(); |
| 837 performGlobalUndo = undoDelete; | 850 performGlobalUndo = undoDelete; |
| 838 } | 851 } |
| 839 | 852 |
| 840 // First, store information about the bookmarks being deleted. | 853 // First, store information about the bookmarks being deleted. |
| 841 selectedIds.forEach(function(id) { | 854 selectedIds.forEach(function(id) { |
| 842 chrome.bookmarks.getSubTree(id, function(results) { | 855 chrome.bookmarks.getSubTree(id, function(results) { |
| 843 lastDeletedNodes.push(results); | 856 lastDeletedNodes.push(results); |
| 844 | 857 |
| 845 // When all nodes have been saved, perform the deletion. | 858 // When all nodes have been saved, perform the deletion. |
| 846 if (lastDeletedNodes.length === selectedIds.length) | 859 if (lastDeletedNodes.length === selectedIds.length) |
| 847 performDelete(); | 860 performDelete(); |
| 861 updateSearchResults(); | |
|
arv (Not doing code reviews)
2013/12/11 16:41:38
I don't understand this. Currently, if I'm deletin
d.halman
2013/12/13 21:04:07
I understand your other comments referring to upda
| |
| 848 }); | 862 }); |
| 849 }); | 863 }); |
| 850 } | 864 } |
| 851 | 865 |
| 852 /** | 866 /** |
| 853 * Restores a tree of bookmarks under a specified folder. | 867 * Restores a tree of bookmarks under a specified folder. |
| 854 * @param {BookmarkTreeNode} node The node to restore. | 868 * @param {BookmarkTreeNode} node The node to restore. |
| 855 * @param {=string} parentId The ID of the folder to restore under. If not | 869 * @param {=string} parentId The ID of the folder to restore under. If not |
| 856 * specified, the original parentId of the node will be used. | 870 * specified, the original parentId of the node will be used. |
| 857 */ | 871 */ |
| 858 function restoreTree(node, parentId) { | 872 function restoreTree(node, parentId) { |
| 859 var bookmarkInfo = { | 873 var bookmarkInfo = { |
| 860 parentId: parentId || node.parentId, | 874 parentId: parentId || node.parentId, |
| 861 title: node.title, | 875 title: node.title, |
| 862 index: node.index, | 876 index: node.index, |
| 863 url: node.url | 877 url: node.url |
| 864 }; | 878 }; |
| 865 | 879 |
| 866 chrome.bookmarks.create(bookmarkInfo, function(result) { | 880 chrome.bookmarks.create(bookmarkInfo, function(result) { |
| 867 if (!result) { | 881 if (!result) { |
| 868 console.error('Failed to restore bookmark.'); | 882 console.error('Failed to restore bookmark.'); |
| 869 return; | 883 return; |
| 870 } | 884 } |
| 871 | 885 |
| 872 if (node.children) { | 886 if (node.children) { |
| 873 // Restore the children using the new ID for this node. | 887 // Restore the children using the new ID for this node. |
| 874 node.children.forEach(function(child) { | 888 node.children.forEach(function(child) { |
| 875 restoreTree(child, result.id); | 889 restoreTree(child, result.id); |
| 876 }); | 890 }); |
| 891 | |
| 892 updateSearchResults(); | |
|
arv (Not doing code reviews)
2013/12/11 16:41:38
This one I think is needed (undo delete does not u
d.halman
2013/12/13 21:04:07
Would there be an efficient way to check restored
arv (Not doing code reviews)
2013/12/13 22:08:14
Not at the moment AFIAK.
| |
| 877 } | 893 } |
| 878 }); | 894 }); |
| 879 } | 895 } |
| 880 | 896 |
| 881 /** | 897 /** |
| 882 * Restores the last set of bookmarks that was deleted. | 898 * Restores the last set of bookmarks that was deleted. |
| 883 */ | 899 */ |
| 884 function undoDelete() { | 900 function undoDelete() { |
| 885 lastDeletedNodes.forEach(function(arr) { | 901 lastDeletedNodes.forEach(function(arr) { |
| 886 arr.forEach(restoreTree); | 902 arr.forEach(restoreTree); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1303 | 1319 |
| 1304 cr.ui.FocusOutlineManager.forDocument(document); | 1320 cr.ui.FocusOutlineManager.forDocument(document); |
| 1305 initializeSplitter(); | 1321 initializeSplitter(); |
| 1306 bmm.addBookmarkModelListeners(); | 1322 bmm.addBookmarkModelListeners(); |
| 1307 dnd.init(selectItemsAfterUserAction); | 1323 dnd.init(selectItemsAfterUserAction); |
| 1308 tree.reload(); | 1324 tree.reload(); |
| 1309 } | 1325 } |
| 1310 | 1326 |
| 1311 initializeBookmarkManager(); | 1327 initializeBookmarkManager(); |
| 1312 })(); | 1328 })(); |
| OLD | NEW |