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 |
42 // TODO(ahe): Make internal to buildUI once all interactions have been moved to | 43 // TODO(ahe): Make internal to buildUI once all interactions have been moved to |
43 // the manager. | 44 // the manager. |
44 InteractionManager interaction; | 45 InteractionManager interaction; |
45 | 46 |
46 DivElement mainEditorPane; | 47 DivElement mainEditorPane; |
47 PreElement outputDiv; | 48 PreElement outputDiv; |
48 DivElement hackDiv; | 49 DivElement hackDiv; |
49 IFrameElement outputFrame; | 50 IFrameElement outputFrame; |
50 MutationObserver observer; | 51 MutationObserver observer; |
51 SpanElement cacheStatusElement; | 52 SpanElement cacheStatusElement; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 SelectElement select = event.target; | 86 SelectElement select = event.target; |
86 String id = select.querySelectorAll('option')[select.selectedIndex].id; | 87 String id = select.querySelectorAll('option')[select.selectedIndex].id; |
87 Function action = codeCallbacks[id]; | 88 Function action = codeCallbacks[id]; |
88 if (action != null) action(event); | 89 if (action != null) action(event); |
89 outputFrame.style.display = 'none'; | 90 outputFrame.style.display = 'none'; |
90 } | 91 } |
91 | 92 |
92 buildUI() { | 93 buildUI() { |
93 interaction = new InteractionManager(); | 94 interaction = new InteractionManager(); |
94 | 95 |
| 96 CompilationUnit.onChanged.listen(interaction.onCompilationUnitChanged); |
| 97 |
95 window.localStorage['currentSample'] = '$currentSample'; | 98 window.localStorage['currentSample'] = '$currentSample'; |
96 | 99 |
97 buildCode(interaction); | 100 buildCode(interaction); |
98 | 101 |
99 (mainEditorPane = new DivElement()) | 102 (mainEditorPane = new DivElement()) |
100 ..classes.add('well') | 103 ..classes.add('well') |
101 ..style.backgroundColor = currentTheme.background.color | 104 ..style.backgroundColor = currentTheme.background.color |
102 ..style.color = currentTheme.foreground.color | 105 ..style.color = currentTheme.foreground.color |
103 ..style.overflow = 'visible' | 106 ..style.overflow = 'visible' |
104 ..style.whiteSpace = 'pre' | 107 ..style.whiteSpace = 'pre' |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 225 } |
223 | 226 |
224 buildCode(InteractionManager interaction) { | 227 buildCode(InteractionManager interaction) { |
225 var codePicker = | 228 var codePicker = |
226 document.getElementById('code-picker') | 229 document.getElementById('code-picker') |
227 ..style.visibility = 'hidden' | 230 ..style.visibility = 'hidden' |
228 ..onChange.listen(onCodeChange); | 231 ..onChange.listen(onCodeChange); |
229 var htmlGroup = new OptGroupElement()..label = 'HTML'; | 232 var htmlGroup = new OptGroupElement()..label = 'HTML'; |
230 var benchmarkGroup = new OptGroupElement()..label = 'Benchmarks'; | 233 var benchmarkGroup = new OptGroupElement()..label = 'Benchmarks'; |
231 | 234 |
232 new Future(() => HttpRequest.getString('project?list').then( | 235 interaction.projectFileNames().then((List<String> names) { |
233 (String response) { | |
234 OptionElement none = new OptionElement() | 236 OptionElement none = new OptionElement() |
235 ..appendText('--') | 237 ..appendText('--') |
236 ..disabled = true; | 238 ..disabled = true; |
237 codePicker.append(none); | 239 codePicker |
238 for (String projectFile in JSON.decode(response)) { | 240 ..append(none) |
239 codePicker.append(buildTab(projectFile, projectFile, (_) { | 241 ..style.visibility = 'visible' |
240 mainEditorPane.contentEditable = 'false'; | 242 ..selectedIndex = 0; |
241 HttpRequest.getString('project/$projectFile').then((String text) { | 243 |
242 mainEditorPane | 244 for (String name in names) { |
243 ..contentEditable = 'true' | 245 codePicker.append(buildTab(name, name, (event) { |
244 ..nodes.clear(); | 246 interaction.onProjectFileSelected(name); |
245 observer.takeRecords(); | |
246 mainEditorPane.appendText(text); | |
247 }); | |
248 })); | 247 })); |
249 } | 248 } |
250 codePicker.style.visibility = 'visible'; | 249 }).catchError((error) { |
251 codePicker.selectedIndex = 0; | |
252 })).catchError((error) { | |
253 codePicker.style.visibility = 'visible'; | 250 codePicker.style.visibility = 'visible'; |
254 print(error); | 251 print(error); |
255 OptionElement none = new OptionElement() | 252 OptionElement none = new OptionElement() |
256 ..appendText('Pick an example') | 253 ..appendText('Pick an example') |
257 ..disabled = true; | 254 ..disabled = true; |
258 codePicker.append(none); | 255 codePicker.append(none); |
259 | 256 |
260 // codePicker.classes.addAll(['nav', 'nav-tabs']); | 257 // codePicker.classes.addAll(['nav', 'nav-tabs']); |
261 codePicker.append(buildTab('Hello, World!', 'EXAMPLE_HELLO', (_) { | 258 codePicker.append(buildTab('Hello, World!', 'EXAMPLE_HELLO', (_) { |
262 mainEditorPane | 259 mainEditorPane |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 window.localStorage['compilationPaused'] = '$compilationPaused'; | 473 window.localStorage['compilationPaused'] = '$compilationPaused'; |
477 window.localStorage['codeFont'] = '$codeFont'; | 474 window.localStorage['codeFont'] = '$codeFont'; |
478 | 475 |
479 dialog.style.height = '0px'; | 476 dialog.style.height = '0px'; |
480 } | 477 } |
481 form.onSubmit.listen(onSubmit); | 478 form.onSubmit.listen(onSubmit); |
482 | 479 |
483 var doneButton = document.getElementById('settings-done'); | 480 var doneButton = document.getElementById('settings-done'); |
484 doneButton.onClick.listen(onSubmit); | 481 doneButton.onClick.listen(onSubmit); |
485 } | 482 } |
OLD | NEW |