| Index: chrome/browser/resources/md_bookmarks/api_listener.js
|
| diff --git a/chrome/browser/resources/md_bookmarks/api_listener.js b/chrome/browser/resources/md_bookmarks/api_listener.js
|
| index 1e8852cbe7d587a12e13c8fe04c9ef2a0978a0bb..0ea93173bf6b790c5b3cf2879e81bbc305c2d99c 100644
|
| --- a/chrome/browser/resources/md_bookmarks/api_listener.js
|
| +++ b/chrome/browser/resources/md_bookmarks/api_listener.js
|
| @@ -11,6 +11,10 @@ cr.define('bookmarks.ApiListener', function() {
|
|
|
| /** @type {?number} */
|
| var timerHandle;
|
| + /** @type {boolean} */
|
| + var trackUpdatedItems = false;
|
| + /** @type {!Array<string>} */
|
| + var updatedItems = [];
|
|
|
| /**
|
| * Batches UI updates so that no changes will be made to UI until the next
|
| @@ -26,9 +30,26 @@ cr.define('bookmarks.ApiListener', function() {
|
| timerHandle = setTimeout(function() {
|
| bookmarks.Store.getInstance().endBatchUpdate();
|
| timerHandle = null;
|
| +
|
| + if (trackUpdatedItems) {
|
| + document.dispatchEvent(new CustomEvent('highlight-items', {
|
| + detail: updatedItems,
|
| + }));
|
| + updatedItems = [];
|
| + trackUpdatedItems = false;
|
| + }
|
| });
|
| }
|
|
|
| + /**
|
| + * Tracks any items that are created or moved until the next batch update is
|
| + * processed, and highlights them in the bookmark list. Should be called when
|
| + * a user action is going to cause new items to appear in the main list.
|
| + */
|
| + function highlightAfterBatchUpdate() {
|
| + trackUpdatedItems = true;
|
| + }
|
| +
|
| /** @param {Action} action */
|
| function dispatch(action) {
|
| bookmarks.Store.getInstance().dispatch(action);
|
| @@ -48,6 +69,8 @@ cr.define('bookmarks.ApiListener', function() {
|
| */
|
| function onBookmarkCreated(id, treeNode) {
|
| batchUIUpdates();
|
| + if (trackUpdatedItems)
|
| + updatedItems.push(id);
|
| dispatch(bookmarks.actions.createBookmark(id, treeNode));
|
| }
|
|
|
| @@ -73,6 +96,8 @@ cr.define('bookmarks.ApiListener', function() {
|
| */
|
| function onBookmarkMoved(id, moveInfo) {
|
| batchUIUpdates();
|
| + if (trackUpdatedItems)
|
| + updatedItems.push(id);
|
| dispatch(bookmarks.actions.moveBookmark(
|
| id, moveInfo.parentId, moveInfo.index, moveInfo.oldParentId,
|
| moveInfo.oldIndex));
|
| @@ -116,14 +141,18 @@ cr.define('bookmarks.ApiListener', function() {
|
| dispatch(bookmarks.actions.setCanEditBookmarks(canEdit));
|
| }
|
|
|
| + var listeners = [
|
| + {api: chrome.bookmarks.onChanged, fn: onBookmarkChanged},
|
| + {api: chrome.bookmarks.onChildrenReordered, fn: onChildrenReordered},
|
| + {api: chrome.bookmarks.onCreated, fn: onBookmarkCreated},
|
| + {api: chrome.bookmarks.onMoved, fn: onBookmarkMoved},
|
| + {api: chrome.bookmarks.onRemoved, fn: onBookmarkRemoved},
|
| + {api: chrome.bookmarks.onImportBegan, fn: onImportBegan},
|
| + {api: chrome.bookmarks.onImportEnded, fn: onImportEnded},
|
| + ];
|
| +
|
| function init() {
|
| - chrome.bookmarks.onChanged.addListener(onBookmarkChanged);
|
| - chrome.bookmarks.onChildrenReordered.addListener(onChildrenReordered);
|
| - chrome.bookmarks.onCreated.addListener(onBookmarkCreated);
|
| - chrome.bookmarks.onMoved.addListener(onBookmarkMoved);
|
| - chrome.bookmarks.onRemoved.addListener(onBookmarkRemoved);
|
| - chrome.bookmarks.onImportBegan.addListener(onImportBegan);
|
| - chrome.bookmarks.onImportEnded.addListener(onImportEnded);
|
| + listeners.forEach((listener) => listener.api.addListener(listener.fn));
|
|
|
| cr.sendWithPromise('getIncognitoAvailability')
|
| .then(onIncognitoAvailabilityChanged);
|
| @@ -135,7 +164,17 @@ cr.define('bookmarks.ApiListener', function() {
|
| 'can-edit-bookmarks-changed', onCanEditBookmarksChanged);
|
| }
|
|
|
| + function destroy() {
|
| + listeners.forEach((listener) => listener.api.removeListener(listener.fn));
|
| + cr.removeWebUIListener(
|
| + 'incognito-availability-changed', onIncognitoAvailabilityChanged);
|
| + cr.removeWebUIListener(
|
| + 'can-edit-bookmarks-changed', onCanEditBookmarksChanged);
|
| + }
|
| +
|
| return {
|
| init: init,
|
| + destroy: destroy,
|
| + highlightAfterBatchUpdate: highlightAfterBatchUpdate,
|
| };
|
| });
|
|
|