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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 * @param {!Common.TextRange} newRange | 207 * @param {!Common.TextRange} newRange |
208 */ | 208 */ |
209 onTextChanged(oldRange, newRange) { | 209 onTextChanged(oldRange, newRange) { |
210 if (this._diff) | 210 if (this._diff) |
211 this._diff.updateDiffMarkersWhenPossible(); | 211 this._diff.updateDiffMarkersWhenPossible(); |
212 super.onTextChanged(oldRange, newRange); | 212 super.onTextChanged(oldRange, newRange); |
213 this._errorPopoverHelper.hidePopover(); | 213 this._errorPopoverHelper.hidePopover(); |
214 if (this._isSettingContent) | 214 if (this._isSettingContent) |
215 return; | 215 return; |
216 this._muteSourceCodeEvents = true; | 216 this._muteSourceCodeEvents = true; |
217 if (this._textEditor.isClean()) | 217 if (this.textEditor.isClean()) |
218 this._uiSourceCode.resetWorkingCopy(); | 218 this._uiSourceCode.resetWorkingCopy(); |
219 else | 219 else |
220 this._uiSourceCode.setWorkingCopyGetter(this._textEditor.text.bind(this._t
extEditor)); | 220 this._uiSourceCode.setWorkingCopyGetter(this.textEditor.text.bind(this.tex
tEditor)); |
221 delete this._muteSourceCodeEvents; | 221 delete this._muteSourceCodeEvents; |
222 } | 222 } |
223 | 223 |
224 /** | 224 /** |
225 * @param {!Common.Event} event | 225 * @param {!Common.Event} event |
226 */ | 226 */ |
227 _onWorkingCopyChanged(event) { | 227 _onWorkingCopyChanged(event) { |
228 if (this._muteSourceCodeEvents) | 228 if (this._muteSourceCodeEvents) |
229 return; | 229 return; |
230 this._innerSetContent(this._uiSourceCode.workingCopy()); | 230 this._innerSetContent(this._uiSourceCode.workingCopy()); |
231 this.onUISourceCodeContentChanged(); | 231 this.onUISourceCodeContentChanged(); |
232 } | 232 } |
233 | 233 |
234 /** | 234 /** |
235 * @param {!Common.Event} event | 235 * @param {!Common.Event} event |
236 */ | 236 */ |
237 _onWorkingCopyCommitted(event) { | 237 _onWorkingCopyCommitted(event) { |
238 if (!this._muteSourceCodeEvents) { | 238 if (!this._muteSourceCodeEvents) { |
239 this._innerSetContent(this._uiSourceCode.workingCopy()); | 239 this._innerSetContent(this._uiSourceCode.workingCopy()); |
240 this.onUISourceCodeContentChanged(); | 240 this.onUISourceCodeContentChanged(); |
241 } | 241 } |
242 this._textEditor.markClean(); | 242 this.textEditor.markClean(); |
243 this._updateStyle(); | 243 this._updateStyle(); |
244 } | 244 } |
245 | 245 |
246 _onBindingChanged() { | 246 _onBindingChanged() { |
247 var binding = Persistence.persistence.binding(this._uiSourceCode); | 247 var binding = Persistence.persistence.binding(this._uiSourceCode); |
248 if (binding === this._persistenceBinding) | 248 if (binding === this._persistenceBinding) |
249 return; | 249 return; |
250 for (var message of this._allMessages()) | 250 for (var message of this._allMessages()) |
251 this._removeMessageFromSource(message); | 251 this._removeMessageFromSource(message); |
252 Common.EventTarget.removeEventListeners(this._messageAndDecorationListeners)
; | 252 Common.EventTarget.removeEventListeners(this._messageAndDecorationListeners)
; |
(...skipping 19 matching lines...) Expand all Loading... |
272 this.element.classList.toggle( | 272 this.element.classList.toggle( |
273 'source-frame-unsaved-committed-changes', | 273 'source-frame-unsaved-committed-changes', |
274 Persistence.persistence.hasUnsavedCommittedChanges(this._uiSourceCode)); | 274 Persistence.persistence.hasUnsavedCommittedChanges(this._uiSourceCode)); |
275 this.setEditable(!this._canEditSource()); | 275 this.setEditable(!this._canEditSource()); |
276 } | 276 } |
277 | 277 |
278 onUISourceCodeContentChanged() { | 278 onUISourceCodeContentChanged() { |
279 } | 279 } |
280 | 280 |
281 _updateAutocomplete() { | 281 _updateAutocomplete() { |
282 this._textEditor.configureAutocomplete( | 282 this.textEditor.configureAutocomplete( |
283 Common.moduleSetting('textEditorAutocompletion').get() ? this._autocompl
eteConfig : null); | 283 Common.moduleSetting('textEditorAutocompletion').get() ? this._autocompl
eteConfig : null); |
284 } | 284 } |
285 | 285 |
286 /** | 286 /** |
287 * @param {?UI.AutocompleteConfig} config | 287 * @param {?UI.AutocompleteConfig} config |
288 */ | 288 */ |
289 configureAutocomplete(config) { | 289 configureAutocomplete(config) { |
290 this._autocompleteConfig = config; | 290 this._autocompleteConfig = config; |
291 this._updateAutocomplete(); | 291 this._updateAutocomplete(); |
292 } | 292 } |
293 | 293 |
294 /** | 294 /** |
295 * @param {string} content | 295 * @param {string} content |
296 */ | 296 */ |
297 _innerSetContent(content) { | 297 _innerSetContent(content) { |
298 this._isSettingContent = true; | 298 this._isSettingContent = true; |
299 if (this._diff) { | 299 if (this._diff) { |
300 var oldContent = this._textEditor.text(); | 300 var oldContent = this.textEditor.text(); |
301 this.setContent(content); | 301 this.setContent(content); |
302 this._diff.highlightModifiedLines(oldContent, content); | 302 this._diff.highlightModifiedLines(oldContent, content); |
303 } else { | 303 } else { |
304 this.setContent(content); | 304 this.setContent(content); |
305 } | 305 } |
306 delete this._isSettingContent; | 306 delete this._isSettingContent; |
307 } | 307 } |
308 | 308 |
309 /** | 309 /** |
310 * @override | 310 * @override |
(...skipping 20 matching lines...) Expand all Loading... |
331 var infobar = infobars[i]; | 331 var infobar = infobars[i]; |
332 if (!infobar) | 332 if (!infobar) |
333 continue; | 333 continue; |
334 this.element.insertBefore(infobar.element, this.element.children[0]); | 334 this.element.insertBefore(infobar.element, this.element.children[0]); |
335 infobar.setParentView(this); | 335 infobar.setParentView(this); |
336 } | 336 } |
337 this.doResize(); | 337 this.doResize(); |
338 } | 338 } |
339 | 339 |
340 dispose() { | 340 dispose() { |
341 this._textEditor.dispose(); | 341 this.textEditor.dispose(); |
342 Common.moduleSetting('textEditorAutocompletion').removeChangeListener(this._
updateAutocomplete, this); | 342 Common.moduleSetting('textEditorAutocompletion').removeChangeListener(this._
updateAutocomplete, this); |
343 this.detach(); | 343 this.detach(); |
344 } | 344 } |
345 | 345 |
346 /** | 346 /** |
347 * @param {!Common.Event} event | 347 * @param {!Common.Event} event |
348 */ | 348 */ |
349 _onMessageAdded(event) { | 349 _onMessageAdded(event) { |
350 var message = /** @type {!Workspace.UISourceCode.Message} */ (event.data); | 350 var message = /** @type {!Workspace.UISourceCode.Message} */ (event.data); |
351 this._addMessageToSource(message); | 351 this._addMessageToSource(message); |
352 } | 352 } |
353 | 353 |
354 /** | 354 /** |
355 * @param {!Workspace.UISourceCode.Message} message | 355 * @param {!Workspace.UISourceCode.Message} message |
356 */ | 356 */ |
357 _addMessageToSource(message) { | 357 _addMessageToSource(message) { |
358 if (!this.loaded) | 358 if (!this.loaded) |
359 return; | 359 return; |
360 var lineNumber = message.lineNumber(); | 360 var lineNumber = message.lineNumber(); |
361 if (lineNumber >= this._textEditor.linesCount) | 361 if (lineNumber >= this.textEditor.linesCount) |
362 lineNumber = this._textEditor.linesCount - 1; | 362 lineNumber = this.textEditor.linesCount - 1; |
363 if (lineNumber < 0) | 363 if (lineNumber < 0) |
364 lineNumber = 0; | 364 lineNumber = 0; |
365 | 365 |
366 var messageBucket = this._rowMessageBuckets.get(lineNumber); | 366 var messageBucket = this._rowMessageBuckets.get(lineNumber); |
367 if (!messageBucket) { | 367 if (!messageBucket) { |
368 messageBucket = new Sources.UISourceCodeFrame.RowMessageBucket(this, this.
_textEditor, lineNumber); | 368 messageBucket = new Sources.UISourceCodeFrame.RowMessageBucket(this, this.
textEditor, lineNumber); |
369 this._rowMessageBuckets.set(lineNumber, messageBucket); | 369 this._rowMessageBuckets.set(lineNumber, messageBucket); |
370 } | 370 } |
371 messageBucket.addMessage(message); | 371 messageBucket.addMessage(message); |
372 } | 372 } |
373 | 373 |
374 /** | 374 /** |
375 * @param {!Common.Event} event | 375 * @param {!Common.Event} event |
376 */ | 376 */ |
377 _onMessageRemoved(event) { | 377 _onMessageRemoved(event) { |
378 var message = /** @type {!Workspace.UISourceCode.Message} */ (event.data); | 378 var message = /** @type {!Workspace.UISourceCode.Message} */ (event.data); |
379 this._removeMessageFromSource(message); | 379 this._removeMessageFromSource(message); |
380 } | 380 } |
381 | 381 |
382 /** | 382 /** |
383 * @param {!Workspace.UISourceCode.Message} message | 383 * @param {!Workspace.UISourceCode.Message} message |
384 */ | 384 */ |
385 _removeMessageFromSource(message) { | 385 _removeMessageFromSource(message) { |
386 if (!this.loaded) | 386 if (!this.loaded) |
387 return; | 387 return; |
388 | 388 |
389 var lineNumber = message.lineNumber(); | 389 var lineNumber = message.lineNumber(); |
390 if (lineNumber >= this._textEditor.linesCount) | 390 if (lineNumber >= this.textEditor.linesCount) |
391 lineNumber = this._textEditor.linesCount - 1; | 391 lineNumber = this.textEditor.linesCount - 1; |
392 if (lineNumber < 0) | 392 if (lineNumber < 0) |
393 lineNumber = 0; | 393 lineNumber = 0; |
394 | 394 |
395 var messageBucket = this._rowMessageBuckets.get(lineNumber); | 395 var messageBucket = this._rowMessageBuckets.get(lineNumber); |
396 if (!messageBucket) | 396 if (!messageBucket) |
397 return; | 397 return; |
398 messageBucket.removeMessage(message); | 398 messageBucket.removeMessage(message); |
399 if (!messageBucket.uniqueMessagesCount()) { | 399 if (!messageBucket.uniqueMessagesCount()) { |
400 messageBucket.detachFromEditor(); | 400 messageBucket.detachFromEditor(); |
401 this._rowMessageBuckets.delete(lineNumber); | 401 this._rowMessageBuckets.delete(lineNumber); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 _decorateTypeThrottled(type) { | 455 _decorateTypeThrottled(type) { |
456 if (this._typeDecorationsPending.has(type)) | 456 if (this._typeDecorationsPending.has(type)) |
457 return; | 457 return; |
458 this._typeDecorationsPending.add(type); | 458 this._typeDecorationsPending.add(type); |
459 self.runtime.extensions(Sources.UISourceCodeFrame.LineDecorator) | 459 self.runtime.extensions(Sources.UISourceCodeFrame.LineDecorator) |
460 .find(extension => extension.descriptor()['decoratorType'] === type) | 460 .find(extension => extension.descriptor()['decoratorType'] === type) |
461 .instance() | 461 .instance() |
462 .then(decorator => { | 462 .then(decorator => { |
463 this._typeDecorationsPending.delete(type); | 463 this._typeDecorationsPending.delete(type); |
464 decorator.decorate( | 464 decorator.decorate( |
465 this._persistenceBinding ? this._persistenceBinding.network : this
.uiSourceCode(), this._textEditor); | 465 this._persistenceBinding ? this._persistenceBinding.network : this
.uiSourceCode(), this.textEditor); |
466 }); | 466 }); |
467 } | 467 } |
468 | 468 |
469 _decorateAllTypes() { | 469 _decorateAllTypes() { |
470 var extensions = self.runtime.extensions(Sources.UISourceCodeFrame.LineDecor
ator); | 470 var extensions = self.runtime.extensions(Sources.UISourceCodeFrame.LineDecor
ator); |
471 extensions.forEach(extension => this._decorateTypeThrottled(extension.descri
ptor()['decoratorType'])); | 471 extensions.forEach(extension => this._decorateTypeThrottled(extension.descri
ptor()['decoratorType'])); |
472 } | 472 } |
473 }; | 473 }; |
474 | 474 |
475 Sources.UISourceCodeFrame._iconClassPerLevel = {}; | 475 Sources.UISourceCodeFrame._iconClassPerLevel = {}; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 * @unrestricted | 555 * @unrestricted |
556 */ | 556 */ |
557 Sources.UISourceCodeFrame.RowMessageBucket = class { | 557 Sources.UISourceCodeFrame.RowMessageBucket = class { |
558 /** | 558 /** |
559 * @param {!Sources.UISourceCodeFrame} sourceFrame | 559 * @param {!Sources.UISourceCodeFrame} sourceFrame |
560 * @param {!TextEditor.CodeMirrorTextEditor} textEditor | 560 * @param {!TextEditor.CodeMirrorTextEditor} textEditor |
561 * @param {number} lineNumber | 561 * @param {number} lineNumber |
562 */ | 562 */ |
563 constructor(sourceFrame, textEditor, lineNumber) { | 563 constructor(sourceFrame, textEditor, lineNumber) { |
564 this._sourceFrame = sourceFrame; | 564 this._sourceFrame = sourceFrame; |
565 this._textEditor = textEditor; | 565 this.textEditor = textEditor; |
566 this._lineHandle = textEditor.textEditorPositionHandle(lineNumber, 0); | 566 this._lineHandle = textEditor.textEditorPositionHandle(lineNumber, 0); |
567 this._decoration = createElementWithClass('div', 'text-editor-line-decoratio
n'); | 567 this._decoration = createElementWithClass('div', 'text-editor-line-decoratio
n'); |
568 this._decoration._messageBucket = this; | 568 this._decoration._messageBucket = this; |
569 this._wave = this._decoration.createChild('div', 'text-editor-line-decoratio
n-wave'); | 569 this._wave = this._decoration.createChild('div', 'text-editor-line-decoratio
n-wave'); |
570 this._icon = this._wave.createChild('label', 'text-editor-line-decoration-ic
on', 'dt-icon-label'); | 570 this._icon = this._wave.createChild('label', 'text-editor-line-decoration-ic
on', 'dt-icon-label'); |
571 this._hasDecoration = false; | 571 this._hasDecoration = false; |
572 | 572 |
573 this._messagesDescriptionElement = createElementWithClass('div', 'text-edito
r-messages-description-container'); | 573 this._messagesDescriptionElement = createElementWithClass('div', 'text-edito
r-messages-description-container'); |
574 /** @type {!Array.<!Sources.UISourceCodeFrame.RowMessage>} */ | 574 /** @type {!Array.<!Sources.UISourceCodeFrame.RowMessage>} */ |
575 this._messages = []; | 575 this._messages = []; |
576 | 576 |
577 this._level = null; | 577 this._level = null; |
578 } | 578 } |
579 | 579 |
580 /** | 580 /** |
581 * @param {number} lineNumber | 581 * @param {number} lineNumber |
582 * @param {number} columnNumber | 582 * @param {number} columnNumber |
583 */ | 583 */ |
584 _updateWavePosition(lineNumber, columnNumber) { | 584 _updateWavePosition(lineNumber, columnNumber) { |
585 lineNumber = Math.min(lineNumber, this._textEditor.linesCount - 1); | 585 lineNumber = Math.min(lineNumber, this.textEditor.linesCount - 1); |
586 var lineText = this._textEditor.line(lineNumber); | 586 var lineText = this.textEditor.line(lineNumber); |
587 columnNumber = Math.min(columnNumber, lineText.length); | 587 columnNumber = Math.min(columnNumber, lineText.length); |
588 var lineIndent = Common.TextUtils.lineIndent(lineText).length; | 588 var lineIndent = Common.TextUtils.lineIndent(lineText).length; |
589 if (this._hasDecoration) | 589 if (this._hasDecoration) |
590 this._textEditor.removeDecoration(this._decoration, lineNumber); | 590 this.textEditor.removeDecoration(this._decoration, lineNumber); |
591 this._hasDecoration = true; | 591 this._hasDecoration = true; |
592 this._textEditor.addDecoration(this._decoration, lineNumber, Math.max(column
Number - 1, lineIndent)); | 592 this.textEditor.addDecoration(this._decoration, lineNumber, Math.max(columnN
umber - 1, lineIndent)); |
593 } | 593 } |
594 | 594 |
595 /** | 595 /** |
596 * @return {!Element} | 596 * @return {!Element} |
597 */ | 597 */ |
598 messagesDescription() { | 598 messagesDescription() { |
599 this._messagesDescriptionElement.removeChildren(); | 599 this._messagesDescriptionElement.removeChildren(); |
600 for (var i = 0; i < this._messages.length; ++i) | 600 for (var i = 0; i < this._messages.length; ++i) |
601 this._messagesDescriptionElement.appendChild(this._messages[i].element); | 601 this._messagesDescriptionElement.appendChild(this._messages[i].element); |
602 | 602 |
603 return this._messagesDescriptionElement; | 603 return this._messagesDescriptionElement; |
604 } | 604 } |
605 | 605 |
606 detachFromEditor() { | 606 detachFromEditor() { |
607 var position = this._lineHandle.resolve(); | 607 var position = this._lineHandle.resolve(); |
608 if (!position) | 608 if (!position) |
609 return; | 609 return; |
610 var lineNumber = position.lineNumber; | 610 var lineNumber = position.lineNumber; |
611 if (this._level) | 611 if (this._level) |
612 this._textEditor.toggleLineClass(lineNumber, Sources.UISourceCodeFrame._li
neClassPerLevel[this._level], false); | 612 this.textEditor.toggleLineClass(lineNumber, Sources.UISourceCodeFrame._lin
eClassPerLevel[this._level], false); |
613 if (this._hasDecoration) | 613 if (this._hasDecoration) |
614 this._textEditor.removeDecoration(this._decoration, lineNumber); | 614 this.textEditor.removeDecoration(this._decoration, lineNumber); |
615 this._hasDecoration = false; | 615 this._hasDecoration = false; |
616 } | 616 } |
617 | 617 |
618 /** | 618 /** |
619 * @return {number} | 619 * @return {number} |
620 */ | 620 */ |
621 uniqueMessagesCount() { | 621 uniqueMessagesCount() { |
622 return this._messages.length; | 622 return this._messages.length; |
623 } | 623 } |
624 | 624 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 var maxMessage = null; | 669 var maxMessage = null; |
670 for (var i = 0; i < this._messages.length; ++i) { | 670 for (var i = 0; i < this._messages.length; ++i) { |
671 var message = this._messages[i].message(); | 671 var message = this._messages[i].message(); |
672 columnNumber = Math.min(columnNumber, message.columnNumber()); | 672 columnNumber = Math.min(columnNumber, message.columnNumber()); |
673 if (!maxMessage || Workspace.UISourceCode.Message.messageLevelComparator(m
axMessage, message) < 0) | 673 if (!maxMessage || Workspace.UISourceCode.Message.messageLevelComparator(m
axMessage, message) < 0) |
674 maxMessage = message; | 674 maxMessage = message; |
675 } | 675 } |
676 this._updateWavePosition(lineNumber, columnNumber); | 676 this._updateWavePosition(lineNumber, columnNumber); |
677 | 677 |
678 if (this._level) { | 678 if (this._level) { |
679 this._textEditor.toggleLineClass(lineNumber, Sources.UISourceCodeFrame._li
neClassPerLevel[this._level], false); | 679 this.textEditor.toggleLineClass(lineNumber, Sources.UISourceCodeFrame._lin
eClassPerLevel[this._level], false); |
680 this._icon.type = ''; | 680 this._icon.type = ''; |
681 } | 681 } |
682 this._level = maxMessage.level(); | 682 this._level = maxMessage.level(); |
683 if (!this._level) | 683 if (!this._level) |
684 return; | 684 return; |
685 this._textEditor.toggleLineClass(lineNumber, Sources.UISourceCodeFrame._line
ClassPerLevel[this._level], true); | 685 this.textEditor.toggleLineClass(lineNumber, Sources.UISourceCodeFrame._lineC
lassPerLevel[this._level], true); |
686 this._icon.type = Sources.UISourceCodeFrame._iconClassPerLevel[this._level]; | 686 this._icon.type = Sources.UISourceCodeFrame._iconClassPerLevel[this._level]; |
687 } | 687 } |
688 }; | 688 }; |
689 | 689 |
690 Workspace.UISourceCode.Message._messageLevelPriority = { | 690 Workspace.UISourceCode.Message._messageLevelPriority = { |
691 'Warning': 3, | 691 'Warning': 3, |
692 'Error': 4 | 692 'Error': 4 |
693 }; | 693 }; |
694 | 694 |
695 /** | 695 /** |
696 * @param {!Workspace.UISourceCode.Message} a | 696 * @param {!Workspace.UISourceCode.Message} a |
697 * @param {!Workspace.UISourceCode.Message} b | 697 * @param {!Workspace.UISourceCode.Message} b |
698 * @return {number} | 698 * @return {number} |
699 */ | 699 */ |
700 Workspace.UISourceCode.Message.messageLevelComparator = function(a, b) { | 700 Workspace.UISourceCode.Message.messageLevelComparator = function(a, b) { |
701 return Workspace.UISourceCode.Message._messageLevelPriority[a.level()] - | 701 return Workspace.UISourceCode.Message._messageLevelPriority[a.level()] - |
702 Workspace.UISourceCode.Message._messageLevelPriority[b.level()]; | 702 Workspace.UISourceCode.Message._messageLevelPriority[b.level()]; |
703 }; | 703 }; |
OLD | NEW |