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 trydart.ui; | 5 library trydart.ui; |
6 | 6 |
7 import 'dart:html'; | 7 import 'dart:html'; |
8 | 8 |
9 import 'dart:async' show | 9 import 'dart:async' show |
10 Future, | 10 Future, |
11 Timer, | 11 Timer, |
12 scheduleMicrotask; | 12 scheduleMicrotask; |
13 | 13 |
14 import 'dart:convert' show JSON; | |
15 | |
16 import 'cache.dart' show | 14 import 'cache.dart' show |
17 onLoad, | 15 onLoad, |
18 updateCacheStatus; | 16 updateCacheStatus; |
19 | 17 |
20 import 'interaction_manager.dart' show InteractionManager; | 18 import 'interaction_manager.dart' show InteractionManager; |
21 | 19 |
22 import 'run.dart' show | 20 import 'run.dart' show |
23 makeOutputFrame; | 21 makeOutputFrame; |
24 | 22 |
25 import 'themes.dart' show | 23 import 'themes.dart' show |
26 THEMES, | 24 THEMES, |
27 Theme; | 25 Theme; |
28 | 26 |
29 import 'samples.dart' show | 27 import 'samples.dart' show |
30 EXAMPLE_FIBONACCI, | 28 EXAMPLE_FIBONACCI, |
31 EXAMPLE_FIBONACCI_HTML, | 29 EXAMPLE_FIBONACCI_HTML, |
32 EXAMPLE_HELLO, | 30 EXAMPLE_HELLO, |
33 EXAMPLE_HELLO_HTML, | 31 EXAMPLE_HELLO_HTML, |
34 EXAMPLE_SUNFLOWER; | 32 EXAMPLE_SUNFLOWER; |
35 | 33 |
36 import 'settings.dart'; | 34 import 'settings.dart'; |
37 | 35 |
38 import 'user_option.dart'; | 36 import 'user_option.dart'; |
39 | 37 |
40 import 'messages.dart' show messages; | 38 import 'messages.dart' show messages; |
41 | 39 |
| 40 import 'compilation_unit.dart' show |
| 41 CompilationUnit; |
| 42 |
| 43 import 'compilation.dart' show |
| 44 currentSource; |
| 45 |
42 // TODO(ahe): Make internal to buildUI once all interactions have been moved to | 46 // TODO(ahe): Make internal to buildUI once all interactions have been moved to |
43 // the manager. | 47 // the manager. |
44 InteractionManager interaction; | 48 InteractionManager interaction; |
45 | 49 |
46 DivElement mainEditorPane; | 50 DivElement mainEditorPane; |
47 PreElement outputDiv; | 51 PreElement outputDiv; |
48 DivElement hackDiv; | 52 DivElement hackDiv; |
49 IFrameElement outputFrame; | 53 IFrameElement outputFrame; |
50 MutationObserver observer; | 54 MutationObserver observer; |
51 SpanElement cacheStatusElement; | 55 SpanElement cacheStatusElement; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 SelectElement select = event.target; | 89 SelectElement select = event.target; |
86 String id = select.querySelectorAll('option')[select.selectedIndex].id; | 90 String id = select.querySelectorAll('option')[select.selectedIndex].id; |
87 Function action = codeCallbacks[id]; | 91 Function action = codeCallbacks[id]; |
88 if (action != null) action(event); | 92 if (action != null) action(event); |
89 outputFrame.style.display = 'none'; | 93 outputFrame.style.display = 'none'; |
90 } | 94 } |
91 | 95 |
92 buildUI() { | 96 buildUI() { |
93 interaction = new InteractionManager(); | 97 interaction = new InteractionManager(); |
94 | 98 |
| 99 CompilationUnit.onChanged.listen(interaction.onCompilationUnitChanged); |
| 100 |
95 window.localStorage['currentSample'] = '$currentSample'; | 101 window.localStorage['currentSample'] = '$currentSample'; |
96 | 102 |
97 buildCode(interaction); | 103 buildCode(interaction); |
98 | 104 |
99 (mainEditorPane = new DivElement()) | 105 (mainEditorPane = new DivElement()) |
100 ..classes.add('well') | 106 ..classes.add('well') |
101 ..style.backgroundColor = currentTheme.background.color | 107 ..style.backgroundColor = currentTheme.background.color |
102 ..style.color = currentTheme.foreground.color | 108 ..style.color = currentTheme.foreground.color |
103 ..style.overflow = 'visible' | 109 ..style.overflow = 'visible' |
104 ..style.whiteSpace = 'pre' | 110 ..style.whiteSpace = 'pre' |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } | 207 } |
202 } | 208 } |
203 outputDiv.appendText('${event.data}\n'); | 209 outputDiv.appendText('${event.data}\n'); |
204 }); | 210 }); |
205 | 211 |
206 observer = new MutationObserver(interaction.onMutation) | 212 observer = new MutationObserver(interaction.onMutation) |
207 ..observe( | 213 ..observe( |
208 mainEditorPane, childList: true, characterData: true, subtree: true); | 214 mainEditorPane, childList: true, characterData: true, subtree: true); |
209 | 215 |
210 scheduleMicrotask(() { | 216 scheduleMicrotask(() { |
211 mainEditorPane.appendText(window.localStorage['currentSource']); | 217 mainEditorPane.appendText(currentSource); |
212 }); | 218 }); |
213 | 219 |
214 // You cannot install event handlers on window.applicationCache | 220 // You cannot install event handlers on window.applicationCache |
215 // until the window has loaded. In dartium, that's later than this | 221 // until the window has loaded. In dartium, that's later than this |
216 // method is called. | 222 // method is called. |
217 window.onLoad.listen(onLoad); | 223 window.onLoad.listen(onLoad); |
218 | 224 |
219 // However, in dart2js, the window has already loaded, and onLoad is | 225 // However, in dart2js, the window has already loaded, and onLoad is |
220 // never called. | 226 // never called. |
221 onLoad(null); | 227 onLoad(null); |
222 } | 228 } |
223 | 229 |
224 buildCode(InteractionManager interaction) { | 230 buildCode(InteractionManager interaction) { |
225 var codePicker = | 231 var codePicker = |
226 document.getElementById('code-picker') | 232 document.getElementById('code-picker') |
227 ..style.visibility = 'hidden' | 233 ..style.visibility = 'hidden' |
228 ..onChange.listen(onCodeChange); | 234 ..onChange.listen(onCodeChange); |
229 var htmlGroup = new OptGroupElement()..label = 'HTML'; | 235 var htmlGroup = new OptGroupElement()..label = 'HTML'; |
230 var benchmarkGroup = new OptGroupElement()..label = 'Benchmarks'; | 236 var benchmarkGroup = new OptGroupElement()..label = 'Benchmarks'; |
231 | 237 |
232 new Future(() => HttpRequest.getString('project?list').then( | 238 interaction.projectFileNames().then((List<String> names) { |
233 (String response) { | |
234 OptionElement none = new OptionElement() | 239 OptionElement none = new OptionElement() |
235 ..appendText('--') | 240 ..appendText('--') |
236 ..disabled = true; | 241 ..disabled = true; |
237 codePicker.append(none); | 242 codePicker |
238 for (String projectFile in JSON.decode(response)) { | 243 ..append(none) |
239 codePicker.append(buildTab(projectFile, projectFile, (_) { | 244 ..style.visibility = 'visible' |
240 mainEditorPane.contentEditable = 'false'; | 245 ..selectedIndex = 0; |
241 HttpRequest.getString('project/$projectFile').then((String text) { | 246 |
242 mainEditorPane | 247 for (String name in names) { |
243 ..contentEditable = 'true' | 248 codePicker.append(buildTab(name, name, (event) { |
244 ..nodes.clear(); | 249 interaction.onProjectFileSelected(name); |
245 observer.takeRecords(); | |
246 mainEditorPane.appendText(text); | |
247 }); | |
248 })); | 250 })); |
249 } | 251 } |
250 codePicker.style.visibility = 'visible'; | 252 }).catchError((error) { |
251 codePicker.selectedIndex = 0; | |
252 })).catchError((error) { | |
253 codePicker.style.visibility = 'visible'; | 253 codePicker.style.visibility = 'visible'; |
254 print(error); | 254 print(error); |
255 OptionElement none = new OptionElement() | 255 OptionElement none = new OptionElement() |
256 ..appendText('Pick an example') | 256 ..appendText('Pick an example') |
257 ..disabled = true; | 257 ..disabled = true; |
258 codePicker.append(none); | 258 codePicker.append(none); |
259 | 259 |
260 // codePicker.classes.addAll(['nav', 'nav-tabs']); | 260 // codePicker.classes.addAll(['nav', 'nav-tabs']); |
261 codePicker.append(buildTab('Hello, World!', 'EXAMPLE_HELLO', (_) { | 261 codePicker.append(buildTab('Hello, World!', 'EXAMPLE_HELLO', (_) { |
262 mainEditorPane | 262 mainEditorPane |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 window.localStorage['compilationPaused'] = '$compilationPaused'; | 476 window.localStorage['compilationPaused'] = '$compilationPaused'; |
477 window.localStorage['codeFont'] = '$codeFont'; | 477 window.localStorage['codeFont'] = '$codeFont'; |
478 | 478 |
479 dialog.style.height = '0px'; | 479 dialog.style.height = '0px'; |
480 } | 480 } |
481 form.onSubmit.listen(onSubmit); | 481 form.onSubmit.listen(onSubmit); |
482 | 482 |
483 var doneButton = document.getElementById('settings-done'); | 483 var doneButton = document.getElementById('settings-done'); |
484 doneButton.onClick.listen(onSubmit); | 484 doneButton.onClick.listen(onSubmit); |
485 } | 485 } |
OLD | NEW |