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

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: rebase and keep settings pure Created 3 years, 8 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
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..c272bcf0549c6cf0fdaab3d3d195ada21e44f0d5 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,46 @@ UI.SettingsUI.createSettingCheckbox = function(name, setting, omitParagraphEleme
};
/**
+ * @param {string} name
+ * @param {!Array<!Runtime.ExtensionDescriptor.Option>} options
+ * @param {!Common.Setting} setting
+ * @return {!Element}
+ */
+UI.SettingsUI.createSettingSelect = function(name, options, setting) {
pfeldman 2017/05/10 20:58:42 Oh, this is a good one!
luoe 2017/05/11 21:39:43 XD
+ 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 = /** @type {!Runtime.ExtensionDescriptor.Option} */ (options[i]);
+ var optionText = /** @type {string} */ (option.text);
+ 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();
+ if (options[select.selectedIndex].value !== newValue) {
pfeldman 2017/05/10 20:58:42 Why did you add this line? I don't think it makes
luoe 2017/05/11 21:39:43 Done.
+ 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
*/

Powered by Google App Engine
This is Rietveld 408576698