OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:html'; | 6 import 'dart:html'; |
7 import 'package:observatory/models.dart' as M show Target; | 7 import 'package:observatory/models.dart' as M show Target; |
8 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | 8 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
9 import 'package:observatory/src/elements/helpers/tag.dart'; | 9 import 'package:observatory/src/elements/helpers/tag.dart'; |
10 import 'package:observatory/src/elements/helpers/uris.dart'; | 10 import 'package:observatory/src/elements/helpers/uris.dart'; |
11 | 11 |
12 class TargetEvent { | 12 class TargetEvent { |
13 final M.Target target; | 13 final M.Target target; |
14 | 14 |
15 TargetEvent(this.target); | 15 TargetEvent(this.target); |
16 } | 16 } |
17 | 17 |
18 class VMConnectTargetElement extends HtmlElement implements Renderable { | 18 class VMConnectTargetElement extends HtmlElement implements Renderable { |
19 | 19 static const tag = const Tag<VMConnectTargetElement>('vm-connect-target'); |
20 static const tag = | |
21 const Tag<VMConnectTargetElement>('vm-connect-target'); | |
22 | 20 |
23 RenderingScheduler<VMConnectTargetElement> _r; | 21 RenderingScheduler<VMConnectTargetElement> _r; |
24 | 22 |
25 Stream<RenderedEvent<VMConnectTargetElement>> get onRendered => _r.onRendered; | 23 Stream<RenderedEvent<VMConnectTargetElement>> get onRendered => _r.onRendered; |
26 | 24 |
27 final StreamController<TargetEvent> _onConnect = | 25 final StreamController<TargetEvent> _onConnect = |
28 new StreamController<TargetEvent>.broadcast(); | 26 new StreamController<TargetEvent>.broadcast(); |
29 Stream<TargetEvent> get onConnect => _onConnect.stream; | 27 Stream<TargetEvent> get onConnect => _onConnect.stream; |
30 final StreamController<TargetEvent> _onDelete = | 28 final StreamController<TargetEvent> _onDelete = |
31 new StreamController<TargetEvent>.broadcast(); | 29 new StreamController<TargetEvent>.broadcast(); |
32 Stream<TargetEvent> get onDelete => _onDelete.stream; | 30 Stream<TargetEvent> get onDelete => _onDelete.stream; |
33 | 31 |
34 M.Target _target; | 32 M.Target _target; |
35 bool _current; | 33 bool _current; |
36 | 34 |
37 M.Target get target => _target; | 35 M.Target get target => _target; |
38 bool get current => _current; | 36 bool get current => _current; |
39 | 37 |
40 factory VMConnectTargetElement(M.Target target, {bool current: false, | 38 factory VMConnectTargetElement(M.Target target, |
41 RenderingQueue queue}) { | 39 {bool current: false, RenderingQueue queue}) { |
42 assert(target != null); | 40 assert(target != null); |
43 assert(current != null); | 41 assert(current != null); |
44 VMConnectTargetElement e = document.createElement(tag.name); | 42 VMConnectTargetElement e = document.createElement(tag.name); |
45 e._r = new RenderingScheduler(e, queue: queue); | 43 e._r = new RenderingScheduler(e, queue: queue); |
46 e._target = target; | 44 e._target = target; |
47 e._current = current; | 45 e._current = current; |
48 return e; | 46 return e; |
49 } | 47 } |
50 | 48 |
51 VMConnectTargetElement.created() : super.created(); | 49 VMConnectTargetElement.created() : super.created(); |
(...skipping 18 matching lines...) Expand all Loading... |
70 void delete() { | 68 void delete() { |
71 _delete(new TargetEvent(target)); | 69 _delete(new TargetEvent(target)); |
72 } | 70 } |
73 | 71 |
74 void render() { | 72 void render() { |
75 children = [ | 73 children = [ |
76 new AnchorElement(href: Uris.vm()) | 74 new AnchorElement(href: Uris.vm()) |
77 ..text = current ? '${target.name} (Connected)' : '${target.name}' | 75 ..text = current ? '${target.name} (Connected)' : '${target.name}' |
78 ..onClick.where(_filter).map(_toEvent).listen(_connect), | 76 ..onClick.where(_filter).map(_toEvent).listen(_connect), |
79 new ButtonElement() | 77 new ButtonElement() |
80 ..text = '✖ Remove' ..classes = ['delete-button'] | 78 ..text = '✖ Remove' |
| 79 ..classes = ['delete-button'] |
81 ..onClick.map(_toEvent).listen(_delete) | 80 ..onClick.map(_toEvent).listen(_delete) |
82 ]; | 81 ]; |
83 } | 82 } |
84 | 83 |
85 void _connect(TargetEvent e) { | 84 void _connect(TargetEvent e) { |
86 _onConnect.add(e); | 85 _onConnect.add(e); |
87 } | 86 } |
88 | 87 |
89 void _delete(TargetEvent e) { | 88 void _delete(TargetEvent e) { |
90 _onDelete.add(e); | 89 _onDelete.add(e); |
91 } | 90 } |
92 | 91 |
93 TargetEvent _toEvent(_) { | 92 TargetEvent _toEvent(_) { |
94 return new TargetEvent(target); | 93 return new TargetEvent(target); |
95 } | 94 } |
96 | 95 |
97 static bool _filter(MouseEvent event) { | 96 static bool _filter(MouseEvent event) { |
98 return !(event.button > 0 || event.metaKey || event.ctrlKey || | 97 return !(event.button > 0 || |
99 event.shiftKey || event.altKey); | 98 event.metaKey || |
| 99 event.ctrlKey || |
| 100 event.shiftKey || |
| 101 event.altKey); |
100 } | 102 } |
101 } | 103 } |
OLD | NEW |