| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) IBM Corp. 2009 All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of IBM Corp. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 WebInspector.WatchExpressionsSidebarPane = function() | |
| 32 { | |
| 33 WebInspector.SidebarPane.call(this, WebInspector.UIString("Watch Expressions
")); | |
| 34 | |
| 35 this.section = new WebInspector.WatchExpressionsSection(); | |
| 36 | |
| 37 this.bodyElement.appendChild(this.section.element); | |
| 38 | |
| 39 var addElement = document.createElement("button"); | |
| 40 addElement.setAttribute("type", "button"); | |
| 41 addElement.textContent = WebInspector.UIString("Add"); | |
| 42 addElement.addEventListener("click", this.section.addExpression.bind(this.se
ction), false); | |
| 43 | |
| 44 var refreshElement = document.createElement("button"); | |
| 45 refreshElement.setAttribute("type", "button"); | |
| 46 refreshElement.textContent = WebInspector.UIString("Refresh"); | |
| 47 refreshElement.addEventListener("click", this.section.update.bind(this.secti
on), false); | |
| 48 | |
| 49 var centerElement = document.createElement("div"); | |
| 50 centerElement.addStyleClass("watch-expressions-buttons-container"); | |
| 51 centerElement.appendChild(addElement); | |
| 52 centerElement.appendChild(refreshElement); | |
| 53 this.bodyElement.appendChild(centerElement); | |
| 54 | |
| 55 this.expanded = this.section.loadSavedExpressions().length > 0; | |
| 56 this.onexpand = this.refreshExpressions.bind(this); | |
| 57 } | |
| 58 | |
| 59 WebInspector.WatchExpressionsSidebarPane.prototype = { | |
| 60 refreshExpressions: function() | |
| 61 { | |
| 62 this.section.update(); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 WebInspector.WatchExpressionsSidebarPane.prototype.__proto__ = WebInspector.Side
barPane.prototype; | |
| 67 | |
| 68 WebInspector.WatchExpressionsSection = function() | |
| 69 { | |
| 70 WebInspector.ObjectPropertiesSection.call(this); | |
| 71 | |
| 72 this.watchExpressions = this.loadSavedExpressions(); | |
| 73 | |
| 74 this.headerElement.className = "hidden"; | |
| 75 this.editable = true; | |
| 76 this.expanded = true; | |
| 77 this.propertiesElement.addStyleClass("watch-expressions"); | |
| 78 | |
| 79 this._watchObjectGroupId = "watch-group"; | |
| 80 } | |
| 81 | |
| 82 WebInspector.WatchExpressionsSection.NewWatchExpression = "\xA0"; | |
| 83 | |
| 84 WebInspector.WatchExpressionsSection.prototype = { | |
| 85 update: function() | |
| 86 { | |
| 87 function appendResult(expression, watchIndex, result, exception) | |
| 88 { | |
| 89 if (exception) { | |
| 90 // Exception results are not wrappers, but text messages. | |
| 91 result = WebInspector.ObjectProxy.wrapPrimitiveValue(result); | |
| 92 } else if (result.type === "string") { | |
| 93 // Evaluation result is intentionally not abbreviated. However,
we'd like to distinguish between null and "null" | |
| 94 result.description = "\"" + result.description + "\""; | |
| 95 } | |
| 96 | |
| 97 var property = new WebInspector.ObjectPropertyProxy(expression, resu
lt); | |
| 98 property.watchIndex = watchIndex; | |
| 99 property.isException = exception; | |
| 100 | |
| 101 // For newly added, empty expressions, set description to "", | |
| 102 // since otherwise you get DOMWindow | |
| 103 if (property.name === WebInspector.WatchExpressionsSection.NewWatchE
xpression) | |
| 104 property.value.description = ""; | |
| 105 | |
| 106 // To clarify what's going on here: | |
| 107 // In the outer function, we calculate the number of properties | |
| 108 // that we're going to be updating, and set that in the | |
| 109 // propertyCount variable. | |
| 110 // In this function, we test to see when we are processing the | |
| 111 // last property, and then call the superclass's updateProperties() | |
| 112 // method to get all the properties refreshed at once. | |
| 113 properties.push(property); | |
| 114 | |
| 115 if (properties.length == propertyCount) | |
| 116 this.updateProperties(properties, WebInspector.WatchExpressionTr
eeElement, WebInspector.WatchExpressionsSection.CompareProperties); | |
| 117 } | |
| 118 | |
| 119 InspectorController.releaseWrapperObjectGroup(this._watchObjectGroupId) | |
| 120 var properties = []; | |
| 121 | |
| 122 // Count the properties, so we known when to call this.updateProperties(
) | |
| 123 // in appendResult() | |
| 124 var propertyCount = 0; | |
| 125 for (var i = 0; i < this.watchExpressions.length; ++i) { | |
| 126 if (!this.watchExpressions[i]) | |
| 127 continue; | |
| 128 ++propertyCount; | |
| 129 } | |
| 130 | |
| 131 // Now process all the expressions, since we have the actual count, | |
| 132 // which is checked in the appendResult inner function. | |
| 133 for (var i = 0; i < this.watchExpressions.length; ++i) { | |
| 134 var expression = this.watchExpressions[i]; | |
| 135 if (!expression) | |
| 136 continue; | |
| 137 | |
| 138 WebInspector.console.evalInInspectedWindow("(" + expression + ")", t
his._watchObjectGroupId, appendResult.bind(this, expression, i)); | |
| 139 } | |
| 140 | |
| 141 // note this is setting the expansion of the tree, not the section; | |
| 142 // with no expressions, and expanded tree, we get some extra vertical | |
| 143 // white space | |
| 144 // FIXME: should change to use header buttons instead of the buttons | |
| 145 // at the bottom of the section, then we can add a "No Watch Expressions | |
| 146 // element when there are no watch expressions, and this issue should | |
| 147 // go away. | |
| 148 this.expanded = (propertyCount != 0); | |
| 149 }, | |
| 150 | |
| 151 addExpression: function() | |
| 152 { | |
| 153 this.watchExpressions.push(WebInspector.WatchExpressionsSection.NewWatch
Expression); | |
| 154 this.update(); | |
| 155 | |
| 156 // After update(), the new empty expression to be edited | |
| 157 // will be in the tree, but we have to find it. | |
| 158 treeElement = this.findAddedTreeElement(); | |
| 159 if (treeElement) | |
| 160 treeElement.startEditing(); | |
| 161 }, | |
| 162 | |
| 163 updateExpression: function(element, value) | |
| 164 { | |
| 165 this.watchExpressions[element.property.watchIndex] = value; | |
| 166 this.saveExpressions(); | |
| 167 this.update(); | |
| 168 }, | |
| 169 | |
| 170 findAddedTreeElement: function() | |
| 171 { | |
| 172 var children = this.propertiesTreeOutline.children; | |
| 173 for (var i = 0; i < children.length; ++i) | |
| 174 if (children[i].property.name === WebInspector.WatchExpressionsSecti
on.NewWatchExpression) | |
| 175 return children[i]; | |
| 176 }, | |
| 177 | |
| 178 loadSavedExpressions: function() | |
| 179 { | |
| 180 var json = InspectorController.setting("watchExpressions"); | |
| 181 if (!json) | |
| 182 return []; | |
| 183 | |
| 184 try { | |
| 185 json = JSON.parse(json); | |
| 186 } catch(e) { | |
| 187 return []; | |
| 188 } | |
| 189 | |
| 190 return json.expressions || []; | |
| 191 }, | |
| 192 | |
| 193 saveExpressions: function() | |
| 194 { | |
| 195 var toSave = []; | |
| 196 for (var i = 0; i < this.watchExpressions.length; i++) | |
| 197 if (this.watchExpressions[i]) | |
| 198 toSave.push(this.watchExpressions[i]); | |
| 199 | |
| 200 var json = JSON.stringify({expressions: toSave}); | |
| 201 InspectorController.setSetting("watchExpressions", json); | |
| 202 | |
| 203 return toSave.length; | |
| 204 } | |
| 205 } | |
| 206 | |
| 207 WebInspector.WatchExpressionsSection.prototype.__proto__ = WebInspector.ObjectPr
opertiesSection.prototype; | |
| 208 | |
| 209 WebInspector.WatchExpressionsSection.CompareProperties = function(propertyA, pro
pertyB) | |
| 210 { | |
| 211 if (propertyA.watchIndex == propertyB.watchIndex) | |
| 212 return 0; | |
| 213 else if (propertyA.watchIndex < propertyB.watchIndex) | |
| 214 return -1; | |
| 215 else | |
| 216 return 1; | |
| 217 } | |
| 218 | |
| 219 WebInspector.WatchExpressionTreeElement = function(property) | |
| 220 { | |
| 221 WebInspector.ObjectPropertyTreeElement.call(this, property); | |
| 222 } | |
| 223 | |
| 224 WebInspector.WatchExpressionTreeElement.prototype = { | |
| 225 update: function() | |
| 226 { | |
| 227 WebInspector.ObjectPropertyTreeElement.prototype.update.call(this); | |
| 228 | |
| 229 if (this.property.isException) | |
| 230 this.valueElement.addStyleClass("watch-expressions-error-level"); | |
| 231 | |
| 232 var deleteButton = document.createElement("input"); | |
| 233 deleteButton.type = "button"; | |
| 234 deleteButton.title = WebInspector.UIString("Delete watch expression."); | |
| 235 deleteButton.addStyleClass("enabled-button"); | |
| 236 deleteButton.addStyleClass("delete-button"); | |
| 237 deleteButton.addEventListener("click", this._deleteButtonClicked.bind(th
is), false); | |
| 238 | |
| 239 this.listItemElement.insertBefore(deleteButton, this.listItemElement.fir
stChild); | |
| 240 }, | |
| 241 | |
| 242 _deleteButtonClicked: function() | |
| 243 { | |
| 244 this.treeOutline.section.updateExpression(this, null); | |
| 245 }, | |
| 246 | |
| 247 startEditing: function() | |
| 248 { | |
| 249 if (WebInspector.isBeingEdited(this.nameElement) || !this.treeOutline.se
ction.editable) | |
| 250 return; | |
| 251 | |
| 252 this.nameElement.textContent = this.property.name.trimWhitespace(); | |
| 253 | |
| 254 var context = { expanded: this.expanded }; | |
| 255 | |
| 256 // collapse temporarily, if required | |
| 257 this.hasChildren = false; | |
| 258 | |
| 259 this.listItemElement.addStyleClass("editing-sub-part"); | |
| 260 | |
| 261 WebInspector.startEditing(this.nameElement, this.editingCommitted.bind(t
his), this.editingCancelled.bind(this), context); | |
| 262 }, | |
| 263 | |
| 264 editingCancelled: function(element, context) | |
| 265 { | |
| 266 if (!this.nameElement.textContent) | |
| 267 this.treeOutline.section.updateExpression(this, null); | |
| 268 | |
| 269 this.update(); | |
| 270 this.editingEnded(context); | |
| 271 }, | |
| 272 | |
| 273 applyExpression: function(expression, updateInterface) | |
| 274 { | |
| 275 expression = expression.trimWhitespace(); | |
| 276 | |
| 277 if (!expression) | |
| 278 expression = null; | |
| 279 | |
| 280 this.property.name = expression; | |
| 281 this.treeOutline.section.updateExpression(this, expression); | |
| 282 } | |
| 283 } | |
| 284 | |
| 285 WebInspector.WatchExpressionTreeElement.prototype.__proto__ = WebInspector.Objec
tPropertyTreeElement.prototype; | |
| OLD | NEW |