| Index: chrome/browser/resources/bookmark_manager/js/main.js
|
| diff --git a/chrome/browser/resources/bookmark_manager/js/main.js b/chrome/browser/resources/bookmark_manager/js/main.js
|
| index d5e157fb5fb0758117cefaa7b93ad98fcba3c23e..4036b48730649800dfc88c1feb5a6ff71a864c32 100644
|
| --- a/chrome/browser/resources/bookmark_manager/js/main.js
|
| +++ b/chrome/browser/resources/bookmark_manager/js/main.js
|
| @@ -144,7 +144,6 @@ function loadLocalizedStrings(data) {
|
| */
|
| function updateHash() {
|
| window.location.hash = tree.selectedItem.bookmarkId;
|
| - updateAllCommands();
|
| }
|
|
|
| /**
|
| @@ -360,21 +359,12 @@ function getAllUrls(nodes) {
|
| */
|
| function getNodesForOpen(target) {
|
| if (target == tree) {
|
| - if (tree.selectedItem != searchTreeItem)
|
| - return tree.selectedFolders;
|
| - // Fall through to use all nodes in the list.
|
| - } else {
|
| - var items = list.selectedItems;
|
| - if (items.length)
|
| - return items;
|
| + var folderItem = tree.selectedItem;
|
| + return folderItem == searchTreeItem ?
|
| + list.dataModel.slice() : tree.selectedFolders;
|
| }
|
| -
|
| - // The list starts off with a null dataModel. We can get here during startup.
|
| - if (!list.dataModel)
|
| - return [];
|
| -
|
| - // Return an array based on the dataModel.
|
| - return list.dataModel.slice();
|
| + var items = list.selectedItems;
|
| + return items.length ? items : list.dataModel.slice();
|
| }
|
|
|
| /**
|
| @@ -457,8 +447,7 @@ function handleCanExecuteForDocument(e) {
|
| e.canExecute = true;
|
| break;
|
| case 'sort-command':
|
| - e.canExecute = !list.isSearch() &&
|
| - list.dataModel && list.dataModel.length > 1;
|
| + e.canExecute = !list.isSearch() && list.dataModel.length > 1;
|
| break;
|
| case 'undo-command':
|
| // The global undo command has no visible UI, so always enable it, and
|
| @@ -646,12 +635,25 @@ function handleCanExecuteForTree(e) {
|
| }
|
|
|
| /**
|
| - * Update the canExecute state of all the commands.
|
| + * Update the canExecute state of the commands when the selection changes.
|
| + * @param {Event} e The change event object.
|
| */
|
| -function updateAllCommands() {
|
| - var commands = document.querySelectorAll('command');
|
| - for (var i = 0; i < commands.length; i++) {
|
| - commands[i].canExecuteChange();
|
| +function updateCommandsBasedOnSelection(e) {
|
| + if (e.target == document.activeElement) {
|
| + // Paste only needs to be updated when the tree selection changes.
|
| + var commandNames = ['copy', 'cut', 'delete', 'rename-folder', 'edit',
|
| + 'add-new-bookmark', 'new-folder', 'open-in-new-tab',
|
| + 'open-in-background-tab', 'open-in-new-window', 'open-incognito-window',
|
| + 'open-in-same-window', 'show-in-folder'];
|
| +
|
| + if (e.target == tree) {
|
| + commandNames.push('paste-from-context-menu', 'paste-from-organize-menu',
|
| + 'sort');
|
| + }
|
| +
|
| + commandNames.forEach(function(baseId) {
|
| + $(baseId + '-command').canExecuteChange();
|
| + });
|
| }
|
| }
|
|
|
| @@ -671,7 +673,7 @@ function updateEditingCommands() {
|
| }
|
|
|
| function handleChangeForTree(e) {
|
| - updateAllCommands();
|
| + updateCommandsBasedOnSelection(e);
|
| navigateTo(tree.selectedItem.bookmarkId, updateHash);
|
| }
|
|
|
| @@ -1215,11 +1217,7 @@ function initializeBookmarkManager() {
|
| if (!chrome.bookmarks)
|
| console.error('Bookmarks extension API is not available');
|
|
|
| - chrome.bookmarkManagerPrivate.getStrings(continueInitializeBookmarkManager);
|
| -}
|
| -
|
| -function continueInitializeBookmarkManager(localizedStrings) {
|
| - loadLocalizedStrings(localizedStrings);
|
| + chrome.bookmarkManagerPrivate.getStrings(loadLocalizedStrings);
|
|
|
| bmm.treeLookup[searchTreeItem.bookmarkId] = searchTreeItem;
|
|
|
| @@ -1231,7 +1229,7 @@ function continueInitializeBookmarkManager(localizedStrings) {
|
|
|
| list.addEventListener('canceledit', handleCancelEdit);
|
| list.addEventListener('canExecute', handleCanExecuteForList);
|
| - list.addEventListener('change', updateAllCommands);
|
| + list.addEventListener('change', updateCommandsBasedOnSelection);
|
| list.addEventListener('contextmenu', updateEditingCommands);
|
| list.addEventListener('dblclick', handleDoubleClickForList);
|
| list.addEventListener('edit', handleEdit);
|
|
|