OLD | NEW |
---|---|
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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 } | 208 } |
209 | 209 |
210 /** | 210 /** |
211 * @constructor | 211 * @constructor |
212 * @extends {WebInspector.SettingsTab} | 212 * @extends {WebInspector.SettingsTab} |
213 */ | 213 */ |
214 WebInspector.GenericSettingsTab = function() | 214 WebInspector.GenericSettingsTab = function() |
215 { | 215 { |
216 WebInspector.SettingsTab.call(this, WebInspector.UIString("General"), "gener al-tab-content"); | 216 WebInspector.SettingsTab.call(this, WebInspector.UIString("General"), "gener al-tab-content"); |
217 | 217 |
218 this._populateSectionsFromExtensions(); | 218 /** @const */ |
219 var explicitSectionOrder = ["", "Appearance", "Elements", "Sources", "Networ k", "Profiler", "Console", "Extensions"]; | |
220 /** @type {!Map<string, !Element>} */ | |
221 this._nameToSection = new Map(); | |
222 /** @type {!Map<string, !Element>} */ | |
223 this._nameToSettingFieldset = new Map(); | |
224 for (var sectionName of explicitSectionOrder) | |
225 this._sectionElement(sectionName); | |
226 self.runtime.extensions("setting").forEach(this._addSetting.bind(this)); | |
227 self.runtime.extensions(WebInspector.SettingUI).forEach(this._addSettingUI.b ind(this)); | |
219 | 228 |
220 this._appendSection().appendChild(createTextButton(WebInspector.UIString("Re store defaults and reload"), restoreAndReload)); | 229 this._appendSection().appendChild(createTextButton(WebInspector.UIString("Re store defaults and reload"), restoreAndReload)); |
221 | 230 |
222 function restoreAndReload() | 231 function restoreAndReload() |
223 { | 232 { |
224 if (window.localStorage) | 233 if (window.localStorage) |
225 window.localStorage.clear(); | 234 window.localStorage.clear(); |
226 WebInspector.reload(); | 235 WebInspector.reload(); |
227 } | 236 } |
228 } | 237 } |
229 | 238 |
230 WebInspector.GenericSettingsTab.prototype = { | 239 WebInspector.GenericSettingsTab.prototype = { |
231 _populateSectionsFromExtensions: function() | 240 /** |
241 * @param {!Runtime.Extension} extension | |
242 */ | |
243 _addSetting: function(extension) | |
232 { | 244 { |
233 /** @const */ | 245 var descriptor = extension.descriptor(); |
234 var explicitSectionOrder = ["", "Appearance", "Elements", "Sources", "Ne twork", "Profiler", "Console", "Extensions"]; | 246 var sectionName = descriptor["category"] || ""; |
235 | 247 |
236 var allExtensions = self.runtime.extensions("ui-setting"); | 248 var settingName = descriptor["settingName"]; |
249 var setting = WebInspector.settings[settingName]; | |
dgozman
2015/04/06 14:40:36
Why not |WI.settings.createSetting(settingName)|?
pfeldman
2015/04/06 17:15:00
Because I don't know the default value yet.
| |
250 var uiTitle = WebInspector.UIString(descriptor["title-" + WebInspector.p latform()] || descriptor["title"]); | |
237 | 251 |
238 /** @type {!Multimap.<string, !Runtime.Extension>} */ | 252 var sectionElement = this._sectionElement(sectionName); |
239 var extensionsBySectionId = new Multimap(); | 253 var parentFieldset = descriptor["parentSettingName"] ? this._nameToSetti ngFieldset.get(descriptor["parentSettingName"]) : null; |
dgozman
2015/04/06 14:40:36
This depends on the order of processing.
pfeldman
2015/04/06 17:15:00
Yes and I kinda think that this is alright.
| |
240 /** @type {!Multimap.<string, !Runtime.Extension>} */ | |
241 var childSettingExtensionsByParentName = new Multimap(); | |
242 | 254 |
243 allExtensions.forEach(function(extension) { | 255 var settingControl; |
244 var descriptor = extension.descriptor(); | 256 |
245 var sectionName = descriptor["section"] || ""; | 257 switch (descriptor["settingType"]) { |
246 if (!sectionName && descriptor["parentSettingName"]) { | 258 case "boolean": |
247 childSettingExtensionsByParentName.set(descriptor["parentSetting Name"], extension); | 259 settingControl = WebInspector.SettingsUI.createSettingCheckbox(uiTit le, setting); |
248 return; | 260 break; |
261 case "enum": | |
262 var descriptorOptions = descriptor["options"]; | |
263 var options = new Array(descriptorOptions.length); | |
264 for (var i = 0; i < options.length; ++i) { | |
265 // The third array item flags that the option name is "raw" (non -i18n-izable). | |
266 var optionName = descriptorOptions[i][2] ? descriptorOptions[i][ 0] : WebInspector.UIString(descriptorOptions[i][0]); | |
267 options[i] = [optionName, descriptorOptions[i][1]]; | |
249 } | 268 } |
250 extensionsBySectionId.set(sectionName, extension); | 269 settingControl = this._createSelectSetting(uiTitle, options, setting ); |
251 }); | 270 break; |
271 default: | |
272 console.error("Invalid setting type: " + descriptor["settingType"]); | |
273 return; | |
274 } | |
252 | 275 |
253 var sectionIds = extensionsBySectionId.keysArray(); | 276 var fieldSet = WebInspector.SettingsUI.createSettingFieldset(setting); |
254 var explicitlyOrderedSections = explicitSectionOrder.keySet(); | 277 this._nameToSettingFieldset.set(settingName, fieldSet); |
255 for (var i = 0; i < explicitSectionOrder.length; ++i) { | 278 settingControl.appendChild(fieldSet); |
dgozman
2015/04/06 14:40:36
Why don't you create fieldset when you need it bec
pfeldman
2015/04/06 17:15:00
Ok, sure.
| |
256 var extensions = extensionsBySectionId.get(explicitSectionOrder[i]); | 279 |
257 if (!extensions.size) | 280 (parentFieldset || sectionElement).appendChild(/** @type {!Element} */ ( settingControl)); |
258 continue; | 281 }, |
259 this._addSectionWithExtensionProvidedSettings(explicitSectionOrder[i ], extensions.valuesArray(), childSettingExtensionsByParentName); | 282 |
260 } | 283 /** |
261 for (var i = 0; i < sectionIds.length; ++i) { | 284 * @param {!Runtime.Extension} extension |
262 if (explicitlyOrderedSections[sectionIds[i]]) | 285 */ |
263 continue; | 286 _addSettingUI: function(extension) |
264 this._addSectionWithExtensionProvidedSettings(sectionIds[i], extensi onsBySectionId.get(sectionIds[i]).valuesArray(), childSettingExtensionsByParentN ame); | 287 { |
288 var descriptor = extension.descriptor(); | |
289 var sectionName = descriptor["category"] || ""; | |
290 extension.instancePromise().then(appendCustomSetting.bind(this)); | |
291 | |
292 /** | |
293 * @param {!Object} object | |
294 * @this {WebInspector.GenericSettingsTab} | |
295 */ | |
296 function appendCustomSetting(object) | |
297 { | |
298 var settingUI = /** @type {!WebInspector.SettingUI} */ (object); | |
299 var element = settingUI.settingElement(); | |
300 if (element) | |
301 this._sectionElement(sectionName).appendChild(element); | |
265 } | 302 } |
266 }, | 303 }, |
267 | 304 |
268 /** | 305 /** |
269 * @param {string} sectionName | 306 * @param {string} sectionName |
270 * @param {!Array.<!Runtime.Extension>} extensions | 307 * @return {!Element} |
271 * @param {!Multimap.<string, !Runtime.Extension>} childSettingExtensionsByP arentName | |
272 */ | 308 */ |
273 _addSectionWithExtensionProvidedSettings: function(sectionName, extensions, childSettingExtensionsByParentName) | 309 _sectionElement: function(sectionName) |
274 { | 310 { |
275 var uiSectionName = sectionName && WebInspector.UIString(sectionName); | 311 var sectionElement = this._nameToSection.get(sectionName); |
276 var sectionElement = this._appendSection(uiSectionName); | 312 if (!sectionElement) { |
277 extensions.forEach(processSetting.bind(this, null)); | 313 var uiSectionName = sectionName && WebInspector.UIString(sectionName ); |
278 | 314 sectionElement = this._appendSection(uiSectionName); |
279 /** | 315 this._nameToSection.set(sectionName, sectionElement); |
280 * @param {?Element} parentFieldset | |
281 * @param {!Runtime.Extension} extension | |
282 * @this {WebInspector.GenericSettingsTab} | |
283 */ | |
284 function processSetting(parentFieldset, extension) | |
285 { | |
286 var descriptor = extension.descriptor(); | |
287 var experimentName = descriptor["experiment"]; | |
288 if (experimentName && !Runtime.experiments.isEnabled(experimentName) ) | |
289 return; | |
290 | |
291 if (descriptor["settingType"] === "custom") { | |
292 extension.instancePromise().then(appendCustomSetting); | |
293 return; | |
294 } | |
295 | |
296 var uiTitle = WebInspector.UIString(descriptor["title"]); | |
297 var settingName = descriptor["settingName"]; | |
298 var setting = WebInspector.settings[settingName]; | |
299 var settingControl = createSettingControl.call(this, uiTitle, settin g, descriptor); | |
300 if (settingName) { | |
301 var childSettings = childSettingExtensionsByParentName.get(setti ngName); | |
302 if (childSettings.size) { | |
303 var fieldSet = WebInspector.SettingsUI.createSettingFieldset (setting); | |
304 settingControl.appendChild(fieldSet); | |
305 childSettings.valuesArray().forEach(function(item) { process Setting.call(this, fieldSet, item); }, this); | |
306 } | |
307 } | |
308 appendAsChild(settingControl); | |
309 | |
310 /** | |
311 * @param {!Object} object | |
312 */ | |
313 function appendCustomSetting(object) | |
314 { | |
315 var uiSettingDelegate = /** @type {!WebInspector.UISettingDelega te} */ (object); | |
316 var element = uiSettingDelegate.settingElement(); | |
317 if (element) | |
318 appendAsChild(element); | |
319 } | |
320 | |
321 /** | |
322 * @param {!Object} settingControl | |
323 */ | |
324 function appendAsChild(settingControl) | |
325 { | |
326 (parentFieldset || sectionElement).appendChild(/** @type {!Eleme nt} */ (settingControl)); | |
327 } | |
328 } | 316 } |
329 | 317 return sectionElement; |
330 /** | |
331 * @param {string} uiTitle | |
332 * @param {!WebInspector.Setting} setting | |
333 * @param {!Object} descriptor | |
334 * @return {!Element} | |
335 * @this {WebInspector.GenericSettingsTab} | |
336 */ | |
337 function createSettingControl(uiTitle, setting, descriptor) | |
338 { | |
339 switch (descriptor["settingType"]) { | |
340 case "checkbox": | |
341 return WebInspector.SettingsUI.createSettingCheckbox(uiTitle, se tting); | |
342 case "select": | |
343 var descriptorOptions = descriptor["options"]; | |
344 var options = new Array(descriptorOptions.length); | |
345 for (var i = 0; i < options.length; ++i) { | |
346 // The third array item flags that the option name is "raw" (non-i18n-izable). | |
347 var optionName = descriptorOptions[i][2] ? descriptorOptions [i][0] : WebInspector.UIString(descriptorOptions[i][0]); | |
348 options[i] = [optionName, descriptorOptions[i][1]]; | |
349 } | |
350 return this._createSelectSetting(uiTitle, options, setting); | |
351 default: | |
352 throw "Invalid setting type: " + descriptor["settingType"]; | |
353 } | |
354 } | |
355 }, | 318 }, |
356 | 319 |
357 __proto__: WebInspector.SettingsTab.prototype | 320 __proto__: WebInspector.SettingsTab.prototype |
358 } | 321 } |
359 | 322 |
360 /** | 323 /** |
361 * @constructor | 324 * @constructor |
362 * @extends {WebInspector.UISettingDelegate} | 325 * @implements {WebInspector.SettingUI} |
363 */ | 326 */ |
364 WebInspector.SettingsScreen.SkipStackFramePatternSettingDelegate = function() | 327 WebInspector.SettingsScreen.SkipStackFramePatternSettingUI = function() |
365 { | 328 { |
366 WebInspector.UISettingDelegate.call(this); | |
367 } | 329 } |
368 | 330 |
369 WebInspector.SettingsScreen.SkipStackFramePatternSettingDelegate.prototype = { | 331 WebInspector.SettingsScreen.SkipStackFramePatternSettingUI.prototype = { |
370 /** | 332 /** |
371 * @override | 333 * @override |
372 * @return {!Element} | 334 * @return {!Element} |
373 */ | 335 */ |
374 settingElement: function() | 336 settingElement: function() |
375 { | 337 { |
376 return createTextButton(WebInspector.manageBlackboxingButtonLabel(), thi s._onManageButtonClick.bind(this), "", WebInspector.UIString("Skip stepping thro ugh sources with particular names")); | 338 return createTextButton(WebInspector.manageBlackboxingButtonLabel(), thi s._onManageButtonClick.bind(this), "", WebInspector.UIString("Skip stepping thro ugh sources with particular names")); |
377 }, | 339 }, |
378 | 340 |
379 _onManageButtonClick: function() | 341 _onManageButtonClick: function() |
380 { | 342 { |
381 WebInspector.FrameworkBlackboxDialog.show(WebInspector.inspectorView.ele ment); | 343 WebInspector.FrameworkBlackboxDialog.show(WebInspector.inspectorView.ele ment); |
382 }, | 344 } |
383 | |
384 __proto__: WebInspector.UISettingDelegate.prototype | |
385 } | 345 } |
386 | 346 |
387 /** | 347 /** |
388 * @constructor | 348 * @constructor |
389 * @extends {WebInspector.SettingsTab} | 349 * @extends {WebInspector.SettingsTab} |
390 */ | 350 */ |
391 WebInspector.WorkspaceSettingsTab = function() | 351 WebInspector.WorkspaceSettingsTab = function() |
392 { | 352 { |
393 WebInspector.SettingsTab.call(this, WebInspector.UIString("Workspace"), "wor kspace-tab-content"); | 353 WebInspector.SettingsTab.call(this, WebInspector.UIString("Workspace"), "wor kspace-tab-content"); |
394 WebInspector.isolatedFileSystemManager.addEventListener(WebInspector.Isolate dFileSystemManager.Events.FileSystemAdded, this._fileSystemAdded, this); | 354 WebInspector.isolatedFileSystemManager.addEventListener(WebInspector.Isolate dFileSystemManager.Events.FileSystemAdded, this._fileSystemAdded, this); |
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1460 var columnId = columns[i]; | 1420 var columnId = columns[i]; |
1461 var editElement = this._addInputElements.get(columnId); | 1421 var editElement = this._addInputElements.get(columnId); |
1462 this._setEditElementValue(editElement, ""); | 1422 this._setEditElementValue(editElement, ""); |
1463 } | 1423 } |
1464 }, | 1424 }, |
1465 | 1425 |
1466 __proto__: WebInspector.SettingsList.prototype | 1426 __proto__: WebInspector.SettingsList.prototype |
1467 } | 1427 } |
1468 | 1428 |
1469 WebInspector._settingsController = new WebInspector.SettingsController(); | 1429 WebInspector._settingsController = new WebInspector.SettingsController(); |
OLD | NEW |