Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 class Settings { | |
| 6 // theme values: | |
| 7 static final THEME_SIMPLE = 1; | |
| 8 static final THEME_BUTTON = 2; | |
| 9 | |
| 10 SettingsDialog ui; | |
| 11 int theme; | |
|
Jacob
2012/04/05 18:06:01
looks like
int theme;
could be private
| |
| 12 | |
| 13 bool _dialogOpened; | |
| 14 | |
| 15 Settings(this.ui, this.theme) : _dialogOpened = false { | |
| 16 ui.settings.on.click.add((MouseEvent e) { | |
| 17 mySettings.dialog(); | |
| 18 e.cancelBubble = true; | |
| 19 }); | |
| 20 ui.simpleTitle.on.click.add((MouseEvent e) { | |
| 21 ui.simple.checked = true; | |
| 22 }); | |
| 23 ui.buttonTitle.on.click.add((MouseEvent e) { | |
| 24 ui.buttons.checked = true; | |
| 25 }); | |
| 26 | |
| 27 } | |
| 28 | |
| 29 /** | |
| 30 * Settings dialog | |
| 31 */ | |
| 32 void dialog() { | |
| 33 decorateDropdown(); | |
| 34 | |
| 35 if (!_dialogOpened) { | |
| 36 ui.simple.checked = theme == THEME_SIMPLE; | |
| 37 ui.buttons.checked = theme == THEME_BUTTON; | |
| 38 | |
| 39 ui.settingsDialog.style.visibility = "visible"; | |
| 40 | |
| 41 _dialogOpened = true; | |
| 42 } else { | |
| 43 close(); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 void decorateDropdown() { | |
| 48 ui.settings.style.backgroundColor = _dialogOpened ? | |
| 49 "transparent" : "#333"; | |
|
Jacob
2012/04/05 18:06:01
make #333 a constant at the top of the file
| |
| 50 } | |
| 51 | |
| 52 bool get isOpen() => _dialogOpened; | |
| 53 | |
| 54 /* | |
| 55 * Optional MouseEvent if passed if the source of event is from outside of | |
| 56 * the dialog then the dialog can be closed. | |
| 57 */ | |
| 58 void close([MouseEvent e]) { | |
| 59 if (isOpen) { | |
| 60 if (ui.simple.checked) { | |
| 61 theme = THEME_SIMPLE; | |
| 62 } else if (ui.buttons.checked) { | |
| 63 theme = THEME_BUTTON; | |
| 64 } | |
| 65 | |
| 66 if (e == null || !ui.settingsDialog.contains(e.srcElement)) { | |
| 67 decorateDropdown(); | |
| 68 ui.settingsDialog.style.visibility = "hidden"; | |
| 69 _dialogOpened = false; | |
| 70 } | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 bool get isSimple() => theme == THEME_SIMPLE; | |
| 75 bool get isButton() => theme == THEME_BUTTON; | |
| 76 | |
| 77 } | |
| OLD | NEW |