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

Unified Diff: third_party/WebKit/Source/devtools/front_end/ui/SettingsUI.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/settings/SettingsScreen.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7cc50addaff718cebb4a396f303cf21831fb54aa..c16b54580f46a147b6e4664e41272982aa70e040 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,43 @@ UI.SettingsUI.createSettingCheckbox = function(name, setting, omitParagraphEleme
};
/**
+ * @param {string} name
+ * @param {!Array<!{text: string, value: *, raw: (boolean|undefined)}>} options
+ * @param {!Common.Setting} setting
+ * @return {!Element}
+ */
+UI.SettingsUI.createSettingSelect = function(name, options, setting) {
+ 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 = options[i];
+ var optionName = option.raw ? option.text : Common.UIString(option.text);
+ select.add(new Option(optionName, option.value));
+ }
+
+ setting.addChangeListener(settingChanged);
+ settingChanged();
+ select.addEventListener('change', selectChanged, false);
+ return p;
+
+ function settingChanged() {
+ var newValue = setting.get();
+ 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
*/
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/settings/SettingsScreen.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698