Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: chrome/browser/resources/bookmark_manager/js/main.js

Issue 62713002: Revert "BMM: Split initialization into two phases" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function() { 5 (function() {
6 /** @const */ var BookmarkList = bmm.BookmarkList; 6 /** @const */ var BookmarkList = bmm.BookmarkList;
7 /** @const */ var BookmarkTree = bmm.BookmarkTree; 7 /** @const */ var BookmarkTree = bmm.BookmarkTree;
8 /** @const */ var Command = cr.ui.Command; 8 /** @const */ var Command = cr.ui.Command;
9 /** @const */ var CommandBinding = cr.ui.CommandBinding; 9 /** @const */ var CommandBinding = cr.ui.CommandBinding;
10 /** @const */ var LinkKind = cr.LinkKind; 10 /** @const */ var LinkKind = cr.LinkKind;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 searchTreeItem.label = loadTimeData.getString('search'); 137 searchTreeItem.label = loadTimeData.getString('search');
138 searchTreeItem.icon = isRTL() ? 'images/bookmark_manager_search_rtl.png' : 138 searchTreeItem.icon = isRTL() ? 'images/bookmark_manager_search_rtl.png' :
139 'images/bookmark_manager_search.png'; 139 'images/bookmark_manager_search.png';
140 } 140 }
141 141
142 /** 142 /**
143 * Updates the location hash to reflect the current state of the application. 143 * Updates the location hash to reflect the current state of the application.
144 */ 144 */
145 function updateHash() { 145 function updateHash() {
146 window.location.hash = tree.selectedItem.bookmarkId; 146 window.location.hash = tree.selectedItem.bookmarkId;
147 updateAllCommands();
148 } 147 }
149 148
150 /** 149 /**
151 * Navigates to a bookmark ID. 150 * Navigates to a bookmark ID.
152 * @param {string} id The ID to navigate to. 151 * @param {string} id The ID to navigate to.
153 * @param {function()} callback Function called when list view loaded or 152 * @param {function()} callback Function called when list view loaded or
154 * displayed specified folder. 153 * displayed specified folder.
155 */ 154 */
156 function navigateTo(id, callback) { 155 function navigateTo(id, callback) {
157 updateHash(id); 156 updateHash(id);
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 return urlsPromise; 352 return urlsPromise;
354 } 353 }
355 354
356 /** 355 /**
357 * Returns the nodes (non recursive) to use for the open commands. 356 * Returns the nodes (non recursive) to use for the open commands.
358 * @param {HTMLElement} target . 357 * @param {HTMLElement} target .
359 * @return {Array.<BookmarkTreeNode>} . 358 * @return {Array.<BookmarkTreeNode>} .
360 */ 359 */
361 function getNodesForOpen(target) { 360 function getNodesForOpen(target) {
362 if (target == tree) { 361 if (target == tree) {
363 if (tree.selectedItem != searchTreeItem) 362 var folderItem = tree.selectedItem;
364 return tree.selectedFolders; 363 return folderItem == searchTreeItem ?
365 // Fall through to use all nodes in the list. 364 list.dataModel.slice() : tree.selectedFolders;
366 } else {
367 var items = list.selectedItems;
368 if (items.length)
369 return items;
370 } 365 }
371 366 var items = list.selectedItems;
372 // The list starts off with a null dataModel. We can get here during startup. 367 return items.length ? items : list.dataModel.slice();
373 if (!list.dataModel)
374 return [];
375
376 // Return an array based on the dataModel.
377 return list.dataModel.slice();
378 } 368 }
379 369
380 /** 370 /**
381 * Returns a promise that will contain all URLs of all the selected bookmarks 371 * Returns a promise that will contain all URLs of all the selected bookmarks
382 * and the nested bookmarks for use with the open commands. 372 * and the nested bookmarks for use with the open commands.
383 * @param {HTMLElement} target The target list or tree. 373 * @param {HTMLElement} target The target list or tree.
384 * @return {Promise} . 374 * @return {Promise} .
385 */ 375 */
386 function getUrlsForOpenCommands(target) { 376 function getUrlsForOpenCommands(target) {
387 return getAllUrls(getNodesForOpen(target)); 377 return getAllUrls(getNodesForOpen(target));
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 var command = e.command; 440 var command = e.command;
451 switch (command.id) { 441 switch (command.id) {
452 case 'import-menu-command': 442 case 'import-menu-command':
453 e.canExecute = canEdit; 443 e.canExecute = canEdit;
454 break; 444 break;
455 case 'export-menu-command': 445 case 'export-menu-command':
456 // We can always execute the export-menu command. 446 // We can always execute the export-menu command.
457 e.canExecute = true; 447 e.canExecute = true;
458 break; 448 break;
459 case 'sort-command': 449 case 'sort-command':
460 e.canExecute = !list.isSearch() && 450 e.canExecute = !list.isSearch() && list.dataModel.length > 1;
461 list.dataModel && list.dataModel.length > 1;
462 break; 451 break;
463 case 'undo-command': 452 case 'undo-command':
464 // The global undo command has no visible UI, so always enable it, and 453 // The global undo command has no visible UI, so always enable it, and
465 // just make it a no-op if undo is not possible. 454 // just make it a no-op if undo is not possible.
466 e.canExecute = true; 455 e.canExecute = true;
467 break; 456 break;
468 default: 457 default:
469 canExecuteForList(e); 458 canExecuteForList(e);
470 break; 459 break;
471 } 460 }
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 case 'copy-command': 628 case 'copy-command':
640 e.canExecute = hasSelected() && !isTopLevelItem(); 629 e.canExecute = hasSelected() && !isTopLevelItem();
641 break; 630 break;
642 631
643 default: 632 default:
644 canExecuteShared(e, isSearch()); 633 canExecuteShared(e, isSearch());
645 } 634 }
646 } 635 }
647 636
648 /** 637 /**
649 * Update the canExecute state of all the commands. 638 * Update the canExecute state of the commands when the selection changes.
639 * @param {Event} e The change event object.
650 */ 640 */
651 function updateAllCommands() { 641 function updateCommandsBasedOnSelection(e) {
652 var commands = document.querySelectorAll('command'); 642 if (e.target == document.activeElement) {
653 for (var i = 0; i < commands.length; i++) { 643 // Paste only needs to be updated when the tree selection changes.
654 commands[i].canExecuteChange(); 644 var commandNames = ['copy', 'cut', 'delete', 'rename-folder', 'edit',
645 'add-new-bookmark', 'new-folder', 'open-in-new-tab',
646 'open-in-background-tab', 'open-in-new-window', 'open-incognito-window',
647 'open-in-same-window', 'show-in-folder'];
648
649 if (e.target == tree) {
650 commandNames.push('paste-from-context-menu', 'paste-from-organize-menu',
651 'sort');
652 }
653
654 commandNames.forEach(function(baseId) {
655 $(baseId + '-command').canExecuteChange();
656 });
655 } 657 }
656 } 658 }
657 659
658 function updateEditingCommands() { 660 function updateEditingCommands() {
659 var editingCommands = ['cut', 'delete', 'rename-folder', 'edit', 661 var editingCommands = ['cut', 'delete', 'rename-folder', 'edit',
660 'add-new-bookmark', 'new-folder', 'sort', 662 'add-new-bookmark', 'new-folder', 'sort',
661 'paste-from-context-menu', 'paste-from-organize-menu']; 663 'paste-from-context-menu', 'paste-from-organize-menu'];
662 664
663 chrome.bookmarkManagerPrivate.canEdit(function(result) { 665 chrome.bookmarkManagerPrivate.canEdit(function(result) {
664 if (result != canEdit) { 666 if (result != canEdit) {
665 canEdit = result; 667 canEdit = result;
666 editingCommands.forEach(function(baseId) { 668 editingCommands.forEach(function(baseId) {
667 $(baseId + '-command').canExecuteChange(); 669 $(baseId + '-command').canExecuteChange();
668 }); 670 });
669 } 671 }
670 }); 672 });
671 } 673 }
672 674
673 function handleChangeForTree(e) { 675 function handleChangeForTree(e) {
674 updateAllCommands(); 676 updateCommandsBasedOnSelection(e);
675 navigateTo(tree.selectedItem.bookmarkId, updateHash); 677 navigateTo(tree.selectedItem.bookmarkId, updateHash);
676 } 678 }
677 679
678 function handleOrganizeButtonClick(e) { 680 function handleOrganizeButtonClick(e) {
679 updateEditingCommands(); 681 updateEditingCommands();
680 $('add-new-bookmark-command').canExecuteChange(); 682 $('add-new-bookmark-command').canExecuteChange();
681 $('new-folder-command').canExecuteChange(); 683 $('new-folder-command').canExecuteChange();
682 $('sort-command').canExecuteChange(); 684 $('sort-command').canExecuteChange();
683 } 685 }
684 686
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 splitter.addEventListener('resize', function(e) { 1210 splitter.addEventListener('resize', function(e) {
1209 localStorage['treeWidth'] = splitter.previousElementSibling.style.width; 1211 localStorage['treeWidth'] = splitter.previousElementSibling.style.width;
1210 }); 1212 });
1211 } 1213 }
1212 1214
1213 function initializeBookmarkManager() { 1215 function initializeBookmarkManager() {
1214 // Sometimes the extension API is not initialized. 1216 // Sometimes the extension API is not initialized.
1215 if (!chrome.bookmarks) 1217 if (!chrome.bookmarks)
1216 console.error('Bookmarks extension API is not available'); 1218 console.error('Bookmarks extension API is not available');
1217 1219
1218 chrome.bookmarkManagerPrivate.getStrings(continueInitializeBookmarkManager); 1220 chrome.bookmarkManagerPrivate.getStrings(loadLocalizedStrings);
1219 }
1220
1221 function continueInitializeBookmarkManager(localizedStrings) {
1222 loadLocalizedStrings(localizedStrings);
1223 1221
1224 bmm.treeLookup[searchTreeItem.bookmarkId] = searchTreeItem; 1222 bmm.treeLookup[searchTreeItem.bookmarkId] = searchTreeItem;
1225 1223
1226 cr.ui.decorate('menu', Menu); 1224 cr.ui.decorate('menu', Menu);
1227 cr.ui.decorate('button[menu]', MenuButton); 1225 cr.ui.decorate('button[menu]', MenuButton);
1228 cr.ui.decorate('command', Command); 1226 cr.ui.decorate('command', Command);
1229 BookmarkList.decorate(list); 1227 BookmarkList.decorate(list);
1230 BookmarkTree.decorate(tree); 1228 BookmarkTree.decorate(tree);
1231 1229
1232 list.addEventListener('canceledit', handleCancelEdit); 1230 list.addEventListener('canceledit', handleCancelEdit);
1233 list.addEventListener('canExecute', handleCanExecuteForList); 1231 list.addEventListener('canExecute', handleCanExecuteForList);
1234 list.addEventListener('change', updateAllCommands); 1232 list.addEventListener('change', updateCommandsBasedOnSelection);
1235 list.addEventListener('contextmenu', updateEditingCommands); 1233 list.addEventListener('contextmenu', updateEditingCommands);
1236 list.addEventListener('dblclick', handleDoubleClickForList); 1234 list.addEventListener('dblclick', handleDoubleClickForList);
1237 list.addEventListener('edit', handleEdit); 1235 list.addEventListener('edit', handleEdit);
1238 list.addEventListener('rename', handleRename); 1236 list.addEventListener('rename', handleRename);
1239 list.addEventListener('urlClicked', handleUrlClickedForList); 1237 list.addEventListener('urlClicked', handleUrlClickedForList);
1240 1238
1241 tree.addEventListener('canExecute', handleCanExecuteForTree); 1239 tree.addEventListener('canExecute', handleCanExecuteForTree);
1242 tree.addEventListener('change', handleChangeForTree); 1240 tree.addEventListener('change', handleChangeForTree);
1243 tree.addEventListener('contextmenu', updateEditingCommands); 1241 tree.addEventListener('contextmenu', updateEditingCommands);
1244 tree.addEventListener('rename', handleRename); 1242 tree.addEventListener('rename', handleRename);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 1301
1304 cr.ui.FocusOutlineManager.forDocument(document); 1302 cr.ui.FocusOutlineManager.forDocument(document);
1305 initializeSplitter(); 1303 initializeSplitter();
1306 bmm.addBookmarkModelListeners(); 1304 bmm.addBookmarkModelListeners();
1307 dnd.init(selectItemsAfterUserAction); 1305 dnd.init(selectItemsAfterUserAction);
1308 tree.reload(); 1306 tree.reload();
1309 } 1307 }
1310 1308
1311 initializeBookmarkManager(); 1309 initializeBookmarkManager();
1312 })(); 1310 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698