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 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 35 | /* eslint-disable rulesdir/no_underscored_properties */ |
| 36 | |
Tim van der Lippe | 021c757 | 2021-04-19 10:49:43 | [diff] [blame^] | 37 | import * as Components from '../../components/components.js'; |
| 38 | import * as Common from '../../core/common/common.js'; |
| 39 | import * as Host from '../../core/host/host.js'; |
| 40 | import * as i18n from '../../core/i18n/i18n.js'; |
| 41 | import * as Platform from '../../core/platform/platform.js'; |
| 42 | import * as SDK from '../../core/sdk/sdk.js'; |
| 43 | import * as ObjectUI from '../../ui/legacy/components/object_ui/object_ui.js'; |
| 44 | import * as UI from '../../ui/legacy/legacy.js'; |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 45 | |
Paul Lewis | 3994495 | 2020-01-22 15:45:18 | [diff] [blame] | 46 | import {UISourceCodeFrame} from './UISourceCodeFrame.js'; |
| 47 | |
Simon Zünd | 697fb0b | 2021-03-01 10:12:42 | [diff] [blame] | 48 | const UIStrings = { |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 49 | /** |
| 50 | *@description A context menu item in the Watch Expressions Sidebar Pane of the Sources panel |
| 51 | */ |
| 52 | addWatchExpression: 'Add watch expression', |
| 53 | /** |
| 54 | *@description Tooltip/screen reader label of a button in the Sources panel that refreshes all watch expressions. |
| 55 | */ |
| 56 | refreshWatchExpressions: 'Refresh watch expressions', |
| 57 | /** |
| 58 | *@description Empty element text content in Watch Expressions Sidebar Pane of the Sources panel |
| 59 | */ |
| 60 | noWatchExpressions: 'No watch expressions', |
| 61 | /** |
| 62 | *@description A context menu item in the Watch Expressions Sidebar Pane of the Sources panel |
| 63 | */ |
| 64 | deleteAllWatchExpressions: 'Delete all watch expressions', |
| 65 | /** |
| 66 | *@description A context menu item in the Watch Expressions Sidebar Pane of the Sources panel |
| 67 | */ |
| 68 | addPropertyPathToWatch: 'Add property path to watch', |
| 69 | /** |
| 70 | *@description A context menu item in the Watch Expressions Sidebar Pane of the Sources panel |
| 71 | */ |
| 72 | deleteWatchExpression: 'Delete watch expression', |
| 73 | /** |
| 74 | *@description Value element text content in Watch Expressions Sidebar Pane of the Sources panel |
| 75 | */ |
| 76 | notAvailable: '<not available>', |
| 77 | /** |
| 78 | *@description A context menu item in the Watch Expressions Sidebar Pane of the Sources panel and Network pane request. |
| 79 | */ |
| 80 | copyValue: 'Copy value', |
| 81 | }; |
Tim van der Lippe | 021c757 | 2021-04-19 10:49:43 | [diff] [blame^] | 82 | const str_ = i18n.i18n.registerUIStrings('panels/sources/WatchExpressionsSidebarPane.ts', UIStrings); |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 83 | const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_); |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 84 | let watchExpressionsSidebarPaneInstance: WatchExpressionsSidebarPane; |
Andres Olivares | fd431fb | 2020-12-10 15:30:04 | [diff] [blame] | 85 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 86 | export class WatchExpressionsSidebarPane extends UI.ThrottledWidget.ThrottledWidget implements |
| 87 | UI.ActionRegistration.ActionDelegate, UI.Toolbar.ItemsProvider, UI.ContextMenu.Provider { |
| 88 | _watchExpressions: WatchExpression[]; |
| 89 | _emptyElement!: HTMLElement; |
| 90 | // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration) |
| 91 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 92 | _watchExpressionsSetting: Common.Settings.Setting<any>; |
| 93 | _addButton: UI.Toolbar.ToolbarButton; |
| 94 | _refreshButton: UI.Toolbar.ToolbarButton; |
| 95 | _treeOutline: ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeOutline; |
| 96 | _expandController: ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeExpandController; |
| 97 | _linkifier: Components.Linkifier.Linkifier; |
| 98 | private constructor() { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 99 | super(true); |
Tim van der Lippe | 0dd7a05 | 2021-04-12 16:44:23 | [diff] [blame] | 100 | this.registerRequiredCSS('ui/legacy/components/object_ui/objectValue.css', {enableLegacyPatching: true}); |
Tim van der Lippe | 021c757 | 2021-04-19 10:49:43 | [diff] [blame^] | 101 | this.registerRequiredCSS('panels/sources/watchExpressionsSidebarPane.css', {enableLegacyPatching: true}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 102 | |
Simon Zünd | 0243c60 | 2020-03-10 06:51:42 | [diff] [blame] | 103 | // TODO(szuend): Replace with a Set once the web test |
Tim van der Lippe | 021c757 | 2021-04-19 10:49:43 | [diff] [blame^] | 104 | // panels/sources/debugger-ui/watch-expressions-preserve-expansion.js is either converted |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 105 | // to an e2e test or no longer accesses this variable directly. |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 106 | this._watchExpressions = []; |
Paul Lewis | 2d7d65c | 2020-03-16 17:26:30 | [diff] [blame] | 107 | this._watchExpressionsSetting = Common.Settings.Settings.instance().createLocalSetting('watchExpressions', []); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 108 | |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 109 | this._addButton = new UI.Toolbar.ToolbarButton(i18nString(UIStrings.addWatchExpression), 'largeicon-add'); |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 110 | this._addButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, _event => { |
Tim van der Lippe | 37a35ff | 2020-03-03 13:49:02 | [diff] [blame] | 111 | this._addButtonClicked(); |
| 112 | }); |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 113 | this._refreshButton = |
| 114 | new UI.Toolbar.ToolbarButton(i18nString(UIStrings.refreshWatchExpressions), 'largeicon-refresh'); |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 115 | this._refreshButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, this.update, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 116 | |
| 117 | this.contentElement.classList.add('watch-expressions'); |
| 118 | this.contentElement.addEventListener('contextmenu', this._contextMenu.bind(this), false); |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 119 | this._treeOutline = new ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeOutline(); |
Tim van der Lippe | 021c757 | 2021-04-19 10:49:43 | [diff] [blame^] | 120 | this._treeOutline.registerRequiredCSS( |
| 121 | 'panels/sources/watchExpressionsSidebarPane.css', {enableLegacyPatching: true}); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 122 | this._treeOutline.setShowSelectionOnKeyboardFocus(/* show */ true); |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 123 | this._expandController = |
| 124 | new ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeExpandController(this._treeOutline); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 125 | |
Tim van der Lippe | d1a00aa | 2020-08-19 16:03:56 | [diff] [blame] | 126 | UI.Context.Context.instance().addFlavorChangeListener(SDK.RuntimeModel.ExecutionContext, this.update, this); |
| 127 | UI.Context.Context.instance().addFlavorChangeListener(SDK.DebuggerModel.CallFrame, this.update, this); |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 128 | this._linkifier = new Components.Linkifier.Linkifier(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 129 | this.update(); |
| 130 | } |
| 131 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 132 | static instance(): WatchExpressionsSidebarPane { |
Andres Olivares | fd431fb | 2020-12-10 15:30:04 | [diff] [blame] | 133 | if (!watchExpressionsSidebarPaneInstance) { |
| 134 | watchExpressionsSidebarPaneInstance = new WatchExpressionsSidebarPane(); |
| 135 | } |
| 136 | return watchExpressionsSidebarPaneInstance; |
| 137 | } |
| 138 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 139 | toolbarItems(): UI.Toolbar.ToolbarItem[] { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 140 | return [this._addButton, this._refreshButton]; |
| 141 | } |
| 142 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 143 | focus(): void { |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 144 | if (this.hasFocus()) { |
| 145 | return; |
| 146 | } |
| 147 | if (this._watchExpressions.length > 0) { |
| 148 | this._treeOutline.forceSelect(); |
| 149 | } |
| 150 | } |
| 151 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 152 | hasExpressions(): boolean { |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 153 | return Boolean(this._watchExpressionsSetting.get().length); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 154 | } |
| 155 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 156 | _saveExpressions(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 157 | const toSave = []; |
| 158 | for (let i = 0; i < this._watchExpressions.length; i++) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 159 | if (this._watchExpressions[i].expression()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 160 | toSave.push(this._watchExpressions[i].expression()); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 161 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | this._watchExpressionsSetting.set(toSave); |
| 165 | } |
| 166 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 167 | async _addButtonClicked(): Promise<void> { |
Paul Lewis | 75c7d0d | 2020-03-19 12:17:26 | [diff] [blame] | 168 | await UI.ViewManager.ViewManager.instance().showView('sources.watch'); |
Jack Lynch | 1752e62 | 2020-08-25 23:50:56 | [diff] [blame] | 169 | this._emptyElement.classList.add('hidden'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 170 | this._createWatchExpression(null).startEditing(); |
| 171 | } |
| 172 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 173 | // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration) |
| 174 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 175 | doUpdate(): Promise<any> { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 176 | this._linkifier.reset(); |
| 177 | this.contentElement.removeChildren(); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 178 | this._treeOutline.removeChildren(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 179 | this._watchExpressions = []; |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 180 | this._emptyElement = (this.contentElement.createChild('div', 'gray-info-message') as HTMLElement); |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 181 | this._emptyElement.textContent = i18nString(UIStrings.noWatchExpressions); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 182 | this._emptyElement.tabIndex = -1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 183 | const watchExpressionStrings = this._watchExpressionsSetting.get(); |
Jack Lynch | 338317a | 2020-08-19 21:59:49 | [diff] [blame] | 184 | if (watchExpressionStrings.length) { |
| 185 | this._emptyElement.classList.add('hidden'); |
| 186 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 187 | for (let i = 0; i < watchExpressionStrings.length; ++i) { |
| 188 | const expression = watchExpressionStrings[i]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 189 | if (!expression) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 190 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 191 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 192 | |
| 193 | this._createWatchExpression(expression); |
| 194 | } |
| 195 | return Promise.resolve(); |
| 196 | } |
| 197 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 198 | _createWatchExpression(expression: string|null): WatchExpression { |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 199 | this.contentElement.appendChild(this._treeOutline.element); |
Tim van der Lippe | 8987f8f | 2020-01-03 15:03:16 | [diff] [blame] | 200 | const watchExpression = new WatchExpression(expression, this._expandController, this._linkifier); |
| 201 | watchExpression.addEventListener(WatchExpression.Events.ExpressionUpdated, this._watchExpressionUpdated, this); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 202 | this._treeOutline.appendChild(watchExpression.treeElement()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 203 | this._watchExpressions.push(watchExpression); |
| 204 | return watchExpression; |
| 205 | } |
| 206 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 207 | _watchExpressionUpdated(event: Common.EventTarget.EventTargetEvent): void { |
| 208 | const watchExpression = (event.data as WatchExpression); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 209 | if (!watchExpression.expression()) { |
Simon Zünd | 0243c60 | 2020-03-10 06:51:42 | [diff] [blame] | 210 | Platform.ArrayUtilities.removeElement(this._watchExpressions, watchExpression); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 211 | this._treeOutline.removeChild(watchExpression.treeElement()); |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 212 | this._emptyElement.classList.toggle('hidden', Boolean(this._watchExpressions.length)); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 213 | if (this._watchExpressions.length === 0) { |
| 214 | this._treeOutline.element.remove(); |
| 215 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | this._saveExpressions(); |
| 219 | } |
| 220 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 221 | _contextMenu(event: MouseEvent): void { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 222 | const contextMenu = new UI.ContextMenu.ContextMenu(event); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 223 | this._populateContextMenu(contextMenu, event); |
| 224 | contextMenu.show(); |
| 225 | } |
| 226 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 227 | _populateContextMenu(contextMenu: UI.ContextMenu.ContextMenu, event: MouseEvent): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 228 | let isEditing = false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 229 | for (const watchExpression of this._watchExpressions) { |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 230 | isEditing = isEditing || watchExpression.isEditing(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 231 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 232 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 233 | if (!isEditing) { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 234 | contextMenu.debugSection().appendItem( |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 235 | i18nString(UIStrings.addWatchExpression), this._addButtonClicked.bind(this)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 236 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 237 | |
| 238 | if (this._watchExpressions.length > 1) { |
| 239 | contextMenu.debugSection().appendItem( |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 240 | i18nString(UIStrings.deleteAllWatchExpressions), this._deleteAllButtonClicked.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 241 | } |
| 242 | |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 243 | const treeElement = this._treeOutline.treeElementFromEvent(event); |
| 244 | if (!treeElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 245 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 246 | } |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 247 | const currentWatchExpression = |
| 248 | this._watchExpressions.find(watchExpression => treeElement.hasAncestorOrSelf(watchExpression.treeElement())); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 249 | if (currentWatchExpression) { |
| 250 | currentWatchExpression._populateContextMenu(contextMenu, event); |
| 251 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 252 | } |
| 253 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 254 | _deleteAllButtonClicked(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 255 | this._watchExpressions = []; |
| 256 | this._saveExpressions(); |
| 257 | this.update(); |
| 258 | } |
| 259 | |
Benedikt Meurer | 61f1eef | 2021-03-17 10:38:29 | [diff] [blame] | 260 | async _focusAndAddExpressionToWatch(expression: string): Promise<void> { |
| 261 | await UI.ViewManager.ViewManager.instance().showView('sources.watch'); |
PhistucK | 065e136 | 2018-05-05 09:51:09 | [diff] [blame] | 262 | this._createWatchExpression(expression); |
| 263 | this._saveExpressions(); |
Jack Lynch | 338317a | 2020-08-19 21:59:49 | [diff] [blame] | 264 | this.update(); |
PhistucK | 065e136 | 2018-05-05 09:51:09 | [diff] [blame] | 265 | } |
| 266 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 267 | handleAction(_context: UI.Context.Context, _actionId: string): boolean { |
Tim van der Lippe | d1a00aa | 2020-08-19 16:03:56 | [diff] [blame] | 268 | const frame = UI.Context.Context.instance().flavor(UISourceCodeFrame); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 269 | if (!frame) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 270 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 271 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 272 | const text = frame.textEditor.text(frame.textEditor.selection()); |
PhistucK | 065e136 | 2018-05-05 09:51:09 | [diff] [blame] | 273 | this._focusAndAddExpressionToWatch(text); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 274 | return true; |
| 275 | } |
| 276 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 277 | appendApplicableItems(event: Event, contextMenu: UI.ContextMenu.ContextMenu, target: Object): void { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 278 | if (target instanceof ObjectUI.ObjectPropertiesSection.ObjectPropertyTreeElement && !target.property.synthetic) { |
PhistucK | 065e136 | 2018-05-05 09:51:09 | [diff] [blame] | 279 | contextMenu.debugSection().appendItem( |
Benedikt Meurer | 61f1eef | 2021-03-17 10:38:29 | [diff] [blame] | 280 | i18nString(UIStrings.addPropertyPathToWatch), () => this._focusAndAddExpressionToWatch(target.path())); |
PhistucK | 065e136 | 2018-05-05 09:51:09 | [diff] [blame] | 281 | } |
| 282 | |
Tim van der Lippe | d1a00aa | 2020-08-19 16:03:56 | [diff] [blame] | 283 | const frame = UI.Context.Context.instance().flavor(UISourceCodeFrame); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 284 | if (!frame || frame.textEditor.selection().isEmpty()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 285 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 286 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 287 | |
| 288 | contextMenu.debugSection().appendAction('sources.add-to-watch'); |
| 289 | } |
Tim van der Lippe | 8987f8f | 2020-01-03 15:03:16 | [diff] [blame] | 290 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 291 | |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 292 | export class WatchExpression extends Common.ObjectWrapper.ObjectWrapper { |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 293 | _treeElement!: UI.TreeOutline.TreeElement; |
| 294 | _nameElement!: Element; |
| 295 | _valueElement!: Element; |
| 296 | _expression: string|null; |
| 297 | _expandController: ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeExpandController; |
| 298 | _element: HTMLDivElement; |
| 299 | _editing: boolean; |
| 300 | _linkifier: Components.Linkifier.Linkifier; |
| 301 | _textPrompt?: ObjectUI.ObjectPropertiesSection.ObjectPropertyPrompt; |
| 302 | _result?: SDK.RemoteObject.RemoteObject|null; |
| 303 | _preventClickTimeout?: number; |
| 304 | constructor( |
| 305 | expression: string|null, |
| 306 | expandController: ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeExpandController, |
| 307 | linkifier: Components.Linkifier.Linkifier) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 308 | super(); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 309 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 310 | this._expression = expression; |
| 311 | this._expandController = expandController; |
Tim van der Lippe | e7f2705 | 2020-05-01 15:15:28 | [diff] [blame] | 312 | this._element = document.createElement('div'); |
| 313 | this._element.classList.add('watch-expression'); |
| 314 | this._element.classList.add('monospace'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 315 | this._editing = false; |
| 316 | this._linkifier = linkifier; |
| 317 | |
| 318 | this._createWatchExpression(); |
| 319 | this.update(); |
| 320 | } |
| 321 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 322 | treeElement(): UI.TreeOutline.TreeElement { |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 323 | return this._treeElement; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 324 | } |
| 325 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 326 | expression(): string|null { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 327 | return this._expression; |
| 328 | } |
| 329 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 330 | update(): void { |
Tim van der Lippe | d1a00aa | 2020-08-19 16:03:56 | [diff] [blame] | 331 | const currentExecutionContext = UI.Context.Context.instance().flavor(SDK.RuntimeModel.ExecutionContext); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 332 | if (currentExecutionContext && this._expression) { |
| 333 | currentExecutionContext |
| 334 | .evaluate( |
| 335 | { |
| 336 | expression: this._expression, |
Tim van der Lippe | 8987f8f | 2020-01-03 15:03:16 | [diff] [blame] | 337 | objectGroup: WatchExpression._watchObjectGroupId, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 338 | includeCommandLineAPI: false, |
| 339 | silent: true, |
| 340 | returnByValue: false, |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 341 | generatePreview: false, |
| 342 | allowUnsafeEvalBlockedByCSP: undefined, |
| 343 | disableBreaks: undefined, |
| 344 | replMode: undefined, |
| 345 | throwOnSideEffect: undefined, |
| 346 | timeout: undefined, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 347 | }, |
| 348 | /* userGesture */ false, |
| 349 | /* awaitPromise */ false) |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 350 | .then(result => { |
| 351 | if ('object' in result) { |
| 352 | this._createWatchExpression(result.object, result.exceptionDetails); |
| 353 | } |
| 354 | }); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 355 | } |
| 356 | } |
| 357 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 358 | startEditing(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 359 | this._editing = true; |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 360 | this._element.removeChildren(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 361 | const newDiv = this._element.createChild('div'); |
| 362 | newDiv.textContent = this._nameElement.textContent; |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 363 | this._textPrompt = new ObjectUI.ObjectPropertiesSection.ObjectPropertyPrompt(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 364 | this._textPrompt.renderAsBlock(); |
Tim van der Lippe | bcd6b5c | 2021-01-13 12:31:51 | [diff] [blame] | 365 | const proxyElement = |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 366 | (this._textPrompt.attachAndStartEditing(newDiv, this._finishEditing.bind(this)) as HTMLElement); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 367 | this._treeElement.listItemElement.classList.add('watch-expression-editing'); |
Michael Liao | ced8395 | 2020-05-30 22:57:03 | [diff] [blame] | 368 | this._treeElement.collapse(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 369 | proxyElement.classList.add('watch-expression-text-prompt-proxy'); |
| 370 | proxyElement.addEventListener('keydown', this._promptKeyDown.bind(this), false); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 371 | const selection = this._element.getComponentSelection(); |
| 372 | if (selection) { |
| 373 | selection.selectAllChildren(newDiv); |
| 374 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 375 | } |
| 376 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 377 | isEditing(): boolean { |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 378 | return Boolean(this._editing); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 379 | } |
| 380 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 381 | _finishEditing(event: Event, canceled?: boolean): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 382 | if (event) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 383 | event.consume(canceled); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 384 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 385 | |
| 386 | this._editing = false; |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 387 | this._treeElement.listItemElement.classList.remove('watch-expression-editing'); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 388 | if (this._textPrompt) { |
| 389 | this._textPrompt.detach(); |
| 390 | const newExpression = canceled ? this._expression : this._textPrompt.text(); |
| 391 | this._textPrompt = undefined; |
| 392 | this._element.removeChildren(); |
| 393 | this._updateExpression(newExpression); |
| 394 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 395 | } |
| 396 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 397 | _dblClickOnWatchExpression(event: Event): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 398 | event.consume(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 399 | if (!this.isEditing()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 400 | this.startEditing(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 401 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 402 | } |
| 403 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 404 | _updateExpression(newExpression: string|null): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 405 | if (this._expression) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 406 | this._expandController.stopWatchSectionsWithId(this._expression); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 407 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 408 | this._expression = newExpression; |
| 409 | this.update(); |
Tim van der Lippe | 8987f8f | 2020-01-03 15:03:16 | [diff] [blame] | 410 | this.dispatchEventToListeners(WatchExpression.Events.ExpressionUpdated, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 411 | } |
| 412 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 413 | _deleteWatchExpression(event: Event): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 414 | event.consume(true); |
| 415 | this._updateExpression(null); |
| 416 | } |
| 417 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 418 | _createWatchExpression(result?: SDK.RemoteObject.RemoteObject, exceptionDetails?: Protocol.Runtime.ExceptionDetails): |
| 419 | void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 420 | this._result = result || null; |
| 421 | |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 422 | this._element.removeChildren(); |
| 423 | const oldTreeElement = this._treeElement; |
| 424 | this._createWatchExpressionTreeElement(result, exceptionDetails); |
| 425 | if (oldTreeElement && oldTreeElement.parent) { |
| 426 | const root = oldTreeElement.parent; |
| 427 | const index = root.indexOfChild(oldTreeElement); |
| 428 | root.removeChild(oldTreeElement); |
| 429 | root.insertChild(this._treeElement, index); |
| 430 | } |
| 431 | this._treeElement.select(); |
| 432 | } |
| 433 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 434 | _createWatchExpressionHeader( |
| 435 | expressionValue?: SDK.RemoteObject.RemoteObject, exceptionDetails?: Protocol.Runtime.ExceptionDetails): Element { |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 436 | const headerElement = this._element.createChild('div', 'watch-expression-header'); |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 437 | const deleteButton = UI.Icon.Icon.create('smallicon-cross', 'watch-expression-delete-button'); |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 438 | UI.Tooltip.Tooltip.install(deleteButton, i18nString(UIStrings.deleteWatchExpression)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 439 | deleteButton.addEventListener('click', this._deleteWatchExpression.bind(this), false); |
| 440 | |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 441 | const titleElement = headerElement.createChild('div', 'watch-expression-title tree-element-title'); |
Jack Lynch | e1767de | 2020-04-22 02:43:55 | [diff] [blame] | 442 | titleElement.appendChild(deleteButton); |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 443 | this._nameElement = ObjectUI.ObjectPropertiesSection.ObjectPropertiesSection.createNameElement(this._expression); |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 444 | if (Boolean(exceptionDetails) || !expressionValue) { |
Tim van der Lippe | e7f2705 | 2020-05-01 15:15:28 | [diff] [blame] | 445 | this._valueElement = document.createElement('span'); |
| 446 | this._valueElement.classList.add('watch-expression-error'); |
| 447 | this._valueElement.classList.add('value'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 448 | titleElement.classList.add('dimmed'); |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 449 | this._valueElement.textContent = i18nString(UIStrings.notAvailable); |
Philip Pfaffe | 7426b00 | 2020-11-30 15:59:22 | [diff] [blame] | 450 | if (exceptionDetails !== undefined && exceptionDetails.exception !== undefined && |
| 451 | exceptionDetails.exception.description !== undefined) { |
| 452 | UI.Tooltip.Tooltip.install(this._valueElement, exceptionDetails.exception.description); |
| 453 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 454 | } else { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 455 | const propertyValue = |
| 456 | ObjectUI.ObjectPropertiesSection.ObjectPropertiesSection.createPropertyValueWithCustomSupport( |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 457 | expressionValue, Boolean(exceptionDetails), false /* showPreview */, titleElement, this._linkifier); |
Connor Moody | 1a5c0d3 | 2019-12-19 07:23:36 | [diff] [blame] | 458 | this._valueElement = propertyValue.element; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 459 | } |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 460 | const separatorElement = document.createElement('span'); |
| 461 | separatorElement.classList.add('watch-expressions-separator'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 462 | separatorElement.textContent = ': '; |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 463 | titleElement.append(this._nameElement, separatorElement, this._valueElement); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 464 | |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 465 | return headerElement; |
| 466 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 467 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 468 | _createWatchExpressionTreeElement( |
| 469 | expressionValue?: SDK.RemoteObject.RemoteObject, exceptionDetails?: Protocol.Runtime.ExceptionDetails): void { |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 470 | const headerElement = this._createWatchExpressionHeader(expressionValue, exceptionDetails); |
| 471 | |
| 472 | if (!exceptionDetails && expressionValue && expressionValue.hasChildren && !expressionValue.customPreview()) { |
| 473 | headerElement.classList.add('watch-expression-object-header'); |
| 474 | this._treeElement = new ObjectUI.ObjectPropertiesSection.RootElement(expressionValue, this._linkifier); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 475 | this._expandController.watchSection( |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 476 | (this._expression as string), (this._treeElement as ObjectUI.ObjectPropertiesSection.RootElement)); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 477 | this._treeElement.toggleOnClick = false; |
| 478 | this._treeElement.listItemElement.addEventListener('click', this._onSectionClick.bind(this), false); |
| 479 | this._treeElement.listItemElement.addEventListener('dblclick', this._dblClickOnWatchExpression.bind(this)); |
| 480 | } else { |
| 481 | headerElement.addEventListener('dblclick', this._dblClickOnWatchExpression.bind(this)); |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 482 | this._treeElement = new UI.TreeOutline.TreeElement(); |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 483 | } |
| 484 | this._treeElement.title = this._element; |
| 485 | this._treeElement.listItemElement.classList.add('watch-expression-tree-item'); |
| 486 | this._treeElement.listItemElement.addEventListener('keydown', event => { |
Tim van der Lippe | bcd6b5c | 2021-01-13 12:31:51 | [diff] [blame] | 487 | if (event.key === 'Enter' && !this.isEditing()) { |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 488 | this.startEditing(); |
| 489 | event.consume(true); |
| 490 | } |
| 491 | }); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 492 | } |
| 493 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 494 | _onSectionClick(event: Event): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 495 | event.consume(true); |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 496 | const mouseEvent = (event as MouseEvent); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 497 | if (mouseEvent.detail === 1) { |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 498 | this._preventClickTimeout = window.setTimeout(handleClick.bind(this), 333); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 499 | } else if (this._preventClickTimeout !== undefined) { |
| 500 | window.clearTimeout(this._preventClickTimeout); |
| 501 | this._preventClickTimeout = undefined; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 502 | } |
| 503 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 504 | function handleClick(this: WatchExpression): void { |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 505 | if (!this._treeElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 506 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 507 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 508 | |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 509 | if (this._treeElement.expanded) { |
| 510 | this._treeElement.collapse(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 511 | } else { |
Jack Lynch | 5db2a3e | 2019-11-05 19:12:31 | [diff] [blame] | 512 | this._treeElement.expand(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 513 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 517 | _promptKeyDown(event: KeyboardEvent): void { |
Tim van der Lippe | bcd6b5c | 2021-01-13 12:31:51 | [diff] [blame] | 518 | if (event.key === 'Enter' || isEscKey(event)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 519 | this._finishEditing(event, isEscKey(event)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 520 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 521 | } |
| 522 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 523 | _populateContextMenu(contextMenu: UI.ContextMenu.ContextMenu, event: Event): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 524 | if (!this.isEditing()) { |
| 525 | contextMenu.editSection().appendItem( |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 526 | i18nString(UIStrings.deleteWatchExpression), this._updateExpression.bind(this, null)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 527 | } |
| 528 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 529 | 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] | 530 | contextMenu.clipboardSection().appendItem( |
Vidal Guillermo Diazleal Ortega | 83edb47 | 2021-02-16 18:39:32 | [diff] [blame] | 531 | i18nString(UIStrings.copyValue), this._copyValueButtonClicked.bind(this)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 532 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 533 | |
Sigurd Schneider | 090c3b6 | 2020-11-10 10:26:49 | [diff] [blame] | 534 | const target = UI.UIUtils.deepElementFromEvent(event); |
Tim van der Lippe | 0ad77da | 2020-10-01 16:38:00 | [diff] [blame] | 535 | if (target && this._valueElement.isSelfOrAncestor(target) && this._result) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 536 | contextMenu.appendApplicableItems(this._result); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 537 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 538 | } |
| 539 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 540 | _copyValueButtonClicked(): void { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 541 | Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(this._valueElement.textContent); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 542 | } |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 543 | |
| 544 | // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration) |
| 545 | // eslint-disable-next-line @typescript-eslint/naming-convention |
| 546 | static readonly _watchObjectGroupId = 'watch-group'; |
Tim van der Lippe | 8987f8f | 2020-01-03 15:03:16 | [diff] [blame] | 547 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 548 | |
Jan Scheffler | 35199b9 | 2021-03-17 09:51:15 | [diff] [blame] | 549 | export namespace WatchExpression { |
| 550 | // TODO(crbug.com/1167717): Make this a const enum again |
| 551 | // eslint-disable-next-line rulesdir/const_enum |
| 552 | export const Events = { |
| 553 | ExpressionUpdated: Symbol('ExpressionUpdated'), |
| 554 | }; |
| 555 | } |