OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 case ('global'): | 68 case ('global'): |
69 storageType = Common.SettingStorageType.Global; | 69 storageType = Common.SettingStorageType.Global; |
70 break; | 70 break; |
71 default: | 71 default: |
72 storageType = Common.SettingStorageType.Global; | 72 storageType = Common.SettingStorageType.Global; |
73 } | 73 } |
74 var setting = isRegex ? this.createRegExpSetting(settingName, defaultValue, undefined, storageType) : | 74 var setting = isRegex ? this.createRegExpSetting(settingName, defaultValue, undefined, storageType) : |
75 this.createSetting(settingName, defaultValue, storag eType); | 75 this.createSetting(settingName, defaultValue, storag eType); |
76 if (descriptor['title']) | 76 if (descriptor['title']) |
77 setting.setTitle(descriptor['title']); | 77 setting.setTitle(descriptor['title']); |
78 if (descriptor['options']) | |
79 setting.setOptions(descriptor['options']); | |
78 this._moduleSettings.set(settingName, setting); | 80 this._moduleSettings.set(settingName, setting); |
79 } | 81 } |
80 | 82 |
81 /** | 83 /** |
82 * @param {string} settingName | 84 * @param {string} settingName |
83 * @return {!Common.Setting} | 85 * @return {!Common.Setting} |
84 */ | 86 */ |
85 moduleSetting(settingName) { | 87 moduleSetting(settingName) { |
86 var setting = this._moduleSettings.get(settingName); | 88 var setting = this._moduleSettings.get(settingName); |
87 if (!setting) | 89 if (!setting) |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 * @param {!Common.SettingsStorage} storage | 258 * @param {!Common.SettingsStorage} storage |
257 */ | 259 */ |
258 constructor(settings, name, defaultValue, eventSupport, storage) { | 260 constructor(settings, name, defaultValue, eventSupport, storage) { |
259 this._settings = settings; | 261 this._settings = settings; |
260 this._name = name; | 262 this._name = name; |
261 this._defaultValue = defaultValue; | 263 this._defaultValue = defaultValue; |
262 this._eventSupport = eventSupport; | 264 this._eventSupport = eventSupport; |
263 this._storage = storage; | 265 this._storage = storage; |
264 /** @type {string} */ | 266 /** @type {string} */ |
265 this._title = ''; | 267 this._title = ''; |
268 /** @type {!Array<!Common.Setting.Option>|undefined} */ | |
269 this._options; | |
266 } | 270 } |
267 | 271 |
268 /** | 272 /** |
269 * @param {function(!Common.Event)} listener | 273 * @param {function(!Common.Event)} listener |
270 * @param {!Object=} thisObject | 274 * @param {!Object=} thisObject |
271 */ | 275 */ |
272 addChangeListener(listener, thisObject) { | 276 addChangeListener(listener, thisObject) { |
273 this._eventSupport.addEventListener(this._name, listener, thisObject); | 277 this._eventSupport.addEventListener(this._name, listener, thisObject); |
274 } | 278 } |
275 | 279 |
(...skipping 17 matching lines...) Expand all Loading... | |
293 } | 297 } |
294 | 298 |
295 /** | 299 /** |
296 * @param {string} title | 300 * @param {string} title |
297 */ | 301 */ |
298 setTitle(title) { | 302 setTitle(title) { |
299 this._title = title; | 303 this._title = title; |
300 } | 304 } |
301 | 305 |
302 /** | 306 /** |
307 * @return {!Array<!Common.Setting.Option>} | |
308 */ | |
309 options() { | |
lushnikov
2017/03/11 00:46:00
Let's not infect Common.Setting with fields which
luoe
2017/05/09 02:58:00
Done.
| |
310 return this._options || []; | |
311 } | |
312 | |
313 /** | |
314 * @param {!Array<!Common.Setting.Option>} options | |
315 */ | |
316 setOptions(options) { | |
317 this._options = options; | |
318 } | |
319 | |
320 /** | |
303 * @return {V} | 321 * @return {V} |
304 */ | 322 */ |
305 get() { | 323 get() { |
306 if (typeof this._value !== 'undefined') | 324 if (typeof this._value !== 'undefined') |
307 return this._value; | 325 return this._value; |
308 | 326 |
309 this._value = this._defaultValue; | 327 this._value = this._defaultValue; |
310 if (this._storage.has(this._name)) { | 328 if (this._storage.has(this._name)) { |
311 try { | 329 try { |
312 this._value = JSON.parse(this._storage.get(this._name)); | 330 this._value = JSON.parse(this._storage.get(this._name)); |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
807 | 825 |
808 /** | 826 /** |
809 * @enum {symbol} | 827 * @enum {symbol} |
810 */ | 828 */ |
811 Common.SettingStorageType = { | 829 Common.SettingStorageType = { |
812 Global: Symbol('Global'), | 830 Global: Symbol('Global'), |
813 Local: Symbol('Local'), | 831 Local: Symbol('Local'), |
814 Session: Symbol('Session') | 832 Session: Symbol('Session') |
815 }; | 833 }; |
816 | 834 |
835 /** @typedef {!{title: string, value: *, raw: (boolean|undefined)}} */ | |
836 Common.Setting.Option; | |
837 | |
817 /** | 838 /** |
818 * @param {string} settingName | 839 * @param {string} settingName |
819 * @return {!Common.Setting} | 840 * @return {!Common.Setting} |
820 */ | 841 */ |
821 Common.moduleSetting = function(settingName) { | 842 Common.moduleSetting = function(settingName) { |
822 return Common.settings.moduleSetting(settingName); | 843 return Common.settings.moduleSetting(settingName); |
823 }; | 844 }; |
824 | 845 |
825 /** | 846 /** |
826 * @param {string} settingName | 847 * @param {string} settingName |
827 * @return {!Common.Setting} | 848 * @return {!Common.Setting} |
828 */ | 849 */ |
829 Common.settingForTest = function(settingName) { | 850 Common.settingForTest = function(settingName) { |
830 return Common.settings.settingForTest(settingName); | 851 return Common.settings.settingForTest(settingName); |
831 }; | 852 }; |
OLD | NEW |