| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. 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 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * | 10 * |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 * @param {!WebInspector.UISourceCode} uiSourceCode | 32 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 33 */ | 33 */ |
| 34 WebInspector.UISourceCodeFrame = function(uiSourceCode) | 34 WebInspector.UISourceCodeFrame = function(uiSourceCode) |
| 35 { | 35 { |
| 36 this._uiSourceCode = uiSourceCode; | 36 this._uiSourceCode = uiSourceCode; |
| 37 WebInspector.SourceFrame.call(this, this._uiSourceCode); | 37 WebInspector.SourceFrame.call(this, this._uiSourceCode); |
| 38 this.textEditor.setAutocompleteDelegate(new WebInspector.SimpleAutocompleteD
elegate()); | 38 this.textEditor.setAutocompleteDelegate(new WebInspector.SimpleAutocompleteD
elegate()); |
| 39 this._rowMessageBuckets = {}; | 39 this._rowMessageBuckets = {}; |
| 40 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working
CopyChanged, this._onWorkingCopyChanged, this); | 40 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working
CopyChanged, this._onWorkingCopyChanged, this); |
| 41 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working
CopyCommitted, this._onWorkingCopyCommitted, this); | 41 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Working
CopyCommitted, this._onWorkingCopyCommitted, this); |
| 42 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Message
Added, this._onMessageAdded, this); |
| 43 this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.Message
Removed, this._onMessageRemoved, this); |
| 42 this._updateStyle(); | 44 this._updateStyle(); |
| 43 | 45 |
| 44 this._errorPopoverHelper = new WebInspector.PopoverHelper(this.element, this
._getErrorAnchor.bind(this), this._showErrorPopover.bind(this)); | 46 this._errorPopoverHelper = new WebInspector.PopoverHelper(this.element, this
._getErrorAnchor.bind(this), this._showErrorPopover.bind(this)); |
| 45 this._errorPopoverHelper.setTimeout(100, 100); | 47 this._errorPopoverHelper.setTimeout(100, 100); |
| 46 } | 48 } |
| 47 | 49 |
| 48 WebInspector.UISourceCodeFrame.prototype = { | 50 WebInspector.UISourceCodeFrame.prototype = { |
| 49 /** | 51 /** |
| 50 * @return {!WebInspector.UISourceCode} | 52 * @return {!WebInspector.UISourceCode} |
| 51 */ | 53 */ |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 commitEditing: function() | 103 commitEditing: function() |
| 102 { | 104 { |
| 103 if (!this._uiSourceCode.isDirty()) | 105 if (!this._uiSourceCode.isDirty()) |
| 104 return; | 106 return; |
| 105 | 107 |
| 106 this._muteSourceCodeEvents = true; | 108 this._muteSourceCodeEvents = true; |
| 107 this._uiSourceCode.commitWorkingCopy(); | 109 this._uiSourceCode.commitWorkingCopy(); |
| 108 delete this._muteSourceCodeEvents; | 110 delete this._muteSourceCodeEvents; |
| 109 }, | 111 }, |
| 110 | 112 |
| 113 /** |
| 114 * @override |
| 115 */ |
| 116 onTextEditorContentLoaded: function() |
| 117 { |
| 118 WebInspector.SourceFrame.prototype.onTextEditorContentLoaded.call(this); |
| 119 for (var message of this._uiSourceCode.messages()) |
| 120 this._addMessageToSource(message); |
| 121 }, |
| 122 |
| 123 /** |
| 124 * @override |
| 125 * @param {!WebInspector.TextRange} oldRange |
| 126 * @param {!WebInspector.TextRange} newRange |
| 127 */ |
| 111 onTextChanged: function(oldRange, newRange) | 128 onTextChanged: function(oldRange, newRange) |
| 112 { | 129 { |
| 113 WebInspector.SourceFrame.prototype.onTextChanged.call(this, oldRange, ne
wRange); | 130 WebInspector.SourceFrame.prototype.onTextChanged.call(this, oldRange, ne
wRange); |
| 114 this.clearMessages(); | 131 this._clearMessages(); |
| 115 if (this._isSettingContent) | 132 if (this._isSettingContent) |
| 116 return; | 133 return; |
| 117 this._muteSourceCodeEvents = true; | 134 this._muteSourceCodeEvents = true; |
| 118 if (this._textEditor.isClean()) | 135 if (this._textEditor.isClean()) |
| 119 this._uiSourceCode.resetWorkingCopy(); | 136 this._uiSourceCode.resetWorkingCopy(); |
| 120 else | 137 else |
| 121 this._uiSourceCode.setWorkingCopyGetter(this._textEditor.text.bind(t
his._textEditor)); | 138 this._uiSourceCode.setWorkingCopyGetter(this._textEditor.text.bind(t
his._textEditor)); |
| 122 delete this._muteSourceCodeEvents; | 139 delete this._muteSourceCodeEvents; |
| 123 }, | 140 }, |
| 124 | 141 |
| 125 onTextEditorContentLoaded: function() | |
| 126 { | |
| 127 WebInspector.SourceFrame.prototype.onTextEditorContentLoaded.call(this); | |
| 128 this.clearMessages(); | |
| 129 }, | |
| 130 | |
| 131 /** | 142 /** |
| 132 * @param {!WebInspector.Event} event | 143 * @param {!WebInspector.Event} event |
| 133 */ | 144 */ |
| 134 _onWorkingCopyChanged: function(event) | 145 _onWorkingCopyChanged: function(event) |
| 135 { | 146 { |
| 136 if (this._muteSourceCodeEvents) | 147 if (this._muteSourceCodeEvents) |
| 137 return; | 148 return; |
| 138 this._innerSetContent(this._uiSourceCode.workingCopy()); | 149 this._innerSetContent(this._uiSourceCode.workingCopy()); |
| 139 this.onUISourceCodeContentChanged(); | 150 this.onUISourceCodeContentChanged(); |
| 140 }, | 151 }, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 this.doResize(); | 205 this.doResize(); |
| 195 }, | 206 }, |
| 196 | 207 |
| 197 dispose: function() | 208 dispose: function() |
| 198 { | 209 { |
| 199 this._textEditor.dispose(); | 210 this._textEditor.dispose(); |
| 200 this.detach(); | 211 this.detach(); |
| 201 }, | 212 }, |
| 202 | 213 |
| 203 /** | 214 /** |
| 215 * @param {!WebInspector.Event} event |
| 216 */ |
| 217 _onMessageAdded: function(event) |
| 218 { |
| 219 if (!this.loaded) |
| 220 return; |
| 221 var message = /** @type {!WebInspector.UISourceCode.Message} */ (event.d
ata); |
| 222 this._addMessageToSource(message); |
| 223 }, |
| 224 |
| 225 /** |
| 204 * @param {!WebInspector.UISourceCode.Message} message | 226 * @param {!WebInspector.UISourceCode.Message} message |
| 205 */ | 227 */ |
| 206 addMessageToSource: function(message) | 228 _addMessageToSource: function(message) |
| 207 { | 229 { |
| 208 var lineNumber = message.lineNumber(); | 230 var lineNumber = message.lineNumber(); |
| 209 if (lineNumber >= this._textEditor.linesCount) | 231 if (lineNumber >= this._textEditor.linesCount) |
| 210 lineNumber = this._textEditor.linesCount - 1; | 232 lineNumber = this._textEditor.linesCount - 1; |
| 211 if (lineNumber < 0) | 233 if (lineNumber < 0) |
| 212 lineNumber = 0; | 234 lineNumber = 0; |
| 213 | 235 |
| 214 if (!this._rowMessageBuckets[lineNumber]) | 236 if (!this._rowMessageBuckets[lineNumber]) |
| 215 this._rowMessageBuckets[lineNumber] = new WebInspector.UISourceCodeF
rame.RowMessageBucket(this, this._textEditor, lineNumber); | 237 this._rowMessageBuckets[lineNumber] = new WebInspector.UISourceCodeF
rame.RowMessageBucket(this, this._textEditor, lineNumber); |
| 216 var messageBucket = this._rowMessageBuckets[lineNumber]; | 238 var messageBucket = this._rowMessageBuckets[lineNumber]; |
| 217 messageBucket.addMessage(message); | 239 messageBucket.addMessage(message); |
| 218 }, | 240 }, |
| 219 | 241 |
| 220 /** | 242 /** |
| 243 * @param {!WebInspector.Event} event |
| 244 */ |
| 245 _onMessageRemoved: function(event) |
| 246 { |
| 247 if (!this.loaded) |
| 248 return; |
| 249 var message = /** @type {!WebInspector.UISourceCode.Message} */ (event.d
ata); |
| 250 this._removeMessageFromSource(message); |
| 251 }, |
| 252 |
| 253 /** |
| 221 * @param {!WebInspector.UISourceCode.Message} message | 254 * @param {!WebInspector.UISourceCode.Message} message |
| 222 */ | 255 */ |
| 223 removeMessageFromSource: function(message) | 256 _removeMessageFromSource: function(message) |
| 224 { | 257 { |
| 225 var lineNumber = message.lineNumber(); | 258 var lineNumber = message.lineNumber(); |
| 226 if (lineNumber >= this._textEditor.linesCount) | 259 if (lineNumber >= this._textEditor.linesCount) |
| 227 lineNumber = this._textEditor.linesCount - 1; | 260 lineNumber = this._textEditor.linesCount - 1; |
| 228 if (lineNumber < 0) | 261 if (lineNumber < 0) |
| 229 lineNumber = 0; | 262 lineNumber = 0; |
| 230 | 263 |
| 231 var messageBucket = this._rowMessageBuckets[lineNumber]; | 264 var messageBucket = this._rowMessageBuckets[lineNumber]; |
| 232 if (!messageBucket) | 265 if (!messageBucket) |
| 233 return; | 266 return; |
| 234 messageBucket.removeMessage(message); | 267 messageBucket.removeMessage(message); |
| 235 if (!messageBucket.uniqueMessagesCount()) { | 268 if (!messageBucket.uniqueMessagesCount()) { |
| 236 messageBucket.detachFromEditor(); | 269 messageBucket.detachFromEditor(); |
| 237 delete this._rowMessageBuckets[lineNumber]; | 270 delete this._rowMessageBuckets[lineNumber]; |
| 238 } | 271 } |
| 239 }, | 272 }, |
| 240 | 273 |
| 241 clearMessages: function() | 274 _clearMessages: function() |
| 242 { | 275 { |
| 243 for (var line in this._rowMessageBuckets) { | 276 for (var line in this._rowMessageBuckets) { |
| 244 var bubble = this._rowMessageBuckets[line]; | 277 var bubble = this._rowMessageBuckets[line]; |
| 245 bubble.detachFromEditor(); | 278 bubble.detachFromEditor(); |
| 246 } | 279 } |
| 247 | 280 |
| 248 this._rowMessageBuckets = {}; | 281 this._rowMessageBuckets = {}; |
| 249 this._errorPopoverHelper.hidePopover(); | 282 this._errorPopoverHelper.hidePopover(); |
| 283 this._uiSourceCode.removeAllMessages(); |
| 250 }, | 284 }, |
| 251 | 285 |
| 252 /** | 286 /** |
| 253 * @param {!Element} target | 287 * @param {!Element} target |
| 254 * @param {!Event} event | 288 * @param {!Event} event |
| 255 * @return {(!Element|undefined)} | 289 * @return {(!Element|undefined)} |
| 256 */ | 290 */ |
| 257 _getErrorAnchor: function(target, event) | 291 _getErrorAnchor: function(target, event) |
| 258 { | 292 { |
| 259 var element = target.enclosingNodeOrSelfWithClass("text-editor-line-deco
ration-icon") | 293 var element = target.enclosingNodeOrSelfWithClass("text-editor-line-deco
ration-icon") |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 dispose: function() | 388 dispose: function() |
| 355 { | 389 { |
| 356 this.element.remove(); | 390 this.element.remove(); |
| 357 this._onResize(); | 391 this._onResize(); |
| 358 delete this._uiSourceCodeFrame; | 392 delete this._uiSourceCodeFrame; |
| 359 }, | 393 }, |
| 360 | 394 |
| 361 __proto__: WebInspector.Infobar.prototype | 395 __proto__: WebInspector.Infobar.prototype |
| 362 } | 396 } |
| 363 | 397 |
| 364 /** | |
| 365 * @param {!WebInspector.ConsoleMessage} consoleMessage | |
| 366 * @param {number} lineNumber | |
| 367 * @param {number} columnNumber | |
| 368 * @return {!WebInspector.UISourceCode.Message} | |
| 369 */ | |
| 370 WebInspector.UISourceCodeFrame.uiMessageFromConsoleMessage = function(consoleMes
sage, lineNumber, columnNumber) | |
| 371 { | |
| 372 console.assert(consoleMessage.level === WebInspector.ConsoleMessage.MessageL
evel.Error || consoleMessage.level === WebInspector.ConsoleMessage.MessageLevel.
Warning); | |
| 373 var level = consoleMessage.level === WebInspector.ConsoleMessage.MessageLeve
l.Error ? WebInspector.UISourceCode.Message.Level.Error : WebInspector.UISourceC
ode.Message.Level.Warning; | |
| 374 return new WebInspector.UISourceCode.Message(level, consoleMessage.messageTe
xt, lineNumber, columnNumber); | |
| 375 } | |
| 376 | |
| 377 WebInspector.UISourceCodeFrame._iconClassPerLevel = {}; | 398 WebInspector.UISourceCodeFrame._iconClassPerLevel = {}; |
| 378 WebInspector.UISourceCodeFrame._iconClassPerLevel[WebInspector.UISourceCode.Mess
age.Level.Error] = "error-icon"; | 399 WebInspector.UISourceCodeFrame._iconClassPerLevel[WebInspector.UISourceCode.Mess
age.Level.Error] = "error-icon"; |
| 379 WebInspector.UISourceCodeFrame._iconClassPerLevel[WebInspector.UISourceCode.Mess
age.Level.Warning] = "warning-icon"; | 400 WebInspector.UISourceCodeFrame._iconClassPerLevel[WebInspector.UISourceCode.Mess
age.Level.Warning] = "warning-icon"; |
| 380 | 401 |
| 381 WebInspector.UISourceCodeFrame._lineClassPerLevel = {}; | 402 WebInspector.UISourceCodeFrame._lineClassPerLevel = {}; |
| 382 WebInspector.UISourceCodeFrame._lineClassPerLevel[WebInspector.UISourceCode.Mess
age.Level.Error] = "text-editor-line-with-error"; | 403 WebInspector.UISourceCodeFrame._lineClassPerLevel[WebInspector.UISourceCode.Mess
age.Level.Error] = "text-editor-line-with-error"; |
| 383 WebInspector.UISourceCodeFrame._lineClassPerLevel[WebInspector.UISourceCode.Mess
age.Level.Warning] = "text-editor-line-with-warning"; | 404 WebInspector.UISourceCodeFrame._lineClassPerLevel[WebInspector.UISourceCode.Mess
age.Level.Warning] = "text-editor-line-with-warning"; |
| 384 | 405 |
| 385 /** | 406 /** |
| 386 * @constructor | 407 * @constructor |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 | 609 |
| 589 /** | 610 /** |
| 590 * @param {!WebInspector.UISourceCode.Message} a | 611 * @param {!WebInspector.UISourceCode.Message} a |
| 591 * @param {!WebInspector.UISourceCode.Message} b | 612 * @param {!WebInspector.UISourceCode.Message} b |
| 592 * @return {number} | 613 * @return {number} |
| 593 */ | 614 */ |
| 594 WebInspector.UISourceCode.Message.messageLevelComparator = function(a, b) | 615 WebInspector.UISourceCode.Message.messageLevelComparator = function(a, b) |
| 595 { | 616 { |
| 596 return WebInspector.UISourceCode.Message._messageLevelPriority[a.level()] -
WebInspector.UISourceCode.Message._messageLevelPriority[b.level()]; | 617 return WebInspector.UISourceCode.Message._messageLevelPriority[a.level()] -
WebInspector.UISourceCode.Message._messageLevelPriority[b.level()]; |
| 597 } | 618 } |
| OLD | NEW |