Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 var BookmarksStore = Polymer({ | 5 var BookmarksStore = Polymer({ |
| 6 is: 'bookmarks-store', | 6 is: 'bookmarks-store', |
| 7 | 7 |
| 8 properties: { | 8 properties: { |
| 9 /** @type {BookmarkTreeNode} */ | 9 /** @type {BookmarkTreeNode} */ |
| 10 rootNode: { | 10 rootNode: { |
| 11 type: Object, | 11 type: Object, |
| 12 notify: true, | 12 notify: true, |
| 13 }, | 13 }, |
| 14 | 14 |
| 15 /** @type {?string} */ | 15 /** @type {?string} */ |
|
tsergeant
2017/01/25 00:23:18
There's now no way for this to be null, right? You
angelayang
2017/01/31 02:25:03
Done.
| |
| 16 selectedId: { | 16 selectedId: { |
| 17 type: String, | 17 type: String, |
| 18 observer: 'updateSelectedDisplay_', | 18 observer: 'updateSelectedDisplay_', |
| 19 notify: true, | 19 notify: true, |
| 20 }, | 20 }, |
| 21 | 21 |
| 22 searchTerm: { | 22 searchTerm: { |
| 23 type: String, | 23 type: String, |
| 24 observer: 'updateSearchDisplay_', | 24 observer: 'updateSearchDisplay_', |
| 25 notify: true, | 25 notify: true, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 if (this.$.router.searchTerm) | 90 if (this.$.router.searchTerm) |
| 91 this.searchTerm = this.$.router.searchTerm; | 91 this.searchTerm = this.$.router.searchTerm; |
| 92 else | 92 else |
| 93 this.fire('selected-folder-changed', this.$.router.selectedId); | 93 this.fire('selected-folder-changed', this.$.router.selectedId); |
| 94 }, | 94 }, |
| 95 | 95 |
| 96 /** @private */ | 96 /** @private */ |
| 97 deselectFolders_: function() { | 97 deselectFolders_: function() { |
| 98 this.unlinkPaths('displayedList'); | 98 this.unlinkPaths('displayedList'); |
| 99 this.set(this.idToNodeMap_[this.selectedId].path + '.isSelected', false); | 99 this.set(this.idToNodeMap_[this.selectedId].path + '.isSelected', false); |
| 100 this.selectedId = null; | |
| 101 }, | 100 }, |
| 102 | 101 |
| 103 /** | 102 /** |
| 104 * @param {BookmarkTreeNode} folder | 103 * @param {BookmarkTreeNode} folder |
| 105 * @private | 104 * @private |
| 106 * @return {boolean} | 105 * @return {boolean} |
| 107 */ | 106 */ |
| 108 isAncestorOfSelected_: function(folder) { | 107 isAncestorOfSelected_: function(folder) { |
| 109 if (!this.selectedId) | 108 if (!this.selectedId) |
| 110 return false; | 109 return false; |
| 111 | 110 |
| 112 var selectedNode = this.idToNodeMap_[this.selectedId]; | 111 var selectedNode = this.idToNodeMap_[this.selectedId]; |
| 113 return selectedNode.path.startsWith(folder.path); | 112 return selectedNode.path.startsWith(folder.path); |
| 114 }, | 113 }, |
| 115 | 114 |
| 116 /** @private */ | 115 /** @private */ |
| 117 updateSearchDisplay_: function() { | 116 updateSearchDisplay_: function() { |
| 118 if (!this.searchTerm) { | 117 if (!this.searchTerm) { |
| 119 this.fire('selected-folder-changed', this.rootNode.children[0].id); | 118 var selectedFolder = |
| 119 this.selectedId ? this.selectedId : this.rootNode.children[0].id; | |
| 120 this.fire('selected-folder-changed', selectedFolder); | |
|
tsergeant
2017/01/25 00:23:18
I mentioned this before, but I think now is the ri
angelayang
2017/01/31 02:25:03
Yep all that works
| |
| 121 this.updateSelectedDisplay_(); | |
| 120 } else { | 122 } else { |
| 121 chrome.bookmarks.search(this.searchTerm, function(results) { | 123 chrome.bookmarks.search(this.searchTerm, function(results) { |
| 122 if (this.selectedId) | 124 if (this.selectedId) |
| 123 this.deselectFolders_(); | 125 this.deselectFolders_(); |
| 124 | 126 |
| 125 this._setDisplayedList(results); | 127 this._setDisplayedList(results); |
| 126 }.bind(this)); | 128 }.bind(this)); |
| 127 } | 129 } |
| 128 }, | 130 }, |
| 129 | 131 |
| 130 /** @private */ | 132 /** @private */ |
| 131 updateSelectedDisplay_: function() { | 133 updateSelectedDisplay_: function() { |
| 132 // Don't change to the selected display if ID was cleared. | |
| 133 if (!this.selectedId) | |
| 134 return; | |
| 135 | |
| 136 var selectedNode = this.idToNodeMap_[this.selectedId]; | 134 var selectedNode = this.idToNodeMap_[this.selectedId]; |
| 137 this.linkPaths('displayedList', selectedNode.path + '.children'); | 135 this.linkPaths('displayedList', selectedNode.path + '.children'); |
| 138 this._setDisplayedList(selectedNode.children); | 136 this._setDisplayedList(selectedNode.children); |
| 139 }, | 137 }, |
| 140 | 138 |
| 141 /** | 139 /** |
| 142 * Remove all descendants of a given node from the map. | 140 * Remove all descendants of a given node from the map. |
| 143 * @param {string} id | 141 * @param {string} id |
| 144 * @private | 142 * @private |
| 145 */ | 143 */ |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 }, | 230 }, |
| 233 | 231 |
| 234 /** | 232 /** |
| 235 * Handles events that open and close folders. | 233 * Handles events that open and close folders. |
| 236 * @param {CustomEvent} e | 234 * @param {CustomEvent} e |
| 237 * @private | 235 * @private |
| 238 */ | 236 */ |
| 239 onFolderOpenChanged_: function(e) { | 237 onFolderOpenChanged_: function(e) { |
| 240 var folder = this.idToNodeMap_[e.detail.id]; | 238 var folder = this.idToNodeMap_[e.detail.id]; |
| 241 this.set(folder.path + '.isOpen', e.detail.open); | 239 this.set(folder.path + '.isOpen', e.detail.open); |
| 242 if (!folder.isOpen && this.isAncestorOfSelected_(folder)) | 240 if (folder.isOpen || !this.isAncestorOfSelected_(folder)) |
| 241 return; | |
| 242 | |
| 243 // Save the closed folder as the selectedId. | |
| 244 if (this.searchTerm) | |
|
angelayang
2017/01/31 02:25:03
This piece of logic reoccurs a few times so i'm go
| |
| 245 this.selectedId = folder.id; | |
| 246 else | |
| 243 this.fire('selected-folder-changed', folder.id); | 247 this.fire('selected-folder-changed', folder.id); |
| 244 }, | 248 }, |
| 245 }); | 249 }); |
| 246 | 250 |
| 247 //////////////////////////////////////////////////////////////////////////////// | 251 //////////////////////////////////////////////////////////////////////////////// |
| 248 // bookmarks-store, static methods: | 252 // bookmarks-store, static methods: |
| 249 | 253 |
| 250 /** | 254 /** |
| 251 * Stores the path from the store to a node inside the node. | 255 * Stores the path from the store to a node inside the node. |
| 252 * @param {BookmarkTreeNode} bookmarkNode | 256 * @param {BookmarkTreeNode} bookmarkNode |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 275 idToNodeMap[bookmarkNode.id] = bookmarkNode; | 279 idToNodeMap[bookmarkNode.id] = bookmarkNode; |
| 276 | 280 |
| 277 if (bookmarkNode.url) | 281 if (bookmarkNode.url) |
| 278 return; | 282 return; |
| 279 | 283 |
| 280 bookmarkNode.isSelected = false; | 284 bookmarkNode.isSelected = false; |
| 281 bookmarkNode.isOpen = true; | 285 bookmarkNode.isOpen = true; |
| 282 for (var i = 0; i < bookmarkNode.children.length; i++) | 286 for (var i = 0; i < bookmarkNode.children.length; i++) |
| 283 BookmarksStore.initNodes(bookmarkNode.children[i], idToNodeMap); | 287 BookmarksStore.initNodes(bookmarkNode.children[i], idToNodeMap); |
| 284 }; | 288 }; |
| OLD | NEW |