OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) IBM Corp. 2009 All rights reserved. | 2 * Copyright (C) IBM Corp. 2009 All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 18 matching lines...) Expand all Loading... | |
29 */ | 29 */ |
30 | 30 |
31 /** | 31 /** |
32 * @constructor | 32 * @constructor |
33 * @extends {WebInspector.SidebarPane} | 33 * @extends {WebInspector.SidebarPane} |
34 */ | 34 */ |
35 WebInspector.WatchExpressionsSidebarPane = function() | 35 WebInspector.WatchExpressionsSidebarPane = function() |
36 { | 36 { |
37 WebInspector.SidebarPane.call(this, WebInspector.UIString("Watch Expressions ")); | 37 WebInspector.SidebarPane.call(this, WebInspector.UIString("Watch Expressions ")); |
38 | 38 |
39 this.section = new WebInspector.WatchExpressionsSection(); | 39 this._requiresUpdate = false; |
40 this.bodyElement.appendChild(this.section.element); | 40 /** @type {!Array.<!WebInspector.WatchExpression>} */ |
41 this._watchExpressions = []; | |
42 | |
43 | |
44 this.bodyElement.classList.add("vbox"); | |
45 this.bodyElement.classList.add("watch-expressions"); | |
46 this.bodyElement.addEventListener("contextmenu", this._contextMenu.bind(this ), false); | |
41 | 47 |
42 var refreshButton = this.titleElement.createChild("button", "pane-title-butt on refresh"); | 48 var refreshButton = this.titleElement.createChild("button", "pane-title-butt on refresh"); |
43 refreshButton.addEventListener("click", this._refreshButtonClicked.bind(this ), false); | 49 refreshButton.addEventListener("click", this._refreshButtonClicked.bind(this ), false); |
44 refreshButton.title = WebInspector.UIString("Refresh"); | 50 refreshButton.title = WebInspector.UIString("Refresh"); |
45 | 51 |
46 var addButton = this.titleElement.createChild("button", "pane-title-button a dd"); | 52 var addButton = this.titleElement.createChild("button", "pane-title-button a dd"); |
47 addButton.addEventListener("click", this._addButtonClicked.bind(this), false ); | 53 addButton.addEventListener("click", this._addButtonClicked.bind(this), false ); |
48 addButton.title = WebInspector.UIString("Add watch expression"); | 54 addButton.title = WebInspector.UIString("Add watch expression"); |
49 | 55 |
50 this._requiresUpdate = true; | 56 this._emptyElement = this.bodyElement.createChild("div", "info"); |
aandrey
2015/02/17 14:42:57
have you considered extending from {WebInspector.N
| |
57 this._emptyElement.textContent = WebInspector.UIString("No Watch Expressions "); | |
58 | |
51 WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext, this.refreshExpressions, this); | 59 WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext, this.refreshExpressions, this); |
52 } | 60 } |
53 | 61 |
54 WebInspector.WatchExpressionsSidebarPane.prototype = { | 62 WebInspector.WatchExpressionsSidebarPane.prototype = { |
55 wasShown: function() | 63 wasShown: function() |
56 { | 64 { |
57 this._refreshExpressionsIfNeeded(); | 65 this._refreshExpressionsIfNeeded(); |
58 }, | 66 }, |
59 | 67 |
60 refreshExpressions: function() | 68 refreshExpressions: function() |
61 { | 69 { |
62 this._requiresUpdate = true; | 70 this._requiresUpdate = true; |
63 this._refreshExpressionsIfNeeded(); | 71 this._refreshExpressionsIfNeeded(); |
64 }, | 72 }, |
65 | 73 |
66 /** | 74 /** |
67 * @param {string} expression | 75 * @param {string} expression |
68 */ | 76 */ |
69 addExpression: function(expression) | 77 addExpression: function(expression) |
70 { | 78 { |
71 this.section.addExpression(expression); | |
72 this.expand(); | 79 this.expand(); |
80 var watchExpression = this._createWatchExpression(expression); | |
81 this._watchExpressions.push(expression); | |
82 this._saveExpressions(); | |
83 }, | |
84 | |
85 _saveExpressions: function() | |
86 { | |
87 var toSave = []; | |
88 for (var i = 0; i < this._watchExpressions.length; i++) | |
89 if (this._watchExpressions[i].expression()) | |
90 toSave.push(this._watchExpressions[i].expression()); | |
91 | |
92 WebInspector.settings.watchExpressions.set(toSave); | |
73 }, | 93 }, |
74 | 94 |
75 _refreshExpressionsIfNeeded: function() | 95 _refreshExpressionsIfNeeded: function() |
76 { | 96 { |
77 if (this._requiresUpdate && this.isShowing()) { | 97 if (this._requiresUpdate && this.isShowing()) { |
78 this.section.update(); | 98 this._rebuildWatchExpressionUIs() |
79 delete this._requiresUpdate; | 99 delete this._requiresUpdate; |
80 } else | 100 } else |
81 this._requiresUpdate = true; | 101 this._requiresUpdate = true; |
82 }, | 102 }, |
83 | 103 |
104 /** | |
105 * @param {!Event} event | |
106 */ | |
84 _addButtonClicked: function(event) | 107 _addButtonClicked: function(event) |
85 { | 108 { |
86 event.consume(); | 109 event.consume(true); |
87 this.expand(); | 110 this.expand(); |
88 this.section.addNewExpressionAndEdit(); | 111 this._createWatchExpression(null).startEditing(); |
89 }, | 112 }, |
90 | 113 |
114 /** | |
115 * @param {!Event} event | |
116 */ | |
91 _refreshButtonClicked: function(event) | 117 _refreshButtonClicked: function(event) |
92 { | 118 { |
93 event.consume(); | 119 event.consume(); |
94 this.refreshExpressions(); | 120 this.refreshExpressions(); |
95 }, | 121 }, |
96 | 122 |
123 _rebuildWatchExpressionUIs: function() | |
124 { | |
125 var watchExpressionStrings = WebInspector.settings.watchExpressions.get( ); | |
126 this.bodyElement.removeChildren(); | |
127 for (var i = 0; i < watchExpressionStrings.length; ++i) { | |
128 var expression = watchExpressionStrings[i]; | |
129 if (!expression) | |
130 continue; | |
131 | |
132 this._createWatchExpression(expression); | |
133 } | |
134 | |
135 this._emptyElement.classList.toggle("hidden", !watchExpressionStrings.le ngth); | |
136 }, | |
137 | |
138 /** | |
139 * @param {?string} expression | |
140 * @return {!WebInspector.WatchExpression} | |
141 */ | |
142 _createWatchExpression: function(expression) | |
143 { | |
144 this._emptyElement.classList.toggle("hidden", true); | |
145 var watchExpression = new WebInspector.WatchExpression(expression); | |
146 watchExpression.addEventListener(WebInspector.WatchExpression.Events.Exp ressionUpdated, this._watchExpressionUpdated.bind(this)); | |
147 this.bodyElement.appendChild(watchExpression.element()); | |
148 this._watchExpressions.push(watchExpression); | |
149 return watchExpression; | |
150 }, | |
151 | |
152 /** | |
153 * @param {!WebInspector.Event} event | |
154 */ | |
155 _watchExpressionUpdated: function(event) | |
156 { | |
157 var watchExpression = /** @type {!WebInspector.WatchExpression} */ (even t.target); | |
158 if (!watchExpression.expression()) { | |
159 this._watchExpressions.remove(watchExpression); | |
160 this.bodyElement.removeChild(watchExpression.element()); | |
161 this._emptyElement.classList.toggle("hidden", !this._watchExpression s.length); | |
162 } | |
163 | |
164 this._saveExpressions(); | |
165 }, | |
166 | |
167 /** | |
168 * @param {!Event} event | |
169 */ | |
170 _contextMenu: function(event) | |
171 { | |
172 var contextMenu = new WebInspector.ContextMenu(event); | |
173 this._populateContextMenu(contextMenu, event); | |
174 contextMenu.show(); | |
175 }, | |
176 | |
177 /** | |
178 * @param {!WebInspector.ContextMenu} contextMenu | |
179 * @param {!Event} event | |
180 */ | |
181 _populateContextMenu: function(contextMenu, event) | |
182 { | |
183 var isEditing = false; | |
184 for (var watchExpression of this._watchExpressions) | |
185 isEditing |= watchExpression.isEditing(); | |
186 | |
187 if (!isEditing) | |
188 contextMenu.appendItem(WebInspector.UIString.capitalize("Add ^watch ^expression"), this._addButtonClicked.bind(this)); | |
189 | |
190 if (this._watchExpressions.length > 1) | |
191 contextMenu.appendItem(WebInspector.UIString.capitalize("Delete ^all ^watch ^expressions"), this._deleteAllButtonClicked.bind(this)); | |
192 | |
193 for (var watchExpression of this._watchExpressions) | |
194 if (watchExpression.element().containsEventPoint(event)) | |
195 watchExpression._populateContextMenu(contextMenu, event); | |
196 }, | |
197 | |
198 _deleteAllButtonClicked: function() | |
199 { | |
200 this._watchExpressions = []; | |
201 this._saveExpressions(); | |
202 this._rebuildWatchExpressionUIs(); | |
203 }, | |
204 | |
97 __proto__: WebInspector.SidebarPane.prototype | 205 __proto__: WebInspector.SidebarPane.prototype |
98 } | 206 } |
99 | 207 |
100 /** | 208 /** |
101 * @constructor | 209 * @constructor |
102 * @extends {WebInspector.PropertiesSection} | 210 * @extends {WebInspector.Object} |
211 * @param {?string} expression | |
103 */ | 212 */ |
104 WebInspector.WatchExpressionsSection = function() | 213 WebInspector.WatchExpression = function(expression) |
105 { | 214 { |
106 this._watchObjectGroupId = "watch-group"; | 215 this._expression = expression; |
107 | 216 this._element = createElementWithClass("div", "watch-expression monospace"); |
108 WebInspector.PropertiesSection.call(this, ""); | 217 this._editing = false; |
109 this.treeElementConstructor = WebInspector.ObjectPropertyTreeElement; | 218 |
110 this.skipProto = false; | 219 this._createWatchExpression(null, false); |
111 | 220 this.update(); |
112 this.emptyElement = createElementWithClass("div", "info"); | 221 |
113 this.emptyElement.textContent = WebInspector.UIString("No Watch Expressions" ); | 222 this._element.addEventListener("mousemove", this._mouseMove.bind(this), true ); |
114 | 223 this._element.addEventListener("mouseleave", this._mouseLeave.bind(this), tr ue); |
115 /** @type {!Array.<string>} */ | |
116 this.watchExpressions = WebInspector.settings.watchExpressions.get(); | |
117 | |
118 this.headerElement.className = "hidden"; | |
119 this.editable = true; | |
120 this.expand(); | |
121 this.propertiesElement.classList.add("watch-expressions"); | |
122 | |
123 this.element.addEventListener("mousemove", this._mouseMove.bind(this), true) ; | |
124 this.element.addEventListener("mouseleave", this._mouseLeave.bind(this), tru e); | |
125 this.element.addEventListener("dblclick", this._sectionDoubleClick.bind(this ), false); | |
126 this.emptyElement.addEventListener("contextmenu", this._emptyElementContextM enu.bind(this), false); | |
127 } | 224 } |
128 | 225 |
129 WebInspector.WatchExpressionsSection.NewWatchExpression = "\xA0"; | 226 WebInspector.WatchExpression._watchObjectGroupId = "watch-group"; |
130 | 227 |
131 WebInspector.WatchExpressionsSection.prototype = { | 228 WebInspector.WatchExpression.Events = { |
132 /** | 229 ExpressionUpdated: "ExpressionUpdated" |
133 * @param {!Event=} e | 230 } |
134 */ | 231 |
135 update: function(e) | 232 WebInspector.WatchExpression.prototype = { |
136 { | 233 |
137 if (e) | 234 /** |
138 e.consume(); | 235 * @return {!Element} |
139 | 236 */ |
140 /*** | 237 element: function() |
141 * @param {string} expression | 238 { |
142 * @param {number} watchIndex | 239 return this._element; |
143 * @param {?WebInspector.RemoteObject} result | 240 }, |
144 * @param {boolean} wasThrown | 241 |
145 * @this {WebInspector.WatchExpressionsSection} | 242 /** |
146 */ | 243 * @return {?string} |
147 function appendResult(expression, watchIndex, result, wasThrown) | 244 */ |
148 { | 245 expression: function() |
149 if (!result) | 246 { |
150 return; | 247 return this._expression; |
151 | 248 }, |
152 var property = new WebInspector.RemoteObjectProperty(expression, res ult); | 249 |
153 property.watchIndex = watchIndex; | 250 update: function() |
154 property.wasThrown = wasThrown; | 251 { |
155 | |
156 // To clarify what's going on here: | |
157 // In the outer function, we calculate the number of properties | |
158 // that we're going to be updating, and set that in the | |
159 // propertyCount variable. | |
160 // In this function, we test to see when we are processing the | |
161 // last property, and then call the superclass's updateProperties() | |
162 // method to get all the properties refreshed at once. | |
163 properties.push(property); | |
164 | |
165 if (properties.length == propertyCount) { | |
166 this.updateProperties(properties); | |
167 | |
168 // check to see if we just added a new watch expression, | |
169 // which will always be the last property | |
170 if (this._newExpressionAdded) { | |
171 delete this._newExpressionAdded; | |
172 | |
173 var treeElement = this.findAddedTreeElement(); | |
174 if (treeElement) | |
175 treeElement.startEditing(); | |
176 } | |
177 | |
178 // Force displaying delete button for hovered element. | |
179 if (this._lastMouseMovePageY) | |
180 this._updateHoveredElement(this._lastMouseMovePageY); | |
181 } | |
182 } | |
183 | |
184 // TODO: pass exact injected script id. | |
185 WebInspector.targetManager.targets().forEach(function(target) { target.r untimeAgent().releaseObjectGroup(this._watchObjectGroupId); }, this); | |
186 var properties = []; | |
187 | |
188 // Count the properties, so we known when to call this.updateProperties( ) | |
189 // in appendResult() | |
190 var propertyCount = 0; | |
191 for (var i = 0; i < this.watchExpressions.length; ++i) { | |
192 if (!this.watchExpressions[i]) | |
193 continue; | |
194 ++propertyCount; | |
195 } | |
196 | |
197 // Now process all the expressions, since we have the actual count, | |
198 // which is checked in the appendResult inner function. | |
199 var currentExecutionContext = WebInspector.context.flavor(WebInspector.E xecutionContext); | 252 var currentExecutionContext = WebInspector.context.flavor(WebInspector.E xecutionContext); |
200 if (currentExecutionContext) { | 253 if (currentExecutionContext && this._expression) |
201 for (var i = 0; i < this.watchExpressions.length; ++i) { | 254 currentExecutionContext.evaluate(this._expression, WebInspector.Watc hExpression._watchObjectGroupId, false, true, false, true, this._createWatchExpr ession.bind(this)); |
202 var expression = this.watchExpressions[i]; | 255 }, |
203 if (!expression) | 256 |
204 continue; | 257 startEditing: function() |
205 | 258 { |
206 currentExecutionContext.evaluate(expression, this._watchObjectGr oupId, false, true, false, false, appendResult.bind(this, expression, i)); | 259 this._editing = true; |
207 } | 260 this._element.removeChild(this._objectPresentationElement); |
208 } | 261 this._element.classList.add("watch-expression-editing"); |
209 | 262 var newDiv = this._element.createChild("div"); |
210 if (!propertyCount) { | 263 newDiv.textContent = this._nameElement.textContent; |
211 this.element.appendChild(this.emptyElement); | 264 this._textPrompt = new WebInspector.ObjectPropertyPrompt(true); |
212 this.propertiesElement.remove(); | 265 var proxyElement = this._textPrompt.attachAndStartEditing(newDiv, this._ finishEditing.bind(this, this._expression)); |
213 this.propertiesTreeOutline.removeChildren(); | 266 proxyElement.classList.add("watch-expression-text-prompt-proxy"); |
214 } else { | 267 proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this), false); |
215 this.element.appendChild(this.propertiesElement); | 268 this._element.getComponentSelection().setBaseAndExtent(newDiv, 0, newDiv , 1); |
216 this.emptyElement.remove(); | 269 }, |
217 } | 270 |
218 }, | 271 /** |
219 | 272 * @return {boolean} |
220 /** | 273 */ |
221 * @param {!Array.<!WebInspector.RemoteObjectProperty>} properties | 274 isEditing: function() |
222 */ | 275 { |
223 updateProperties: function(properties) | 276 return !!this._editing; |
224 { | 277 }, |
225 this.propertiesTreeOutline.removeChildren(); | 278 |
226 WebInspector.ObjectPropertyTreeElement.populateWithProperties(this.prope rtiesTreeOutline, properties, [], | 279 /** |
227 WebInspector.WatchExpressionTreeElement, WebInspector.WatchExpressio nsSection.CompareProperties, false, null); | 280 * @param {?string} newExpression |
228 | 281 * @param {!Event} event |
229 this.propertiesForTest = properties; | 282 */ |
230 }, | 283 _finishEditing: function(newExpression, event) |
231 | 284 { |
232 /** | 285 if (event) |
233 * @param {string} expression | 286 event.consume(true); |
234 */ | 287 |
235 addExpression: function(expression) | 288 this._editing = false; |
236 { | 289 this._textPrompt.detach(); |
237 this.watchExpressions.push(expression); | 290 delete this._textPrompt; |
238 this.saveExpressions(); | 291 this._element.removeChildren(); |
292 this._element.classList.remove("watch-expression-editing"); | |
293 this._element.appendChild(this._objectPresentationElement); | |
294 this._updateExpression(newExpression); | |
295 }, | |
296 | |
297 /** | |
298 * @param {!Event} event | |
299 */ | |
300 _dblClickOnWatchExpression: function(event) | |
301 { | |
302 event.consume(); | |
303 if (!this.isEditing()) | |
304 this.startEditing(); | |
305 }, | |
306 | |
307 /** | |
308 * @param {?string} newExpression | |
309 */ | |
310 _updateExpression: function(newExpression) | |
311 { | |
312 this._expression = newExpression; | |
239 this.update(); | 313 this.update(); |
240 }, | 314 this.dispatchEventToListeners(WebInspector.WatchExpression.Events.Expres sionUpdated); |
241 | 315 }, |
242 addNewExpressionAndEdit: function() | 316 |
243 { | 317 /** |
244 this._newExpressionAdded = true; | 318 * @param {?WebInspector.RemoteObject} result |
245 this.watchExpressions.push(WebInspector.WatchExpressionsSection.NewWatch Expression); | 319 * @param {boolean} wasThrown |
246 this.update(); | 320 */ |
247 }, | 321 _createWatchExpression: function(result, wasThrown) |
248 | 322 { |
249 _sectionDoubleClick: function(event) | 323 this._result = result; |
250 { | 324 this._element.removeChildren(); |
251 if (event.target !== this.element && event.target !== this.propertiesEle ment && event.target !== this.emptyElement) | |
252 return; | |
253 event.consume(); | |
254 this.addNewExpressionAndEdit(); | |
255 }, | |
256 | |
257 /** | |
258 * @param {!WebInspector.ObjectPropertyTreeElement} element | |
259 * @param {?string} value | |
260 */ | |
261 updateExpression: function(element, value) | |
262 { | |
263 if (value === null) { | |
264 var index = element.property.watchIndex; | |
265 this.watchExpressions.splice(index, 1); | |
266 } else { | |
267 this.watchExpressions[element.property.watchIndex] = value; | |
268 } | |
269 this.saveExpressions(); | |
270 this.update(); | |
271 }, | |
272 | |
273 _deleteAllExpressions: function() | |
274 { | |
275 this.watchExpressions = []; | |
276 this.saveExpressions(); | |
277 this.update(); | |
278 }, | |
279 | |
280 /** | |
281 * @return {?TreeElement} | |
282 */ | |
283 findAddedTreeElement: function() | |
284 { | |
285 var children = this.propertiesTreeOutline.children; | |
286 for (var i = 0; i < children.length; ++i) { | |
287 if (children[i].property.name === WebInspector.WatchExpressionsSecti on.NewWatchExpression) | |
288 return children[i]; | |
289 } | |
290 return null; | |
291 }, | |
292 | |
293 /** | |
294 * @return {number} | |
295 */ | |
296 saveExpressions: function() | |
297 { | |
298 var toSave = []; | |
299 for (var i = 0; i < this.watchExpressions.length; i++) | |
300 if (this.watchExpressions[i]) | |
301 toSave.push(this.watchExpressions[i]); | |
302 | |
303 WebInspector.settings.watchExpressions.set(toSave); | |
304 return toSave.length; | |
305 }, | |
306 | |
307 _mouseMove: function(e) | |
308 { | |
309 if (this.propertiesElement.firstChild) | |
310 this._updateHoveredElement(e.pageY); | |
311 }, | |
312 | |
313 _mouseLeave: function() | |
314 { | |
315 if (this._hoveredElement) { | |
316 this._hoveredElement.classList.remove("hovered"); | |
317 delete this._hoveredElement; | |
318 } | |
319 delete this._lastMouseMovePageY; | |
320 }, | |
321 | |
322 _updateHoveredElement: function(pageY) | |
323 { | |
324 var candidateElement = this.propertiesElement.firstChild; | |
325 while (true) { | |
326 var next = candidateElement.nextSibling; | |
327 while (next && !next.clientHeight) | |
328 next = next.nextSibling; | |
329 if (!next || next.totalOffsetTop() > pageY) | |
330 break; | |
331 candidateElement = next; | |
332 } | |
333 | |
334 if (this._hoveredElement !== candidateElement) { | |
335 if (this._hoveredElement) | |
336 this._hoveredElement.classList.remove("hovered"); | |
337 if (candidateElement) | |
338 candidateElement.classList.add("hovered"); | |
339 this._hoveredElement = candidateElement; | |
340 } | |
341 | |
342 this._lastMouseMovePageY = pageY; | |
343 }, | |
344 | |
345 _emptyElementContextMenu: function(event) | |
346 { | |
347 var contextMenu = new WebInspector.ContextMenu(event); | |
348 contextMenu.appendItem(WebInspector.UIString.capitalize("Add ^watch ^exp ression"), this.addNewExpressionAndEdit.bind(this)); | |
349 contextMenu.show(); | |
350 }, | |
351 | |
352 __proto__: WebInspector.PropertiesSection.prototype | |
353 } | |
354 | |
355 /** | |
356 * @param {!WebInspector.RemoteObjectProperty} propertyA | |
357 * @param {!WebInspector.RemoteObjectProperty} propertyB | |
358 * @return {number} | |
359 */ | |
360 WebInspector.WatchExpressionsSection.CompareProperties = function(propertyA, pro pertyB) | |
361 { | |
362 if (propertyA.watchIndex == propertyB.watchIndex) | |
363 return 0; | |
364 else if (propertyA.watchIndex < propertyB.watchIndex) | |
365 return -1; | |
366 else | |
367 return 1; | |
368 } | |
369 | |
370 /** | |
371 * @constructor | |
372 * @extends {WebInspector.ObjectPropertyTreeElement} | |
373 * @param {!WebInspector.RemoteObjectProperty} property | |
374 */ | |
375 WebInspector.WatchExpressionTreeElement = function(property) | |
376 { | |
377 WebInspector.ObjectPropertyTreeElement.call(this, property); | |
378 } | |
379 | |
380 WebInspector.WatchExpressionTreeElement.prototype = { | |
381 /** | |
382 * @override | |
383 * @return {*} | |
384 */ | |
385 elementIdentity: function() | |
386 { | |
387 return this.property.name; | |
388 }, | |
389 | |
390 update: function() | |
391 { | |
392 WebInspector.ObjectPropertyTreeElement.prototype.update.call(this); | |
393 | |
394 if (this.property.wasThrown) { | |
395 this.valueElement.textContent = WebInspector.UIString("<not availabl e>"); | |
396 this.listItemElement.classList.add("dimmed"); | |
397 } else { | |
398 this.listItemElement.classList.remove("dimmed"); | |
399 } | |
400 | |
401 var deleteButton = createElementWithClass("button", "delete-button"); | 325 var deleteButton = createElementWithClass("button", "delete-button"); |
402 deleteButton.title = WebInspector.UIString("Delete watch expression"); | 326 deleteButton.title = WebInspector.UIString("Delete watch expression"); |
403 deleteButton.addEventListener("click", this._deleteButtonClicked.bind(th is), false); | 327 deleteButton.addEventListener("click", this._updateExpression.bind(this, null), false); |
404 this.listItemElement.addEventListener("contextmenu", this._contextMenu.b ind(this), false); | 328 this._element.appendChild(deleteButton); |
405 this.listItemElement.insertBefore(deleteButton, this.listItemElement.fir stChild); | 329 |
330 var titleElement = createElementWithClass("div", "watch-expression-title "); | |
331 | |
332 this._nameElement = WebInspector.ObjectPropertiesSection.createNameEleme nt(this._expression); | |
333 if (wasThrown || !result) { | |
334 this._valueElement = createElementWithClass("span", "console-formatt ed-undefined"); | |
335 titleElement.classList.add("dimmed"); | |
336 this._valueElement.textContent = WebInspector.UIString("<not availab le>"); | |
337 } else { | |
338 this._valueElement = WebInspector.ObjectPropertiesSection.createValu eElement(result, wasThrown, titleElement); | |
339 } | |
340 var separatorElement = createElementWithClass("span", "separator"); | |
341 separatorElement.textContent = ": "; | |
342 | |
343 titleElement.appendChildren(this._nameElement, separatorElement, this._v alueElement); | |
344 if (!wasThrown && result && result.hasChildren) { | |
345 var objectPropertiesSection = new WebInspector.ObjectPropertiesSecti on(result, titleElement); | |
346 this._objectPresentationElement = objectPropertiesSection.element; | |
347 objectPropertiesSection.headerElement.addEventListener("click", this ._onSectionClick.bind(this, objectPropertiesSection), true); | |
348 } else { | |
349 this._objectPresentationElement = titleElement; | |
350 } | |
351 | |
352 this._element.appendChild(this._objectPresentationElement); | |
353 this._element.addEventListener("dblclick", this._dblClickOnWatchExpressi on.bind(this)); | |
354 }, | |
355 | |
356 /** | |
357 * @param {!WebInspector.ObjectPropertiesSection} objectPropertiesSection | |
358 * @param {!Event} event | |
359 */ | |
360 _onSectionClick: function(objectPropertiesSection, event) | |
361 { | |
362 event.consume(true); | |
363 if (event.detail == 1) { | |
364 this._preventClickTimeout = setTimeout(handleClick, 333); | |
365 } else { | |
366 clearTimeout(this._preventClickTimeout); | |
367 delete this._preventClickTimeout; | |
368 } | |
369 | |
370 function handleClick() | |
371 { | |
372 if (objectPropertiesSection.expanded) | |
373 objectPropertiesSection.collapse(); | |
374 else | |
375 objectPropertiesSection.expand(); | |
376 } | |
377 }, | |
378 | |
379 /** | |
380 * @param {!Event} event | |
381 */ | |
382 _promptKeyDown: function(event) | |
383 { | |
384 if (isEnterKey(event)) { | |
385 this._finishEditing(this._textPrompt.text(), event); | |
386 return; | |
387 } | |
388 if (event.keyIdentifier === "U+001B") { // Esc | |
389 this._finishEditing(this._expression, event); | |
390 return; | |
391 } | |
406 }, | 392 }, |
407 | 393 |
408 /** | 394 /** |
409 * @param {!WebInspector.ContextMenu} contextMenu | 395 * @param {!WebInspector.ContextMenu} contextMenu |
410 * @override | 396 * @param {!Event} event |
411 */ | 397 */ |
412 populateContextMenu: function(contextMenu) | 398 _populateContextMenu: function(contextMenu, event) |
413 { | 399 { |
414 if (!this.isEditing()) { | 400 if (!this.isEditing()) |
415 contextMenu.appendItem(WebInspector.UIString.capitalize("Add ^watch ^expression"), this.treeOutline.section.addNewExpressionAndEdit.bind(this.treeOu tline.section)); | 401 contextMenu.appendItem(WebInspector.UIString.capitalize("Delete ^wat ch ^expression"), this._updateExpression.bind(this, null)); |
416 contextMenu.appendItem(WebInspector.UIString.capitalize("Delete ^wat ch ^expression"), this._deleteButtonClicked.bind(this, null)); | 402 |
417 } | 403 if (!this.isEditing() && this._result && (this._result.type === "number" || this._result.type === "string")) |
418 if (this.treeOutline.section.watchExpressions.length > 1) | |
419 contextMenu.appendItem(WebInspector.UIString.capitalize("Delete ^all ^watch ^expressions"), this._deleteAllButtonClicked.bind(this)); | |
420 if (!this.isEditing() && (this.property.value.type === "number" || this. property.value.type === "string")) | |
421 contextMenu.appendItem(WebInspector.UIString.capitalize("Copy ^value "), this._copyValueButtonClicked.bind(this)); | 404 contextMenu.appendItem(WebInspector.UIString.capitalize("Copy ^value "), this._copyValueButtonClicked.bind(this)); |
422 }, | 405 |
423 | 406 if (this._valueElement.containsEventPoint(event)) |
424 _contextMenu: function(event) | 407 contextMenu.appendApplicableItems(this._result); |
425 { | |
426 var contextMenu = new WebInspector.ContextMenu(event); | |
427 this.populateContextMenu(contextMenu); | |
428 contextMenu.show(); | |
429 }, | |
430 | |
431 _deleteAllButtonClicked: function() | |
432 { | |
433 this.treeOutline.section._deleteAllExpressions(); | |
434 }, | |
435 | |
436 _deleteButtonClicked: function(event) | |
437 { | |
438 if (event) | |
439 event.consume(); | |
440 this.treeOutline.section.updateExpression(this, null); | |
441 }, | 408 }, |
442 | 409 |
443 _copyValueButtonClicked: function() | 410 _copyValueButtonClicked: function() |
444 { | 411 { |
445 InspectorFrontendHost.copyText(this.valueElement.textContent); | 412 InspectorFrontendHost.copyText(this._valueElement.textContent); |
446 }, | 413 }, |
447 | 414 |
448 /** | 415 _mouseMove: function() |
449 * @override | 416 { |
450 * @return {boolean} | 417 this._element.classList.add("hovered"); |
451 */ | 418 }, |
452 renderPromptAsBlock: function() | 419 |
453 { | 420 _mouseLeave: function() |
454 return true; | 421 { |
455 }, | 422 this._element.classList.remove("hovered"); |
456 | 423 }, |
457 /** | 424 |
458 * @override | 425 __proto__: WebInspector.Object.prototype |
459 * @return {{element: !Element, value: (string|undefined)}} | |
460 */ | |
461 elementAndValueToEdit: function() | |
462 { | |
463 return { element: this.nameElement, value: this.property.name.trim() }; | |
464 }, | |
465 | |
466 /** | |
467 * @override | |
468 */ | |
469 editingCancelled: function(element, context) | |
470 { | |
471 if (!context.elementToEdit.textContent) | |
472 this.treeOutline.section.updateExpression(this, null); | |
473 | |
474 WebInspector.ObjectPropertyTreeElement.prototype.editingCancelled.call(t his, element, context); | |
475 }, | |
476 | |
477 /** | |
478 * @override | |
479 * @param {string} expression | |
480 */ | |
481 applyExpression: function(expression) | |
482 { | |
483 expression = expression.trim(); | |
484 this.property.name = expression || null; | |
485 this.treeOutline.section.updateExpression(this, expression); | |
486 }, | |
487 | |
488 __proto__: WebInspector.ObjectPropertyTreeElement.prototype | |
489 } | 426 } |
OLD | NEW |