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 4036b48730649800dfc88c1feb5a6ff71a864c32..7060e2a64ba5ca8e2eacf36e5033e1299366270e 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(); |
} |
/** |
@@ -363,8 +364,16 @@ function getNodesForOpen(target) { |
return folderItem == searchTreeItem ? |
list.dataModel.slice() : tree.selectedFolders; |
} |
+ |
var items = list.selectedItems; |
- return items.length ? items : list.dataModel.slice(); |
+ if (items.length) |
+ return items; |
+ |
+ // The list starts off with a null dataModel. We can get here during startup. |
+ if (!list.dataModel) |
+ return []; |
+ |
+ return list.dataModel.slice(); |
Dan Beam
2013/11/04 22:19:21
nit: if this is to make a copy, can you comment th
arv (Not doing code reviews)
2013/11/04 22:29:22
Freezing is not an option. I'll add a comment.
|
} |
/** |
@@ -447,7 +456,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 +645,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 +670,7 @@ function updateEditingCommands() { |
} |
function handleChangeForTree(e) { |
- updateCommandsBasedOnSelection(e); |
+ updateAllCommands(); |
navigateTo(tree.selectedItem.bookmarkId, updateHash); |
} |
@@ -1229,7 +1226,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); |