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

Unified Diff: Source/devtools/front_end/ModuleManager.js

Issue 218613013: DevTools: Decouple shortcuts from actions, introduce shortcut contexts (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased patch Created 6 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/Main.js ('k') | Source/devtools/front_end/TabbedPane.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/ModuleManager.js
diff --git a/Source/devtools/front_end/ModuleManager.js b/Source/devtools/front_end/ModuleManager.js
index 7724d15c4131560004db64a0d0b84c03d57ff23d..53dad754aae932c24d3b70df2a397498883e7ac8 100644
--- a/Source/devtools/front_end/ModuleManager.js
+++ b/Source/devtools/front_end/ModuleManager.js
@@ -60,6 +60,69 @@ WebInspector.ModuleManager = function(descriptors)
this._descriptorsMap[descriptors[i]["name"]] = descriptors[i];
}
+/**
+ * @param {!WebInspector.ModuleManager.Extension} extension
+ * @param {?function(!Function):boolean} predicate
+ */
+WebInspector.ModuleManager._checkExtensionApplicability = function(extension, predicate)
+{
+ if (!predicate)
+ return false;
+ var contextTypes = /** @type {!Array.<string>|undefined} */ (extension.descriptor().contextTypes);
+ if (!contextTypes)
+ return true;
+ for (var i = 0; i < contextTypes.length; ++i) {
+ var contextType = /** @type {!Function} */ (window.eval(contextTypes[i]));
+ var isMatching = predicate(contextType);
+ if (isMatching)
+ return true;
+ }
+ return false;
+}
+
+/**
+ * @param {!WebInspector.ModuleManager.Extension} extension
+ * @param {?Object} context
+ * @return {boolean}
+ */
+WebInspector.ModuleManager.isExtensionApplicableToContext = function(extension, context)
+{
+ if (!context)
+ return true;
+ return WebInspector.ModuleManager._checkExtensionApplicability(extension, isInstanceOf);
+
+ /**
+ * @param {!Function} targetType
+ * @return {boolean}
+ */
+ function isInstanceOf(targetType)
+ {
+ return context instanceof targetType;
+ }
+}
+
+/**
+ * @param {!WebInspector.ModuleManager.Extension} extension
+ * @param {!Set.<!Function>=} currentContextTypes
+ * @return {boolean}
+ */
+WebInspector.ModuleManager.isExtensionApplicableToContextTypes = function(extension, currentContextTypes)
+{
+ if (!extension.descriptor().contextTypes)
+ return true;
+
+ return WebInspector.ModuleManager._checkExtensionApplicability(extension, currentContextTypes ? isContextTypeKnown : null);
+
+ /**
+ * @param {!Function} targetType
+ * @return {boolean}
+ */
+ function isContextTypeKnown(targetType)
+ {
+ return currentContextTypes.contains(targetType);
+ }
+}
+
WebInspector.ModuleManager.prototype = {
/**
* @param {!Array.<string>} configuration
@@ -338,15 +401,7 @@ WebInspector.ModuleManager.Extension.prototype = {
*/
isApplicable: function(context)
{
- var contextTypes = /** @type {!Array.<string>|undefined} */ (this._descriptor.contextTypes);
- if (!contextTypes)
- return true;
- for (var i = 0; i < contextTypes.length; ++i) {
- var contextType = /** @type {!Function} */ (window.eval(contextTypes[i]));
- if (context instanceof contextType)
- return true;
- }
- return false;
+ return WebInspector.ModuleManager.isExtensionApplicableToContext(this, context);
},
/**
@@ -412,19 +467,4 @@ WebInspector.Revealer.prototype = {
reveal: function(object) {}
}
-/**
- * @interface
- */
-WebInspector.ActionDelegate = function()
-{
-}
-
-WebInspector.ActionDelegate.prototype = {
- /**
- * @param {!Event} event
- * @return {boolean}
- */
- handleAction: function(event) {}
-}
-
WebInspector.moduleManager = new WebInspector.ModuleManager(allDescriptors);
« no previous file with comments | « Source/devtools/front_end/Main.js ('k') | Source/devtools/front_end/TabbedPane.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698