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

Side by Side Diff: chrome/browser/resources/md_bookmarks/command_manager.js

Issue 2924253002: [MD Bookmarks] Add bookmark count to context menu for multiple items. (Closed)
Patch Set: rebase, address comments Created 3 years, 6 months 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
« no previous file with comments | « chrome/browser/resources/md_bookmarks/command_manager.html ('k') | 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 /** 5 /**
6 * @fileoverview Element which shows context menus and handles keyboard 6 * @fileoverview Element which shows context menus and handles keyboard
7 * shortcuts. 7 * shortcuts.
8 */ 8 */
9 cr.define('bookmarks', function() { 9 cr.define('bookmarks', function() {
10 10
(...skipping 15 matching lines...) Expand all
26 Command.DELETE, 26 Command.DELETE,
27 // <hr> 27 // <hr>
28 Command.OPEN_NEW_TAB, 28 Command.OPEN_NEW_TAB,
29 Command.OPEN_NEW_WINDOW, 29 Command.OPEN_NEW_WINDOW,
30 Command.OPEN_INCOGNITO, 30 Command.OPEN_INCOGNITO,
31 ]; 31 ];
32 }, 32 },
33 }, 33 },
34 34
35 /** @private {Set<string>} */ 35 /** @private {Set<string>} */
36 menuIds_: Object, 36 menuIds_: {
37 type: Object,
38 observer: 'onMenuIdsChanged_',
39 },
40
41 /** @private */
42 hasAnySublabel_: {
43 type: Boolean,
44 reflectToAttribute: true,
45 },
37 46
38 /** @private */ 47 /** @private */
39 globalCanEdit_: Boolean, 48 globalCanEdit_: Boolean,
40 }, 49 },
41 50
42 attached: function() { 51 attached: function() {
43 assert(CommandManager.instance_ == null); 52 assert(CommandManager.instance_ == null);
44 CommandManager.instance_ = this; 53 CommandManager.instance_ = this;
45 54
46 this.watch('globalCanEdit_', function(state) { 55 this.watch('globalCanEdit_', function(state) {
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 } else { 400 } else {
392 this.openCommandMenuAtPosition(e.detail.x, e.detail.y); 401 this.openCommandMenuAtPosition(e.detail.x, e.detail.y);
393 } 402 }
394 }, 403 },
395 404
396 /** 405 /**
397 * @param {Event} e 406 * @param {Event} e
398 * @private 407 * @private
399 */ 408 */
400 onCommandClick_: function(e) { 409 onCommandClick_: function(e) {
401 this.handle(e.target.getAttribute('command'), assert(this.menuIds_)); 410 this.handle(
411 e.currentTarget.getAttribute('command'), assert(this.menuIds_));
402 this.closeCommandMenu(); 412 this.closeCommandMenu();
403 }, 413 },
404 414
405 /** 415 /**
406 * @param {!Event} e 416 * @param {!Event} e
407 * @private 417 * @private
408 */ 418 */
409 onKeydown_: function(e) { 419 onKeydown_: function(e) {
410 var selection = this.getState().selection.items; 420 var selection = this.getState().selection.items;
411 if (e.target == document.body) 421 if (e.target == document.body)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 case Command.OPEN_INCOGNITO: 471 case Command.OPEN_INCOGNITO:
462 label = multipleNodes ? 'menuOpenAllIncognito' : 'menuOpenIncognito'; 472 label = multipleNodes ? 'menuOpenAllIncognito' : 'menuOpenIncognito';
463 break; 473 break;
464 } 474 }
465 475
466 return loadTimeData.getString(assert(label)); 476 return loadTimeData.getString(assert(label));
467 }, 477 },
468 478
469 /** 479 /**
470 * @param {Command} command 480 * @param {Command} command
481 * @return {string}
482 * @private
483 */
484 getCommandSublabel_: function(command) {
485 var multipleNodes = this.menuIds_.size > 1 ||
486 this.containsMatchingNode_(this.menuIds_, function(node) {
487 return !node.url;
488 });
489 switch (command) {
490 case Command.OPEN_NEW_TAB:
491 var urls = this.expandUrls_(this.menuIds_);
492 return multipleNodes && urls.length > 0 ? String(urls.length) : '';
493 default:
494 return '';
495 }
496 },
497
498 /** @private */
499 onMenuIdsChanged_: function() {
500 if (!this.menuIds_)
501 return;
502
503 this.hasAnySublabel_ = this.menuCommands_.some(function(command) {
504 return this.getCommandSublabel_(command) != '';
505 }.bind(this));
506 },
507
508 /**
509 * @param {Command} command
471 * @return {boolean} 510 * @return {boolean}
472 * @private 511 * @private
473 */ 512 */
474 showDividerAfter_: function(command, itemIds) { 513 showDividerAfter_: function(command, itemIds) {
475 return command == Command.DELETE && 514 return command == Command.DELETE &&
476 (this.globalCanEdit_ || this.isSingleBookmark_(itemIds)); 515 (this.globalCanEdit_ || this.isSingleBookmark_(itemIds));
477 }, 516 },
478 }); 517 });
479 518
480 /** @private {bookmarks.CommandManager} */ 519 /** @private {bookmarks.CommandManager} */
481 CommandManager.instance_ = null; 520 CommandManager.instance_ = null;
482 521
483 /** @return {!bookmarks.CommandManager} */ 522 /** @return {!bookmarks.CommandManager} */
484 CommandManager.getInstance = function() { 523 CommandManager.getInstance = function() {
485 return assert(CommandManager.instance_); 524 return assert(CommandManager.instance_);
486 }; 525 };
487 526
488 return { 527 return {
489 CommandManager: CommandManager, 528 CommandManager: CommandManager,
490 }; 529 };
491 }); 530 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/command_manager.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698