Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/settings/SettingsScreen.js

Issue 2744883003: DevTools: generalize setting UI for enum/select settings (Closed)
Patch Set: ac Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 if (Array.isArray(descriptor['options']))
222 var options = new Array(descriptorOptions.length); 199 settingControl = UI.SettingsUI.createSettingSelect(uiTitle, descriptor ['options'], setting);
223 for (var i = 0; i < options.length; ++i) { 200 else
224 // The "raw" flag indicates text is non-i18n-izable. 201 console.error('Enum setting defined without options');
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; 202 break;
231 default: 203 default:
232 console.error('Invalid setting type: ' + descriptor['settingType']); 204 console.error('Invalid setting type: ' + descriptor['settingType']);
233 return; 205 return;
234 } 206 }
235 this._nameToSettingElement.set(settingName, settingControl); 207 if (settingControl) {
236 sectionElement.appendChild(/** @type {!Element} */ (settingControl)); 208 this._nameToSettingElement.set(settingName, settingControl);
209 sectionElement.appendChild(settingControl);
210 }
237 } 211 }
238 212
239 /** 213 /**
240 * @param {!Runtime.Extension} extension 214 * @param {!Runtime.Extension} extension
241 */ 215 */
242 _addSettingUI(extension) { 216 _addSettingUI(extension) {
243 var descriptor = extension.descriptor(); 217 var descriptor = extension.descriptor();
244 var sectionName = descriptor['category'] || ''; 218 var sectionName = descriptor['category'] || '';
245 extension.instance().then(appendCustomSetting.bind(this)); 219 extension.instance().then(appendCustomSetting.bind(this));
246 220
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 return; 372 return;
399 var settings = extension.descriptor()['settings']; 373 var settings = extension.descriptor()['settings'];
400 if (settings && settings.indexOf(setting.name) !== -1) { 374 if (settings && settings.indexOf(setting.name) !== -1) {
401 InspectorFrontendHost.bringToFront(); 375 InspectorFrontendHost.bringToFront();
402 Settings.SettingsScreen._showSettingsScreen(extension.descriptor()['id'] ); 376 Settings.SettingsScreen._showSettingsScreen(extension.descriptor()['id'] );
403 success = true; 377 success = true;
404 } 378 }
405 } 379 }
406 } 380 }
407 }; 381 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698