diff options
author | arv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-02 21:22:36 +0000 |
---|---|---|
committer | arv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-02 21:22:36 +0000 |
commit | 857bff35929a3af15166bd3e7f885e1d7113c050 (patch) | |
tree | ae104d0f19d371ce39b9239fddb31f280dd358bc /chrome/browser/resources/bookmark_manager/js/bmm.js | |
parent | 1036feaea6379716f3819c87b83b2018498b5dd8 (diff) | |
download | chromium_src-857bff35929a3af15166bd3e7f885e1d7113c050.zip chromium_src-857bff35929a3af15166bd3e7f885e1d7113c050.tar.gz chromium_src-857bff35929a3af15166bd3e7f885e1d7113c050.tar.bz2 |
Bookmark manager fixes
1. Implement "Add page" and "Add folder".
2. Fix issue where dragging a folder to a subfolder regressed.
3. Disable "Open ..." on folders that have no bookmark descendandts.
4. Add bmm.TreeLoader so we can reuse the call to getTree.
5. Add bmm.TreeIterator so we do not have to duplicate tree traversal code.
6. Fix issue where fast changes in the tree caused infinite navigation hangs.
7. Add some more strings.
8. Remove old temporary hack for the strings since we really need the experimental API at this point anyway.
9. Prevent system beep on copy and cut.
BUG=32194, 36457, 36459
TEST=None
Review URL: http://codereview.chromium.org/660196
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40433 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources/bookmark_manager/js/bmm.js')
-rw-r--r-- | chrome/browser/resources/bookmark_manager/js/bmm.js | 82 |
1 files changed, 78 insertions, 4 deletions
diff --git a/chrome/browser/resources/bookmark_manager/js/bmm.js b/chrome/browser/resources/bookmark_manager/js/bmm.js index 24c4ad0..73cefa6 100644 --- a/chrome/browser/resources/bookmark_manager/js/bmm.js +++ b/chrome/browser/resources/bookmark_manager/js/bmm.js @@ -3,10 +3,15 @@ // found in the LICENSE file. cr.define('bmm', function() { - function isFolder(bookmarkNode) { - return !bookmarkNode.url; - } + const TreeIterator = bmm.TreeIterator; + const Promise = cr.Promise; + /** + * Whether a node contains another node. + * @param {!BookmarkTreeNode} parent + * @param {!BookmarkTreeNode} descendant + * @return {boolean} Whether the parent contains the descendant. + */ function contains(parent, descendant) { if (descendant.parentId == parent.id) return true; @@ -17,8 +22,77 @@ cr.define('bmm', function() { return this.contains(parent, parentTreeItem.bookmarkNode); } + /** + * @param {!BookmarkTreeNode} node The node to test. + * @return {boolean} Whether a bookmark node is a folder. + */ + function isFolder(node) { + return !('url' in node); + } + + var loadingPromise; + + /** + * Loads the entire bookmark tree and returns a {@code cr.Promise} that will + * be fulfilled when done. This reuses multiple loads so that we never load + * more than one tree at the same time. + * @return {!cr.Promise} The future promise for the load. + */ + function loadTree() { + var p = new Promise; + if (!loadingPromise) { + loadingPromise = new Promise; + chrome.bookmarks.getTree(function(nodes) { + loadingPromise.value = nodes[0]; + loadingPromise = null; + }); + } + loadingPromise.addListener(function(n) { + p.value = n; + }); + return p; + } + + /** + * Helper function for {@code loadSubtree}. This does an in order search of + * the tree. + * @param {!BookmarkTreeNode} node The node to start searching at. + * @param {string} id The ID of the node to find. + * @return {BookmarkTreeNode} The found node or null if not found. + */ + function findNode(node, id) { + var it = new TreeIterator(node); + var n; + while (it.moveNext()) { + n = it.current; + if (n.id == id) + return n; + } + return null; + } + + /** + * Loads a subtree of the bookmark tree and returns a {@code cr.Promise} that + * will be fulfilled when done. This reuses multiple loads so that we never + * load more than one tree at the same time. (This actually loads the entire + * tree but it will only return the relevant subtree in the value of the + * future promise.) + * @return {!cr.Promise} The future promise for the load. + */ + function loadSubtree(id) { + var p = new Promise; + var lp = loadTree(); + lp.addListener(function(tree) { + var node = findNode(tree, id); + p.value = node || Error('Failed to load subtree ' + id); + }); + return p; + } + return { + contains: contains, isFolder: isFolder, - contains: contains + loadSubtree: loadSubtree, + loadTree: loadTree }; }); |