Commit 97dc7f85 authored by kbr@chromium.org's avatar kbr@chromium.org

Revert "BMM: Split initialization into two phases"

This reverts commit 31f458db.

Revert "Update command state on "load" of a folder"

This reverts commit 778b807f.

These caused the browser_test BookmarksTest.CommandOpensBookmarksTab
to hang on Linux Aura.

BUG=312356,313592,315408
TBR=arv@chromium.org,dbeam@chromium.org

Review URL: https://codereview.chromium.org/62713002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233314 0039d316-1c4b-4281-b951-d872f2087c98
parent a53aa155
...@@ -144,7 +144,6 @@ function loadLocalizedStrings(data) { ...@@ -144,7 +144,6 @@ function loadLocalizedStrings(data) {
*/ */
function updateHash() { function updateHash() {
window.location.hash = tree.selectedItem.bookmarkId; window.location.hash = tree.selectedItem.bookmarkId;
updateAllCommands();
} }
/** /**
...@@ -360,21 +359,12 @@ function getAllUrls(nodes) { ...@@ -360,21 +359,12 @@ function getAllUrls(nodes) {
*/ */
function getNodesForOpen(target) { function getNodesForOpen(target) {
if (target == tree) { if (target == tree) {
if (tree.selectedItem != searchTreeItem) var folderItem = tree.selectedItem;
return tree.selectedFolders; return folderItem == searchTreeItem ?
// Fall through to use all nodes in the list. list.dataModel.slice() : tree.selectedFolders;
} else {
var items = list.selectedItems;
if (items.length)
return items;
} }
var items = list.selectedItems;
// The list starts off with a null dataModel. We can get here during startup. return items.length ? items : list.dataModel.slice();
if (!list.dataModel)
return [];
// Return an array based on the dataModel.
return list.dataModel.slice();
} }
/** /**
...@@ -457,8 +447,7 @@ function handleCanExecuteForDocument(e) { ...@@ -457,8 +447,7 @@ function handleCanExecuteForDocument(e) {
e.canExecute = true; e.canExecute = true;
break; break;
case 'sort-command': case 'sort-command':
e.canExecute = !list.isSearch() && e.canExecute = !list.isSearch() && list.dataModel.length > 1;
list.dataModel && list.dataModel.length > 1;
break; break;
case 'undo-command': case 'undo-command':
// The global undo command has no visible UI, so always enable it, and // The global undo command has no visible UI, so always enable it, and
...@@ -646,12 +635,25 @@ function handleCanExecuteForTree(e) { ...@@ -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() { function updateCommandsBasedOnSelection(e) {
var commands = document.querySelectorAll('command'); if (e.target == document.activeElement) {
for (var i = 0; i < commands.length; i++) { // Paste only needs to be updated when the tree selection changes.
commands[i].canExecuteChange(); 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() { ...@@ -671,7 +673,7 @@ function updateEditingCommands() {
} }
function handleChangeForTree(e) { function handleChangeForTree(e) {
updateAllCommands(); updateCommandsBasedOnSelection(e);
navigateTo(tree.selectedItem.bookmarkId, updateHash); navigateTo(tree.selectedItem.bookmarkId, updateHash);
} }
...@@ -1215,11 +1217,7 @@ function initializeBookmarkManager() { ...@@ -1215,11 +1217,7 @@ function initializeBookmarkManager() {
if (!chrome.bookmarks) if (!chrome.bookmarks)
console.error('Bookmarks extension API is not available'); console.error('Bookmarks extension API is not available');
chrome.bookmarkManagerPrivate.getStrings(continueInitializeBookmarkManager); chrome.bookmarkManagerPrivate.getStrings(loadLocalizedStrings);
}
function continueInitializeBookmarkManager(localizedStrings) {
loadLocalizedStrings(localizedStrings);
bmm.treeLookup[searchTreeItem.bookmarkId] = searchTreeItem; bmm.treeLookup[searchTreeItem.bookmarkId] = searchTreeItem;
...@@ -1231,7 +1229,7 @@ function continueInitializeBookmarkManager(localizedStrings) { ...@@ -1231,7 +1229,7 @@ function continueInitializeBookmarkManager(localizedStrings) {
list.addEventListener('canceledit', handleCancelEdit); list.addEventListener('canceledit', handleCancelEdit);
list.addEventListener('canExecute', handleCanExecuteForList); list.addEventListener('canExecute', handleCanExecuteForList);
list.addEventListener('change', updateAllCommands); list.addEventListener('change', updateCommandsBasedOnSelection);
list.addEventListener('contextmenu', updateEditingCommands); list.addEventListener('contextmenu', updateEditingCommands);
list.addEventListener('dblclick', handleDoubleClickForList); list.addEventListener('dblclick', handleDoubleClickForList);
list.addEventListener('edit', handleEdit); list.addEventListener('edit', handleEdit);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment