| 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. |
| 8 /// |
| 9 /// Options included in [options] in settings.dart will automatically be |
| 10 /// included in the settings UI unless [isHidden] is true. |
| 11 /// |
| 12 /// The value of an option is persisted in [storage] which is normally the |
| 13 /// browser's "localStorage", and [name] is a key in "localStorage". This |
| 14 /// means that hidden options can be controlled by opening the JavaScript |
| 15 /// console and evaluate: |
| 16 /// |
| 17 /// localStorage['name'] = value // or |
| 18 /// localStorage.name = value |
| 19 /// |
| 20 /// An option can be reset to the default value using: |
| 21 /// |
| 22 /// delete localStorage['name'] // or |
| 23 /// delete localStorage.name |
| 7 class UserOption { | 24 class UserOption { |
| 8 final String name; | 25 final String name; |
| 9 | 26 |
| 10 final bool isHidden; | 27 final bool isHidden; |
| 11 | 28 |
| 12 static var storage; | 29 static var storage; |
| 13 | 30 |
| 14 const UserOption(this.name, {this.isHidden: false}); | 31 const UserOption(this.name, {this.isHidden: false}); |
| 15 | 32 |
| 16 get value => storage[name]; | 33 get value => storage[name]; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 34 class StringUserOption extends UserOption { | 51 class StringUserOption extends UserOption { |
| 35 const StringUserOption(String name, {bool isHidden: false}) | 52 const StringUserOption(String name, {bool isHidden: false}) |
| 36 : super(name, isHidden: isHidden); | 53 : super(name, isHidden: isHidden); |
| 37 | 54 |
| 38 String get value => super.value == null ? '' : super.value; | 55 String get value => super.value == null ? '' : super.value; |
| 39 | 56 |
| 40 void set value(String newValue) { | 57 void set value(String newValue) { |
| 41 super.value = newValue; | 58 super.value = newValue; |
| 42 } | 59 } |
| 43 } | 60 } |
| OLD | NEW |