Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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(); | |
| 147 } | 148 } |
| 148 | 149 |
| 149 /** | 150 /** |
| 150 * Navigates to a bookmark ID. | 151 * Navigates to a bookmark ID. |
| 151 * @param {string} id The ID to navigate to. | 152 * @param {string} id The ID to navigate to. |
| 152 * @param {function()} callback Function called when list view loaded or | 153 * @param {function()} callback Function called when list view loaded or |
| 153 * displayed specified folder. | 154 * displayed specified folder. |
| 154 */ | 155 */ |
| 155 function navigateTo(id, callback) { | 156 function navigateTo(id, callback) { |
| 156 updateHash(id); | 157 updateHash(id); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 * Returns the nodes (non recursive) to use for the open commands. | 357 * Returns the nodes (non recursive) to use for the open commands. |
| 357 * @param {HTMLElement} target . | 358 * @param {HTMLElement} target . |
| 358 * @return {Array.<BookmarkTreeNode>} . | 359 * @return {Array.<BookmarkTreeNode>} . |
| 359 */ | 360 */ |
| 360 function getNodesForOpen(target) { | 361 function getNodesForOpen(target) { |
| 361 if (target == tree) { | 362 if (target == tree) { |
| 362 var folderItem = tree.selectedItem; | 363 var folderItem = tree.selectedItem; |
| 363 return folderItem == searchTreeItem ? | 364 return folderItem == searchTreeItem ? |
| 364 list.dataModel.slice() : tree.selectedFolders; | 365 list.dataModel.slice() : tree.selectedFolders; |
| 365 } | 366 } |
| 367 | |
| 366 var items = list.selectedItems; | 368 var items = list.selectedItems; |
| 367 return items.length ? items : list.dataModel.slice(); | 369 if (items.length) |
| 370 return items; | |
| 371 | |
| 372 // The list starts off with a null dataModel. We can get here during startup. | |
| 373 if (!list.dataModel) | |
| 374 return []; | |
| 375 | |
| 376 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.
| |
| 368 } | 377 } |
| 369 | 378 |
| 370 /** | 379 /** |
| 371 * Returns a promise that will contain all URLs of all the selected bookmarks | 380 * Returns a promise that will contain all URLs of all the selected bookmarks |
| 372 * and the nested bookmarks for use with the open commands. | 381 * and the nested bookmarks for use with the open commands. |
| 373 * @param {HTMLElement} target The target list or tree. | 382 * @param {HTMLElement} target The target list or tree. |
| 374 * @return {Promise} . | 383 * @return {Promise} . |
| 375 */ | 384 */ |
| 376 function getUrlsForOpenCommands(target) { | 385 function getUrlsForOpenCommands(target) { |
| 377 return getAllUrls(getNodesForOpen(target)); | 386 return getAllUrls(getNodesForOpen(target)); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 var command = e.command; | 449 var command = e.command; |
| 441 switch (command.id) { | 450 switch (command.id) { |
| 442 case 'import-menu-command': | 451 case 'import-menu-command': |
| 443 e.canExecute = canEdit; | 452 e.canExecute = canEdit; |
| 444 break; | 453 break; |
| 445 case 'export-menu-command': | 454 case 'export-menu-command': |
| 446 // We can always execute the export-menu command. | 455 // We can always execute the export-menu command. |
| 447 e.canExecute = true; | 456 e.canExecute = true; |
| 448 break; | 457 break; |
| 449 case 'sort-command': | 458 case 'sort-command': |
| 450 e.canExecute = !list.isSearch() && list.dataModel.length > 1; | 459 e.canExecute = !list.isSearch() && |
| 460 list.dataModel && list.dataModel.length > 1; | |
| 451 break; | 461 break; |
| 452 case 'undo-command': | 462 case 'undo-command': |
| 453 // The global undo command has no visible UI, so always enable it, and | 463 // The global undo command has no visible UI, so always enable it, and |
| 454 // just make it a no-op if undo is not possible. | 464 // just make it a no-op if undo is not possible. |
| 455 e.canExecute = true; | 465 e.canExecute = true; |
| 456 break; | 466 break; |
| 457 default: | 467 default: |
| 458 canExecuteForList(e); | 468 canExecuteForList(e); |
| 459 break; | 469 break; |
| 460 } | 470 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 628 case 'copy-command': | 638 case 'copy-command': |
| 629 e.canExecute = hasSelected() && !isTopLevelItem(); | 639 e.canExecute = hasSelected() && !isTopLevelItem(); |
| 630 break; | 640 break; |
| 631 | 641 |
| 632 default: | 642 default: |
| 633 canExecuteShared(e, isSearch()); | 643 canExecuteShared(e, isSearch()); |
| 634 } | 644 } |
| 635 } | 645 } |
| 636 | 646 |
| 637 /** | 647 /** |
| 638 * Update the canExecute state of the commands when the selection changes. | 648 * Update the canExecute state of all the commands. |
| 639 * @param {Event} e The change event object. | |
| 640 */ | 649 */ |
| 641 function updateCommandsBasedOnSelection(e) { | 650 function updateAllCommands() { |
| 642 if (e.target == document.activeElement) { | 651 var commands = document.querySelectorAll('command'); |
| 643 // Paste only needs to be updated when the tree selection changes. | 652 for (var i = 0; i < commands.length; i++) { |
| 644 var commandNames = ['copy', 'cut', 'delete', 'rename-folder', 'edit', | 653 commands[i].canExecuteChange(); |
| 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 }); | |
| 657 } | 654 } |
| 658 } | 655 } |
| 659 | 656 |
| 660 function updateEditingCommands() { | 657 function updateEditingCommands() { |
| 661 var editingCommands = ['cut', 'delete', 'rename-folder', 'edit', | 658 var editingCommands = ['cut', 'delete', 'rename-folder', 'edit', |
| 662 'add-new-bookmark', 'new-folder', 'sort', | 659 'add-new-bookmark', 'new-folder', 'sort', |
| 663 'paste-from-context-menu', 'paste-from-organize-menu']; | 660 'paste-from-context-menu', 'paste-from-organize-menu']; |
| 664 | 661 |
| 665 chrome.bookmarkManagerPrivate.canEdit(function(result) { | 662 chrome.bookmarkManagerPrivate.canEdit(function(result) { |
| 666 if (result != canEdit) { | 663 if (result != canEdit) { |
| 667 canEdit = result; | 664 canEdit = result; |
| 668 editingCommands.forEach(function(baseId) { | 665 editingCommands.forEach(function(baseId) { |
| 669 $(baseId + '-command').canExecuteChange(); | 666 $(baseId + '-command').canExecuteChange(); |
| 670 }); | 667 }); |
| 671 } | 668 } |
| 672 }); | 669 }); |
| 673 } | 670 } |
| 674 | 671 |
| 675 function handleChangeForTree(e) { | 672 function handleChangeForTree(e) { |
| 676 updateCommandsBasedOnSelection(e); | 673 updateAllCommands(); |
| 677 navigateTo(tree.selectedItem.bookmarkId, updateHash); | 674 navigateTo(tree.selectedItem.bookmarkId, updateHash); |
| 678 } | 675 } |
| 679 | 676 |
| 680 function handleOrganizeButtonClick(e) { | 677 function handleOrganizeButtonClick(e) { |
| 681 updateEditingCommands(); | 678 updateEditingCommands(); |
| 682 $('add-new-bookmark-command').canExecuteChange(); | 679 $('add-new-bookmark-command').canExecuteChange(); |
| 683 $('new-folder-command').canExecuteChange(); | 680 $('new-folder-command').canExecuteChange(); |
| 684 $('sort-command').canExecuteChange(); | 681 $('sort-command').canExecuteChange(); |
| 685 } | 682 } |
| 686 | 683 |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1222 bmm.treeLookup[searchTreeItem.bookmarkId] = searchTreeItem; | 1219 bmm.treeLookup[searchTreeItem.bookmarkId] = searchTreeItem; |
| 1223 | 1220 |
| 1224 cr.ui.decorate('menu', Menu); | 1221 cr.ui.decorate('menu', Menu); |
| 1225 cr.ui.decorate('button[menu]', MenuButton); | 1222 cr.ui.decorate('button[menu]', MenuButton); |
| 1226 cr.ui.decorate('command', Command); | 1223 cr.ui.decorate('command', Command); |
| 1227 BookmarkList.decorate(list); | 1224 BookmarkList.decorate(list); |
| 1228 BookmarkTree.decorate(tree); | 1225 BookmarkTree.decorate(tree); |
| 1229 | 1226 |
| 1230 list.addEventListener('canceledit', handleCancelEdit); | 1227 list.addEventListener('canceledit', handleCancelEdit); |
| 1231 list.addEventListener('canExecute', handleCanExecuteForList); | 1228 list.addEventListener('canExecute', handleCanExecuteForList); |
| 1232 list.addEventListener('change', updateCommandsBasedOnSelection); | 1229 list.addEventListener('change', updateAllCommands); |
| 1233 list.addEventListener('contextmenu', updateEditingCommands); | 1230 list.addEventListener('contextmenu', updateEditingCommands); |
| 1234 list.addEventListener('dblclick', handleDoubleClickForList); | 1231 list.addEventListener('dblclick', handleDoubleClickForList); |
| 1235 list.addEventListener('edit', handleEdit); | 1232 list.addEventListener('edit', handleEdit); |
| 1236 list.addEventListener('rename', handleRename); | 1233 list.addEventListener('rename', handleRename); |
| 1237 list.addEventListener('urlClicked', handleUrlClickedForList); | 1234 list.addEventListener('urlClicked', handleUrlClickedForList); |
| 1238 | 1235 |
| 1239 tree.addEventListener('canExecute', handleCanExecuteForTree); | 1236 tree.addEventListener('canExecute', handleCanExecuteForTree); |
| 1240 tree.addEventListener('change', handleChangeForTree); | 1237 tree.addEventListener('change', handleChangeForTree); |
| 1241 tree.addEventListener('contextmenu', updateEditingCommands); | 1238 tree.addEventListener('contextmenu', updateEditingCommands); |
| 1242 tree.addEventListener('rename', handleRename); | 1239 tree.addEventListener('rename', handleRename); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1301 | 1298 |
| 1302 cr.ui.FocusOutlineManager.forDocument(document); | 1299 cr.ui.FocusOutlineManager.forDocument(document); |
| 1303 initializeSplitter(); | 1300 initializeSplitter(); |
| 1304 bmm.addBookmarkModelListeners(); | 1301 bmm.addBookmarkModelListeners(); |
| 1305 dnd.init(selectItemsAfterUserAction); | 1302 dnd.init(selectItemsAfterUserAction); |
| 1306 tree.reload(); | 1303 tree.reload(); |
| 1307 } | 1304 } |
| 1308 | 1305 |
| 1309 initializeBookmarkManager(); | 1306 initializeBookmarkManager(); |
| 1310 })(); | 1307 })(); |
| OLD | NEW |