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

Unified Diff: Source/devtools/front_end/ui/Toolbar.js

Issue 1105643002: Devtools: Introduce WI.ExtensibleToolbar (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Use common styles Created 5 years, 8 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
« no previous file with comments | « Source/devtools/front_end/settings/module.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/ui/Toolbar.js
diff --git a/Source/devtools/front_end/ui/Toolbar.js b/Source/devtools/front_end/ui/Toolbar.js
index 3720720fb16a54a16cca5ac7bd0707cf58c40c5c..8bc9a16f7bc06a06cb2611c906e91f2786789677 100644
--- a/Source/devtools/front_end/ui/Toolbar.js
+++ b/Source/devtools/front_end/ui/Toolbar.js
@@ -911,3 +911,82 @@ WebInspector.ToolbarStatesSettingButton.prototype = {
__proto__: WebInspector.ToolbarButton.prototype
}
+
+/**
+ * @constructor
+ * @extends {WebInspector.Toolbar}
+ * @param {string} location
+ * @param {!Element=} parentElement
+ */
+WebInspector.ExtensibleToolbar = function(location, parentElement)
+{
+ WebInspector.Toolbar.call(this, parentElement);
+ this._loadItems(location);
+}
+
+WebInspector.ExtensibleToolbar.prototype = {
+ /**
+ * @param {string} location
+ */
+ _loadItems: function(location)
+ {
+ var extensions = self.runtime.extensions(WebInspector.ToolbarItem.Provider);
+ var promises = [];
+ for (var i = 0; i < extensions.length; ++i) {
+ if (extensions[i].descriptor()["location"] === location)
+ promises.push(resolveItem(extensions[i]));
+ }
+ Promise.all(promises).then(appendItemsInOrder.bind(this));
+
+ /**
+ * @param {!Runtime.Extension} extension
+ * @return {!Promise.<?WebInspector.ToolbarItem>}
+ */
+ function resolveItem(extension)
+ {
+ var descriptor = extension.descriptor();
+ if (!descriptor.className)
+ return Promise.resolve(new WebInspector.ToolbarButton(WebInspector.UIString(descriptor["title"]), descriptor["elementClass"])).then(attachHandler);
+ return extension.instancePromise().then(fetchItemFromProvider).then(attachHandler);
+
+ /**
+ * @param {!Object} provider
+ */
+ function fetchItemFromProvider(provider)
+ {
+ return /** @type {!WebInspector.ToolbarItem.Provider} */ (provider).item();
+ }
+
+ /**
+ * @param {?WebInspector.ToolbarItem} item
+ * @return {?WebInspector.ToolbarItem} item
+ */
+ function attachHandler(item)
+ {
+ if (extension.descriptor()["actionId"] && item)
+ item.addEventListener("click", handler);
+ return item;
+ }
+
+ function handler()
+ {
+ WebInspector.actionRegistry.execute(extension.descriptor()["actionId"]);
+ }
+ }
+
+ /**
+ * @param {!Array.<?WebInspector.ToolbarItem>} items
+ * @this {WebInspector.ExtensibleToolbar}
+ */
+ function appendItemsInOrder(items)
+ {
+ for (var i = 0; i < items.length; ++i) {
+ var item = items[i];
+ if (item)
+ this.appendToolbarItem(item);
+ }
+ }
+ },
+
+ __proto__: WebInspector.Toolbar.prototype
+}
« no previous file with comments | « Source/devtools/front_end/settings/module.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698