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 |
| 80 WebInspector.WatchExpressionsSection.NewWatchExpression = "\xA0"; |
| 81 |
| 82 WebInspector.WatchExpressionsSection.prototype = { |
| 83 update: function() |
| 84 { |
| 85 function appendResult(expression, watchIndex, result, exception) |
| 86 { |
| 87 // The null check catches some other cases, like null itself, and Na
N |
| 88 if ((typeof result !== "object") || (result == null)) |
| 89 result = new WebInspector.ObjectProxy(null, [], 0, String(result
), false); |
| 90 |
| 91 var property = new WebInspector.ObjectPropertyProxy(expression, resu
lt); |
| 92 property.watchIndex = watchIndex; |
| 93 |
| 94 // For newly added, empty expressions, set description to "", |
| 95 // since otherwise you get DOMWindow |
| 96 if (property.name === WebInspector.WatchExpressionsSection.NewWatchE
xpression) |
| 97 property.value.description = ""; |
| 98 |
| 99 // To clarify what's going on here: |
| 100 // In the outer function, we calculate the number of properties |
| 101 // that we're going to be updating, and set that in the |
| 102 // propertyCount variable. |
| 103 // In this function, we test to see when we are processing the |
| 104 // last property, and then call the superclass's updateProperties() |
| 105 // method to get all the properties refreshed at once. |
| 106 properties.push(property); |
| 107 |
| 108 if (properties.length == propertyCount) |
| 109 this.updateProperties(properties, WebInspector.WatchExpressionTr
eeElement, WebInspector.WatchExpressionsSection.CompareProperties); |
| 110 } |
| 111 |
| 112 var properties = []; |
| 113 |
| 114 // Count the properties, so we known when to call this.updateProperties(
) |
| 115 // in appendResult() |
| 116 var propertyCount = 0; |
| 117 for (var i = 0; i < this.watchExpressions.length; ++i) { |
| 118 if (!this.watchExpressions[i]) |
| 119 continue; |
| 120 ++propertyCount; |
| 121 } |
| 122 |
| 123 // Now process all the expressions, since we have the actual count, |
| 124 // which is checked in the appendResult inner function. |
| 125 for (var i = 0; i < this.watchExpressions.length; ++i) { |
| 126 var expression = this.watchExpressions[i]; |
| 127 if (!expression) |
| 128 continue; |
| 129 |
| 130 WebInspector.console.evalInInspectedWindow("(" + expression + ")", a
ppendResult.bind(this, expression, i)); |
| 131 } |
| 132 |
| 133 // note this is setting the expansion of the tree, not the section; |
| 134 // with no expressions, and expanded tree, we get some extra vertical |
| 135 // white space |
| 136 // FIXME: should change to use header buttons instead of the buttons |
| 137 // at the bottom of the section, then we can add a "No Watch Expressions |
| 138 // element when there are no watch expressions, and this issue should |
| 139 // go away. |
| 140 this.expanded = (propertyCount != 0); |
| 141 }, |
| 142 |
| 143 addExpression: function() |
| 144 { |
| 145 this.watchExpressions.push(WebInspector.WatchExpressionsSection.NewWatch
Expression); |
| 146 this.update(); |
| 147 |
| 148 // After update(), the new empty expression to be edited |
| 149 // will be in the tree, but we have to find it. |
| 150 treeElement = this.findAddedTreeElement(); |
| 151 if (treeElement) |
| 152 treeElement.startEditing(); |
| 153 }, |
| 154 |
| 155 updateExpression: function(element, value) |
| 156 { |
| 157 this.watchExpressions[element.property.watchIndex] = value; |
| 158 this.saveExpressions(); |
| 159 this.update(); |
| 160 }, |
| 161 |
| 162 findAddedTreeElement: function() |
| 163 { |
| 164 var children = this.propertiesTreeOutline.children; |
| 165 for (var i = 0; i < children.length; ++i) |
| 166 if (children[i].property.name === WebInspector.WatchExpressionsSecti
on.NewWatchExpression) |
| 167 return children[i]; |
| 168 }, |
| 169 |
| 170 loadSavedExpressions: function() |
| 171 { |
| 172 var json = InspectorController.setting("watchExpressions"); |
| 173 if (!json) |
| 174 return []; |
| 175 |
| 176 try { |
| 177 json = JSON.parse(json); |
| 178 } catch(e) { |
| 179 return []; |
| 180 } |
| 181 |
| 182 return json.expressions || []; |
| 183 }, |
| 184 |
| 185 saveExpressions: function() |
| 186 { |
| 187 var toSave = []; |
| 188 for (var i = 0; i < this.watchExpressions.length; i++) |
| 189 if (this.watchExpressions[i]) |
| 190 toSave.push(this.watchExpressions[i]); |
| 191 |
| 192 var json = JSON.stringify({expressions: toSave}); |
| 193 InspectorController.setSetting("watchExpressions", json); |
| 194 |
| 195 return toSave.length; |
| 196 } |
| 197 } |
| 198 |
| 199 WebInspector.WatchExpressionsSection.prototype.__proto__ = WebInspector.ObjectPr
opertiesSection.prototype; |
| 200 |
| 201 WebInspector.WatchExpressionsSection.CompareProperties = function(propertyA, pro
pertyB) |
| 202 { |
| 203 if (propertyA.watchIndex == propertyB.watchIndex) |
| 204 return 0; |
| 205 else if (propertyA.watchIndex < propertyB.watchIndex) |
| 206 return -1; |
| 207 else |
| 208 return 1; |
| 209 } |
| 210 |
| 211 WebInspector.WatchExpressionTreeElement = function(property) |
| 212 { |
| 213 WebInspector.ObjectPropertyTreeElement.call(this, property); |
| 214 } |
| 215 |
| 216 WebInspector.WatchExpressionTreeElement.prototype = { |
| 217 update: function() |
| 218 { |
| 219 WebInspector.ObjectPropertyTreeElement.prototype.update.call(this); |
| 220 |
| 221 var deleteButton = document.createElement("input"); |
| 222 deleteButton.type = "button"; |
| 223 deleteButton.title = WebInspector.UIString("Delete watch expression."); |
| 224 deleteButton.addStyleClass("enabled-button"); |
| 225 deleteButton.addStyleClass("delete-button"); |
| 226 deleteButton.addEventListener("click", this._deleteButtonClicked.bind(th
is), false); |
| 227 |
| 228 this.listItemElement.insertBefore(deleteButton, this.listItemElement.fir
stChild); |
| 229 }, |
| 230 |
| 231 _deleteButtonClicked: function() |
| 232 { |
| 233 this.treeOutline.section.updateExpression(this, null); |
| 234 }, |
| 235 |
| 236 startEditing: function() |
| 237 { |
| 238 if (WebInspector.isBeingEdited(this.nameElement) || !this.treeOutline.se
ction.editable) |
| 239 return; |
| 240 |
| 241 this.nameElement.textContent = this.property.name.trimWhitespace(); |
| 242 |
| 243 var context = { expanded: this.expanded }; |
| 244 |
| 245 // collapse temporarily, if required |
| 246 this.hasChildren = false; |
| 247 |
| 248 this.listItemElement.addStyleClass("editing-sub-part"); |
| 249 |
| 250 WebInspector.startEditing(this.nameElement, this.editingCommitted.bind(t
his), this.editingCancelled.bind(this), context); |
| 251 }, |
| 252 |
| 253 editingCancelled: function(element, context) |
| 254 { |
| 255 if (!this.nameElement.textContent) |
| 256 this.treeOutline.section.updateExpression(this, null); |
| 257 |
| 258 this.update(); |
| 259 this.editingEnded(context); |
| 260 }, |
| 261 |
| 262 applyExpression: function(expression, updateInterface) |
| 263 { |
| 264 expression = expression.trimWhitespace(); |
| 265 |
| 266 if (!expression) |
| 267 expression = null; |
| 268 |
| 269 this.property.name = expression; |
| 270 this.treeOutline.section.updateExpression(this, expression); |
| 271 } |
| 272 } |
| 273 |
| 274 WebInspector.WatchExpressionTreeElement.prototype.__proto__ = WebInspector.Objec
tPropertyTreeElement.prototype; |
OLD | NEW |