Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.userOption; | 5 library trydart.userOption; |
| 6 | 6 |
| 7 /// Persistent user-configurable option. | 7 /// Persistent user-configurable option. |
| 8 /// | 8 /// |
| 9 /// Options included in [options] in settings.dart will automatically be | 9 /// Options included in [options] in settings.dart will automatically be |
| 10 /// included in the settings UI unless [isHidden] is true. | 10 /// included in the settings UI unless [isHidden] is true. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 | 28 |
| 29 static var storage; | 29 static var storage; |
| 30 | 30 |
| 31 const UserOption(this.name, {this.isHidden: false}); | 31 const UserOption(this.name, {this.isHidden: false}); |
| 32 | 32 |
| 33 get value => storage[name]; | 33 get value => storage[name]; |
| 34 | 34 |
| 35 void set value(newValue) { | 35 void set value(newValue) { |
| 36 storage[name] = newValue; | 36 storage[name] = newValue; |
| 37 } | 37 } |
| 38 | |
| 39 void setIfNotInitialized(dynamic newValueEvaluator()) { | |
|
ahe
2014/08/19 13:02:49
Remove "dynamic".
| |
| 40 if (storage[name] == null) { | |
| 41 value = newValueEvaluator(); | |
| 42 } | |
| 43 } | |
| 38 } | 44 } |
| 39 | 45 |
| 40 class BooleanUserOption extends UserOption { | 46 class BooleanUserOption extends UserOption { |
| 41 const BooleanUserOption(String name, {bool isHidden: false}) | 47 const BooleanUserOption(String name, {bool isHidden: false}) |
| 42 : super(name, isHidden: isHidden); | 48 : super(name, isHidden: isHidden); |
| 43 | 49 |
| 44 bool get value => super.value == 'true'; | 50 bool get value => super.value == 'true'; |
| 45 | 51 |
| 46 void set value(bool newValue) { | 52 void set value(bool newValue) { |
| 47 super.value = '$newValue'; | 53 super.value = '$newValue'; |
| 48 } | 54 } |
| 49 } | 55 } |
| 50 | 56 |
| 51 class StringUserOption extends UserOption { | 57 class StringUserOption extends UserOption { |
| 52 const StringUserOption(String name, {bool isHidden: false}) | 58 const StringUserOption(String name, {bool isHidden: false}) |
| 53 : super(name, isHidden: isHidden); | 59 : super(name, isHidden: isHidden); |
| 54 | 60 |
| 55 String get value => super.value == null ? '' : super.value; | 61 String get value => super.value == null ? '' : super.value; |
| 56 | 62 |
| 57 void set value(String newValue) { | 63 void set value(String newValue) { |
| 58 super.value = newValue; | 64 super.value = newValue; |
| 59 } | 65 } |
| 60 } | 66 } |
| OLD | NEW |