| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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:html'); | 5 #import('dart:html'); |
| 6 #source('tape.dart'); | 6 #source('tape.dart'); |
| 7 #source('settings.dart'); | 7 #source('settings.dart'); |
| 8 #source('calcui.dart'); | 8 #source('calcui.dart'); |
| 9 | 9 |
| 10 var padUI; // Calculator Pad UI. | 10 var padUI; // Calculator Pad UI. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 dotKeyPresses = new Set.from([190 /* . */, | 64 dotKeyPresses = new Set.from([190 /* . */, |
| 65 110 /* Keypad . */]); | 65 110 /* Keypad . */]); |
| 66 backspacePresses = new Set.from([8 /* Keypad <- or Backspace */]); | 66 backspacePresses = new Set.from([8 /* Keypad <- or Backspace */]); |
| 67 | 67 |
| 68 addPadEvents(); | 68 addPadEvents(); |
| 69 | 69 |
| 70 // Catch user keypresses, decide whether to use them or pass to the browser. | 70 // Catch user keypresses, decide whether to use them or pass to the browser. |
| 71 document.on.keyUp.add((e) { | 71 document.on.keyUp.add((e) { |
| 72 processKeyEvent(e); | 72 processKeyEvent(e); |
| 73 }); | 73 }); |
| 74 | 74 |
| 75 document.on.click.add((MouseEvent e) { | 75 document.on.click.add((MouseEvent e) { |
| 76 bool wasOpened = mySettings.isOpen; |
| 77 |
| 76 // If settings dialog is open close it. | 78 // If settings dialog is open close it. |
| 77 mySettings.close(e); | 79 mySettings.close(e); |
| 78 | 80 |
| 79 renderPad(document.body.elements.last()); | 81 renderPad(document.body.elements.last()); |
| 80 addPadEvents(); | 82 if (wasOpened) { |
| 83 removePadEvents(); |
| 84 addPadEvents(); |
| 85 } |
| 81 }); | 86 }); |
| 82 } | 87 } |
| 83 | 88 |
| 84 void addPadEvents() { | 89 void addPadEvents() { |
| 85 // Hook-up number key events: | 90 // Hook-up number key events: |
| 86 padUI.keyZero.on.click.add((MouseEvent e) { doCalc(48); }); | 91 padUI.keyZero.on.click.add((MouseEvent e) { doCalc(48); }); |
| 87 padUI.keyOne.on.click.add((MouseEvent e) { doCalc(49); }); | 92 padUI.keyOne.on.click.add((MouseEvent e) { doCalc(49); }); |
| 88 padUI.keyTwo.on.click.add((MouseEvent e) { doCalc(50); }); | 93 padUI.keyTwo.on.click.add((MouseEvent e) { doCalc(50); }); |
| 89 padUI.keyThree.on.click.add((MouseEvent e) { doCalc(51); }); | 94 padUI.keyThree.on.click.add((MouseEvent e) { doCalc(51); }); |
| 90 padUI.keyFour.on.click.add((MouseEvent e) { doCalc(52); }); | 95 padUI.keyFour.on.click.add((MouseEvent e) { doCalc(52); }); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 } | 360 } |
| 356 } | 361 } |
| 357 } | 362 } |
| 358 | 363 |
| 359 void main() { | 364 void main() { |
| 360 final Element element = new Element.tag('div'); | 365 final Element element = new Element.tag('div'); |
| 361 | 366 |
| 362 // Create our Tape UI. | 367 // Create our Tape UI. |
| 363 tapeUI = new TapeUI(); | 368 tapeUI = new TapeUI(); |
| 364 element.elements.add(tapeUI.root); | 369 element.elements.add(tapeUI.root); |
| 365 | 370 |
| 366 // Create our tape controller. | 371 // Create our tape controller. |
| 367 tape = new Tape(); | 372 tape = new Tape(); |
| 368 | 373 |
| 369 renderPad(element); | 374 renderPad(element); |
| 370 | 375 |
| 371 // Render the UI. | 376 // Render the UI. |
| 372 document.body.elements.add(element); | 377 document.body.elements.add(element); |
| 373 | 378 |
| 374 currentRegister = ""; | 379 currentRegister = ""; |
| 375 total = 0.0; | 380 total = 0.0; |
| 376 | 381 |
| 377 setupEvents(); | 382 setupEvents(); |
| 378 } | 383 } |
| OLD | NEW |