diff options
author | arv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-15 21:46:51 +0000 |
---|---|---|
committer | arv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-15 21:46:51 +0000 |
commit | 7dfda6e7fd5942b818f88d85aeaea096b1e76079 (patch) | |
tree | fa77184abf2173eaac73d1de2ddcf416cee27d77 | |
parent | a18bc8f6a04e1a2bc9dc5c03b96d946bd7ba417d (diff) | |
download | chromium_src-7dfda6e7fd5942b818f88d85aeaea096b1e76079.zip chromium_src-7dfda6e7fd5942b818f88d85aeaea096b1e76079.tar.gz chromium_src-7dfda6e7fd5942b818f88d85aeaea096b1e76079.tar.bz2 |
Merge 234842 "BMM: Fix issue with disabled context menu items fo..."
> BMM: Fix issue with disabled context menu items for search "folder".
>
> Revert of revert r233314
>
> Update command state on "load" of a folder.
>
> We used to only update the command when selection changes. However, when
> a folder is loaded the selection does not change, it goes from [] to []
> so no event is fired. However, we do have callbacks after the folder is
> populated. Use that to update the state of all the commands.
>
> BUG=313592
> TBR=kbr@chromium.org
>
> Review URL: https://codereview.chromium.org/65303007
TBR=arv@chromium.org
Review URL: https://codereview.chromium.org/74423002
git-svn-id: svn://svn.chromium.org/chrome/branches/1700/src@235436 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/resources/bookmark_manager/js/main.js | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/chrome/browser/resources/bookmark_manager/js/main.js b/chrome/browser/resources/bookmark_manager/js/main.js index 4036b48..e07ae48 100644 --- a/chrome/browser/resources/bookmark_manager/js/main.js +++ b/chrome/browser/resources/bookmark_manager/js/main.js @@ -144,6 +144,7 @@ function loadLocalizedStrings(data) { */ function updateHash() { window.location.hash = tree.selectedItem.bookmarkId; + updateAllCommands(); } /** @@ -359,12 +360,21 @@ function getAllUrls(nodes) { */ function getNodesForOpen(target) { if (target == tree) { - var folderItem = tree.selectedItem; - return folderItem == searchTreeItem ? - list.dataModel.slice() : tree.selectedFolders; + 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 items = list.selectedItems; - return items.length ? items : list.dataModel.slice(); + + // 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(); } /** @@ -447,7 +457,8 @@ function handleCanExecuteForDocument(e) { e.canExecute = true; break; case 'sort-command': - e.canExecute = !list.isSearch() && list.dataModel.length > 1; + e.canExecute = !list.isSearch() && + list.dataModel && list.dataModel.length > 1; break; case 'undo-command': // The global undo command has no visible UI, so always enable it, and @@ -635,25 +646,12 @@ function handleCanExecuteForTree(e) { } /** - * Update the canExecute state of the commands when the selection changes. - * @param {Event} e The change event object. + * Update the canExecute state of all the commands. */ -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(); - }); +function updateAllCommands() { + var commands = document.querySelectorAll('command'); + for (var i = 0; i < commands.length; i++) { + commands[i].canExecuteChange(); } } @@ -673,7 +671,7 @@ function updateEditingCommands() { } function handleChangeForTree(e) { - updateCommandsBasedOnSelection(e); + updateAllCommands(); navigateTo(tree.selectedItem.bookmarkId, updateHash); } @@ -1229,7 +1227,7 @@ function initializeBookmarkManager() { list.addEventListener('canceledit', handleCancelEdit); list.addEventListener('canExecute', handleCanExecuteForList); - list.addEventListener('change', updateCommandsBasedOnSelection); + list.addEventListener('change', updateAllCommands); list.addEventListener('contextmenu', updateEditingCommands); list.addEventListener('dblclick', handleDoubleClickForList); list.addEventListener('edit', handleEdit); |