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

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

Issue 102713002: Support folders in bookmark search (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handle single node restoration and only update once per batch delete Created 7 years 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
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 806 matching lines...) Expand 10 before | Expand all | Expand 10 after
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() {
831 if (list.isSearch()) {
832 list.reload();
833 }
834 }
835
836 /**
827 * Deletes the selected bookmarks. The bookmarks are saved in memory in case 837 * Deletes the selected bookmarks. The bookmarks are saved in memory in case
828 * the user needs to undo the deletion. 838 * the user needs to undo the deletion.
829 */ 839 */
830 function deleteBookmarks() { 840 function deleteBookmarks() {
831 var selectedIds = getSelectedBookmarkIds(); 841 var selectedIds = getSelectedBookmarkIds();
832 lastDeletedNodes = []; 842 lastDeletedNodes = [];
833 843
834 function performDelete() { 844 function performDelete() {
835 chrome.bookmarkManagerPrivate.removeTrees(selectedIds); 845 chrome.bookmarkManagerPrivate.removeTrees(selectedIds);
836 $('undo-delete-command').canExecuteChange(); 846 $('undo-delete-command').canExecuteChange();
837 performGlobalUndo = undoDelete; 847 performGlobalUndo = undoDelete;
838 } 848 }
839 849
840 // First, store information about the bookmarks being deleted. 850 // First, store information about the bookmarks being deleted.
841 selectedIds.forEach(function(id) { 851 selectedIds.forEach(function(id) {
842 chrome.bookmarks.getSubTree(id, function(results) { 852 chrome.bookmarks.getSubTree(id, function(results) {
843 lastDeletedNodes.push(results); 853 lastDeletedNodes.push(results);
844 854
845 // When all nodes have been saved, perform the deletion. 855 // When all nodes have been saved, perform the deletion.
846 if (lastDeletedNodes.length === selectedIds.length) 856 if (lastDeletedNodes.length === selectedIds.length) {
847 performDelete(); 857 performDelete();
858 updateSearchResults();
859 }
848 }); 860 });
849 }); 861 });
850 } 862 }
851 863
852 /** 864 /**
853 * Restores a tree of bookmarks under a specified folder. 865 * Restores a tree of bookmarks under a specified folder.
854 * @param {BookmarkTreeNode} node The node to restore. 866 * @param {BookmarkTreeNode} node The node to restore.
855 * @param {=string} parentId The ID of the folder to restore under. If not 867 * @param {=string} parentId The ID of the folder to restore under. If not
856 * specified, the original parentId of the node will be used. 868 * specified, the original parentId of the node will be used.
857 */ 869 */
(...skipping 10 matching lines...) Expand all
868 console.error('Failed to restore bookmark.'); 880 console.error('Failed to restore bookmark.');
869 return; 881 return;
870 } 882 }
871 883
872 if (node.children) { 884 if (node.children) {
873 // Restore the children using the new ID for this node. 885 // Restore the children using the new ID for this node.
874 node.children.forEach(function(child) { 886 node.children.forEach(function(child) {
875 restoreTree(child, result.id); 887 restoreTree(child, result.id);
876 }); 888 });
877 } 889 }
890
891 updateSearchResults();
878 }); 892 });
879 } 893 }
880 894
881 /** 895 /**
882 * Restores the last set of bookmarks that was deleted. 896 * Restores the last set of bookmarks that was deleted.
883 */ 897 */
884 function undoDelete() { 898 function undoDelete() {
885 lastDeletedNodes.forEach(function(arr) { 899 lastDeletedNodes.forEach(function(arr) {
886 arr.forEach(restoreTree); 900 arr.forEach(restoreTree);
887 }); 901 });
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 1317
1304 cr.ui.FocusOutlineManager.forDocument(document); 1318 cr.ui.FocusOutlineManager.forDocument(document);
1305 initializeSplitter(); 1319 initializeSplitter();
1306 bmm.addBookmarkModelListeners(); 1320 bmm.addBookmarkModelListeners();
1307 dnd.init(selectItemsAfterUserAction); 1321 dnd.init(selectItemsAfterUserAction);
1308 tree.reload(); 1322 tree.reload();
1309 } 1323 }
1310 1324
1311 initializeBookmarkManager(); 1325 initializeBookmarkManager();
1312 })(); 1326 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698