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

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: 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
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 14 matching lines...) Expand all
25 Command.COPY, 25 Command.COPY,
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 /** @type {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 47
39 attached: function() { 48 attached: function() {
40 assert(CommandManager.instance_ == null); 49 assert(CommandManager.instance_ == null);
41 CommandManager.instance_ = this; 50 CommandManager.instance_ = this;
42 51
43 /** @private {function(!Event)} */ 52 /** @private {function(!Event)} */
44 this.boundOnOpenItemMenu_ = this.onOpenItemMenu_.bind(this); 53 this.boundOnOpenItemMenu_ = this.onOpenItemMenu_.bind(this);
45 document.addEventListener('open-item-menu', this.boundOnOpenItemMenu_); 54 document.addEventListener('open-item-menu', this.boundOnOpenItemMenu_);
46 55
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } else { 355 } else {
347 this.openCommandMenuAtPosition(e.detail.x, e.detail.y); 356 this.openCommandMenuAtPosition(e.detail.x, e.detail.y);
348 } 357 }
349 }, 358 },
350 359
351 /** 360 /**
352 * @param {Event} e 361 * @param {Event} e
353 * @private 362 * @private
354 */ 363 */
355 onCommandClick_: function(e) { 364 onCommandClick_: function(e) {
356 this.handle(e.target.getAttribute('command'), assert(this.menuIds_)); 365 this.handle(
366 e.currentTarget.getAttribute('command'), assert(this.menuIds_));
357 this.closeCommandMenu(); 367 this.closeCommandMenu();
358 }, 368 },
359 369
360 /** 370 /**
361 * @param {!Event} e 371 * @param {!Event} e
362 * @private 372 * @private
363 */ 373 */
364 onKeydown_: function(e) { 374 onKeydown_: function(e) {
365 var selection = this.getState().selection.items; 375 var selection = this.getState().selection.items;
366 if (e.target == document.body) 376 if (e.target == document.body)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 case Command.OPEN_INCOGNITO: 426 case Command.OPEN_INCOGNITO:
417 label = multipleNodes ? 'menuOpenAllIncognito' : 'menuOpenIncognito'; 427 label = multipleNodes ? 'menuOpenAllIncognito' : 'menuOpenIncognito';
418 break; 428 break;
419 } 429 }
420 430
421 return loadTimeData.getString(assert(label)); 431 return loadTimeData.getString(assert(label));
422 }, 432 },
423 433
424 /** 434 /**
425 * @param {Command} command 435 * @param {Command} command
436 * @return {string}
437 * @private
438 */
439 getCommandSublabel_: function(command) {
440 var multipleNodes = this.menuIds_.size > 1 ||
441 this.containsMatchingNode_(this.menuIds_, function(node) {
442 return !node.url;
443 });
444 switch (command) {
445 case Command.OPEN_NEW_TAB:
446 var urls = this.expandUrls_(this.menuIds_);
447 return multipleNodes && urls.length > 0 ? String(urls.length) : '';
448 default:
449 return '';
450 }
451 },
452
453 /** @private */
454 onMenuIdsChanged_: function() {
455 if (!this.menuIds_)
456 return;
457
458 this.hasAnySublabel_ = this.menuCommands_.some(function(command) {
459 return this.getCommandSublabel_(command) != '';
460 }.bind(this));
461 },
462
463 /**
464 * @param {Command} command
426 * @return {boolean} 465 * @return {boolean}
427 * @private 466 * @private
428 */ 467 */
429 showDividerAfter_: function(command) { 468 showDividerAfter_: function(command) {
430 return command == Command.DELETE; 469 return command == Command.DELETE;
431 }, 470 },
432 }); 471 });
433 472
434 /** @private {bookmarks.CommandManager} */ 473 /** @private {bookmarks.CommandManager} */
435 CommandManager.instance_ = null; 474 CommandManager.instance_ = null;
436 475
437 /** @return {!bookmarks.CommandManager} */ 476 /** @return {!bookmarks.CommandManager} */
438 CommandManager.getInstance = function() { 477 CommandManager.getInstance = function() {
439 return assert(CommandManager.instance_); 478 return assert(CommandManager.instance_);
440 }; 479 };
441 480
442 return { 481 return {
443 CommandManager: CommandManager, 482 CommandManager: CommandManager,
444 }; 483 };
445 }); 484 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698