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'; |
Jaroslav Sevcik | 9b05a52 | 2022-11-30 15:43:21 | [diff] [blame] | 39 | import * as Root from '../../core/root/root.js'; |
Tim van der Lippe | 021c757 | 2021-04-19 10:49:43 | [diff] [blame] | 40 | import * as SDK from '../../core/sdk/sdk.js'; |
Simon Zünd | 5e6e1f8 | 2023-11-23 10:55:31 | [diff] [blame^] | 41 | import type * as Protocol from '../../generated/protocol.js'; |
Jaroslav Sevcik | 9b05a52 | 2022-11-30 15:43:21 | [diff] [blame] | 42 | import * as Formatter from '../../models/formatter/formatter.js'; |
| 43 | import * as SourceMapScopes from '../../models/source_map_scopes/source_map_scopes.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 |
| 93 | UI.ActionRegistration.ActionDelegate, UI.Toolbar.ItemsProvider, UI.ContextMenu.Provider { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 94 | private watchExpressions: WatchExpression[]; |
| 95 | private emptyElement!: HTMLElement; |
| 96 | private readonly watchExpressionsSetting: Common.Settings.Setting<string[]>; |
| 97 | private readonly addButton: UI.Toolbar.ToolbarButton; |
| 98 | private readonly refreshButton: UI.Toolbar.ToolbarButton; |
| 99 | private readonly treeOutline: ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeOutline; |
| 100 | private readonly expandController: ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeExpandController; |
| 101 | private readonly linkifier: Components.Linkifier.Linkifier; |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 102 | private constructor() { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 103 | super(true); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 104 | |
Simon Zünd | 0243c60 | 2020-03-10 06:51:42 | [diff] [blame] | 105 | // TODO(szuend): Replace with a Set once the web test |
Tim van der Lippe | 021c757 | 2021-04-19 10:49:43 | [diff] [blame] | 106 | // panels/sources/debugger-ui/watch-expressions-preserve-expansion.js is either converted |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 107 | // to an e2e test or no longer accesses this variable directly. |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 108 | this.watchExpressions = []; |
| 109 | this.watchExpressionsSetting = |
Sigurd Schneider | 8641b42 | 2021-07-16 06:13:35 | [diff] [blame] | 110 | Common.Settings.Settings.instance().createLocalSetting<string[]>('watchExpressions', []); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 111 | |
Benedikt Meurer | 7d5cc37 | 2023-04-12 12:20:41 | [diff] [blame] | 112 | this.addButton = new UI.Toolbar.ToolbarButton(i18nString(UIStrings.addWatchExpression), 'plus'); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 113 | this.addButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, _event => { |
Tim van der Lippe | 2d9a95c | 2022-01-04 15:18:03 | [diff] [blame] | 114 | void this.addButtonClicked(); |
Tim van der Lippe | 37a35ff | 2020-03-03 13:49:02 | [diff] [blame] | 115 | }); |
Benedikt Meurer | 3247623 | 2023-04-11 13:19:58 | [diff] [blame] | 116 | this.refreshButton = new UI.Toolbar.ToolbarButton(i18nString(UIStrings.refreshWatchExpressions), 'refresh'); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 117 | this.refreshButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, this.update, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 118 | |
| 119 | this.contentElement.classList.add('watch-expressions'); |
Simon Zünd | 5e6e1f8 | 2023-11-23 10:55:31 | [diff] [blame^] | 120 | this.contentElement.setAttribute('jslog', `${VisualLogging.pane().context('debugger-watch')}`); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 121 | this.contentElement.addEventListener('contextmenu', this.contextMenu.bind(this), false); |
| 122 | this.treeOutline = new ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeOutline(); |
Kriti Sapra | ae8f17e | 2021-08-18 10:28:02 | [diff] [blame] | 123 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 124 | this.treeOutline.setShowSelectionOnKeyboardFocus(/* show */ true); |
| 125 | this.expandController = |
| 126 | new ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeExpandController(this.treeOutline); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 127 | |
Tim van der Lippe | d1a00aa | 2020-08-19 16:03:56 | [diff] [blame] | 128 | UI.Context.Context.instance().addFlavorChangeListener(SDK.RuntimeModel.ExecutionContext, this.update, this); |
| 129 | UI.Context.Context.instance().addFlavorChangeListener(SDK.DebuggerModel.CallFrame, this.update, this); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 130 | this.linkifier = new Components.Linkifier.Linkifier(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 131 | this.update(); |
| 132 | } |
| 133 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 134 | static instance(): WatchExpressionsSidebarPane { |
Andres Olivares | fd431fb | 2020-12-10 15:30:04 | [diff] [blame] | 135 | if (!watchExpressionsSidebarPaneInstance) { |
| 136 | watchExpressionsSidebarPaneInstance = new WatchExpressionsSidebarPane(); |
| 137 | } |
| 138 | return watchExpressionsSidebarPaneInstance; |
| 139 | } |
| 140 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 141 | toolbarItems(): UI.Toolbar.ToolbarItem[] { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 142 | return [this.addButton, this.refreshButton]; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 143 | } |
| 144 | |
Randolf Jung | ffd1424 | 2023-04-19 00:32:25 | [diff] [blame] | 145 | override focus(): void { |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 146 | if (this.hasFocus()) { |
| 147 | return; |
| 148 | } |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 149 | if (this.watchExpressions.length > 0) { |
| 150 | this.treeOutline.forceSelect(); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 154 | hasExpressions(): boolean { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 155 | return Boolean(this.watchExpressionsSetting.get().length); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 156 | } |
| 157 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 158 | private saveExpressions(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 159 | const toSave = []; |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 160 | for (let i = 0; i < this.watchExpressions.length; i++) { |
| 161 | const expression = this.watchExpressions[i].expression(); |
Sigurd Schneider | 8641b42 | 2021-07-16 06:13:35 | [diff] [blame] | 162 | if (expression) { |
| 163 | toSave.push(expression); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 164 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 165 | } |
| 166 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 167 | this.watchExpressionsSetting.set(toSave); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 168 | } |
| 169 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 170 | private async addButtonClicked(): Promise<void> { |
Paul Lewis | 75c7d0d | 2020-03-19 12:17:26 | [diff] [blame] | 171 | await UI.ViewManager.ViewManager.instance().showView('sources.watch'); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 172 | this.emptyElement.classList.add('hidden'); |
| 173 | this.createWatchExpression(null).startEditing(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 174 | } |
| 175 | |
Randolf Jung | ffd1424 | 2023-04-19 00:32:25 | [diff] [blame] | 176 | override async doUpdate(): Promise<void> { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 177 | this.linkifier.reset(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 178 | this.contentElement.removeChildren(); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 179 | this.treeOutline.removeChildren(); |
| 180 | this.watchExpressions = []; |
| 181 | this.emptyElement = (this.contentElement.createChild('div', 'gray-info-message') as HTMLElement); |
| 182 | this.emptyElement.textContent = i18nString(UIStrings.noWatchExpressions); |
| 183 | this.emptyElement.tabIndex = -1; |
| 184 | const watchExpressionStrings = this.watchExpressionsSetting.get(); |
Jack Lynch | 338317a | 2020-08-19 21:59:49 | [diff] [blame] | 185 | if (watchExpressionStrings.length) { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 186 | this.emptyElement.classList.add('hidden'); |
Jack Lynch | 338317a | 2020-08-19 21:59:49 | [diff] [blame] | 187 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 188 | for (let i = 0; i < watchExpressionStrings.length; ++i) { |
| 189 | const expression = watchExpressionStrings[i]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 190 | if (!expression) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 191 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 192 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 193 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 194 | this.createWatchExpression(expression); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 195 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 196 | } |
| 197 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 198 | private createWatchExpression(expression: string|null): WatchExpression { |
| 199 | this.contentElement.appendChild(this.treeOutline.element); |
| 200 | const watchExpression = new WatchExpression(expression, this.expandController, this.linkifier); |
Benedikt Meurer | e02230c | 2021-09-09 13:57:22 | [diff] [blame] | 201 | watchExpression.addEventListener(Events.ExpressionUpdated, this.watchExpressionUpdated, this); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 202 | this.treeOutline.appendChild(watchExpression.treeElement()); |
| 203 | this.watchExpressions.push(watchExpression); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 204 | return watchExpression; |
| 205 | } |
| 206 | |
Benedikt Meurer | e02230c | 2021-09-09 13:57:22 | [diff] [blame] | 207 | private watchExpressionUpdated({data: watchExpression}: Common.EventTarget.EventTargetEvent<WatchExpression>): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 208 | if (!watchExpression.expression()) { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 209 | Platform.ArrayUtilities.removeElement(this.watchExpressions, watchExpression); |
| 210 | this.treeOutline.removeChild(watchExpression.treeElement()); |
| 211 | this.emptyElement.classList.toggle('hidden', Boolean(this.watchExpressions.length)); |
| 212 | if (this.watchExpressions.length === 0) { |
| 213 | this.treeOutline.element.remove(); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 214 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 215 | } |
| 216 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 217 | this.saveExpressions(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 218 | } |
| 219 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 220 | private contextMenu(event: MouseEvent): void { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 221 | const contextMenu = new UI.ContextMenu.ContextMenu(event); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 222 | this.populateContextMenu(contextMenu, event); |
Tim van der Lippe | 2d9a95c | 2022-01-04 15:18:03 | [diff] [blame] | 223 | void contextMenu.show(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 224 | } |
| 225 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 226 | private populateContextMenu(contextMenu: UI.ContextMenu.ContextMenu, event: MouseEvent): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 227 | let isEditing = false; |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 228 | for (const watchExpression of this.watchExpressions) { |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 229 | isEditing = isEditing || watchExpression.isEditing(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 230 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 231 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 232 | if (!isEditing) { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 233 | contextMenu.debugSection().appendItem(i18nString(UIStrings.addWatchExpression), this.addButtonClicked.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 234 | } |
| 235 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 236 | if (this.watchExpressions.length > 1) { |
Changhao Han | 8eb616e | 2021-08-11 05:45:27 | [diff] [blame] | 237 | contextMenu.debugSection().appendItem( |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 238 | i18nString(UIStrings.deleteAllWatchExpressions), this.deleteAllButtonClicked.bind(this)); |
Changhao Han | 8eb616e | 2021-08-11 05:45:27 | [diff] [blame] | 239 | } |
| 240 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 241 | const treeElement = this.treeOutline.treeElementFromEvent(event); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 242 | if (!treeElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 243 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 244 | } |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 245 | const currentWatchExpression = |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 246 | this.watchExpressions.find(watchExpression => treeElement.hasAncestorOrSelf(watchExpression.treeElement())); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 247 | if (currentWatchExpression) { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 248 | currentWatchExpression.populateContextMenu(contextMenu, event); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 249 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 250 | } |
| 251 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 252 | private deleteAllButtonClicked(): void { |
| 253 | this.watchExpressions = []; |
| 254 | this.saveExpressions(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 255 | this.update(); |
| 256 | } |
| 257 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 258 | private async focusAndAddExpressionToWatch(expression: string): Promise<void> { |
Benedikt Meurer | 61f1eef | 2021-03-17 10:38:29 | [diff] [blame] | 259 | await UI.ViewManager.ViewManager.instance().showView('sources.watch'); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 260 | this.createWatchExpression(expression); |
| 261 | this.saveExpressions(); |
Jack Lynch | 338317a | 2020-08-19 21:59:49 | [diff] [blame] | 262 | this.update(); |
PhistucK | 065e136 | 2018-05-05 09:51:09 | [diff] [blame] | 263 | } |
| 264 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 265 | handleAction(_context: UI.Context.Context, _actionId: string): boolean { |
Tim van der Lippe | d1a00aa | 2020-08-19 16:03:56 | [diff] [blame] | 266 | const frame = UI.Context.Context.instance().flavor(UISourceCodeFrame); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 267 | if (!frame) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 268 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 269 | } |
Tim van der Lippe | c1ab112 | 2021-11-12 16:10:31 | [diff] [blame] | 270 | const {state} = frame.textEditor; |
| 271 | 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] | 272 | void this.focusAndAddExpressionToWatch(text); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 273 | return true; |
| 274 | } |
| 275 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 276 | appendApplicableItems(event: Event, contextMenu: UI.ContextMenu.ContextMenu, target: Object): void { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 277 | if (target instanceof ObjectUI.ObjectPropertiesSection.ObjectPropertyTreeElement && !target.property.synthetic) { |
PhistucK | 065e136 | 2018-05-05 09:51:09 | [diff] [blame] | 278 | contextMenu.debugSection().appendItem( |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 279 | i18nString(UIStrings.addPropertyPathToWatch), () => this.focusAndAddExpressionToWatch(target.path())); |
PhistucK | 065e136 | 2018-05-05 09:51:09 | [diff] [blame] | 280 | } |
| 281 | |
Tim van der Lippe | d1a00aa | 2020-08-19 16:03:56 | [diff] [blame] | 282 | const frame = UI.Context.Context.instance().flavor(UISourceCodeFrame); |
Tim van der Lippe | c1ab112 | 2021-11-12 16:10:31 | [diff] [blame] | 283 | if (!frame || frame.textEditor.state.selection.main.empty) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 284 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 285 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 286 | |
| 287 | contextMenu.debugSection().appendAction('sources.add-to-watch'); |
| 288 | } |
Randolf Jung | ffd1424 | 2023-04-19 00:32:25 | [diff] [blame] | 289 | override wasShown(): void { |
Kriti Sapra | ae8f17e | 2021-08-18 10:28:02 | [diff] [blame] | 290 | super.wasShown(); |
| 291 | this.treeOutline.registerCSSFiles([watchExpressionsSidebarPaneStyles]); |
| 292 | this.registerCSSFiles([watchExpressionsSidebarPaneStyles, objectValueStyles]); |
| 293 | } |
Tim van der Lippe | 8987f8f | 2020-01-03 15:03:16 | [diff] [blame] | 294 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 295 | |
Benedikt Meurer | e02230c | 2021-09-09 13:57:22 | [diff] [blame] | 296 | export class WatchExpression extends Common.ObjectWrapper.ObjectWrapper<EventTypes> { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 297 | private treeElementInternal!: UI.TreeOutline.TreeElement; |
| 298 | private nameElement!: Element; |
| 299 | private valueElement!: Element; |
| 300 | private expressionInternal: string|null; |
| 301 | private readonly expandController: ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeExpandController; |
| 302 | private element: HTMLDivElement; |
| 303 | private editing: boolean; |
| 304 | private linkifier: Components.Linkifier.Linkifier; |
| 305 | private textPrompt?: ObjectUI.ObjectPropertiesSection.ObjectPropertyPrompt; |
| 306 | private result?: SDK.RemoteObject.RemoteObject|null; |
| 307 | private preventClickTimeout?: number; |
Kateryna Prokopenko | 52a9b59 | 2021-10-20 15:06:01 | [diff] [blame] | 308 | private resizeObserver?: ResizeObserver; |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 309 | constructor( |
| 310 | expression: string|null, |
| 311 | expandController: ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeExpandController, |
| 312 | linkifier: Components.Linkifier.Linkifier) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 313 | super(); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 314 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 315 | this.expressionInternal = expression; |
| 316 | this.expandController = expandController; |
| 317 | this.element = document.createElement('div'); |
| 318 | this.element.classList.add('watch-expression'); |
| 319 | this.element.classList.add('monospace'); |
| 320 | this.editing = false; |
| 321 | this.linkifier = linkifier; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 322 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 323 | this.createWatchExpression(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 324 | this.update(); |
| 325 | } |
| 326 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 327 | treeElement(): UI.TreeOutline.TreeElement { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 328 | return this.treeElementInternal; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 329 | } |
| 330 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 331 | expression(): string|null { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 332 | return this.expressionInternal; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 333 | } |
| 334 | |
Jaroslav Sevcik | 9b05a52 | 2022-11-30 15:43:21 | [diff] [blame] | 335 | async #evaluateExpression(executionContext: SDK.RuntimeModel.ExecutionContext, expression: string): |
| 336 | Promise<SDK.RuntimeModel.EvaluationResult> { |
| 337 | if (Root.Runtime.experiments.isEnabled('evaluateExpressionsWithSourceMaps')) { |
| 338 | const callFrame = executionContext.debuggerModel.selectedCallFrame(); |
| 339 | if (callFrame) { |
| 340 | const nameMap = await SourceMapScopes.NamesResolver.allVariablesInCallFrame(callFrame); |
| 341 | try { |
| 342 | expression = |
| 343 | await Formatter.FormatterWorkerPool.formatterWorkerPool().javaScriptSubstitute(expression, nameMap); |
| 344 | } catch { |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | return executionContext.evaluate( |
| 350 | { |
| 351 | expression, |
| 352 | objectGroup: WatchExpression.watchObjectGroupId, |
| 353 | includeCommandLineAPI: false, |
| 354 | silent: true, |
| 355 | returnByValue: false, |
| 356 | generatePreview: false, |
Jaroslav Sevcik | 9b05a52 | 2022-11-30 15:43:21 | [diff] [blame] | 357 | }, |
| 358 | /* userGesture */ false, |
| 359 | /* awaitPromise */ false); |
| 360 | } |
| 361 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 362 | update(): void { |
Tim van der Lippe | d1a00aa | 2020-08-19 16:03:56 | [diff] [blame] | 363 | const currentExecutionContext = UI.Context.Context.instance().flavor(SDK.RuntimeModel.ExecutionContext); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 364 | if (currentExecutionContext && this.expressionInternal) { |
Jaroslav Sevcik | 9b05a52 | 2022-11-30 15:43:21 | [diff] [blame] | 365 | void this.#evaluateExpression(currentExecutionContext, this.expressionInternal).then(result => { |
| 366 | if ('object' in result) { |
| 367 | this.createWatchExpression(result.object, result.exceptionDetails); |
| 368 | } else { |
| 369 | this.createWatchExpression(); |
| 370 | } |
| 371 | }); |
Sigurd Schneider | 53dc648 | 2021-06-30 11:22:02 | [diff] [blame] | 372 | } else { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 373 | this.createWatchExpression(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 377 | startEditing(): void { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 378 | this.editing = true; |
| 379 | this.treeElementInternal.setDisableSelectFocus(true); |
| 380 | this.element.removeChildren(); |
| 381 | const newDiv = this.element.createChild('div'); |
| 382 | newDiv.textContent = this.nameElement.textContent; |
| 383 | this.textPrompt = new ObjectUI.ObjectPropertiesSection.ObjectPropertyPrompt(); |
| 384 | this.textPrompt.renderAsBlock(); |
| 385 | const proxyElement = (this.textPrompt.attachAndStartEditing(newDiv, this.finishEditing.bind(this)) as HTMLElement); |
| 386 | this.treeElementInternal.listItemElement.classList.add('watch-expression-editing'); |
| 387 | this.treeElementInternal.collapse(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 388 | proxyElement.classList.add('watch-expression-text-prompt-proxy'); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 389 | proxyElement.addEventListener('keydown', this.promptKeyDown.bind(this), false); |
| 390 | const selection = this.element.getComponentSelection(); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 391 | if (selection) { |
| 392 | selection.selectAllChildren(newDiv); |
| 393 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 394 | } |
| 395 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 396 | isEditing(): boolean { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 397 | return Boolean(this.editing); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 398 | } |
| 399 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 400 | private finishEditing(event: Event, canceled?: boolean): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 401 | if (event) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 402 | event.consume(canceled); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 403 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 404 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 405 | this.editing = false; |
| 406 | this.treeElementInternal.setDisableSelectFocus(false); |
| 407 | this.treeElementInternal.listItemElement.classList.remove('watch-expression-editing'); |
| 408 | if (this.textPrompt) { |
| 409 | this.textPrompt.detach(); |
| 410 | const newExpression = canceled ? this.expressionInternal : this.textPrompt.text(); |
| 411 | this.textPrompt = undefined; |
| 412 | this.element.removeChildren(); |
| 413 | this.updateExpression(newExpression); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 414 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 415 | } |
| 416 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 417 | private dblClickOnWatchExpression(event: Event): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 418 | event.consume(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 419 | if (!this.isEditing()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 420 | this.startEditing(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 421 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 422 | } |
| 423 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 424 | private updateExpression(newExpression: string|null): void { |
| 425 | if (this.expressionInternal) { |
| 426 | this.expandController.stopWatchSectionsWithId(this.expressionInternal); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 427 | } |
Kateryna Prokopenko | 52a9b59 | 2021-10-20 15:06:01 | [diff] [blame] | 428 | this.resizeObserver?.disconnect(); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 429 | this.expressionInternal = newExpression; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 430 | this.update(); |
Benedikt Meurer | e02230c | 2021-09-09 13:57:22 | [diff] [blame] | 431 | this.dispatchEventToListeners(Events.ExpressionUpdated, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 432 | } |
| 433 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 434 | private deleteWatchExpression(event: Event): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 435 | event.consume(true); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 436 | this.updateExpression(null); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 437 | } |
| 438 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 439 | private createWatchExpression( |
| 440 | result?: SDK.RemoteObject.RemoteObject, exceptionDetails?: Protocol.Runtime.ExceptionDetails): void { |
| 441 | this.result = result || null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 442 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 443 | this.element.removeChildren(); |
| 444 | const oldTreeElement = this.treeElementInternal; |
| 445 | this.createWatchExpressionTreeElement(result, exceptionDetails); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 446 | if (oldTreeElement && oldTreeElement.parent) { |
| 447 | const root = oldTreeElement.parent; |
| 448 | const index = root.indexOfChild(oldTreeElement); |
| 449 | root.removeChild(oldTreeElement); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 450 | root.insertChild(this.treeElementInternal, index); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 451 | } |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 452 | this.treeElementInternal.select(); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 453 | } |
| 454 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 455 | private createWatchExpressionHeader( |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 456 | expressionValue?: SDK.RemoteObject.RemoteObject, exceptionDetails?: Protocol.Runtime.ExceptionDetails): Element { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 457 | const headerElement = this.element.createChild('div', 'watch-expression-header'); |
Benedikt Meurer | 6337cf1 | 2023-04-17 11:10:20 | [diff] [blame] | 458 | const deleteButton = UI.Icon.Icon.create('cross', 'watch-expression-delete-button'); |
Kateryna Prokopenko | 52a9b59 | 2021-10-20 15:06:01 | [diff] [blame] | 459 | this.resizeObserver = new ResizeObserver(entries => { |
| 460 | entries.forEach(entry => { |
| 461 | // 55 serves as a width threshold here (in px) |
| 462 | if (entry.contentRect.width < 55) { |
| 463 | deleteButton.classList.remove('right-aligned'); |
| 464 | deleteButton.classList.add('left-aligned'); |
| 465 | } else { |
| 466 | deleteButton.classList.remove('left-aligned'); |
| 467 | deleteButton.classList.add('right-aligned'); |
| 468 | } |
| 469 | }); |
| 470 | }); |
| 471 | this.resizeObserver.observe(headerElement); |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 472 | UI.Tooltip.Tooltip.install(deleteButton, i18nString(UIStrings.deleteWatchExpression)); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 473 | deleteButton.addEventListener('click', this.deleteWatchExpression.bind(this), false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 474 | |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 475 | const titleElement = headerElement.createChild('div', 'watch-expression-title tree-element-title'); |
Jack Lynch | e1767de | 2020-04-22 02:43:55 | [diff] [blame] | 476 | titleElement.appendChild(deleteButton); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 477 | this.nameElement = |
| 478 | ObjectUI.ObjectPropertiesSection.ObjectPropertiesSection.createNameElement(this.expressionInternal); |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 479 | if (Boolean(exceptionDetails) || !expressionValue) { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 480 | this.valueElement = document.createElement('span'); |
| 481 | this.valueElement.classList.add('watch-expression-error'); |
| 482 | this.valueElement.classList.add('value'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 483 | titleElement.classList.add('dimmed'); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 484 | this.valueElement.textContent = i18nString(UIStrings.notAvailable); |
Philip Pfaffe | 7426b00 | 2020-11-30 15:59:22 | [diff] [blame] | 485 | if (exceptionDetails !== undefined && exceptionDetails.exception !== undefined && |
| 486 | exceptionDetails.exception.description !== undefined) { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 487 | UI.Tooltip.Tooltip.install(this.valueElement as HTMLElement, exceptionDetails.exception.description); |
Philip Pfaffe | 7426b00 | 2020-11-30 15:59:22 | [diff] [blame] | 488 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 489 | } else { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 490 | const propertyValue = |
| 491 | ObjectUI.ObjectPropertiesSection.ObjectPropertiesSection.createPropertyValueWithCustomSupport( |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 492 | expressionValue, Boolean(exceptionDetails), false /* showPreview */, titleElement, this.linkifier); |
| 493 | this.valueElement = propertyValue.element; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 494 | } |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 495 | const separatorElement = document.createElement('span'); |
| 496 | separatorElement.classList.add('watch-expressions-separator'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 497 | separatorElement.textContent = ': '; |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 498 | titleElement.append(this.nameElement, separatorElement, this.valueElement); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 499 | |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 500 | return headerElement; |
| 501 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 502 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 503 | private createWatchExpressionTreeElement( |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 504 | expressionValue?: SDK.RemoteObject.RemoteObject, exceptionDetails?: Protocol.Runtime.ExceptionDetails): void { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 505 | const headerElement = this.createWatchExpressionHeader(expressionValue, exceptionDetails); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 506 | |
| 507 | if (!exceptionDetails && expressionValue && expressionValue.hasChildren && !expressionValue.customPreview()) { |
| 508 | headerElement.classList.add('watch-expression-object-header'); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 509 | this.treeElementInternal = new ObjectUI.ObjectPropertiesSection.RootElement(expressionValue, this.linkifier); |
| 510 | this.expandController.watchSection( |
| 511 | (this.expressionInternal as string), |
| 512 | (this.treeElementInternal as ObjectUI.ObjectPropertiesSection.RootElement)); |
| 513 | this.treeElementInternal.toggleOnClick = false; |
| 514 | this.treeElementInternal.listItemElement.addEventListener('click', this.onSectionClick.bind(this), false); |
| 515 | this.treeElementInternal.listItemElement.addEventListener('dblclick', this.dblClickOnWatchExpression.bind(this)); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 516 | } else { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 517 | headerElement.addEventListener('dblclick', this.dblClickOnWatchExpression.bind(this)); |
| 518 | this.treeElementInternal = new UI.TreeOutline.TreeElement(); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 519 | } |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 520 | this.treeElementInternal.title = this.element; |
| 521 | this.treeElementInternal.listItemElement.classList.add('watch-expression-tree-item'); |
| 522 | this.treeElementInternal.listItemElement.addEventListener('keydown', event => { |
Tim van der Lippe | bcd6b5c | 2021-01-13 12:31:51 | [diff] [blame] | 523 | if (event.key === 'Enter' && !this.isEditing()) { |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 524 | this.startEditing(); |
| 525 | event.consume(true); |
Jaroslav Sevcik | 9b05a52 | 2022-11-30 15:43:21 | [diff] [blame] | 526 | } else if (event.key === 'Delete' && !this.isEditing()) { |
| 527 | this.deleteWatchExpression(event); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 528 | } |
| 529 | }); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 530 | } |
| 531 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 532 | private onSectionClick(event: Event): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 533 | event.consume(true); |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 534 | const mouseEvent = (event as MouseEvent); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 535 | if (mouseEvent.detail === 1) { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 536 | this.preventClickTimeout = window.setTimeout(handleClick.bind(this), 333); |
| 537 | } else if (this.preventClickTimeout !== undefined) { |
| 538 | window.clearTimeout(this.preventClickTimeout); |
| 539 | this.preventClickTimeout = undefined; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 540 | } |
| 541 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 542 | function handleClick(this: WatchExpression): void { |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 543 | if (!this.treeElementInternal) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 544 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 545 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 546 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 547 | if (this.treeElementInternal.expanded) { |
| 548 | this.treeElementInternal.collapse(); |
| 549 | } else if (!this.editing) { |
| 550 | this.treeElementInternal.expand(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 551 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 555 | private promptKeyDown(event: KeyboardEvent): void { |
Jack Franklin | e24bc6f | 2022-10-07 10:36:18 | [diff] [blame] | 556 | const isEscapeKey = Platform.KeyboardUtilities.isEscKey(event); |
| 557 | if (event.key === 'Enter' || isEscapeKey) { |
| 558 | this.finishEditing(event, isEscapeKey); |
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 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 562 | populateContextMenu(contextMenu: UI.ContextMenu.ContextMenu, event: Event): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 563 | if (!this.isEditing()) { |
| 564 | contextMenu.editSection().appendItem( |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 565 | i18nString(UIStrings.deleteWatchExpression), this.updateExpression.bind(this, null)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 566 | } |
| 567 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 568 | 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] | 569 | contextMenu.clipboardSection().appendItem( |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 570 | i18nString(UIStrings.copyValue), this.copyValueButtonClicked.bind(this)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 571 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 572 | |
Sigurd Schneider | 090c3b6 | 2020-11-10 10:26:49 | [diff] [blame] | 573 | const target = UI.UIUtils.deepElementFromEvent(event); |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 574 | if (target && this.valueElement.isSelfOrAncestor(target) && this.result) { |
| 575 | contextMenu.appendApplicableItems(this.result); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 576 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 577 | } |
| 578 | |
Jan Scheffler | a222c63 | 2021-08-13 12:46:15 | [diff] [blame] | 579 | private copyValueButtonClicked(): void { |
| 580 | Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(this.valueElement.textContent); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 581 | } |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 582 | |
Sigurd Schneider | 8641b42 | 2021-07-16 06:13:35 | [diff] [blame] | 583 | private static readonly watchObjectGroupId = 'watch-group'; |
Tim van der Lippe | 8987f8f | 2020-01-03 15:03:16 | [diff] [blame] | 584 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 585 | |
Benedikt Meurer | e02230c | 2021-09-09 13:57:22 | [diff] [blame] | 586 | const enum Events { |
| 587 | ExpressionUpdated = 'ExpressionUpdated', |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 588 | } |
Benedikt Meurer | e02230c | 2021-09-09 13:57:22 | [diff] [blame] | 589 | |
| 590 | type EventTypes = { |
| 591 | [Events.ExpressionUpdated]: WatchExpression, |
| 592 | }; |