| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library script_inset_element; | 5 library script_inset_element; |
| 6 | 6 |
| 7 import 'observatory_element.dart'; | 7 import 'observatory_element.dart'; |
| 8 import 'package:observatory/service.dart'; | 8 import 'package:observatory/service.dart'; |
| 9 import 'package:polymer/polymer.dart'; | 9 import 'package:polymer/polymer.dart'; |
| 10 | 10 |
| 11 /// Displays an Error response. | 11 /// Box with script source code in it. |
| 12 @CustomTag('script-inset') | 12 @CustomTag('script-inset') |
| 13 class ScriptInsetElement extends ObservatoryElement { | 13 class ScriptInsetElement extends ObservatoryElement { |
| 14 @published Script script; | 14 @published Script script; |
| 15 @published int pos; | 15 @published int pos; |
| 16 @published int endPos; |
| 17 @published bool coverage = false; |
| 16 | 18 |
| 17 @observable List<ScriptLine> lines = toObservable([]); | 19 @observable List<ScriptLine> lines = toObservable([]); |
| 18 | 20 |
| 19 void scriptChanged(oldValue) { | 21 void scriptChanged(oldValue) { |
| 20 _updateProperties(); | 22 _updateProperties(); |
| 23 notifyPropertyChange(#hitStyle, 0, 1); |
| 21 } | 24 } |
| 22 | 25 |
| 23 void posChanged(oldValue) { | 26 void posChanged(oldValue) { |
| 24 _updateProperties(); | 27 _updateProperties(); |
| 25 } | 28 } |
| 26 | 29 |
| 30 coverageChanged(oldValue) { |
| 31 notifyPropertyChange(#lines, 0, 1); |
| 32 notifyPropertyChange(#hitStyle, 0, 1); |
| 33 } |
| 34 |
| 35 static const hitStyleNone = 'min-width:32px;'; |
| 36 static const hitStyleExecuted = 'min-width:32px;background-color:green'; |
| 37 static const hitStyleNotExecuted = 'min-width:32px;background-color:red'; |
| 38 |
| 39 @observable String hitStyle(ScriptLine line) { |
| 40 if ((script == null) || !coverage) { |
| 41 return hitStyleNone; |
| 42 } |
| 43 var hit = script.hits[line.line]; |
| 44 if (hit == null) { |
| 45 return hitStyleNone; |
| 46 } |
| 47 if (hit == 0) { |
| 48 return hitStyleNotExecuted; |
| 49 } |
| 50 assert(hit > 0); |
| 51 return hitStyleExecuted; |
| 52 } |
| 53 |
| 54 |
| 27 void _updateProperties() { | 55 void _updateProperties() { |
| 28 if (!script.loaded) { | 56 if (!script.loaded) { |
| 29 script.load().then((_) { | 57 script.load().then((_) { |
| 30 if (script.loaded) { | 58 if (script.loaded) { |
| 31 _updateProperties(); | 59 _updateProperties(); |
| 32 } | 60 } |
| 33 }); | 61 }); |
| 34 return; | 62 return; |
| 35 } | 63 } |
| 36 notifyPropertyChange(#lines, 0, 1); | 64 notifyPropertyChange(#lines, 0, 1); |
| 37 var lineNumber = script.tokenToLine(pos); | |
| 38 lines.clear(); | 65 lines.clear(); |
| 39 lines.add(script.lines[lineNumber-1]); | 66 var startLineNumber = script.tokenToLine(pos); |
| 67 if (endPos == null) { |
| 68 lines.add(script.lines[startLineNumber - 1]); |
| 69 } else { |
| 70 var endLineNumber = script.tokenToLine(endPos); |
| 71 assert(endLineNumber != null); |
| 72 for (var i = startLineNumber; i <= endLineNumber; i++) { |
| 73 lines.add(script.lines[i - 1]); |
| 74 } |
| 75 } |
| 40 } | 76 } |
| 41 | 77 |
| 42 ScriptInsetElement.created() : super.created(); | 78 ScriptInsetElement.created() : super.created(); |
| 43 } | 79 } |
| OLD | NEW |