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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/md_bookmarks/command_manager.js
diff --git a/chrome/browser/resources/md_bookmarks/command_manager.js b/chrome/browser/resources/md_bookmarks/command_manager.js
index be258a32c7548144d7aca5cbc2fd02cb8618c576..397c5c01c8f0559c5faeb824b7d188c4e1dc89f9 100644
--- a/chrome/browser/resources/md_bookmarks/command_manager.js
+++ b/chrome/browser/resources/md_bookmarks/command_manager.js
@@ -32,8 +32,17 @@ cr.define('bookmarks', function() {
},
},
- /** @type {Set<string>} */
- menuIds_: Object,
+ /** @private {Set<string>} */
+ menuIds_: {
+ type: Object,
+ observer: 'onMenuIdsChanged_',
+ },
+
+ /** @private */
+ hasAnySublabel_: {
+ type: Boolean,
+ reflectToAttribute: true,
+ }
},
attached: function() {
@@ -353,7 +362,8 @@ cr.define('bookmarks', function() {
* @private
*/
onCommandClick_: function(e) {
- this.handle(e.target.getAttribute('command'), assert(this.menuIds_));
+ this.handle(
+ e.currentTarget.getAttribute('command'), assert(this.menuIds_));
this.closeCommandMenu();
},
@@ -421,6 +431,35 @@ cr.define('bookmarks', function() {
return loadTimeData.getString(assert(label));
},
+ /**
+ * @param {Command} command
+ * @return {string}
+ * @private
+ */
+ getCommandSublabel_: function(command) {
+ var multipleNodes = this.menuIds_.size > 1 ||
+ this.containsMatchingNode_(this.menuIds_, function(node) {
+ return !node.url;
+ });
+ switch (command) {
+ case Command.OPEN_NEW_TAB:
+ var urls = this.expandUrls_(this.menuIds_);
+ return multipleNodes && urls.length > 0 ? String(urls.length) : '';
+ default:
+ return '';
+ }
+ },
+
+ /** @private */
+ onMenuIdsChanged_: function() {
+ if (!this.menuIds_)
+ return;
+
+ this.hasAnySublabel_ = this.menuCommands_.some(function(command) {
+ return this.getCommandSublabel_(command) != '';
+ }.bind(this));
+ },
+
/**
* @param {Command} command
* @return {boolean}

Powered by Google App Engine
This is Rietveld 408576698