Chromium Code Reviews| Index: samples/calculator/settings.dart |
| diff --git a/samples/calculator/settings.dart b/samples/calculator/settings.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..290404dad42f88b3d756a3f3f615c71128affbd3 |
| --- /dev/null |
| +++ b/samples/calculator/settings.dart |
| @@ -0,0 +1,77 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +class Settings { |
| + // theme values: |
| + static final THEME_SIMPLE = 1; |
| + static final THEME_BUTTON = 2; |
| + |
| + SettingsDialog ui; |
| + int theme; |
|
Jacob
2012/04/05 18:06:01
looks like
int theme;
could be private
|
| + |
| + bool _dialogOpened; |
| + |
| + Settings(this.ui, this.theme) : _dialogOpened = false { |
| + ui.settings.on.click.add((MouseEvent e) { |
| + mySettings.dialog(); |
| + e.cancelBubble = true; |
| + }); |
| + ui.simpleTitle.on.click.add((MouseEvent e) { |
| + ui.simple.checked = true; |
| + }); |
| + ui.buttonTitle.on.click.add((MouseEvent e) { |
| + ui.buttons.checked = true; |
| + }); |
| + |
| + } |
| + |
| + /** |
| + * Settings dialog |
| + */ |
| + void dialog() { |
| + decorateDropdown(); |
| + |
| + if (!_dialogOpened) { |
| + ui.simple.checked = theme == THEME_SIMPLE; |
| + ui.buttons.checked = theme == THEME_BUTTON; |
| + |
| + ui.settingsDialog.style.visibility = "visible"; |
| + |
| + _dialogOpened = true; |
| + } else { |
| + close(); |
| + } |
| + } |
| + |
| + void decorateDropdown() { |
| + ui.settings.style.backgroundColor = _dialogOpened ? |
| + "transparent" : "#333"; |
|
Jacob
2012/04/05 18:06:01
make #333 a constant at the top of the file
|
| + } |
| + |
| + bool get isOpen() => _dialogOpened; |
| + |
| + /* |
| + * Optional MouseEvent if passed if the source of event is from outside of |
| + * the dialog then the dialog can be closed. |
| + */ |
| + void close([MouseEvent e]) { |
| + if (isOpen) { |
| + if (ui.simple.checked) { |
| + theme = THEME_SIMPLE; |
| + } else if (ui.buttons.checked) { |
| + theme = THEME_BUTTON; |
| + } |
| + |
| + if (e == null || !ui.settingsDialog.contains(e.srcElement)) { |
| + decorateDropdown(); |
| + ui.settingsDialog.style.visibility = "hidden"; |
| + _dialogOpened = false; |
| + } |
| + } |
| + } |
| + |
| + bool get isSimple() => theme == THEME_SIMPLE; |
| + bool get isButton() => theme == THEME_BUTTON; |
| + |
| +} |