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

Side by Side Diff: chrome/browser/resources/md_bookmarks/store.js

Issue 2675503002: [MD Bookmarks] Remove Multiple Selected Items. (Closed)
Patch Set: section Created 3 years, 10 months 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
« no previous file with comments | « chrome/browser/resources/md_bookmarks/list.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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: {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 }, 51 },
52 52
53 /** @private {Object} */ 53 /** @private {Object} */
54 documentListeners_: null, 54 documentListeners_: null,
55 55
56 /** @override */ 56 /** @override */
57 attached: function() { 57 attached: function() {
58 this.documentListeners_ = { 58 this.documentListeners_ = {
59 'folder-open-changed': this.onFolderOpenChanged_.bind(this), 59 'folder-open-changed': this.onFolderOpenChanged_.bind(this),
60 'open-item': this.onItemOpened_.bind(this), 60 'open-item': this.onItemOpened_.bind(this),
61 'remove-item': this.onItemRemoved_.bind(this),
61 'search-term-changed': this.onSearchTermChanged_.bind(this), 62 'search-term-changed': this.onSearchTermChanged_.bind(this),
62 'select-item': this.onItemSelected_.bind(this), 63 'select-item': this.onItemSelected_.bind(this),
63 'selected-folder-changed': this.onSelectedFolderChanged_.bind(this), 64 'selected-folder-changed': this.onSelectedFolderChanged_.bind(this),
64 }; 65 };
65 for (var event in this.documentListeners_) 66 for (var event in this.documentListeners_)
66 document.addEventListener(event, this.documentListeners_[event]); 67 document.addEventListener(event, this.documentListeners_[event]);
67 }, 68 },
68 69
69 /** @override */ 70 /** @override */
70 detached: function() { 71 detached: function() {
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 * Selects a single item in the displayedList. 268 * Selects a single item in the displayedList.
268 * @param {BookmarkTreeNode} item 269 * @param {BookmarkTreeNode} item
269 * @private 270 * @private
270 */ 271 */
271 selectItem_: function(item) { 272 selectItem_: function(item) {
272 this.anchorIndex_ = this.getIndexInList_(item); 273 this.anchorIndex_ = this.getIndexInList_(item);
273 this.set('displayedList.#' + this.anchorIndex_ + '.isSelectedItem', true); 274 this.set('displayedList.#' + this.anchorIndex_ + '.isSelectedItem', true);
274 this.selectedIndexSet_.add(this.anchorIndex_); 275 this.selectedIndexSet_.add(this.anchorIndex_);
275 }, 276 },
276 277
278 /**
279 * @param {BookmarkTreeNode} item
280 * @private
281 */
282 removeSingleItem_: function(item) {
283 if (item.url) {
284 chrome.bookmarks.remove(item.id, function() {
285 // TODO(jiaxi): Add toast later.
286 }.bind(this));
287 } else {
288 chrome.bookmarks.removeTree(item.id, function() {
289 // TODO(jiaxi): Add toast later.
290 }.bind(this));
291 }
292 },
293
277 ////////////////////////////////////////////////////////////////////////////// 294 //////////////////////////////////////////////////////////////////////////////
278 // bookmarks-store, bookmarks API event listeners: 295 // bookmarks-store, bookmarks API event listeners:
279 296
280 /** 297 /**
281 * Callback for when a bookmark node is removed. 298 * Callback for when a bookmark node is removed.
282 * If a folder is selected or is an ancestor of a selected folder, the parent 299 * If a folder is selected or is an ancestor of a selected folder, the parent
283 * of the removed folder will be selected. 300 * of the removed folder will be selected.
284 * @param {string} id The id of the removed bookmark node. 301 * @param {string} id The id of the removed bookmark node.
285 * @param {!{index: number, 302 * @param {!{index: number,
286 * parentId: string, 303 * parentId: string,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 chrome.tabs.create({url: item.url}); 443 chrome.tabs.create({url: item.url});
427 } else { 444 } else {
428 for (let index of this.selectedIndexSet_) { 445 for (let index of this.selectedIndexSet_) {
429 if (!this.displayedList[index].url) 446 if (!this.displayedList[index].url)
430 continue; 447 continue;
431 448
432 chrome.tabs.create({url: this.displayedList[index].url}); 449 chrome.tabs.create({url: this.displayedList[index].url});
433 } 450 }
434 } 451 }
435 }, 452 },
453
454 /**
455 * @param {CustomEvent} e
456 * @private
457 */
458 onItemRemoved_: function(e) {
459 var item = /** BookmarkTreeNode */ (e.detail);
460 if (this.selectedIndexSet_.size == 1 || !item.isSelectedItem) {
461 this.removeSingleItem_(item);
462 } else {
463 var itemsToRemoved = [];
464 for (let index of this.selectedIndexSet_)
465 itemsToRemoved.push(this.displayedList[index]);
466
467 for (var i = 0; i < itemsToRemoved.length; i++)
468 this.removeSingleItem_(itemsToRemoved[i]);
jiaxi 2017/02/01 23:32:13 This probably needs a test but I'm not sure how to
tsergeant 2017/02/02 02:12:15 That sounds like a reasonable way to do it.
jiaxi 2017/02/02 05:37:19 Done.
469 }
470 },
436 }); 471 });
437 472
438 //////////////////////////////////////////////////////////////////////////////// 473 ////////////////////////////////////////////////////////////////////////////////
439 // bookmarks-store, static methods: 474 // bookmarks-store, static methods:
440 475
441 /** 476 /**
442 * Stores the path from the store to a node inside the node. 477 * Stores the path from the store to a node inside the node.
443 * @param {BookmarkTreeNode} bookmarkNode 478 * @param {BookmarkTreeNode} bookmarkNode
444 * @param {number} startIndex 479 * @param {number} startIndex
445 */ 480 */
(...skipping 21 matching lines...) Expand all
467 idToNodeMap[bookmarkNode.id] = bookmarkNode; 502 idToNodeMap[bookmarkNode.id] = bookmarkNode;
468 503
469 if (bookmarkNode.url) 504 if (bookmarkNode.url)
470 return; 505 return;
471 506
472 bookmarkNode.isSelectedFolder = false; 507 bookmarkNode.isSelectedFolder = false;
473 bookmarkNode.isOpen = true; 508 bookmarkNode.isOpen = true;
474 for (var i = 0; i < bookmarkNode.children.length; i++) 509 for (var i = 0; i < bookmarkNode.children.length; i++)
475 BookmarksStore.initNodes(bookmarkNode.children[i], idToNodeMap); 510 BookmarksStore.initNodes(bookmarkNode.children[i], idToNodeMap);
476 }; 511 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/list.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698