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

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: rebase and keep settings pure 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 settingControl = UI.SettingsUI.createSettingSelect(uiTitle, descriptor[' options'], 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 return; 513 return;
545 var settings = extension.descriptor()['settings']; 514 var settings = extension.descriptor()['settings'];
546 if (settings && settings.indexOf(setting.name) !== -1) { 515 if (settings && settings.indexOf(setting.name) !== -1) {
547 InspectorFrontendHost.bringToFront(); 516 InspectorFrontendHost.bringToFront();
548 Settings.SettingsScreen._showSettingsScreen(extension.descriptor()['id'] ); 517 Settings.SettingsScreen._showSettingsScreen(extension.descriptor()['id'] );
549 success = true; 518 success = true;
550 } 519 }
551 } 520 }
552 } 521 }
553 }; 522 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698