Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/ui/SettingsUI.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/ui/SettingsUI.js b/third_party/WebKit/Source/devtools/front_end/ui/SettingsUI.js |
| index abb0b9c1875c065117ed006023aca3dcbf024e22..c272bcf0549c6cf0fdaab3d3d195ada21e44f0d5 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/ui/SettingsUI.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/ui/SettingsUI.js |
| @@ -54,6 +54,46 @@ UI.SettingsUI.createSettingCheckbox = function(name, setting, omitParagraphEleme |
| }; |
| /** |
| + * @param {string} name |
| + * @param {!Array<!Runtime.ExtensionDescriptor.Option>} options |
| + * @param {!Common.Setting} setting |
| + * @return {!Element} |
| + */ |
| +UI.SettingsUI.createSettingSelect = function(name, options, setting) { |
|
pfeldman
2017/05/10 20:58:42
Oh, this is a good one!
luoe
2017/05/11 21:39:43
XD
|
| + var p = createElement('p'); |
| + p.createChild('label').textContent = name; |
| + var select = p.createChild('select', 'chrome-select'); |
| + |
| + for (var i = 0; i < options.length; ++i) { |
| + // The "raw" flag indicates text is non-i18n-izable. |
| + var option = /** @type {!Runtime.ExtensionDescriptor.Option} */ (options[i]); |
| + var optionText = /** @type {string} */ (option.text); |
| + var optionName = option.raw ? optionText : Common.UIString(optionText); |
| + select.add(new Option(optionName, option.value)); |
| + } |
| + |
| + setting.addChangeListener(settingChanged); |
| + settingChanged(); |
| + select.addEventListener('change', selectChanged, false); |
| + return p; |
| + |
| + function settingChanged() { |
| + var newValue = setting.get(); |
| + if (options[select.selectedIndex].value !== newValue) { |
|
pfeldman
2017/05/10 20:58:42
Why did you add this line? I don't think it makes
luoe
2017/05/11 21:39:43
Done.
|
| + for (var i = 0; i < options.length; i++) { |
| + if (options[i].value === newValue) |
| + select.selectedIndex = i; |
| + } |
| + } |
| + } |
| + |
| + function selectChanged() { |
| + // Don't use event.target.value to avoid conversion of the value to string. |
| + setting.set(options[select.selectedIndex].value); |
| + } |
| +}; |
| + |
| +/** |
| * @param {!Element} input |
| * @param {!Common.Setting} setting |
| */ |