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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 * @constructor | 203 * @constructor |
204 * @extends {WebInspector.Setting} | 204 * @extends {WebInspector.Setting} |
205 * @param {string} name | 205 * @param {string} name |
206 * @param {string} defaultValue | 206 * @param {string} defaultValue |
207 * @param {!WebInspector.Object} eventSupport | 207 * @param {!WebInspector.Object} eventSupport |
208 * @param {?Storage} storage | 208 * @param {?Storage} storage |
209 * @param {string=} regexFlags | 209 * @param {string=} regexFlags |
210 */ | 210 */ |
211 WebInspector.RegExpSetting = function(name, defaultValue, eventSupport, storage, regexFlags) | 211 WebInspector.RegExpSetting = function(name, defaultValue, eventSupport, storage, regexFlags) |
212 { | 212 { |
213 WebInspector.Setting.call(this, name, [defaultValue], eventSupport, storage) ; | 213 WebInspector.Setting.call(this, name, defaultValue ? [{ pattern: defaultValu e }] : [], eventSupport, storage); |
214 this._regexFlags = regexFlags; | 214 this._regexFlags = regexFlags; |
215 } | 215 } |
216 | 216 |
217 WebInspector.RegExpSetting.prototype = { | 217 WebInspector.RegExpSetting.prototype = { |
218 /** | 218 /** |
219 * @override | 219 * @override |
220 * @return {string} | 220 * @return {string} |
221 */ | 221 */ |
222 get: function() | 222 get: function() |
223 { | 223 { |
224 return this.getAsArray().join("|"); | 224 var result = []; |
225 var items = this.getAsArray(); | |
226 for (var i = 0; i < items.length; ++i) { | |
227 var item = items[i]; | |
228 if (item.pattern && !item.disabled) | |
229 result.push(item.pattern); | |
230 } | |
231 return result.join("|"); | |
225 }, | 232 }, |
226 | 233 |
227 /** | 234 /** |
228 * @return {!Array.<string>} | 235 * @return {!Array.<{pattern: string, disabled: (boolean|undefined)}>} |
229 */ | 236 */ |
230 getAsArray: function() | 237 getAsArray: function() |
231 { | 238 { |
232 var value = WebInspector.Setting.prototype.get.call(this); | 239 var value = WebInspector.Setting.prototype.get.call(this); |
233 if (typeof value === "string") // Backward compatibility. | 240 // Backward compatibility #1. |
vsevik
2014/07/28 08:27:57
Can we use WebInspector.VersionController to avoid
aandrey
2014/07/28 12:42:38
Done.
| |
241 if (typeof value === "string") | |
234 value = [value]; | 242 value = [value]; |
235 value.remove(""); | 243 // Backward compatibility #2. |
236 return value; | 244 var result = []; |
245 for (var i = 0; i < value.length; ++i) { | |
246 if (typeof value[i] === "string") | |
247 value[i] = { pattern: value[i] }; | |
248 if (value[i].pattern) | |
249 result.push(value[i]); | |
250 } | |
251 return result; | |
237 }, | 252 }, |
238 | 253 |
239 /** | 254 /** |
240 * @override | 255 * @override |
241 * @param {string} value | 256 * @param {string} value |
242 */ | 257 */ |
243 set: function(value) | 258 set: function(value) |
244 { | 259 { |
245 this.setAsArray([value]); | 260 this.setAsArray([{ pattern: value }]); |
246 }, | 261 }, |
247 | 262 |
248 /** | 263 /** |
249 * @param {!Array.<string>} value | 264 * @param {!Array.<{pattern: string, disabled: (boolean|undefined)}>} value |
250 */ | 265 */ |
251 setAsArray: function(value) | 266 setAsArray: function(value) |
252 { | 267 { |
253 delete this._regex; | 268 delete this._regex; |
254 value.remove(""); | 269 var result = []; |
255 WebInspector.Setting.prototype.set.call(this, value); | 270 for (var i = 0; i < value.length; ++i) { |
271 if (value[i].pattern) | |
272 result.push(value[i]); | |
273 } | |
274 WebInspector.Setting.prototype.set.call(this, result); | |
256 }, | 275 }, |
257 | 276 |
258 /** | 277 /** |
259 * @return {?RegExp} | 278 * @return {?RegExp} |
260 */ | 279 */ |
261 asRegExp: function() | 280 asRegExp: function() |
262 { | 281 { |
263 if (typeof this._regex !== "undefined") | 282 if (typeof this._regex !== "undefined") |
264 return this._regex; | 283 return this._regex; |
265 this._regex = null; | 284 this._regex = null; |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
731 | 750 |
732 _fireChangedIfNeeded: function() | 751 _fireChangedIfNeeded: function() |
733 { | 752 { |
734 var newValue = this._calculateValue(); | 753 var newValue = this._calculateValue(); |
735 if (newValue === this._value) | 754 if (newValue === this._value) |
736 return; | 755 return; |
737 this._value = newValue; | 756 this._value = newValue; |
738 this._eventSupport.dispatchEventToListeners(this._name, this._value); | 757 this._eventSupport.dispatchEventToListeners(this._name, this._value); |
739 } | 758 } |
740 } | 759 } |
OLD | NEW |