| Index: chrome/browser/resources/md_bookmarks/store.js
|
| diff --git a/chrome/browser/resources/md_bookmarks/store.js b/chrome/browser/resources/md_bookmarks/store.js
|
| index 18506dd4c5fb23e050954454e0357013d7f97005..ff21459643282c4ca1f49947b3c86a09bcb8dd36 100644
|
| --- a/chrome/browser/resources/md_bookmarks/store.js
|
| +++ b/chrome/browser/resources/md_bookmarks/store.js
|
| @@ -14,18 +14,24 @@ var BookmarksStore = Polymer({
|
|
|
| selectedId: {
|
| type: String,
|
| - observer: 'updateSelectedNode_',
|
| + observer: 'updateSelectedDisplay_',
|
| + notify: true,
|
| + },
|
| +
|
| + idToNodeMap_: Object,
|
| +
|
| + searchTerm: {
|
| + type: String,
|
| + observer: 'updateSearchDisplay_',
|
| notify: true,
|
| },
|
|
|
| /** @type {BookmarkTreeNode} */
|
| - selectedNode: {
|
| - type: Object,
|
| + displayedList: {
|
| + type: Array,
|
| notify: true,
|
| readOnly: true,
|
| },
|
| -
|
| - idToNodeMap_: Object,
|
| },
|
|
|
| /** @private {Object} */
|
| @@ -36,6 +42,7 @@ var BookmarksStore = Polymer({
|
| this.documentListeners_ = {
|
| 'selected-folder-changed': this.onSelectedFolderChanged_.bind(this),
|
| 'folder-open-changed': this.onFolderOpenChanged_.bind(this),
|
| + 'search-term-changed': this.onSearchTermChanged_.bind(this),
|
| };
|
| for (var event in this.documentListeners_)
|
| document.addEventListener(event, this.documentListeners_[event]);
|
| @@ -78,6 +85,9 @@ var BookmarksStore = Polymer({
|
| * @private
|
| */
|
| onSelectedFolderChanged_: function(e) {
|
| + if (this.searchTerm)
|
| + this.searchTerm = '';
|
| +
|
| // Deselect the old folder if defined.
|
| if (this.selectedId)
|
| this.set(this.idToNodeMap_[this.selectedId].path + '.isSelected', false);
|
| @@ -88,6 +98,12 @@ var BookmarksStore = Polymer({
|
| this.selectedId = selectedId;
|
| },
|
|
|
| + /** @private */
|
| + deselectFolders_: function() {
|
| + this.set(this.idToNodeMap_[this.selectedId].path + '.isSelected', false);
|
| + this.selectedId = null;
|
| + },
|
| +
|
| /**
|
| * Handles events that open and close folders.
|
| * @param {CustomEvent} e
|
| @@ -106,14 +122,36 @@ var BookmarksStore = Polymer({
|
| * @return {boolean}
|
| */
|
| isAncestorOfSelected_: function(folder) {
|
| - return this.selectedNode.path.startsWith(folder.path);
|
| + if (!this.selectedId)
|
| + return;
|
| +
|
| + var selectedNode = this.idToNodeMap_[this.selectedId];
|
| + return selectedNode.path.startsWith(folder.path);
|
| + },
|
| +
|
| + /** @private */
|
| + updateSearchDisplay_: function() {
|
| + if (this.searchTerm == '') {
|
| + this.fire('selected-folder-changed', this.rootNode.children[0].id);
|
| + } else {
|
| + chrome.bookmarks.search(this.searchTerm, function(results) {
|
| + if (this.selectedId)
|
| + this.deselectFolders_();
|
| +
|
| + this._setDisplayedList(results);
|
| + }.bind(this));
|
| + }
|
| },
|
|
|
| /** @private */
|
| - updateSelectedNode_: function() {
|
| + updateSelectedDisplay_: function() {
|
| + // Don't do change to selected display if ID was cleared.
|
| + if (!this.selectedId)
|
| + return;
|
| +
|
| var selectedNode = this.idToNodeMap_[this.selectedId];
|
| - this.linkPaths('selectedNode', selectedNode.path);
|
| - this._setSelectedNode(selectedNode);
|
| + this.linkPaths('displayedList', selectedNode.path + '.children');
|
| + this._setDisplayedList(selectedNode.children);
|
| },
|
|
|
| /**
|
| @@ -126,13 +164,47 @@ var BookmarksStore = Polymer({
|
| * node: BookmarkTreeNode}} removeInfo
|
| */
|
| onBookmarkRemoved_: function(id, removeInfo) {
|
| - if (this.isAncestorOfSelected_(this.idToNodeMap_[id]))
|
| + if (this.isAncestorOfSelected_(this.idToNodeMap_[id])) {
|
| + // TODO (angelayang): does this ever happen?
|
| this.fire('selected-folder-changed', removeInfo.parentId);
|
| + }
|
|
|
| var parentNode = this.idToNodeMap_[removeInfo.parentId];
|
| this.splice(parentNode.path + '.children', removeInfo.index, 1);
|
| this.removeDescendantsFromMap_(id);
|
| BookmarksStore.generatePaths(parentNode, removeInfo.index);
|
| +
|
| + // Regenerate the search list if its displayed.
|
| + if (this.searchTerm)
|
| + this.updateSearchDisplay_();
|
| + },
|
| +
|
| + /**
|
| + * Initializes the nodes in the bookmarks tree as follows:
|
| + * - Populates |idToNodeMap_| with a mapping of all node ids to their
|
| + * corresponding BookmarkTreeNode.
|
| + * - Sets all the nodes to not selected and open by default.
|
| + * @param {BookmarkTreeNode} bookmarkNode
|
| + * @private
|
| + */
|
| + initNodes_: function(bookmarkNode) {
|
| + this.idToNodeMap_[bookmarkNode.id] = bookmarkNode;
|
| + if (bookmarkNode.url)
|
| + return;
|
| +
|
| + bookmarkNode.isSelected = false;
|
| + bookmarkNode.isOpen = true;
|
| + for (var i = 0; i < bookmarkNode.children.length; i++) {
|
| + this.initNodes_(bookmarkNode.children[i]);
|
| + }
|
| + },
|
| +
|
| + /**
|
| + * @param {Event} e
|
| + * @private
|
| + */
|
| + onSearchTermChanged_: function(e) {
|
| + this.searchTerm = /** @type {string} */ (e.detail);
|
| },
|
|
|
| /**
|
|
|