Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 5 | /* |
| 6 | * Copyright (C) IBM Corp. 2009 All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions are |
| 10 | * met: |
| 11 | * |
| 12 | * * Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * * Redistributions in binary form must reproduce the above |
| 15 | * copyright notice, this list of conditions and the following disclaimer |
| 16 | * in the documentation and/or other materials provided with the |
| 17 | * distribution. |
| 18 | * * Neither the name of IBM Corp. nor the names of its |
| 19 | * contributors may be used to endorse or promote products derived from |
| 20 | * this software without specific prior written permission. |
| 21 | * |
| 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | */ |
Tim van der Lippe | 8987f8f | 2020-01-03 15:03:16 | [diff] [blame] | 34 | |
Tim van der Lippe | 021c757 | 2021-04-19 10:49:43 | [diff] [blame] | 35 | import * as Common from '../../core/common/common.js'; |
| 36 | import * as Host from '../../core/host/host.js'; |
| 37 | import * as i18n from '../../core/i18n/i18n.js'; |
| 38 | import * as Platform from '../../core/platform/platform.js'; |
Tim van der Lippe | 021c757 | 2021-04-19 10:49:43 | [diff] [blame] | 39 | import * as SDK from '../../core/sdk/sdk.js'; |
Simon Zünd | 5e6e1f8 | 2023-11-23 10:55:31 | [diff] [blame] | 40 | import type * as Protocol from '../../generated/protocol.js'; |
Jaroslav Sevcik | 9b05a52 | 2022-11-30 15:43:21 | [diff] [blame] | 41 | import * as Formatter from '../../models/formatter/formatter.js'; |
| 42 | import * as SourceMapScopes from '../../models/source_map_scopes/source_map_scopes.js'; |
Benedikt Meurer | d8a9565 | 2024-01-04 08:29:17 | [diff] [blame] | 43 | import * as Buttons from '../../ui/components/buttons/buttons.js'; |
Tim van der Lippe | 021c757 | 2021-04-19 10:49:43 | [diff] [blame] | 44 | import * as ObjectUI from '../../ui/legacy/components/object_ui/object_ui.js'; |
Kriti Sapra | ae8f17e | 2021-08-18 10:28:02 | [diff] [blame] | 45 | // eslint-disable-next-line rulesdir/es_modules_import |
| 46 | import objectValueStyles from '../../ui/legacy/components/object_ui/objectValue.css.js'; |
Tim van der Lippe | 339ad26 | 2021-04-21 12:23:36 | [diff] [blame] | 47 | import * as Components from '../../ui/legacy/components/utils/utils.js'; |
Tim van der Lippe | 021c757 | 2021-04-19 10:49:43 | [diff] [blame] | 48 | import * as UI from '../../ui/legacy/legacy.js'; |
Simon Zünd | 5e6e1f8 | 2023-11-23 10:55:31 | [diff] [blame] | 49 | import * as VisualLogging from '../../ui/visual_logging/visual_logging.js'; |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 50 | |
Paul Lewis | 3994495 | 2020-01-22 15:45:18 | [diff] [blame] | 51 | import {UISourceCodeFrame} from './UISourceCodeFrame.js'; |
Simon Zünd | 5e6e1f8 | 2023-11-23 10:55:31 | [diff] [blame] | 52 | import watchExpressionsSidebarPaneStyles from './watchExpressionsSidebarPane.css.js'; |
Paul Lewis | 3994495 | 2020-01-22 15:45:18 | [diff] [blame] | 53 | |
Simon Zünd | 697fb0b | 2021-03-01 10:12:42 | [diff] [blame] | 54 | const UIStrings = { |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 55 | /** |
Jack Franklin | fd72c07 | 2022-12-21 11:45:01 | [diff] [blame] | 56 | *@description A context menu item in the Watch Expressions Sidebar Pane of the Sources panel |
| 57 | */ |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 58 | addWatchExpression: 'Add watch expression', |
| 59 | /** |
Jack Franklin | fd72c07 | 2022-12-21 11:45:01 | [diff] [blame] | 60 | *@description Tooltip/screen reader label of a button in the Sources panel that refreshes all watch expressions. |
| 61 | */ |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 62 | refreshWatchExpressions: 'Refresh watch expressions', |
| 63 | /** |
Jack Franklin | fd72c07 | 2022-12-21 11:45:01 | [diff] [blame] | 64 | *@description Empty element text content in Watch Expressions Sidebar Pane of the Sources panel |
| 65 | */ |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 66 | noWatchExpressions: 'No watch expressions', |
| 67 | /** |
Jack Franklin | fd72c07 | 2022-12-21 11:45:01 | [diff] [blame] | 68 | *@description A context menu item in the Watch Expressions Sidebar Pane of the Sources panel |
| 69 | */ |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 70 | deleteAllWatchExpressions: 'Delete all watch expressions', |
| 71 | /** |
Jack Franklin | fd72c07 | 2022-12-21 11:45:01 | [diff] [blame] | 72 | *@description A context menu item in the Watch Expressions Sidebar Pane of the Sources panel |
| 73 | */ |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 74 | addPropertyPathToWatch: 'Add property path to watch', |
| 75 | /** |
Jack Franklin | fd72c07 | 2022-12-21 11:45:01 | [diff] [blame] | 76 | *@description A context menu item in the Watch Expressions Sidebar Pane of the Sources panel |
| 77 | */ |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 78 | deleteWatchExpression: 'Delete watch expression', |
| 79 | /** |
Jack Franklin | fd72c07 | 2022-12-21 11:45:01 | [diff] [blame] | 80 | *@description Value element text content in Watch Expressions Sidebar Pane of the Sources panel |
| 81 | */ |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 82 | notAvailable: '<not available>', |
| 83 | /** |
Jack Franklin | fd72c07 | 2022-12-21 11:45:01 | [diff] [blame] | 84 | *@description A context menu item in the Watch Expressions Sidebar Pane of the Sources panel and Network pane request. |
| 85 | */ |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 86 | copyValue: 'Copy value', |
| 87 | }; |
Tim van der Lippe | 021c757 | 2021-04-19 10:49:43 | [diff] [blame] | 88 | const str_ = i18n.i18n.registerUIStrings('panels/sources/WatchExpressionsSidebarPane.ts', UIStrings); |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 89 | const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_); |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 90 | let watchExpressionsSidebarPaneInstance: WatchExpressionsSidebarPane; |
Andres Olivares | fd431fb | 2020-12-10 15:30:04 | [diff] [blame] | 91 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 92 | export class WatchExpressionsSidebarPane extends UI.ThrottledWidget.ThrottledWidget implements |
Benedikt Meurer | 9812888 | 2023-12-03 13:59:49 | [diff] [blame] | 93 | UI.ActionRegistration.ActionDelegate, UI.Toolbar.ItemsProvider, |
| 94 | UI.ContextMenu.Provider<ObjectUI.ObjectPropertiesSection.ObjectPropertyTreeElement|UISourceCodeFrame> { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 95 | private watchExpressions: WatchExpression[]; |
| 96 | private emptyElement!: HTMLElement; |
| 97 | private readonly watchExpressionsSetting: Common.Settings.Setting<string[]>; |
| 98 | private readonly addButton: UI.Toolbar.ToolbarButton; |
| 99 | private readonly refreshButton: UI.Toolbar.ToolbarButton; |
| 100 | private readonly treeOutline: ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeOutline; |
| 101 | private readonly expandController: ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeExpandController; |
| 102 | private readonly linkifier: Components.Linkifier.Linkifier; |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 103 | private constructor() { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 104 | super(true); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 105 | |
Simon Zünd | 0243c60 | 2020-03-10 06:51:42 | [diff] [blame] | 106 | // TODO(szuend): Replace with a Set once the web test |
Tim van der Lippe | 021c757 | 2021-04-19 10:49:43 | [diff] [blame] | 107 | // panels/sources/debugger-ui/watch-expressions-preserve-expansion.js is either converted |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 108 | // to an e2e test or no longer accesses this variable directly. |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 109 | this.watchExpressions = []; |
| 110 | this.watchExpressionsSetting = |
Danil Somsikov | 2bfb906 | 2024-01-30 16:31:09 | [diff] [blame] | 111 | Common.Settings.Settings.instance().createLocalSetting<string[]>('watch-expressions', []); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 112 | |
Simon Zünd | 0009385 | 2023-11-28 08:29:18 | [diff] [blame] | 113 | this.addButton = new UI.Toolbar.ToolbarButton( |
| 114 | i18nString(UIStrings.addWatchExpression), 'plus', undefined, 'add-watch-expression'); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 115 | this.addButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, _event => { |
Tim van der Lippe | 2d9a95c | 2022-01-04 15:18:03 | [diff] [blame] | 116 | void this.addButtonClicked(); |
Tim van der Lippe | 37a35ff | 2020-03-03 13:49:02 | [diff] [blame] | 117 | }); |
Simon Zünd | 0009385 | 2023-11-28 08:29:18 | [diff] [blame] | 118 | this.refreshButton = new UI.Toolbar.ToolbarButton( |
| 119 | i18nString(UIStrings.refreshWatchExpressions), 'refresh', undefined, 'refresh-watch-expressions'); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 120 | this.refreshButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, this.update, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 121 | |
| 122 | this.contentElement.classList.add('watch-expressions'); |
Danil Somsikov | 0cb9746 | 2024-01-30 15:11:29 | [diff] [blame] | 123 | this.contentElement.setAttribute('jslog', `${VisualLogging.section('sources.watch')}`); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 124 | this.contentElement.addEventListener('contextmenu', this.contextMenu.bind(this), false); |
| 125 | this.treeOutline = new ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeOutline(); |
Benedikt Meurer | 699358f | 2023-12-15 12:50:01 | [diff] [blame] | 126 | this.treeOutline.hideOverflow(); |
Kriti Sapra | ae8f17e | 2021-08-18 10:28:02 | [diff] [blame] | 127 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 128 | this.treeOutline.setShowSelectionOnKeyboardFocus(/* show */ true); |
| 129 | this.expandController = |
| 130 | new ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeExpandController(this.treeOutline); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 131 | |
Tim van der Lippe | d1a00aa | 2020-08-19 16:03:56 | [diff] [blame] | 132 | UI.Context.Context.instance().addFlavorChangeListener(SDK.RuntimeModel.ExecutionContext, this.update, this); |
| 133 | UI.Context.Context.instance().addFlavorChangeListener(SDK.DebuggerModel.CallFrame, this.update, this); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 134 | this.linkifier = new Components.Linkifier.Linkifier(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 135 | this.update(); |
| 136 | } |
| 137 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 138 | static instance(): WatchExpressionsSidebarPane { |
Andres Olivares | fd431fb | 2020-12-10 15:30:04 | [diff] [blame] | 139 | if (!watchExpressionsSidebarPaneInstance) { |
| 140 | watchExpressionsSidebarPaneInstance = new WatchExpressionsSidebarPane(); |
| 141 | } |
| 142 | return watchExpressionsSidebarPaneInstance; |
| 143 | } |
| 144 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 145 | toolbarItems(): UI.Toolbar.ToolbarItem[] { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 146 | return [this.addButton, this.refreshButton]; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 147 | } |
| 148 | |
Randolf Jung | ffd1424 | 2023-04-19 00:32:25 | [diff] [blame] | 149 | override focus(): void { |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 150 | if (this.hasFocus()) { |
| 151 | return; |
| 152 | } |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 153 | if (this.watchExpressions.length > 0) { |
| 154 | this.treeOutline.forceSelect(); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 158 | hasExpressions(): boolean { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 159 | return Boolean(this.watchExpressionsSetting.get().length); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 160 | } |
| 161 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 162 | private saveExpressions(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 163 | const toSave = []; |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 164 | for (let i = 0; i < this.watchExpressions.length; i++) { |
| 165 | const expression = this.watchExpressions[i].expression(); |
Sigurd Schneider | 8641b42 | 2021-07-16 06:13:35 | [diff] [blame] | 166 | if (expression) { |
| 167 | toSave.push(expression); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 168 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 169 | } |
| 170 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 171 | this.watchExpressionsSetting.set(toSave); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 172 | } |
| 173 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 174 | private async addButtonClicked(): Promise<void> { |
Paul Lewis | 75c7d0d | 2020-03-19 12:17:26 | [diff] [blame] | 175 | await UI.ViewManager.ViewManager.instance().showView('sources.watch'); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 176 | this.emptyElement.classList.add('hidden'); |
| 177 | this.createWatchExpression(null).startEditing(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 178 | } |
| 179 | |
Randolf Jung | ffd1424 | 2023-04-19 00:32:25 | [diff] [blame] | 180 | override async doUpdate(): Promise<void> { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 181 | this.linkifier.reset(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 182 | this.contentElement.removeChildren(); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 183 | this.treeOutline.removeChildren(); |
| 184 | this.watchExpressions = []; |
| 185 | this.emptyElement = (this.contentElement.createChild('div', 'gray-info-message') as HTMLElement); |
| 186 | this.emptyElement.textContent = i18nString(UIStrings.noWatchExpressions); |
| 187 | this.emptyElement.tabIndex = -1; |
| 188 | const watchExpressionStrings = this.watchExpressionsSetting.get(); |
Jack Lynch | 338317a | 2020-08-19 21:59:49 | [diff] [blame] | 189 | if (watchExpressionStrings.length) { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 190 | this.emptyElement.classList.add('hidden'); |
Jack Lynch | 338317a | 2020-08-19 21:59:49 | [diff] [blame] | 191 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 192 | for (let i = 0; i < watchExpressionStrings.length; ++i) { |
| 193 | const expression = watchExpressionStrings[i]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 194 | if (!expression) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 195 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 196 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 197 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 198 | this.createWatchExpression(expression); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 199 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 200 | } |
| 201 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 202 | private createWatchExpression(expression: string|null): WatchExpression { |
| 203 | this.contentElement.appendChild(this.treeOutline.element); |
| 204 | const watchExpression = new WatchExpression(expression, this.expandController, this.linkifier); |
Natasha Lee | 030b867 | 2024-06-25 21:35:56 | [diff] [blame] | 205 | UI.ARIAUtils.setLabel(this.contentElement, i18nString(UIStrings.addWatchExpression)); |
Benedikt Meurer | e02230c | 2021-09-09 13:57:22 | [diff] [blame] | 206 | watchExpression.addEventListener(Events.ExpressionUpdated, this.watchExpressionUpdated, this); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 207 | this.treeOutline.appendChild(watchExpression.treeElement()); |
| 208 | this.watchExpressions.push(watchExpression); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 209 | return watchExpression; |
| 210 | } |
| 211 | |
Benedikt Meurer | e02230c | 2021-09-09 13:57:22 | [diff] [blame] | 212 | private watchExpressionUpdated({data: watchExpression}: Common.EventTarget.EventTargetEvent<WatchExpression>): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 213 | if (!watchExpression.expression()) { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 214 | Platform.ArrayUtilities.removeElement(this.watchExpressions, watchExpression); |
| 215 | this.treeOutline.removeChild(watchExpression.treeElement()); |
| 216 | this.emptyElement.classList.toggle('hidden', Boolean(this.watchExpressions.length)); |
| 217 | if (this.watchExpressions.length === 0) { |
| 218 | this.treeOutline.element.remove(); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 219 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 220 | } |
| 221 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 222 | this.saveExpressions(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 223 | } |
| 224 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 225 | private contextMenu(event: MouseEvent): void { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 226 | const contextMenu = new UI.ContextMenu.ContextMenu(event); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 227 | this.populateContextMenu(contextMenu, event); |
Tim van der Lippe | 2d9a95c | 2022-01-04 15:18:03 | [diff] [blame] | 228 | void contextMenu.show(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 229 | } |
| 230 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 231 | private populateContextMenu(contextMenu: UI.ContextMenu.ContextMenu, event: MouseEvent): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 232 | let isEditing = false; |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 233 | for (const watchExpression of this.watchExpressions) { |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 234 | isEditing = isEditing || watchExpression.isEditing(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 235 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 236 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 237 | if (!isEditing) { |
Simon Zünd | 0009385 | 2023-11-28 08:29:18 | [diff] [blame] | 238 | contextMenu.debugSection().appendItem( |
| 239 | i18nString(UIStrings.addWatchExpression), this.addButtonClicked.bind(this), |
| 240 | {jslogContext: 'add-watch-expression'}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 241 | } |
| 242 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 243 | if (this.watchExpressions.length > 1) { |
Changhao Han | 8eb616e | 2021-08-11 05:45:27 | [diff] [blame] | 244 | contextMenu.debugSection().appendItem( |
Simon Zünd | 0009385 | 2023-11-28 08:29:18 | [diff] [blame] | 245 | i18nString(UIStrings.deleteAllWatchExpressions), this.deleteAllButtonClicked.bind(this), |
| 246 | {jslogContext: 'delete-all-watch-expressions'}); |
Changhao Han | 8eb616e | 2021-08-11 05:45:27 | [diff] [blame] | 247 | } |
| 248 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 249 | const treeElement = this.treeOutline.treeElementFromEvent(event); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 250 | if (!treeElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 251 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 252 | } |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 253 | const currentWatchExpression = |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 254 | this.watchExpressions.find(watchExpression => treeElement.hasAncestorOrSelf(watchExpression.treeElement())); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 255 | if (currentWatchExpression) { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 256 | currentWatchExpression.populateContextMenu(contextMenu, event); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 257 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 258 | } |
| 259 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 260 | private deleteAllButtonClicked(): void { |
| 261 | this.watchExpressions = []; |
| 262 | this.saveExpressions(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 263 | this.update(); |
| 264 | } |
| 265 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 266 | private async focusAndAddExpressionToWatch(expression: string): Promise<void> { |
Benedikt Meurer | 61f1eef | 2021-03-17 10:38:29 | [diff] [blame] | 267 | await UI.ViewManager.ViewManager.instance().showView('sources.watch'); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 268 | this.createWatchExpression(expression); |
| 269 | this.saveExpressions(); |
Jack Lynch | 338317a | 2020-08-19 21:59:49 | [diff] [blame] | 270 | this.update(); |
PhistucK | 065e136 | 2018-05-05 09:51:09 | [diff] [blame] | 271 | } |
| 272 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 273 | handleAction(_context: UI.Context.Context, _actionId: string): boolean { |
Tim van der Lippe | d1a00aa | 2020-08-19 16:03:56 | [diff] [blame] | 274 | const frame = UI.Context.Context.instance().flavor(UISourceCodeFrame); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 275 | if (!frame) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 276 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 277 | } |
Tim van der Lippe | c1ab112 | 2021-11-12 16:10:31 | [diff] [blame] | 278 | const {state} = frame.textEditor; |
| 279 | const text = state.sliceDoc(state.selection.main.from, state.selection.main.to); |
Tim van der Lippe | 2d9a95c | 2022-01-04 15:18:03 | [diff] [blame] | 280 | void this.focusAndAddExpressionToWatch(text); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 281 | return true; |
| 282 | } |
| 283 | |
Benedikt Meurer | 9812888 | 2023-12-03 13:59:49 | [diff] [blame] | 284 | appendApplicableItems( |
| 285 | _event: Event, contextMenu: UI.ContextMenu.ContextMenu, |
| 286 | target: ObjectUI.ObjectPropertiesSection.ObjectPropertyTreeElement|UISourceCodeFrame): void { |
| 287 | if (target instanceof ObjectUI.ObjectPropertiesSection.ObjectPropertyTreeElement) { |
| 288 | if (!target.property.synthetic) { |
| 289 | contextMenu.debugSection().appendItem( |
Danil Somsikov | 1b6ec85 | 2024-02-23 08:53:25 | [diff] [blame] | 290 | i18nString(UIStrings.addPropertyPathToWatch), () => this.focusAndAddExpressionToWatch(target.path()), |
| 291 | {jslogContext: 'add-property-path-to-watch'}); |
Benedikt Meurer | 9812888 | 2023-12-03 13:59:49 | [diff] [blame] | 292 | } |
| 293 | return; |
PhistucK | 065e136 | 2018-05-05 09:51:09 | [diff] [blame] | 294 | } |
| 295 | |
Benedikt Meurer | 9812888 | 2023-12-03 13:59:49 | [diff] [blame] | 296 | if (target.textEditor.state.selection.main.empty) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 297 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 298 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 299 | |
| 300 | contextMenu.debugSection().appendAction('sources.add-to-watch'); |
| 301 | } |
Benedikt Meurer | 9812888 | 2023-12-03 13:59:49 | [diff] [blame] | 302 | |
Randolf Jung | ffd1424 | 2023-04-19 00:32:25 | [diff] [blame] | 303 | override wasShown(): void { |
Kriti Sapra | ae8f17e | 2021-08-18 10:28:02 | [diff] [blame] | 304 | super.wasShown(); |
| 305 | this.treeOutline.registerCSSFiles([watchExpressionsSidebarPaneStyles]); |
| 306 | this.registerCSSFiles([watchExpressionsSidebarPaneStyles, objectValueStyles]); |
| 307 | } |
Tim van der Lippe | 8987f8f | 2020-01-03 15:03:16 | [diff] [blame] | 308 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 309 | |
Benedikt Meurer | e02230c | 2021-09-09 13:57:22 | [diff] [blame] | 310 | export class WatchExpression extends Common.ObjectWrapper.ObjectWrapper<EventTypes> { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 311 | private treeElementInternal!: UI.TreeOutline.TreeElement; |
| 312 | private nameElement!: Element; |
| 313 | private valueElement!: Element; |
| 314 | private expressionInternal: string|null; |
| 315 | private readonly expandController: ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeExpandController; |
| 316 | private element: HTMLDivElement; |
| 317 | private editing: boolean; |
| 318 | private linkifier: Components.Linkifier.Linkifier; |
| 319 | private textPrompt?: ObjectUI.ObjectPropertiesSection.ObjectPropertyPrompt; |
| 320 | private result?: SDK.RemoteObject.RemoteObject|null; |
| 321 | private preventClickTimeout?: number; |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 322 | constructor( |
| 323 | expression: string|null, |
| 324 | expandController: ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeExpandController, |
| 325 | linkifier: Components.Linkifier.Linkifier) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 326 | super(); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 327 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 328 | this.expressionInternal = expression; |
| 329 | this.expandController = expandController; |
| 330 | this.element = document.createElement('div'); |
| 331 | this.element.classList.add('watch-expression'); |
| 332 | this.element.classList.add('monospace'); |
| 333 | this.editing = false; |
| 334 | this.linkifier = linkifier; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 335 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 336 | this.createWatchExpression(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 337 | this.update(); |
| 338 | } |
| 339 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 340 | treeElement(): UI.TreeOutline.TreeElement { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 341 | return this.treeElementInternal; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 342 | } |
| 343 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 344 | expression(): string|null { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 345 | return this.expressionInternal; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 346 | } |
| 347 | |
Jaroslav Sevcik | 9b05a52 | 2022-11-30 15:43:21 | [diff] [blame] | 348 | async #evaluateExpression(executionContext: SDK.RuntimeModel.ExecutionContext, expression: string): |
| 349 | Promise<SDK.RuntimeModel.EvaluationResult> { |
Simon Zünd | e77e31ee | 2024-04-29 10:04:04 | [diff] [blame] | 350 | const callFrame = executionContext.debuggerModel.selectedCallFrame(); |
tombl | e650087 | 2024-05-29 09:15:29 | [diff] [blame] | 351 | if (callFrame && callFrame.script.isJavaScript()) { |
Simon Zünd | e77e31ee | 2024-04-29 10:04:04 | [diff] [blame] | 352 | const nameMap = await SourceMapScopes.NamesResolver.allVariablesInCallFrame(callFrame); |
| 353 | try { |
| 354 | expression = |
| 355 | await Formatter.FormatterWorkerPool.formatterWorkerPool().javaScriptSubstitute(expression, nameMap); |
| 356 | } catch { |
Jaroslav Sevcik | 9b05a52 | 2022-11-30 15:43:21 | [diff] [blame] | 357 | } |
| 358 | } |
| 359 | |
| 360 | return executionContext.evaluate( |
| 361 | { |
| 362 | expression, |
| 363 | objectGroup: WatchExpression.watchObjectGroupId, |
| 364 | includeCommandLineAPI: false, |
| 365 | silent: true, |
| 366 | returnByValue: false, |
| 367 | generatePreview: false, |
Jaroslav Sevcik | 9b05a52 | 2022-11-30 15:43:21 | [diff] [blame] | 368 | }, |
| 369 | /* userGesture */ false, |
| 370 | /* awaitPromise */ false); |
| 371 | } |
| 372 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 373 | update(): void { |
Tim van der Lippe | d1a00aa | 2020-08-19 16:03:56 | [diff] [blame] | 374 | const currentExecutionContext = UI.Context.Context.instance().flavor(SDK.RuntimeModel.ExecutionContext); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 375 | if (currentExecutionContext && this.expressionInternal) { |
Jaroslav Sevcik | 9b05a52 | 2022-11-30 15:43:21 | [diff] [blame] | 376 | void this.#evaluateExpression(currentExecutionContext, this.expressionInternal).then(result => { |
| 377 | if ('object' in result) { |
| 378 | this.createWatchExpression(result.object, result.exceptionDetails); |
| 379 | } else { |
| 380 | this.createWatchExpression(); |
| 381 | } |
| 382 | }); |
Sigurd Schneider | 53dc648 | 2021-06-30 11:22:02 | [diff] [blame] | 383 | } else { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 384 | this.createWatchExpression(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 388 | startEditing(): void { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 389 | this.editing = true; |
| 390 | this.treeElementInternal.setDisableSelectFocus(true); |
| 391 | this.element.removeChildren(); |
| 392 | const newDiv = this.element.createChild('div'); |
| 393 | newDiv.textContent = this.nameElement.textContent; |
| 394 | this.textPrompt = new ObjectUI.ObjectPropertiesSection.ObjectPropertyPrompt(); |
| 395 | this.textPrompt.renderAsBlock(); |
| 396 | const proxyElement = (this.textPrompt.attachAndStartEditing(newDiv, this.finishEditing.bind(this)) as HTMLElement); |
| 397 | this.treeElementInternal.listItemElement.classList.add('watch-expression-editing'); |
| 398 | this.treeElementInternal.collapse(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 399 | proxyElement.classList.add('watch-expression-text-prompt-proxy'); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 400 | proxyElement.addEventListener('keydown', this.promptKeyDown.bind(this), false); |
| 401 | const selection = this.element.getComponentSelection(); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 402 | if (selection) { |
| 403 | selection.selectAllChildren(newDiv); |
| 404 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 405 | } |
| 406 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 407 | isEditing(): boolean { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 408 | return Boolean(this.editing); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 409 | } |
| 410 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 411 | private finishEditing(event: Event, canceled?: boolean): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 412 | if (event) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 413 | event.consume(canceled); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 414 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 415 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 416 | this.editing = false; |
| 417 | this.treeElementInternal.setDisableSelectFocus(false); |
| 418 | this.treeElementInternal.listItemElement.classList.remove('watch-expression-editing'); |
| 419 | if (this.textPrompt) { |
| 420 | this.textPrompt.detach(); |
| 421 | const newExpression = canceled ? this.expressionInternal : this.textPrompt.text(); |
| 422 | this.textPrompt = undefined; |
| 423 | this.element.removeChildren(); |
| 424 | this.updateExpression(newExpression); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 425 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 426 | } |
| 427 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 428 | private dblClickOnWatchExpression(event: Event): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 429 | event.consume(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 430 | if (!this.isEditing()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 431 | this.startEditing(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 432 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 433 | } |
| 434 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 435 | private updateExpression(newExpression: string|null): void { |
| 436 | if (this.expressionInternal) { |
| 437 | this.expandController.stopWatchSectionsWithId(this.expressionInternal); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 438 | } |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 439 | this.expressionInternal = newExpression; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 440 | this.update(); |
Benedikt Meurer | e02230c | 2021-09-09 13:57:22 | [diff] [blame] | 441 | this.dispatchEventToListeners(Events.ExpressionUpdated, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 442 | } |
| 443 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 444 | private deleteWatchExpression(event: Event): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 445 | event.consume(true); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 446 | this.updateExpression(null); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 447 | } |
| 448 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 449 | private createWatchExpression( |
| 450 | result?: SDK.RemoteObject.RemoteObject, exceptionDetails?: Protocol.Runtime.ExceptionDetails): void { |
| 451 | this.result = result || null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 452 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 453 | this.element.removeChildren(); |
| 454 | const oldTreeElement = this.treeElementInternal; |
| 455 | this.createWatchExpressionTreeElement(result, exceptionDetails); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 456 | if (oldTreeElement && oldTreeElement.parent) { |
| 457 | const root = oldTreeElement.parent; |
| 458 | const index = root.indexOfChild(oldTreeElement); |
| 459 | root.removeChild(oldTreeElement); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 460 | root.insertChild(this.treeElementInternal, index); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 461 | } |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 462 | this.treeElementInternal.select(); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 463 | } |
| 464 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 465 | private createWatchExpressionHeader( |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 466 | expressionValue?: SDK.RemoteObject.RemoteObject, exceptionDetails?: Protocol.Runtime.ExceptionDetails): Element { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 467 | const headerElement = this.element.createChild('div', 'watch-expression-header'); |
Benedikt Meurer | d8a9565 | 2024-01-04 08:29:17 | [diff] [blame] | 468 | const deleteButton = new Buttons.Button.Button(); |
Kateryna Prokopenko | 0895c17 | 2024-04-17 09:49:13 | [diff] [blame] | 469 | deleteButton.variant = Buttons.Button.Variant.ICON; |
Benedikt Meurer | d8a9565 | 2024-01-04 08:29:17 | [diff] [blame] | 470 | deleteButton.iconName = 'bin'; |
| 471 | deleteButton.className = 'watch-expression-delete-button'; |
| 472 | deleteButton.jslogContext = 'delete-watch-expression'; |
| 473 | deleteButton.size = Buttons.Button.Size.SMALL; |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 474 | UI.Tooltip.Tooltip.install(deleteButton, i18nString(UIStrings.deleteWatchExpression)); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 475 | deleteButton.addEventListener('click', this.deleteWatchExpression.bind(this), false); |
Jayson Chen | 377e475 | 2024-04-17 19:56:43 | [diff] [blame] | 476 | deleteButton.addEventListener('keydown', event => { |
| 477 | if (event.key === 'Enter') { |
| 478 | this.deleteWatchExpression(event); |
| 479 | } |
| 480 | }); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 481 | |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 482 | const titleElement = headerElement.createChild('div', 'watch-expression-title tree-element-title'); |
Jack Lynch | e1767de | 2020-04-22 02:43:55 | [diff] [blame] | 483 | titleElement.appendChild(deleteButton); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 484 | this.nameElement = |
| 485 | ObjectUI.ObjectPropertiesSection.ObjectPropertiesSection.createNameElement(this.expressionInternal); |
Benedikt Meurer | 1732430 | 2023-12-20 13:00:13 | [diff] [blame] | 486 | UI.Tooltip.Tooltip.install(this.nameElement as HTMLElement, this.expressionInternal); |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 487 | if (Boolean(exceptionDetails) || !expressionValue) { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 488 | this.valueElement = document.createElement('span'); |
| 489 | this.valueElement.classList.add('watch-expression-error'); |
| 490 | this.valueElement.classList.add('value'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 491 | titleElement.classList.add('dimmed'); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 492 | this.valueElement.textContent = i18nString(UIStrings.notAvailable); |
Philip Pfaffe | 7426b00 | 2020-11-30 15:59:22 | [diff] [blame] | 493 | if (exceptionDetails !== undefined && exceptionDetails.exception !== undefined && |
| 494 | exceptionDetails.exception.description !== undefined) { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 495 | UI.Tooltip.Tooltip.install(this.valueElement as HTMLElement, exceptionDetails.exception.description); |
Philip Pfaffe | 7426b00 | 2020-11-30 15:59:22 | [diff] [blame] | 496 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 497 | } else { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 498 | const propertyValue = |
| 499 | ObjectUI.ObjectPropertiesSection.ObjectPropertiesSection.createPropertyValueWithCustomSupport( |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 500 | expressionValue, Boolean(exceptionDetails), false /* showPreview */, titleElement, this.linkifier); |
| 501 | this.valueElement = propertyValue.element; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 502 | } |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 503 | const separatorElement = document.createElement('span'); |
| 504 | separatorElement.classList.add('watch-expressions-separator'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 505 | separatorElement.textContent = ': '; |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 506 | titleElement.append(this.nameElement, separatorElement, this.valueElement); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 507 | |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 508 | return headerElement; |
| 509 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 510 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 511 | private createWatchExpressionTreeElement( |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 512 | expressionValue?: SDK.RemoteObject.RemoteObject, exceptionDetails?: Protocol.Runtime.ExceptionDetails): void { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 513 | const headerElement = this.createWatchExpressionHeader(expressionValue, exceptionDetails); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 514 | |
| 515 | if (!exceptionDetails && expressionValue && expressionValue.hasChildren && !expressionValue.customPreview()) { |
| 516 | headerElement.classList.add('watch-expression-object-header'); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 517 | this.treeElementInternal = new ObjectUI.ObjectPropertiesSection.RootElement(expressionValue, this.linkifier); |
| 518 | this.expandController.watchSection( |
| 519 | (this.expressionInternal as string), |
| 520 | (this.treeElementInternal as ObjectUI.ObjectPropertiesSection.RootElement)); |
| 521 | this.treeElementInternal.toggleOnClick = false; |
| 522 | this.treeElementInternal.listItemElement.addEventListener('click', this.onSectionClick.bind(this), false); |
| 523 | this.treeElementInternal.listItemElement.addEventListener('dblclick', this.dblClickOnWatchExpression.bind(this)); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 524 | } else { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 525 | headerElement.addEventListener('dblclick', this.dblClickOnWatchExpression.bind(this)); |
| 526 | this.treeElementInternal = new UI.TreeOutline.TreeElement(); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 527 | } |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 528 | this.treeElementInternal.title = this.element; |
| 529 | this.treeElementInternal.listItemElement.classList.add('watch-expression-tree-item'); |
| 530 | this.treeElementInternal.listItemElement.addEventListener('keydown', event => { |
Tim van der Lippe | bcd6b5c | 2021-01-13 12:31:51 | [diff] [blame] | 531 | if (event.key === 'Enter' && !this.isEditing()) { |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 532 | this.startEditing(); |
| 533 | event.consume(true); |
Jaroslav Sevcik | 9b05a52 | 2022-11-30 15:43:21 | [diff] [blame] | 534 | } else if (event.key === 'Delete' && !this.isEditing()) { |
| 535 | this.deleteWatchExpression(event); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 536 | } |
| 537 | }); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 538 | } |
| 539 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 540 | private onSectionClick(event: Event): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 541 | event.consume(true); |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 542 | const mouseEvent = (event as MouseEvent); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 543 | if (mouseEvent.detail === 1) { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 544 | this.preventClickTimeout = window.setTimeout(handleClick.bind(this), 333); |
| 545 | } else if (this.preventClickTimeout !== undefined) { |
| 546 | window.clearTimeout(this.preventClickTimeout); |
| 547 | this.preventClickTimeout = undefined; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 548 | } |
| 549 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 550 | function handleClick(this: WatchExpression): void { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 551 | if (!this.treeElementInternal) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 552 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 553 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 554 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 555 | if (this.treeElementInternal.expanded) { |
| 556 | this.treeElementInternal.collapse(); |
| 557 | } else if (!this.editing) { |
| 558 | this.treeElementInternal.expand(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 559 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 563 | private promptKeyDown(event: KeyboardEvent): void { |
Jack Franklin | e24bc6f | 2022-10-07 10:36:18 | [diff] [blame] | 564 | const isEscapeKey = Platform.KeyboardUtilities.isEscKey(event); |
| 565 | if (event.key === 'Enter' || isEscapeKey) { |
| 566 | this.finishEditing(event, isEscapeKey); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 567 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 568 | } |
| 569 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 570 | populateContextMenu(contextMenu: UI.ContextMenu.ContextMenu, event: Event): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 571 | if (!this.isEditing()) { |
| 572 | contextMenu.editSection().appendItem( |
Simon Zünd | 0009385 | 2023-11-28 08:29:18 | [diff] [blame] | 573 | i18nString(UIStrings.deleteWatchExpression), this.updateExpression.bind(this, null), |
| 574 | {jslogContext: 'delete-watch-expression'}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 575 | } |
| 576 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 577 | if (!this.isEditing() && this.result && (this.result.type === 'number' || this.result.type === 'string')) { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 578 | contextMenu.clipboardSection().appendItem( |
Simon Zünd | 0009385 | 2023-11-28 08:29:18 | [diff] [blame] | 579 | i18nString(UIStrings.copyValue), this.copyValueButtonClicked.bind(this), |
| 580 | {jslogContext: 'copy-watch-expression-value'}); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 581 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 582 | |
Sigurd Schneider | 090c3b6 | 2020-11-10 10:26:49 | [diff] [blame] | 583 | const target = UI.UIUtils.deepElementFromEvent(event); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 584 | if (target && this.valueElement.isSelfOrAncestor(target) && this.result) { |
| 585 | contextMenu.appendApplicableItems(this.result); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 586 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 587 | } |
| 588 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 589 | private copyValueButtonClicked(): void { |
| 590 | Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(this.valueElement.textContent); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 591 | } |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 592 | |
Sigurd Schneider | 8641b42 | 2021-07-16 06:13:35 | [diff] [blame] | 593 | private static readonly watchObjectGroupId = 'watch-group'; |
Tim van der Lippe | 8987f8f | 2020-01-03 15:03:16 | [diff] [blame] | 594 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 595 | |
Benedikt Meurer | e02230c | 2021-09-09 13:57:22 | [diff] [blame] | 596 | const enum Events { |
| 597 | ExpressionUpdated = 'ExpressionUpdated', |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 598 | } |
Benedikt Meurer | e02230c | 2021-09-09 13:57:22 | [diff] [blame] | 599 | |
| 600 | type EventTypes = { |
| 601 | [Events.ExpressionUpdated]: WatchExpression, |
| 602 | }; |