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

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: acc 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 abb0b9c1875c065117ed006023aca3dcbf024e22..a6070a21f9870b250df041cf711e6c9703a38241 100644
--- a/third_party/WebKit/Source/devtools/front_end/ui/SettingsUI.js
+++ b/third_party/WebKit/Source/devtools/front_end/ui/SettingsUI.js
@@ -53,6 +53,44 @@ UI.SettingsUI.createSettingCheckbox = function(name, setting, omitParagraphEleme
return p;
};
+/**
+ * @param {string} name
+ * @param {!Array<!{title: string, text: (string|undefined), value: *, raw: (boolean|undefined)}>} options
dgozman 2017/05/15 18:57:25 You are not using title anywhere.
luoe 2017/05/16 00:05:37 Done.
+ * @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 optionText = /** @type {string} */ (option.text);
dgozman 2017/05/15 18:57:25 option.text || '' Or even better - make text non-
luoe 2017/05/16 00:05:38 Yeah, it makes sense that a select dropdown requir
+ var optionName = option.raw ? optionText : Common.UIString(optionText);
+ 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