| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 */ | 139 */ |
| 140 Settings.GenericSettingsTab = class extends Settings.SettingsTab { | 140 Settings.GenericSettingsTab = class extends Settings.SettingsTab { |
| 141 constructor() { | 141 constructor() { |
| 142 super(Common.UIString('Preferences'), 'preferences-tab-content'); | 142 super(Common.UIString('Preferences'), 'preferences-tab-content'); |
| 143 | 143 |
| 144 /** @const */ | 144 /** @const */ |
| 145 var explicitSectionOrder = | 145 var explicitSectionOrder = |
| 146 ['', 'Appearance', 'Elements', 'Sources', 'Network', 'Profiler', 'Consol
e', 'Extensions']; | 146 ['', 'Appearance', 'Elements', 'Sources', 'Network', 'Profiler', 'Consol
e', 'Extensions']; |
| 147 /** @type {!Map<string, !Element>} */ | 147 /** @type {!Map<string, !Element>} */ |
| 148 this._nameToSection = new Map(); | 148 this._nameToSection = new Map(); |
| 149 /** @type {!Map<string, !Element>} */ | |
| 150 this._nameToSettingElement = new Map(); | |
| 151 for (var sectionName of explicitSectionOrder) | 149 for (var sectionName of explicitSectionOrder) |
| 152 this._sectionElement(sectionName); | 150 this._sectionElement(sectionName); |
| 153 self.runtime.extensions('setting').forEach(this._addSetting.bind(this)); | 151 self.runtime.extensions('setting').forEach(this._addSetting.bind(this)); |
| 154 self.runtime.extensions(UI.SettingUI).forEach(this._addSettingUI.bind(this))
; | 152 self.runtime.extensions(UI.SettingUI).forEach(this._addSettingUI.bind(this))
; |
| 155 | 153 |
| 156 this._appendSection().appendChild( | 154 this._appendSection().appendChild( |
| 157 UI.createTextButton(Common.UIString('Restore defaults and reload'), rest
oreAndReload)); | 155 UI.createTextButton(Common.UIString('Restore defaults and reload'), rest
oreAndReload)); |
| 158 | 156 |
| 159 function restoreAndReload() { | 157 function restoreAndReload() { |
| 160 Common.settings.clearAll(); | 158 Common.settings.clearAll(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 174 return false; | 172 return false; |
| 175 return true; | 173 return true; |
| 176 } | 174 } |
| 177 | 175 |
| 178 /** | 176 /** |
| 179 * @param {!Runtime.Extension} extension | 177 * @param {!Runtime.Extension} extension |
| 180 */ | 178 */ |
| 181 _addSetting(extension) { | 179 _addSetting(extension) { |
| 182 if (!Settings.GenericSettingsTab.isSettingVisible(extension)) | 180 if (!Settings.GenericSettingsTab.isSettingVisible(extension)) |
| 183 return; | 181 return; |
| 184 var descriptor = extension.descriptor(); | 182 var sectionElement = this._sectionElement(extension.descriptor()['category']
); |
| 185 var sectionName = descriptor['category']; | 183 var setting = Common.moduleSetting(extension.descriptor()['settingName']); |
| 186 var settingName = descriptor['settingName']; | 184 var settingControl = UI.SettingsUI.createControlForSetting(setting); |
| 187 var setting = Common.moduleSetting(settingName); | 185 if (settingControl) |
| 188 var uiTitle = Common.UIString(extension.title()); | |
| 189 | |
| 190 var sectionElement = this._sectionElement(sectionName); | |
| 191 var settingControl; | |
| 192 | |
| 193 switch (descriptor['settingType']) { | |
| 194 case 'boolean': | |
| 195 settingControl = UI.SettingsUI.createSettingCheckbox(uiTitle, setting); | |
| 196 break; | |
| 197 case 'enum': | |
| 198 if (Array.isArray(descriptor['options'])) | |
| 199 settingControl = UI.SettingsUI.createSettingSelect(uiTitle, descriptor
['options'], setting); | |
| 200 else | |
| 201 console.error('Enum setting defined without options'); | |
| 202 break; | |
| 203 default: | |
| 204 console.error('Invalid setting type: ' + descriptor['settingType']); | |
| 205 return; | |
| 206 } | |
| 207 if (settingControl) { | |
| 208 this._nameToSettingElement.set(settingName, settingControl); | |
| 209 sectionElement.appendChild(settingControl); | 186 sectionElement.appendChild(settingControl); |
| 210 } | |
| 211 } | 187 } |
| 212 | 188 |
| 213 /** | 189 /** |
| 214 * @param {!Runtime.Extension} extension | 190 * @param {!Runtime.Extension} extension |
| 215 */ | 191 */ |
| 216 _addSettingUI(extension) { | 192 _addSettingUI(extension) { |
| 217 var descriptor = extension.descriptor(); | 193 var descriptor = extension.descriptor(); |
| 218 var sectionName = descriptor['category'] || ''; | 194 var sectionName = descriptor['category'] || ''; |
| 219 extension.instance().then(appendCustomSetting.bind(this)); | 195 extension.instance().then(appendCustomSetting.bind(this)); |
| 220 | 196 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 return; | 348 return; |
| 373 var settings = extension.descriptor()['settings']; | 349 var settings = extension.descriptor()['settings']; |
| 374 if (settings && settings.indexOf(setting.name) !== -1) { | 350 if (settings && settings.indexOf(setting.name) !== -1) { |
| 375 InspectorFrontendHost.bringToFront(); | 351 InspectorFrontendHost.bringToFront(); |
| 376 Settings.SettingsScreen._showSettingsScreen(extension.descriptor()['id']
); | 352 Settings.SettingsScreen._showSettingsScreen(extension.descriptor()['id']
); |
| 377 success = true; | 353 success = true; |
| 378 } | 354 } |
| 379 } | 355 } |
| 380 } | 356 } |
| 381 }; | 357 }; |
| OLD | NEW |