Andres Olivares | 6490c00 | 2020-12-02 16:03:35 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors. All rights reserved. |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Tim van der Lippe | aa61faf | 2021-04-07 15:32:07 | [diff] [blame] | 5 | import * as Common from '../../core/common/common.js'; |
Douglas Chiang | 5f52fb6 | 2023-04-05 08:43:10 | [diff] [blame] | 6 | import * as i18n from '../../core/i18n/i18n.js'; |
Jack Franklin | a75ae7c | 2021-05-11 13:22:54 | [diff] [blame] | 7 | import type * as Platform from '../../core/platform/platform.js'; |
Tim van der Lippe | aa61faf | 2021-04-07 15:32:07 | [diff] [blame] | 8 | import * as Root from '../../core/root/root.js'; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 9 | |
| 10 | import {Context} from './Context.js'; |
| 11 | |
Douglas Chiang | 5f52fb6 | 2023-04-05 08:43:10 | [diff] [blame] | 12 | const UIStrings = { |
| 13 | /** |
| 14 | *@description Title of the keybind category 'Elements' in Settings' Shortcuts pannel. |
| 15 | */ |
| 16 | elements: 'Elements', |
| 17 | /** |
| 18 | *@description Title of the keybind category 'Screenshot' in Settings' Shortcuts pannel. |
| 19 | */ |
| 20 | screenshot: 'Screenshot', |
| 21 | /** |
| 22 | *@description Title of the keybind category 'Network' in Settings' Shortcuts pannel. |
| 23 | */ |
| 24 | network: 'Network', |
| 25 | /** |
| 26 | *@description Title of the keybind category 'Memory' in Settings' Shortcuts pannel. |
| 27 | */ |
| 28 | memory: 'Memory', |
| 29 | /** |
| 30 | *@description Title of the keybind category 'JavaScript Profiler' in Settings' Shortcuts pannel. |
| 31 | */ |
| 32 | javascript_profiler: 'JavaScript Profiler', |
| 33 | /** |
| 34 | *@description Title of the keybind category 'Console' in Settings' Shortcuts pannel. |
| 35 | */ |
| 36 | console: 'Console', |
| 37 | /** |
| 38 | *@description Title of the keybind category 'Performance' in Settings' Shortcuts pannel. |
| 39 | */ |
| 40 | performance: 'Performance', |
| 41 | /** |
| 42 | *@description Title of the keybind category 'Mobile' in Settings' Shortcuts pannel. |
| 43 | */ |
| 44 | mobile: 'Mobile', |
| 45 | /** |
| 46 | *@description Title of the keybind category 'Help' in Settings' Shortcuts pannel. |
| 47 | */ |
| 48 | help: 'Help', |
| 49 | /** |
| 50 | *@description Title of the keybind category 'Layers' in Settings' Shortcuts pannel. |
| 51 | */ |
| 52 | layers: 'Layers', |
| 53 | /** |
| 54 | *@description Title of the keybind category 'Navigation' in Settings' Shortcuts pannel. |
| 55 | */ |
| 56 | navigation: 'Navigation', |
| 57 | /** |
| 58 | *@description Title of the keybind category 'Drawer' in Settings' Shortcuts pannel. |
| 59 | */ |
| 60 | drawer: 'Drawer', |
| 61 | /** |
| 62 | *@description Title of the keybind category 'Global' in Settings' Shortcuts pannel. |
| 63 | */ |
| 64 | global: 'Global', |
| 65 | /** |
| 66 | *@description Title of the keybind category 'Resources' in Settings' Shortcuts pannel. |
| 67 | */ |
| 68 | resources: 'Resources', |
| 69 | /** |
| 70 | *@description Title of the keybind category 'Background Services' in Settings' Shortcuts pannel. |
| 71 | */ |
| 72 | background_services: 'Background Services', |
| 73 | /** |
| 74 | *@description Title of the keybind category 'Settings' in Settings' Shortcuts pannel. |
| 75 | */ |
| 76 | settings: 'Settings', |
| 77 | /** |
| 78 | *@description Title of the keybind category 'Debugger' in Settings' Shortcuts pannel. |
| 79 | */ |
| 80 | debugger: 'Debugger', |
| 81 | /** |
| 82 | *@description Title of the keybind category 'Sources' in Settings' Shortcuts pannel. |
| 83 | */ |
| 84 | sources: 'Sources', |
| 85 | /** |
| 86 | *@description Title of the keybind category 'Rendering' in Settings' Shortcuts pannel. |
| 87 | */ |
| 88 | rendering: 'Rendering', |
| 89 | }; |
| 90 | const str_ = i18n.i18n.registerUIStrings('ui/legacy/ActionRegistration.ts', UIStrings); |
| 91 | const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_); |
| 92 | |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 93 | export interface ActionDelegate { |
| 94 | handleAction(_context: Context, _actionId: string): boolean; |
| 95 | } |
| 96 | |
Kateryna Prokopenko | a72448b | 2021-08-31 14:16:16 | [diff] [blame] | 97 | export class Action extends Common.ObjectWrapper.ObjectWrapper<EventTypes> { |
Jan Scheffler | 01eab3c | 2021-08-16 17:18:07 | [diff] [blame] | 98 | private enabledInternal = true; |
| 99 | private toggledInternal = false; |
Jack Franklin | 01d09b0 | 2020-12-02 15:15:20 | [diff] [blame] | 100 | private actionRegistration: ActionRegistration; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 101 | constructor(actionRegistration: ActionRegistration) { |
| 102 | super(); |
Jack Franklin | 01d09b0 | 2020-12-02 15:15:20 | [diff] [blame] | 103 | this.actionRegistration = actionRegistration; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | id(): string { |
Jack Franklin | 01d09b0 | 2020-12-02 15:15:20 | [diff] [blame] | 107 | return this.actionRegistration.actionId; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | async execute(): Promise<boolean> { |
Jack Franklin | 01d09b0 | 2020-12-02 15:15:20 | [diff] [blame] | 111 | if (!this.actionRegistration.loadActionDelegate) { |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 112 | return false; |
| 113 | } |
Jack Franklin | 01d09b0 | 2020-12-02 15:15:20 | [diff] [blame] | 114 | const delegate = await this.actionRegistration.loadActionDelegate(); |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 115 | const actionId = this.id(); |
| 116 | return delegate.handleAction(Context.instance(), actionId); |
| 117 | } |
| 118 | |
| 119 | icon(): string|undefined { |
Jack Franklin | 01d09b0 | 2020-12-02 15:15:20 | [diff] [blame] | 120 | return this.actionRegistration.iconClass; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | toggledIcon(): string|undefined { |
Jack Franklin | 01d09b0 | 2020-12-02 15:15:20 | [diff] [blame] | 124 | return this.actionRegistration.toggledIconClass; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | toggleWithRedColor(): boolean { |
Tim van der Lippe | ba0e645 | 2021-01-07 13:46:34 | [diff] [blame] | 128 | return Boolean(this.actionRegistration.toggleWithRedColor); |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 129 | } |
| 130 | |
Tim van der Lippe | d946df0 | 2020-12-14 14:35:49 | [diff] [blame] | 131 | setEnabled(enabled: boolean): void { |
Jan Scheffler | 01eab3c | 2021-08-16 17:18:07 | [diff] [blame] | 132 | if (this.enabledInternal === enabled) { |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 133 | return; |
| 134 | } |
| 135 | |
Jan Scheffler | 01eab3c | 2021-08-16 17:18:07 | [diff] [blame] | 136 | this.enabledInternal = enabled; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 137 | this.dispatchEventToListeners(Events.Enabled, enabled); |
| 138 | } |
| 139 | |
| 140 | enabled(): boolean { |
Jan Scheffler | 01eab3c | 2021-08-16 17:18:07 | [diff] [blame] | 141 | return this.enabledInternal; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 142 | } |
| 143 | |
Douglas Chiang | 5f52fb6 | 2023-04-05 08:43:10 | [diff] [blame] | 144 | category(): ActionCategory { |
Jack Franklin | 01d09b0 | 2020-12-02 15:15:20 | [diff] [blame] | 145 | return this.actionRegistration.category; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 146 | } |
| 147 | |
Andres Olivares | 344120f | 2020-12-07 17:43:28 | [diff] [blame] | 148 | tags(): string|void { |
| 149 | if (this.actionRegistration.tags) { |
| 150 | // Get localized keys and separate by null character to prevent fuzzy matching from matching across them. |
Andres Olivares | 4ce36a5 | 2021-01-18 18:35:05 | [diff] [blame] | 151 | return this.actionRegistration.tags.map(tag => tag()).join('\0'); |
Andres Olivares | 344120f | 2020-12-07 17:43:28 | [diff] [blame] | 152 | } |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | toggleable(): boolean { |
Tim van der Lippe | ba0e645 | 2021-01-07 13:46:34 | [diff] [blame] | 156 | return Boolean(this.actionRegistration.toggleable); |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 157 | } |
| 158 | |
Simon Zünd | 6eb94e3 | 2023-04-11 05:28:22 | [diff] [blame] | 159 | title(): Common.UIString.LocalizedString { |
| 160 | let title = this.actionRegistration.title ? this.actionRegistration.title() : i18n.i18n.lockedString(''); |
Jack Franklin | 01d09b0 | 2020-12-02 15:15:20 | [diff] [blame] | 161 | const options = this.actionRegistration.options; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 162 | if (options) { |
| 163 | // Actions with an 'options' property don't have a title field. Instead, the displayed |
| 164 | // title is taken from the 'title' property of the option that is not active. Only one of the |
| 165 | // two options can be active at a given moment and the 'toggled' property of the action along |
| 166 | // with the 'value' of the options are used to determine which one it is. |
| 167 | |
| 168 | for (const pair of options) { |
Jan Scheffler | 01eab3c | 2021-08-16 17:18:07 | [diff] [blame] | 169 | if (pair.value !== this.toggledInternal) { |
Andres Olivares | 4ce36a5 | 2021-01-18 18:35:05 | [diff] [blame] | 170 | title = pair.title(); |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | } |
| 174 | return title; |
| 175 | } |
| 176 | |
| 177 | toggled(): boolean { |
Jan Scheffler | 01eab3c | 2021-08-16 17:18:07 | [diff] [blame] | 178 | return this.toggledInternal; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 179 | } |
| 180 | |
Tim van der Lippe | d946df0 | 2020-12-14 14:35:49 | [diff] [blame] | 181 | setToggled(toggled: boolean): void { |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 182 | console.assert(this.toggleable(), 'Shouldn\'t be toggling an untoggleable action', this.id()); |
Jan Scheffler | 01eab3c | 2021-08-16 17:18:07 | [diff] [blame] | 183 | if (this.toggledInternal === toggled) { |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 184 | return; |
| 185 | } |
| 186 | |
Jan Scheffler | 01eab3c | 2021-08-16 17:18:07 | [diff] [blame] | 187 | this.toggledInternal = toggled; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 188 | this.dispatchEventToListeners(Events.Toggled, toggled); |
| 189 | } |
| 190 | |
| 191 | options(): undefined|Array<ExtensionOption> { |
Jack Franklin | 01d09b0 | 2020-12-02 15:15:20 | [diff] [blame] | 192 | return this.actionRegistration.options; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 193 | } |
| 194 | |
Sigurd Schneider | 61fc9bd | 2021-07-14 09:01:53 | [diff] [blame] | 195 | contextTypes(): undefined|Array<Function> { |
Jack Franklin | 01d09b0 | 2020-12-02 15:15:20 | [diff] [blame] | 196 | if (this.actionRegistration.contextTypes) { |
| 197 | return this.actionRegistration.contextTypes(); |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 198 | } |
| 199 | return undefined; |
| 200 | } |
| 201 | |
| 202 | canInstantiate(): boolean { |
Tim van der Lippe | ba0e645 | 2021-01-07 13:46:34 | [diff] [blame] | 203 | return Boolean(this.actionRegistration.loadActionDelegate); |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | bindings(): Array<Binding>|undefined { |
Jack Franklin | 01d09b0 | 2020-12-02 15:15:20 | [diff] [blame] | 207 | return this.actionRegistration.bindings; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | experiment(): string|undefined { |
Jack Franklin | 01d09b0 | 2020-12-02 15:15:20 | [diff] [blame] | 211 | return this.actionRegistration.experiment; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | condition(): string|undefined { |
Jack Franklin | 01d09b0 | 2020-12-02 15:15:20 | [diff] [blame] | 215 | return this.actionRegistration.condition; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 216 | } |
Andres Olivares | 4dba130 | 2021-01-28 23:17:32 | [diff] [blame] | 217 | |
| 218 | order(): number|undefined { |
| 219 | return this.actionRegistration.order; |
| 220 | } |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 221 | } |
| 222 | |
Andres Olivares | f2a2ddd | 2021-02-03 17:27:51 | [diff] [blame] | 223 | const registeredActionExtensions: Array<Action> = []; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 224 | |
| 225 | const actionIdSet = new Set<string>(); |
| 226 | |
Tim van der Lippe | d946df0 | 2020-12-14 14:35:49 | [diff] [blame] | 227 | export function registerActionExtension(registration: ActionRegistration): void { |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 228 | const actionId = registration.actionId; |
| 229 | if (actionIdSet.has(actionId)) { |
| 230 | throw new Error(`Duplicate Action id '${actionId}': ${new Error().stack}`); |
| 231 | } |
| 232 | actionIdSet.add(actionId); |
Andres Olivares | f2a2ddd | 2021-02-03 17:27:51 | [diff] [blame] | 233 | registeredActionExtensions.push(new Action(registration)); |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 234 | } |
| 235 | |
Andrés Olivares | b0fcd18 | 2023-02-21 10:13:28 | [diff] [blame] | 236 | export function reset(): void { |
| 237 | actionIdSet.clear(); |
| 238 | registeredActionExtensions.length = 0; |
| 239 | } |
| 240 | |
Andres Olivares | f2a2ddd | 2021-02-03 17:27:51 | [diff] [blame] | 241 | export function getRegisteredActionExtensions(): Array<Action> { |
Andres Olivares | 4dba130 | 2021-01-28 23:17:32 | [diff] [blame] | 242 | return registeredActionExtensions |
| 243 | .filter( |
| 244 | action => Root.Runtime.Runtime.isDescriptorEnabled( |
| 245 | {experiment: action.experiment(), condition: action.condition()})) |
| 246 | .sort((firstAction, secondAction) => { |
| 247 | const order1 = firstAction.order() || 0; |
| 248 | const order2 = secondAction.order() || 0; |
| 249 | return order1 - order2; |
| 250 | }); |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 251 | } |
| 252 | |
Andres Olivares | 975c302 | 2021-03-29 13:45:24 | [diff] [blame] | 253 | export function maybeRemoveActionExtension(actionId: string): boolean { |
| 254 | const actionIndex = registeredActionExtensions.findIndex(action => action.id() === actionId); |
| 255 | if (actionIndex < 0 || !actionIdSet.delete(actionId)) { |
| 256 | return false; |
| 257 | } |
| 258 | registeredActionExtensions.splice(actionIndex, 1); |
| 259 | return true; |
| 260 | } |
| 261 | |
Andres Olivares | 4ce36a5 | 2021-01-18 18:35:05 | [diff] [blame] | 262 | export const enum Platforms { |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 263 | All = 'All platforms', |
| 264 | Mac = 'mac', |
| 265 | WindowsLinux = 'windows,linux', |
| 266 | Android = 'Android', |
Andres Olivares | 70556d6 | 2021-02-02 19:09:01 | [diff] [blame] | 267 | Windows = 'windows', |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 268 | } |
| 269 | |
Kateryna Prokopenko | a72448b | 2021-08-31 14:16:16 | [diff] [blame] | 270 | export const enum Events { |
| 271 | Enabled = 'Enabled', |
| 272 | Toggled = 'Toggled', |
| 273 | } |
| 274 | |
| 275 | export type EventTypes = { |
| 276 | [Events.Enabled]: boolean, |
| 277 | [Events.Toggled]: boolean, |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 278 | }; |
| 279 | |
Douglas Chiang | 5f52fb6 | 2023-04-05 08:43:10 | [diff] [blame] | 280 | // eslint-disable-next-line rulesdir/const_enum |
| 281 | export enum ActionCategory { |
| 282 | NONE = '', // `NONE` must be a falsy value. Legacy code uses if-checks for the category. |
| 283 | ELEMENTS = 'ELEMENTS', |
| 284 | SCREENSHOT = 'SCREENSHOT', |
| 285 | NETWORK = 'NETWORK', |
| 286 | MEMORY = 'MEMORY', |
| 287 | JAVASCRIPT_PROFILER = 'JAVASCRIPT_PROFILER', |
| 288 | CONSOLE = 'CONSOLE', |
| 289 | PERFORMANCE = 'PERFORMANCE', |
| 290 | MOBILE = 'MOBILE', |
| 291 | HELP = 'HELP', |
| 292 | LAYERS = 'LAYERS', |
| 293 | NAVIGATION = 'NAVIGATION', |
| 294 | DRAWER = 'DRAWER', |
| 295 | GLOBAL = 'GLOBAL', |
| 296 | RESOURCES = 'RESOURCES', |
| 297 | BACKGROUND_SERVICES = 'BACKGROUND_SERVICES', |
| 298 | SETTINGS = 'SETTINGS', |
| 299 | DEBUGGER = 'DEBUGGER', |
| 300 | SOURCES = 'SOURCES', |
| 301 | RENDERING = 'RENDERING', |
| 302 | } |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 303 | |
Douglas Chiang | 5f52fb6 | 2023-04-05 08:43:10 | [diff] [blame] | 304 | export function getLocalizedActionCategory(category: ActionCategory): Platform.UIString.LocalizedString { |
| 305 | switch (category) { |
| 306 | case ActionCategory.ELEMENTS: |
| 307 | return i18nString(UIStrings.elements); |
| 308 | case ActionCategory.SCREENSHOT: |
| 309 | return i18nString(UIStrings.screenshot); |
| 310 | case ActionCategory.NETWORK: |
| 311 | return i18nString(UIStrings.network); |
| 312 | case ActionCategory.MEMORY: |
| 313 | return i18nString(UIStrings.memory); |
| 314 | case ActionCategory.JAVASCRIPT_PROFILER: |
| 315 | return i18nString(UIStrings.javascript_profiler); |
| 316 | case ActionCategory.CONSOLE: |
| 317 | return i18nString(UIStrings.console); |
| 318 | case ActionCategory.PERFORMANCE: |
| 319 | return i18nString(UIStrings.performance); |
| 320 | case ActionCategory.MOBILE: |
| 321 | return i18nString(UIStrings.mobile); |
| 322 | case ActionCategory.HELP: |
| 323 | return i18nString(UIStrings.help); |
| 324 | case ActionCategory.LAYERS: |
| 325 | return i18nString(UIStrings.layers); |
| 326 | case ActionCategory.NAVIGATION: |
| 327 | return i18nString(UIStrings.navigation); |
| 328 | case ActionCategory.DRAWER: |
| 329 | return i18nString(UIStrings.drawer); |
| 330 | case ActionCategory.GLOBAL: |
| 331 | return i18nString(UIStrings.global); |
| 332 | case ActionCategory.RESOURCES: |
| 333 | return i18nString(UIStrings.resources); |
| 334 | case ActionCategory.BACKGROUND_SERVICES: |
| 335 | return i18nString(UIStrings.background_services); |
| 336 | case ActionCategory.SETTINGS: |
| 337 | return i18nString(UIStrings.settings); |
| 338 | case ActionCategory.DEBUGGER: |
| 339 | return i18nString(UIStrings.debugger); |
| 340 | case ActionCategory.SOURCES: |
| 341 | return i18nString(UIStrings.sources); |
| 342 | case ActionCategory.RENDERING: |
| 343 | return i18nString(UIStrings.rendering); |
| 344 | case ActionCategory.NONE: |
| 345 | return i18n.i18n.lockedString(''); |
| 346 | } |
Simon Zünd | d2132fb | 2023-04-05 11:39:15 | [diff] [blame] | 347 | // Not all categories are cleanly typed yet. Return the category as-is in this case. |
| 348 | return i18n.i18n.lockedString(category); |
Douglas Chiang | 5f52fb6 | 2023-04-05 08:43:10 | [diff] [blame] | 349 | } |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 350 | |
| 351 | export const enum IconClass { |
Kateryna Prokopenko | 910cb53 | 2023-03-28 09:36:46 | [diff] [blame] | 352 | LARGEICON_NODE_SEARCH = 'select-element', |
Kateryna Prokopenko | 75da971 | 2023-03-31 11:56:38 | [diff] [blame] | 353 | START_RECORDING = 'record-start', |
| 354 | STOP_RECORDING = 'record-stop', |
Kateryna Prokopenko | 551f9c8 | 2023-04-04 14:34:21 | [diff] [blame] | 355 | REFRESH = 'refresh', |
Kateryna Prokopenko | 05ade9a | 2023-03-31 10:57:05 | [diff] [blame] | 356 | CLEAR = 'clear', |
| 357 | EYE = 'eye', |
Kateryna Prokopenko | 910cb53 | 2023-03-28 09:36:46 | [diff] [blame] | 358 | LARGEICON_PHONE = 'devices', |
Andres Olivares | a7b7b49 | 2021-01-28 16:12:37 | [diff] [blame] | 359 | LARGEICON_PLAY = 'largeicon-play', |
Benedikt Meurer | c4ad9d9 | 2023-04-11 07:25:02 | [diff] [blame] | 360 | DOWNLOAD = 'download', |
Benedikt Meurer | 4878f6a | 2023-03-29 12:01:44 | [diff] [blame] | 361 | LARGEICON_PAUSE = 'pause', |
| 362 | LARGEICON_RESUME = 'resume', |
Benedikt Meurer | 178c0c3 | 2023-03-31 04:50:06 | [diff] [blame] | 363 | BIN = 'bin', |
Kateryna Prokopenko | 910cb53 | 2023-03-28 09:36:46 | [diff] [blame] | 364 | LARGEICON_SETTINGS_GEAR = 'gear', |
Benedikt Meurer | 4878f6a | 2023-03-29 12:01:44 | [diff] [blame] | 365 | LARGEICON_STEP_OVER = 'step-over', |
| 366 | LARGE_ICON_STEP_INTO = 'step-into', |
| 367 | LARGE_ICON_STEP = 'step', |
| 368 | LARGE_ICON_STEP_OUT = 'step-out', |
Benedikt Meurer | 32c2a1b | 2023-03-30 07:09:59 | [diff] [blame] | 369 | BREAKPOINT_CROSSED_FILLED = 'breakpoint-crossed-filled', |
| 370 | BREAKPOINT_CROSSED = 'breakpoint-crossed', |
Benedikt Meurer | 7d5cc37 | 2023-04-12 12:20:41 | [diff] [blame^] | 371 | PLUS = 'plus', |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | export const enum KeybindSet { |
| 375 | DEVTOOLS_DEFAULT = 'devToolsDefault', |
| 376 | VS_CODE = 'vsCode', |
| 377 | } |
| 378 | |
| 379 | export interface ExtensionOption { |
| 380 | value: boolean; |
Andres Olivares | 4ce36a5 | 2021-01-18 18:35:05 | [diff] [blame] | 381 | title: () => Platform.UIString.LocalizedString; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 382 | text?: string; |
| 383 | } |
| 384 | |
| 385 | export interface Binding { |
Andres Olivares | 4ce36a5 | 2021-01-18 18:35:05 | [diff] [blame] | 386 | platform?: Platforms; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 387 | shortcut: string; |
| 388 | keybindSets?: Array<KeybindSet>; |
| 389 | } |
| 390 | |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 391 | /** |
| 392 | * The representation of an action extension to be registered. |
| 393 | */ |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 394 | export interface ActionRegistration { |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 395 | /** |
| 396 | * The unique id of an Action extension. |
| 397 | */ |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 398 | actionId: string; |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 399 | /** |
| 400 | * The category with which the action is displayed in the UI. |
| 401 | */ |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 402 | category: ActionCategory; |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 403 | /** |
| 404 | * The title with which the action is displayed in the UI. |
| 405 | */ |
Andres Olivares | 4ce36a5 | 2021-01-18 18:35:05 | [diff] [blame] | 406 | title?: () => Platform.UIString.LocalizedString; |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 407 | /** |
| 408 | * The type of the icon used to trigger the action. |
| 409 | */ |
Andres Olivares | 844c58d | 2021-01-26 13:09:07 | [diff] [blame] | 410 | iconClass?: IconClass; |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 411 | /** |
| 412 | * Whether the style of the icon toggles on interaction. |
| 413 | */ |
Andres Olivares | 844c58d | 2021-01-26 13:09:07 | [diff] [blame] | 414 | toggledIconClass?: IconClass; |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 415 | /** |
| 416 | * Whether the class 'toolbar-toggle-with-red-color' is toggled on the icon on interaction. |
| 417 | */ |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 418 | toggleWithRedColor?: boolean; |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 419 | /** |
| 420 | * Words used to find an action in the Command Menu. |
| 421 | */ |
Andres Olivares | 4ce36a5 | 2021-01-18 18:35:05 | [diff] [blame] | 422 | tags?: Array<() => Platform.UIString.LocalizedString>; |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 423 | /** |
| 424 | * Whether the action is toggleable. |
| 425 | */ |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 426 | toggleable?: boolean; |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 427 | /** |
Andres Olivares | a0cdb38 | 2021-01-21 15:44:33 | [diff] [blame] | 428 | * Loads the class that handles the action when it is triggered. The common pattern for implementing |
| 429 | * this function relies on having the module that contains the action’s handler lazily loaded. For example: |
| 430 | * ```js |
| 431 | * let loadedElementsModule; |
| 432 | * |
| 433 | * async function loadElementsModule() { |
| 434 | * |
| 435 | * if (!loadedElementsModule) { |
| 436 | * loadedElementsModule = await import('./elements.js'); |
| 437 | * } |
| 438 | * return loadedElementsModule; |
| 439 | * } |
| 440 | * UI.ActionRegistration.registerActionExtension({ |
| 441 | * <...> |
| 442 | * async loadActionDelegate() { |
| 443 | * const Elements = await loadElementsModule(); |
| 444 | * return Elements.ElementsPanel.ElementsActionDelegate.instance(); |
| 445 | * }, |
| 446 | * <...> |
| 447 | * }); |
| 448 | * ``` |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 449 | */ |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 450 | loadActionDelegate?: () => Promise<ActionDelegate>; |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 451 | /** |
| 452 | * Returns the classes that represent the 'context flavors' under which the action is available for triggering. |
| 453 | * The context of the application is described in 'flavors' that are usually views added and removed to the context |
| 454 | * as the user interacts with the application (e.g when the user moves across views). (See UI.Context) |
| 455 | * When the action is supposed to be available globally, that is, it does not depend on the application to have |
| 456 | * a specific context, the value of this property should be undefined. |
| 457 | * |
| 458 | * Because the method is synchronous, context types should be already loaded when the method is invoked. |
| 459 | * In the case that an action has context types it depends on, and they haven't been loaded yet, the function should |
| 460 | * return an empty array. Once the context types have been loaded, the function should return an array with all types |
| 461 | * that it depends on. |
| 462 | * |
| 463 | * The common pattern for implementing this function is relying on having the module with the corresponding context |
| 464 | * types loaded and stored when the related 'view' extension is loaded asynchronously. As an example: |
| 465 | * |
| 466 | * ```js |
| 467 | * let loadedElementsModule; |
| 468 | * |
| 469 | * async function loadElementsModule() { |
| 470 | * |
| 471 | * if (!loadedElementsModule) { |
| 472 | * loadedElementsModule = await import('./elements.js'); |
| 473 | * } |
| 474 | * return loadedElementsModule; |
| 475 | * } |
| 476 | * function maybeRetrieveContextTypes(getClassCallBack: (elementsModule: typeof Elements) => unknown[]): unknown[] { |
| 477 | * |
| 478 | * if (loadedElementsModule === undefined) { |
| 479 | * return []; |
| 480 | * } |
| 481 | * return getClassCallBack(loadedElementsModule); |
| 482 | * } |
| 483 | * UI.ActionRegistration.registerActionExtension({ |
| 484 | * |
| 485 | * contextTypes() { |
| 486 | * return maybeRetrieveContextTypes(Elements => [Elements.ElementsPanel.ElementsPanel]); |
| 487 | * } |
| 488 | * <...> |
| 489 | * }); |
| 490 | * ``` |
| 491 | */ |
Sigurd Schneider | 61fc9bd | 2021-07-14 09:01:53 | [diff] [blame] | 492 | contextTypes?: () => Array<Function>; |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 493 | /** |
Andres Olivares | a0cdb38 | 2021-01-21 15:44:33 | [diff] [blame] | 494 | * The descriptions for each of the two states in which a toggleable action can be. |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 495 | */ |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 496 | options?: Array<ExtensionOption>; |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 497 | /** |
| 498 | * The description of the variables (e.g. platform, keys and keybind sets) under which a keyboard shortcut triggers the action. |
| 499 | * If a keybind must be available on all platforms, its 'platform' property must be undefined. The same applies to keybind sets |
| 500 | * and the keybindSet property. |
| 501 | * |
| 502 | * Keybinds also depend on the context types of their corresponding action, and so they will only be available when such context types |
| 503 | * are flavors of the current appliaction context. |
| 504 | */ |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 505 | bindings?: Array<Binding>; |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 506 | /** |
Andres Olivares | a0cdb38 | 2021-01-21 15:44:33 | [diff] [blame] | 507 | * The name of the experiment an action is associated with. Enabling and disabling the declared |
| 508 | * experiment will enable and disable the action respectively. |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 509 | */ |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 510 | experiment?: Root.Runtime.ExperimentName; |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 511 | /** |
Andres Olivares | a0cdb38 | 2021-01-21 15:44:33 | [diff] [blame] | 512 | * A condition represented as a string the action's availability depends on. Conditions come |
| 513 | * from the queryParamsObject defined in Runtime and just as the experiment field, they determine the availability |
| 514 | * of the setting. A condition can be negated by prepending a ‘!’ to the value of the condition |
| 515 | * property and in that case the behaviour of the action's availability will be inverted. |
Andres Olivares | 3f49f13 | 2020-12-03 13:10:27 | [diff] [blame] | 516 | */ |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 517 | condition?: Root.Runtime.ConditionName; |
Andres Olivares | 4dba130 | 2021-01-28 23:17:32 | [diff] [blame] | 518 | /** |
| 519 | * Used to sort actions when all registered actions are queried. |
| 520 | */ |
| 521 | order?: number; |
Andres Olivares | 0e3a9e8 | 2020-12-01 14:03:20 | [diff] [blame] | 522 | } |