| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 /** | 125 /** |
| 126 * @param {string=} name | 126 * @param {string=} name |
| 127 * @return {!Element} | 127 * @return {!Element} |
| 128 */ | 128 */ |
| 129 _appendSection(name) { | 129 _appendSection(name) { |
| 130 var block = this.containerElement.createChild('div', 'help-block'); | 130 var block = this.containerElement.createChild('div', 'help-block'); |
| 131 if (name) | 131 if (name) |
| 132 block.createChild('div', 'help-section-title').textContent = name; | 132 block.createChild('div', 'help-section-title').textContent = name; |
| 133 return block; | 133 return block; |
| 134 } | 134 } |
| 135 | |
| 136 _createSelectSetting(name, options, setting) { | |
| 137 var p = createElement('p'); | |
| 138 p.createChild('label').textContent = name; | |
| 139 | |
| 140 var select = p.createChild('select', 'chrome-select'); | |
| 141 var settingValue = setting.get(); | |
| 142 | |
| 143 for (var i = 0; i < options.length; ++i) { | |
| 144 var option = options[i]; | |
| 145 select.add(new Option(option[0], option[1])); | |
| 146 if (settingValue === option[1]) | |
| 147 select.selectedIndex = i; | |
| 148 } | |
| 149 | |
| 150 function changeListener(e) { | |
| 151 // Don't use e.target.value to avoid conversion of the value to string. | |
| 152 setting.set(options[select.selectedIndex][1]); | |
| 153 } | |
| 154 | |
| 155 select.addEventListener('change', changeListener, false); | |
| 156 return p; | |
| 157 } | |
| 158 }; | 135 }; |
| 159 | 136 |
| 160 /** | 137 /** |
| 161 * @unrestricted | 138 * @unrestricted |
| 162 */ | 139 */ |
| 163 Settings.GenericSettingsTab = class extends Settings.SettingsTab { | 140 Settings.GenericSettingsTab = class extends Settings.SettingsTab { |
| 164 constructor() { | 141 constructor() { |
| 165 super(Common.UIString('Preferences'), 'preferences-tab-content'); | 142 super(Common.UIString('Preferences'), 'preferences-tab-content'); |
| 166 | 143 |
| 167 /** @const */ | 144 /** @const */ |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 var uiTitle = Common.UIString(extension.title()); | 188 var uiTitle = Common.UIString(extension.title()); |
| 212 | 189 |
| 213 var sectionElement = this._sectionElement(sectionName); | 190 var sectionElement = this._sectionElement(sectionName); |
| 214 var settingControl; | 191 var settingControl; |
| 215 | 192 |
| 216 switch (descriptor['settingType']) { | 193 switch (descriptor['settingType']) { |
| 217 case 'boolean': | 194 case 'boolean': |
| 218 settingControl = UI.SettingsUI.createSettingCheckbox(uiTitle, setting); | 195 settingControl = UI.SettingsUI.createSettingCheckbox(uiTitle, setting); |
| 219 break; | 196 break; |
| 220 case 'enum': | 197 case 'enum': |
| 221 var descriptorOptions = descriptor['options']; | 198 settingControl = UI.SettingsUI.createSettingSelect(uiTitle, setting); |
| 222 var options = new Array(descriptorOptions.length); | |
| 223 for (var i = 0; i < options.length; ++i) { | |
| 224 // The "raw" flag indicates text is non-i18n-izable. | |
| 225 var optionName = descriptorOptions[i]['raw'] ? descriptorOptions[i]['t
ext'] : | |
| 226 Common.UIString(descrip
torOptions[i]['text']); | |
| 227 options[i] = [optionName, descriptorOptions[i]['value']]; | |
| 228 } | |
| 229 settingControl = this._createSelectSetting(uiTitle, options, setting); | |
| 230 break; | 199 break; |
| 231 default: | 200 default: |
| 232 console.error('Invalid setting type: ' + descriptor['settingType']); | 201 console.error('Invalid setting type: ' + descriptor['settingType']); |
| 233 return; | 202 return; |
| 234 } | 203 } |
| 235 this._nameToSettingElement.set(settingName, settingControl); | 204 this._nameToSettingElement.set(settingName, settingControl); |
| 236 sectionElement.appendChild(/** @type {!Element} */ (settingControl)); | 205 sectionElement.appendChild(/** @type {!Element} */ (settingControl)); |
| 237 } | 206 } |
| 238 | 207 |
| 239 /** | 208 /** |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 return; | 514 return; |
| 546 var settings = extension.descriptor()['settings']; | 515 var settings = extension.descriptor()['settings']; |
| 547 if (settings && settings.indexOf(setting.name) !== -1) { | 516 if (settings && settings.indexOf(setting.name) !== -1) { |
| 548 InspectorFrontendHost.bringToFront(); | 517 InspectorFrontendHost.bringToFront(); |
| 549 Settings.SettingsScreen._showSettingsScreen(extension.descriptor()['id']
); | 518 Settings.SettingsScreen._showSettingsScreen(extension.descriptor()['id']
); |
| 550 success = true; | 519 success = true; |
| 551 } | 520 } |
| 552 } | 521 } |
| 553 } | 522 } |
| 554 }; | 523 }; |
| OLD | NEW |