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 LinkKind = cr.LinkKind; | 9 /** @const */ var LinkKind = cr.LinkKind; |
10 /** @const */ var ListItem = cr.ui.ListItem; | 10 /** @const */ var ListItem = cr.ui.ListItem; |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 else if (document.activeElement == bmm.tree) | 463 else if (document.activeElement == bmm.tree) |
464 cmd = 'paste-from-folders-menu-command'; | 464 cmd = 'paste-from-folders-menu-command'; |
465 | 465 |
466 if (cmd) | 466 if (cmd) |
467 update('paste-from-context-menu-command', !$(cmd).disabled); | 467 update('paste-from-context-menu-command', !$(cmd).disabled); |
468 | 468 |
469 if (opt_f) opt_f(); | 469 if (opt_f) opt_f(); |
470 }); | 470 }); |
471 } | 471 } |
472 | 472 |
473 function handleCanExecuteForSearchBox(e) { | |
474 var command = e.command; | |
475 switch (command.id) { | |
476 case 'delete-command': | |
477 case 'undo-command': | |
478 // Pass the delete and undo commands through | |
479 // (fixes http://crbug.com/278112). | |
480 e.canExecute = false; | |
481 break; | |
482 } | |
483 } | |
484 | |
473 function handleCanExecuteForDocument(e) { | 485 function handleCanExecuteForDocument(e) { |
474 var command = e.command; | 486 var command = e.command; |
475 switch (command.id) { | 487 switch (command.id) { |
476 case 'import-menu-command': | 488 case 'import-menu-command': |
477 e.canExecute = canEdit; | 489 e.canExecute = canEdit; |
478 break; | 490 break; |
479 | 491 |
480 case 'export-menu-command': | 492 case 'export-menu-command': |
481 // We can always execute the export-menu command. | 493 // We can always execute the export-menu command. |
482 e.canExecute = true; | 494 e.canExecute = true; |
483 break; | 495 break; |
484 | 496 |
485 case 'sort-command': | 497 case 'sort-command': |
486 e.canExecute = !bmm.list.isSearch() && | 498 e.canExecute = !bmm.list.isSearch() && |
487 bmm.list.dataModel && bmm.list.dataModel.length > 1 && | 499 bmm.list.dataModel && bmm.list.dataModel.length > 1 && |
488 !isUnmodifiable(bmm.tree.getBookmarkNodeById(bmm.list.parentId)); | 500 !isUnmodifiable(bmm.tree.getBookmarkNodeById(bmm.list.parentId)); |
489 break; | 501 break; |
490 | 502 |
491 case 'undo-command': | 503 case 'undo-command': |
492 // If the search box is active, pass the undo command through | 504 // Because the global undo command has no visible UI, always enable it, |
493 // (fixes http://crbug.com/278112). Otherwise, because | 505 // and just make it a no-op if undo is not possible. |
494 // the global undo command has no visible UI, always enable it, and | |
495 // just make it a no-op if undo is not possible. | |
496 e.canExecute = e.currentTarget.activeElement !== $('term'); | 506 e.canExecute = e.currentTarget.activeElement !== $('term'); |
Bernhard Bauer
2015/04/16 08:08:04
Wait, this should be unconditionally set to true (
| |
497 break; | 507 break; |
498 | 508 |
499 default: | 509 default: |
500 canExecuteForList(e); | 510 canExecuteForList(e); |
501 if (!e.defaultPrevented) | 511 if (!e.defaultPrevented) |
502 canExecuteForTree(e); | 512 canExecuteForTree(e); |
503 break; | 513 break; |
504 } | 514 } |
505 } | 515 } |
506 | 516 |
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1457 // when // the user goes back and forward in the history. | 1467 // when // the user goes back and forward in the history. |
1458 window.addEventListener('hashchange', processHash); | 1468 window.addEventListener('hashchange', processHash); |
1459 | 1469 |
1460 document.querySelector('header form').onsubmit = | 1470 document.querySelector('header form').onsubmit = |
1461 /** @type {function(Event=)} */(function(e) { | 1471 /** @type {function(Event=)} */(function(e) { |
1462 setSearch($('term').value); | 1472 setSearch($('term').value); |
1463 e.preventDefault(); | 1473 e.preventDefault(); |
1464 }); | 1474 }); |
1465 | 1475 |
1466 $('term').addEventListener('search', handleSearch); | 1476 $('term').addEventListener('search', handleSearch); |
1477 $('term').addEventListener('canExecute', handleCanExecuteForSearchBox); | |
1467 | 1478 |
1468 $('folders-button').addEventListener('click', handleMenuButtonClicked); | 1479 $('folders-button').addEventListener('click', handleMenuButtonClicked); |
1469 $('organize-button').addEventListener('click', handleMenuButtonClicked); | 1480 $('organize-button').addEventListener('click', handleMenuButtonClicked); |
1470 | 1481 |
1471 document.addEventListener('canExecute', handleCanExecuteForDocument); | 1482 document.addEventListener('canExecute', handleCanExecuteForDocument); |
1472 document.addEventListener('command', handleCommand); | 1483 document.addEventListener('command', handleCommand); |
1473 | 1484 |
1474 // Listen to copy, cut and paste events and execute the associated commands. | 1485 // Listen to copy, cut and paste events and execute the associated commands. |
1475 installEventHandlerForCommand('copy', 'copy-command'); | 1486 installEventHandlerForCommand('copy', 'copy-command'); |
1476 installEventHandlerForCommand('cut', 'cut-command'); | 1487 installEventHandlerForCommand('cut', 'cut-command'); |
(...skipping 29 matching lines...) Expand all Loading... | |
1506 | 1517 |
1507 cr.ui.FocusOutlineManager.forDocument(document); | 1518 cr.ui.FocusOutlineManager.forDocument(document); |
1508 initializeSplitter(); | 1519 initializeSplitter(); |
1509 bmm.addBookmarkModelListeners(); | 1520 bmm.addBookmarkModelListeners(); |
1510 dnd.init(selectItemsAfterUserAction); | 1521 dnd.init(selectItemsAfterUserAction); |
1511 bmm.tree.reload(); | 1522 bmm.tree.reload(); |
1512 } | 1523 } |
1513 | 1524 |
1514 initializeBookmarkManager(); | 1525 initializeBookmarkManager(); |
1515 })(); | 1526 })(); |
OLD | NEW |