| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 WebInspector.ActionRegistry = class { | 7 UI.ActionRegistry = class { |
| 8 constructor() { | 8 constructor() { |
| 9 /** @type {!Map.<string, !WebInspector.Action>} */ | 9 /** @type {!Map.<string, !UI.Action>} */ |
| 10 this._actionsById = new Map(); | 10 this._actionsById = new Map(); |
| 11 this._registerActions(); | 11 this._registerActions(); |
| 12 } | 12 } |
| 13 | 13 |
| 14 _registerActions() { | 14 _registerActions() { |
| 15 self.runtime.extensions(WebInspector.ActionDelegate).forEach(registerExtensi
on, this); | 15 self.runtime.extensions(UI.ActionDelegate).forEach(registerExtension, this); |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * @param {!Runtime.Extension} extension | 18 * @param {!Runtime.Extension} extension |
| 19 * @this {WebInspector.ActionRegistry} | 19 * @this {UI.ActionRegistry} |
| 20 */ | 20 */ |
| 21 function registerExtension(extension) { | 21 function registerExtension(extension) { |
| 22 var actionId = extension.descriptor()['actionId']; | 22 var actionId = extension.descriptor()['actionId']; |
| 23 console.assert(actionId); | 23 console.assert(actionId); |
| 24 console.assert(!this._actionsById.get(actionId)); | 24 console.assert(!this._actionsById.get(actionId)); |
| 25 this._actionsById.set(actionId, new WebInspector.Action(extension)); | 25 this._actionsById.set(actionId, new UI.Action(extension)); |
| 26 } | 26 } |
| 27 } | 27 } |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * @return {!Array.<!WebInspector.Action>} | 30 * @return {!Array.<!UI.Action>} |
| 31 */ | 31 */ |
| 32 availableActions() { | 32 availableActions() { |
| 33 return this.applicableActions(this._actionsById.keysArray(), WebInspector.co
ntext); | 33 return this.applicableActions(this._actionsById.keysArray(), UI.context); |
| 34 } | 34 } |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * @param {!Array.<string>} actionIds | 37 * @param {!Array.<string>} actionIds |
| 38 * @param {!WebInspector.Context} context | 38 * @param {!UI.Context} context |
| 39 * @return {!Array.<!WebInspector.Action>} | 39 * @return {!Array.<!UI.Action>} |
| 40 */ | 40 */ |
| 41 applicableActions(actionIds, context) { | 41 applicableActions(actionIds, context) { |
| 42 var extensions = []; | 42 var extensions = []; |
| 43 actionIds.forEach(function(actionId) { | 43 actionIds.forEach(function(actionId) { |
| 44 var action = this._actionsById.get(actionId); | 44 var action = this._actionsById.get(actionId); |
| 45 if (action) | 45 if (action) |
| 46 extensions.push(action._extension); | 46 extensions.push(action._extension); |
| 47 }, this); | 47 }, this); |
| 48 return context.applicableExtensions(extensions).valuesArray().map(extensionT
oAction.bind(this)); | 48 return context.applicableExtensions(extensions).valuesArray().map(extensionT
oAction.bind(this)); |
| 49 | 49 |
| 50 /** | 50 /** |
| 51 * @param {!Runtime.Extension} extension | 51 * @param {!Runtime.Extension} extension |
| 52 * @return {!WebInspector.Action} | 52 * @return {!UI.Action} |
| 53 * @this {WebInspector.ActionRegistry} | 53 * @this {UI.ActionRegistry} |
| 54 */ | 54 */ |
| 55 function extensionToAction(extension) { | 55 function extensionToAction(extension) { |
| 56 return /** @type {!WebInspector.Action} */ (this.action(extension.descript
or()['actionId'])); | 56 return /** @type {!UI.Action} */ (this.action(extension.descriptor()['acti
onId'])); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * @param {string} actionId | 61 * @param {string} actionId |
| 62 * @return {?WebInspector.Action} | 62 * @return {?UI.Action} |
| 63 */ | 63 */ |
| 64 action(actionId) { | 64 action(actionId) { |
| 65 return this._actionsById.get(actionId) || null; | 65 return this._actionsById.get(actionId) || null; |
| 66 } | 66 } |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 /** | 69 /** |
| 70 * @unrestricted | 70 * @unrestricted |
| 71 */ | 71 */ |
| 72 WebInspector.Action = class extends WebInspector.Object { | 72 UI.Action = class extends Common.Object { |
| 73 /** | 73 /** |
| 74 * @param {!Runtime.Extension} extension | 74 * @param {!Runtime.Extension} extension |
| 75 */ | 75 */ |
| 76 constructor(extension) { | 76 constructor(extension) { |
| 77 super(); | 77 super(); |
| 78 this._extension = extension; | 78 this._extension = extension; |
| 79 this._enabled = true; | 79 this._enabled = true; |
| 80 this._toggled = false; | 80 this._toggled = false; |
| 81 } | 81 } |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * @return {string} | 84 * @return {string} |
| 85 */ | 85 */ |
| 86 id() { | 86 id() { |
| 87 return this._extension.descriptor()['actionId']; | 87 return this._extension.descriptor()['actionId']; |
| 88 } | 88 } |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * @return {!Promise.<boolean>} | 91 * @return {!Promise.<boolean>} |
| 92 */ | 92 */ |
| 93 execute() { | 93 execute() { |
| 94 return this._extension.instance().then(handleAction.bind(this)); | 94 return this._extension.instance().then(handleAction.bind(this)); |
| 95 | 95 |
| 96 /** | 96 /** |
| 97 * @param {!Object} actionDelegate | 97 * @param {!Object} actionDelegate |
| 98 * @return {boolean} | 98 * @return {boolean} |
| 99 * @this {WebInspector.Action} | 99 * @this {UI.Action} |
| 100 */ | 100 */ |
| 101 function handleAction(actionDelegate) { | 101 function handleAction(actionDelegate) { |
| 102 var actionId = this._extension.descriptor()['actionId']; | 102 var actionId = this._extension.descriptor()['actionId']; |
| 103 var delegate = /** @type {!WebInspector.ActionDelegate} */ (actionDelegate
); | 103 var delegate = /** @type {!UI.ActionDelegate} */ (actionDelegate); |
| 104 return delegate.handleAction(WebInspector.context, actionId); | 104 return delegate.handleAction(UI.context, actionId); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 /** | 108 /** |
| 109 * @return {string} | 109 * @return {string} |
| 110 */ | 110 */ |
| 111 icon() { | 111 icon() { |
| 112 return this._extension.descriptor()['iconClass'] || ''; | 112 return this._extension.descriptor()['iconClass'] || ''; |
| 113 } | 113 } |
| 114 | 114 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 127 } | 127 } |
| 128 | 128 |
| 129 /** | 129 /** |
| 130 * @param {boolean} enabled | 130 * @param {boolean} enabled |
| 131 */ | 131 */ |
| 132 setEnabled(enabled) { | 132 setEnabled(enabled) { |
| 133 if (this._enabled === enabled) | 133 if (this._enabled === enabled) |
| 134 return; | 134 return; |
| 135 | 135 |
| 136 this._enabled = enabled; | 136 this._enabled = enabled; |
| 137 this.dispatchEventToListeners(WebInspector.Action.Events.Enabled, enabled); | 137 this.dispatchEventToListeners(UI.Action.Events.Enabled, enabled); |
| 138 } | 138 } |
| 139 | 139 |
| 140 /** | 140 /** |
| 141 * @return {boolean} | 141 * @return {boolean} |
| 142 */ | 142 */ |
| 143 enabled() { | 143 enabled() { |
| 144 return this._enabled; | 144 return this._enabled; |
| 145 } | 145 } |
| 146 | 146 |
| 147 /** | 147 /** |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 181 } |
| 182 | 182 |
| 183 /** | 183 /** |
| 184 * @param {boolean} toggled | 184 * @param {boolean} toggled |
| 185 */ | 185 */ |
| 186 setToggled(toggled) { | 186 setToggled(toggled) { |
| 187 if (this._toggled === toggled) | 187 if (this._toggled === toggled) |
| 188 return; | 188 return; |
| 189 | 189 |
| 190 this._toggled = toggled; | 190 this._toggled = toggled; |
| 191 this.dispatchEventToListeners(WebInspector.Action.Events.Toggled, toggled); | 191 this.dispatchEventToListeners(UI.Action.Events.Toggled, toggled); |
| 192 } | 192 } |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 /** @enum {symbol} */ | 195 /** @enum {symbol} */ |
| 196 WebInspector.Action.Events = { | 196 UI.Action.Events = { |
| 197 Enabled: Symbol('Enabled'), | 197 Enabled: Symbol('Enabled'), |
| 198 Toggled: Symbol('Toggled') | 198 Toggled: Symbol('Toggled') |
| 199 }; | 199 }; |
| 200 | 200 |
| 201 /** | 201 /** |
| 202 * @interface | 202 * @interface |
| 203 */ | 203 */ |
| 204 WebInspector.ActionDelegate = function() {}; | 204 UI.ActionDelegate = function() {}; |
| 205 | 205 |
| 206 WebInspector.ActionDelegate.prototype = { | 206 UI.ActionDelegate.prototype = { |
| 207 /** | 207 /** |
| 208 * @param {!WebInspector.Context} context | 208 * @param {!UI.Context} context |
| 209 * @param {string} actionId | 209 * @param {string} actionId |
| 210 * @return {boolean} | 210 * @return {boolean} |
| 211 */ | 211 */ |
| 212 handleAction: function(context, actionId) {} | 212 handleAction: function(context, actionId) {} |
| 213 }; | 213 }; |
| 214 | 214 |
| 215 /** @type {!WebInspector.ActionRegistry} */ | 215 /** @type {!UI.ActionRegistry} */ |
| 216 WebInspector.actionRegistry; | 216 UI.actionRegistry; |
| OLD | NEW |