summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources
diff options
context:
space:
mode:
authorarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-02 18:40:47 +0000
committerarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-02 18:40:47 +0000
commitbe6cf039815e7a2e27f305283c64aa08c92ff5f6 (patch)
treea26f30d5905caf20e966c8a3b14a31155d6734d4 /chrome/browser/resources
parentaae59c124ade1f6314cec70a4d5e9bc8df9af67b (diff)
downloadchromium_src-be6cf039815e7a2e27f305283c64aa08c92ff5f6.zip
chromium_src-be6cf039815e7a2e27f305283c64aa08c92ff5f6.tar.gz
chromium_src-be6cf039815e7a2e27f305283c64aa08c92ff5f6.tar.bz2
Bookmarks: Make sure we update the UI on import
We used to assume that all bookmark imports were adding a folder to "Other bookmarks". This is not always the case so now we reload the tree and the list instead. BUG=39893 TEST=Start with an empty profile. Click "Import bookmarks" on the bookmarks toolbar. The imported bookmarks and bookmarks folders should show up. Review URL: http://codereview.chromium.org/2485002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48743 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources')
-rw-r--r--chrome/browser/resources/bookmark_manager/js/bmm/bookmark_list.js17
-rw-r--r--chrome/browser/resources/bookmark_manager/js/bmm/bookmark_tree.js20
-rw-r--r--chrome/browser/resources/bookmark_manager/main.html34
3 files changed, 53 insertions, 18 deletions
diff --git a/chrome/browser/resources/bookmark_manager/js/bmm/bookmark_list.js b/chrome/browser/resources/bookmark_manager/js/bmm/bookmark_list.js
index e095600..add55e5 100644
--- a/chrome/browser/resources/bookmark_manager/js/bmm/bookmark_list.js
+++ b/chrome/browser/resources/bookmark_manager/js/bmm/bookmark_list.js
@@ -57,6 +57,17 @@ cr.define('bmm', function() {
var oldParentId = this.parentId_;
this.parentId_ = parentId;
+ this.reload();
+
+ cr.dispatchPropertyChange(this, 'parentId', parentId, oldParentId);
+ },
+
+ /**
+ * Reloads the list from the bookmarks backend.
+ */
+ reload: function() {
+ var parentId = this.parentId;
+
var callback = cr.bind(this.handleBookmarkCallback, this);
this.loading_ = true;
@@ -69,8 +80,6 @@ cr.define('bmm', function() {
} else {
chrome.bookmarks.getChildren(parentId, callback);
}
-
- cr.dispatchPropertyChange(this, 'parentId', parentId, oldParentId);
},
handleBookmarkCallback: function(items) {
@@ -103,8 +112,8 @@ cr.define('bmm', function() {
},
/**
- * The bookmark node that the list is currently displaying. If we are currently
- * displaying recent or search this returns null.
+ * The bookmark node that the list is currently displaying. If we are
+ * currently displaying recent or search this returns null.
* @type {BookmarkTreeNode}
*/
get bookmarkNode() {
diff --git a/chrome/browser/resources/bookmark_manager/js/bmm/bookmark_tree.js b/chrome/browser/resources/bookmark_manager/js/bmm/bookmark_tree.js
index 42e0a10..181210b 100644
--- a/chrome/browser/resources/bookmark_manager/js/bmm/bookmark_tree.js
+++ b/chrome/browser/resources/bookmark_manager/js/bmm/bookmark_tree.js
@@ -149,13 +149,12 @@ cr.define('bmm', function() {
/**
* Fetches the bookmark items and builds the tree control.
*/
- buildTree: function() {
-
+ reload: function() {
/**
* Recursive helper function that adds all the directories to the
* parentTreeItem.
- * @param {!cr.ui.Tree|!cr.ui.TreeItem} parentTreeItem The parent tree element
- * to append to.
+ * @param {!cr.ui.Tree|!cr.ui.TreeItem} parentTreeItem The parent tree
+ * element to append to.
* @param {!Array.<BookmarkTreeNode>} bookmarkNodes
* @return {boolean} Whether any directories where added.
*/
@@ -175,9 +174,22 @@ cr.define('bmm', function() {
var self = this;
chrome.experimental.bookmarkManager.getSubtree('', true, function(root) {
+ self.clear();
buildTreeItems(self, root[0].children);
cr.dispatchSimpleEvent(self, 'load');
});
+ },
+
+ /**
+ * Clears the tree.
+ */
+ clear: function() {
+ // Remove all fields without recreating the object since other code
+ // references it.
+ for (var id in treeLookup){
+ delete treeLookup[id];
+ }
+ this.textContent = '';
}
};
diff --git a/chrome/browser/resources/bookmark_manager/main.html b/chrome/browser/resources/bookmark_manager/main.html
index fa205a0..8cf3174 100644
--- a/chrome/browser/resources/bookmark_manager/main.html
+++ b/chrome/browser/resources/bookmark_manager/main.html
@@ -452,18 +452,30 @@ function handleRemoved(id, removeInfo) {
function handleImportBegan() {
chrome.bookmarks.onCreated.removeListener(handleCreated);
+ chrome.bookmarks.onChanged.removeListener(handleBookmarkChanged);
}
function handleImportEnded() {
- chrome.bookmarks.onCreated.addListener(handleCreated);
- var p = bmm.loadTree();
- p.addListener(function(node) {
- var otherBookmarks = node.children[1].children;
- var importedFolder = otherBookmarks[otherBookmarks.length - 1];
- var importId = importedFolder.id;
- tree.insertSubtree(importedFolder);
- navigateTo(importId)
- });
+ // When importing is done we reload the tree and the list.
+
+ function f() {
+ tree.removeEventListener('load', f);
+
+ chrome.bookmarks.onCreated.addListener(handleCreated);
+ chrome.bookmarks.onChanged.addListener(handleBookmarkChanged);
+
+ if (list.selectImportedFolder) {
+ var otherBookmarks = tree.items[1].items;
+ var importedFolder = otherBookmarks[otherBookmarks.length - 1];
+ navigateTo(importedFolder.bookmarkId)
+ list.selectImportedFolder = false
+ } else {
+ list.reload();
+ }
+ }
+
+ tree.addEventListener('load', f);
+ tree.reload();
}
/**
@@ -516,7 +528,7 @@ tree.addEventListener('load', function(e) {
}
});
-tree.buildTree();
+tree.reload();
addBookmarkModelListeners();
var dnd = {
@@ -1287,6 +1299,8 @@ document.addEventListener('command', function(e) {
var commandId = command.id;
console.log(command.id, 'executed', 'on', e.target);
if (commandId == 'import-menu-command') {
+ // Set a flag on the list so we can select the newly imported folder.
+ list.selectImportedFolder = true;
chrome.bookmarks.import();
} else if (command.id == 'export-menu-command') {
chrome.bookmarks.export();