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 |
11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 * distribution. | 13 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 /** |
31 /** | |
32 * @constructor | |
33 * @extends {WebInspector.VBox} | |
34 * @implements {WebInspector.ViewLocationResolver} | 31 * @implements {WebInspector.ViewLocationResolver} |
35 */ | 32 * @unrestricted |
36 WebInspector.SettingsScreen = function() | 33 */ |
37 { | 34 WebInspector.SettingsScreen = class extends WebInspector.VBox { |
38 WebInspector.VBox.call(this, true); | 35 constructor() { |
39 this.registerRequiredCSS("settings/settingsScreen.css"); | 36 super(true); |
| 37 this.registerRequiredCSS('settings/settingsScreen.css'); |
40 | 38 |
41 this.contentElement.tabIndex = 0; | 39 this.contentElement.tabIndex = 0; |
42 this.contentElement.classList.add("help-window-main"); | 40 this.contentElement.classList.add('help-window-main'); |
43 this.contentElement.classList.add("vbox"); | 41 this.contentElement.classList.add('vbox'); |
44 | 42 |
45 var settingsLabelElement = createElement("div"); | 43 var settingsLabelElement = createElement('div'); |
46 WebInspector.createShadowRootWithCoreStyles(settingsLabelElement, "settings/
settingsScreen.css").createChild("div", "settings-window-title").textContent = W
ebInspector.UIString("Settings"); | 44 WebInspector.createShadowRootWithCoreStyles(settingsLabelElement, 'settings/
settingsScreen.css') |
47 | 45 .createChild('div', 'settings-window-title') |
48 this._tabbedLocation = WebInspector.viewManager.createTabbedLocation(() => W
ebInspector.SettingsScreen._showSettingsScreen(), "settings-view"); | 46 .textContent = WebInspector.UIString('Settings'); |
| 47 |
| 48 this._tabbedLocation = WebInspector.viewManager.createTabbedLocation( |
| 49 () => WebInspector.SettingsScreen._showSettingsScreen(), 'settings-view'
); |
49 var tabbedPane = this._tabbedLocation.tabbedPane(); | 50 var tabbedPane = this._tabbedLocation.tabbedPane(); |
50 tabbedPane.leftToolbar().appendToolbarItem(new WebInspector.ToolbarItem(sett
ingsLabelElement)); | 51 tabbedPane.leftToolbar().appendToolbarItem(new WebInspector.ToolbarItem(sett
ingsLabelElement)); |
51 tabbedPane.setShrinkableTabs(false); | 52 tabbedPane.setShrinkableTabs(false); |
52 tabbedPane.setVerticalTabLayout(true); | 53 tabbedPane.setVerticalTabLayout(true); |
53 var shortcutsView = new WebInspector.SimpleView(WebInspector.UIString("Short
cuts")); | 54 var shortcutsView = new WebInspector.SimpleView(WebInspector.UIString('Short
cuts')); |
54 WebInspector.shortcutsScreen.createShortcutsTabView().show(shortcutsView.ele
ment); | 55 WebInspector.shortcutsScreen.createShortcutsTabView().show(shortcutsView.ele
ment); |
55 this._tabbedLocation.appendView(shortcutsView); | 56 this._tabbedLocation.appendView(shortcutsView); |
56 tabbedPane.show(this.contentElement); | 57 tabbedPane.show(this.contentElement); |
57 | 58 |
58 this.element.addEventListener("keydown", this._keyDown.bind(this), false); | 59 this.element.addEventListener('keydown', this._keyDown.bind(this), false); |
59 this._developerModeCounter = 0; | 60 this._developerModeCounter = 0; |
60 this.setDefaultFocusedElement(this.contentElement); | 61 this.setDefaultFocusedElement(this.contentElement); |
61 }; | 62 } |
62 | 63 |
63 /** | 64 /** |
64 * @param {string=} name | 65 * @param {string=} name |
65 */ | 66 */ |
66 WebInspector.SettingsScreen._showSettingsScreen = function(name) | 67 static _showSettingsScreen(name) { |
67 { | 68 var settingsScreen = |
68 var settingsScreen = /** @type {!WebInspector.SettingsScreen} */ (self.runti
me.sharedInstance(WebInspector.SettingsScreen)); | 69 /** @type {!WebInspector.SettingsScreen} */ (self.runtime.sharedInstance
(WebInspector.SettingsScreen)); |
69 if (settingsScreen.isShowing()) | 70 if (settingsScreen.isShowing()) |
70 return; | 71 return; |
71 var dialog = new WebInspector.Dialog(); | 72 var dialog = new WebInspector.Dialog(); |
72 dialog.addCloseButton(); | 73 dialog.addCloseButton(); |
73 settingsScreen.show(dialog.element); | 74 settingsScreen.show(dialog.element); |
74 dialog.show(); | 75 dialog.show(); |
75 settingsScreen._selectTab(name || "preferences"); | 76 settingsScreen._selectTab(name || 'preferences'); |
| 77 } |
| 78 |
| 79 /** |
| 80 * @override |
| 81 * @param {string} locationName |
| 82 * @return {?WebInspector.ViewLocation} |
| 83 */ |
| 84 resolveLocation(locationName) { |
| 85 return this._tabbedLocation; |
| 86 } |
| 87 |
| 88 /** |
| 89 * @param {string} name |
| 90 */ |
| 91 _selectTab(name) { |
| 92 WebInspector.viewManager.showView(name); |
| 93 } |
| 94 |
| 95 /** |
| 96 * @param {!Event} event |
| 97 */ |
| 98 _keyDown(event) { |
| 99 var shiftKeyCode = 16; |
| 100 if (event.keyCode === shiftKeyCode && ++this._developerModeCounter > 5) |
| 101 this.contentElement.classList.add('settings-developer-mode'); |
| 102 } |
76 }; | 103 }; |
77 | 104 |
78 WebInspector.SettingsScreen.prototype = { | 105 |
79 /** | 106 /** |
80 * @override | 107 * @unrestricted |
81 * @param {string} locationName | 108 */ |
82 * @return {?WebInspector.ViewLocation} | 109 WebInspector.SettingsTab = class extends WebInspector.VBox { |
83 */ | 110 /** |
84 resolveLocation: function(locationName) | 111 * @param {string} name |
85 { | 112 * @param {string=} id |
86 return this._tabbedLocation; | 113 */ |
87 }, | 114 constructor(name, id) { |
88 | 115 super(); |
89 /** | 116 this.element.classList.add('settings-tab-container'); |
90 * @param {string} name | 117 if (id) |
91 */ | 118 this.element.id = id; |
92 _selectTab: function(name) | 119 var header = this.element.createChild('header'); |
93 { | 120 header.createChild('h3').createTextChild(name); |
94 WebInspector.viewManager.showView(name); | 121 this.containerElement = this.element.createChild('div', 'help-container-wrap
per') |
95 }, | 122 .createChild('div', 'settings-tab help-content h
elp-container'); |
96 | 123 } |
97 /** | 124 |
98 * @param {!Event} event | 125 /** |
99 */ | 126 * @param {string=} name |
100 _keyDown: function(event) | 127 * @return {!Element} |
101 { | 128 */ |
102 var shiftKeyCode = 16; | 129 _appendSection(name) { |
103 if (event.keyCode === shiftKeyCode && ++this._developerModeCounter > 5) | 130 var block = this.containerElement.createChild('div', 'help-block'); |
104 this.contentElement.classList.add("settings-developer-mode"); | 131 if (name) |
105 }, | 132 block.createChild('div', 'help-section-title').textContent = name; |
106 | 133 return block; |
107 __proto__: WebInspector.VBox.prototype | 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 } |
108 }; | 158 }; |
109 | 159 |
110 /** | 160 /** |
111 * @constructor | 161 * @unrestricted |
112 * @extends {WebInspector.VBox} | 162 */ |
113 * @param {string} name | 163 WebInspector.GenericSettingsTab = class extends WebInspector.SettingsTab { |
114 * @param {string=} id | 164 constructor() { |
115 */ | 165 super(WebInspector.UIString('Preferences'), 'preferences-tab-content'); |
116 WebInspector.SettingsTab = function(name, id) | |
117 { | |
118 WebInspector.VBox.call(this); | |
119 this.element.classList.add("settings-tab-container"); | |
120 if (id) | |
121 this.element.id = id; | |
122 var header = this.element.createChild("header"); | |
123 header.createChild("h3").createTextChild(name); | |
124 this.containerElement = this.element.createChild("div", "help-container-wrap
per").createChild("div", "settings-tab help-content help-container"); | |
125 }; | |
126 | |
127 WebInspector.SettingsTab.prototype = { | |
128 /** | |
129 * @param {string=} name | |
130 * @return {!Element} | |
131 */ | |
132 _appendSection: function(name) | |
133 { | |
134 var block = this.containerElement.createChild("div", "help-block"); | |
135 if (name) | |
136 block.createChild("div", "help-section-title").textContent = name; | |
137 return block; | |
138 }, | |
139 | |
140 _createSelectSetting: function(name, options, setting) | |
141 { | |
142 var p = createElement("p"); | |
143 p.createChild("label").textContent = name; | |
144 | |
145 var select = p.createChild("select", "chrome-select"); | |
146 var settingValue = setting.get(); | |
147 | |
148 for (var i = 0; i < options.length; ++i) { | |
149 var option = options[i]; | |
150 select.add(new Option(option[0], option[1])); | |
151 if (settingValue === option[1]) | |
152 select.selectedIndex = i; | |
153 } | |
154 | |
155 function changeListener(e) | |
156 { | |
157 // Don't use e.target.value to avoid conversion of the value to stri
ng. | |
158 setting.set(options[select.selectedIndex][1]); | |
159 } | |
160 | |
161 select.addEventListener("change", changeListener, false); | |
162 return p; | |
163 }, | |
164 | |
165 __proto__: WebInspector.VBox.prototype | |
166 }; | |
167 | |
168 /** | |
169 * @constructor | |
170 * @extends {WebInspector.SettingsTab} | |
171 */ | |
172 WebInspector.GenericSettingsTab = function() | |
173 { | |
174 WebInspector.SettingsTab.call(this, WebInspector.UIString("Preferences"), "p
references-tab-content"); | |
175 | 166 |
176 /** @const */ | 167 /** @const */ |
177 var explicitSectionOrder = ["", "Appearance", "Elements", "Sources", "Networ
k", "Profiler", "Console", "Extensions"]; | 168 var explicitSectionOrder = |
| 169 ['', 'Appearance', 'Elements', 'Sources', 'Network', 'Profiler', 'Consol
e', 'Extensions']; |
178 /** @type {!Map<string, !Element>} */ | 170 /** @type {!Map<string, !Element>} */ |
179 this._nameToSection = new Map(); | 171 this._nameToSection = new Map(); |
180 /** @type {!Map<string, !Element>} */ | 172 /** @type {!Map<string, !Element>} */ |
181 this._nameToSettingElement = new Map(); | 173 this._nameToSettingElement = new Map(); |
182 for (var sectionName of explicitSectionOrder) | 174 for (var sectionName of explicitSectionOrder) |
183 this._sectionElement(sectionName); | 175 this._sectionElement(sectionName); |
184 self.runtime.extensions("setting").forEach(this._addSetting.bind(this)); | 176 self.runtime.extensions('setting').forEach(this._addSetting.bind(this)); |
185 self.runtime.extensions(WebInspector.SettingUI).forEach(this._addSettingUI.b
ind(this)); | 177 self.runtime.extensions(WebInspector.SettingUI).forEach(this._addSettingUI.b
ind(this)); |
186 | 178 |
187 this._appendSection().appendChild(createTextButton(WebInspector.UIString("Re
store defaults and reload"), restoreAndReload)); | 179 this._appendSection().appendChild( |
188 | 180 createTextButton(WebInspector.UIString('Restore defaults and reload'), r
estoreAndReload)); |
189 function restoreAndReload() | 181 |
190 { | 182 function restoreAndReload() { |
191 WebInspector.settings.clearAll(); | 183 WebInspector.settings.clearAll(); |
192 WebInspector.reload(); | 184 WebInspector.reload(); |
193 } | 185 } |
| 186 } |
| 187 |
| 188 /** |
| 189 * @param {!Runtime.Extension} extension |
| 190 * @return {boolean} |
| 191 */ |
| 192 static isSettingVisible(extension) { |
| 193 var descriptor = extension.descriptor(); |
| 194 if (!('title' in descriptor)) |
| 195 return false; |
| 196 if (!('category' in descriptor)) |
| 197 return false; |
| 198 return true; |
| 199 } |
| 200 |
| 201 /** |
| 202 * @param {!Runtime.Extension} extension |
| 203 */ |
| 204 _addSetting(extension) { |
| 205 if (!WebInspector.GenericSettingsTab.isSettingVisible(extension)) |
| 206 return; |
| 207 var descriptor = extension.descriptor(); |
| 208 var sectionName = descriptor['category']; |
| 209 var settingName = descriptor['settingName']; |
| 210 var setting = WebInspector.moduleSetting(settingName); |
| 211 var uiTitle = WebInspector.UIString(extension.title()); |
| 212 |
| 213 var sectionElement = this._sectionElement(sectionName); |
| 214 var settingControl; |
| 215 |
| 216 switch (descriptor['settingType']) { |
| 217 case 'boolean': |
| 218 settingControl = WebInspector.SettingsUI.createSettingCheckbox(uiTitle,
setting); |
| 219 break; |
| 220 case 'enum': |
| 221 var descriptorOptions = descriptor['options']; |
| 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 WebInspector.UIString(d
escriptorOptions[i]['text']); |
| 227 options[i] = [optionName, descriptorOptions[i]['value']]; |
| 228 } |
| 229 settingControl = this._createSelectSetting(uiTitle, options, setting); |
| 230 break; |
| 231 default: |
| 232 console.error('Invalid setting type: ' + descriptor['settingType']); |
| 233 return; |
| 234 } |
| 235 this._nameToSettingElement.set(settingName, settingControl); |
| 236 sectionElement.appendChild(/** @type {!Element} */ (settingControl)); |
| 237 } |
| 238 |
| 239 /** |
| 240 * @param {!Runtime.Extension} extension |
| 241 */ |
| 242 _addSettingUI(extension) { |
| 243 var descriptor = extension.descriptor(); |
| 244 var sectionName = descriptor['category'] || ''; |
| 245 extension.instance().then(appendCustomSetting.bind(this)); |
| 246 |
| 247 /** |
| 248 * @param {!Object} object |
| 249 * @this {WebInspector.GenericSettingsTab} |
| 250 */ |
| 251 function appendCustomSetting(object) { |
| 252 var settingUI = /** @type {!WebInspector.SettingUI} */ (object); |
| 253 var element = settingUI.settingElement(); |
| 254 if (element) |
| 255 this._sectionElement(sectionName).appendChild(element); |
| 256 } |
| 257 } |
| 258 |
| 259 /** |
| 260 * @param {string} sectionName |
| 261 * @return {!Element} |
| 262 */ |
| 263 _sectionElement(sectionName) { |
| 264 var sectionElement = this._nameToSection.get(sectionName); |
| 265 if (!sectionElement) { |
| 266 var uiSectionName = sectionName && WebInspector.UIString(sectionName); |
| 267 sectionElement = this._appendSection(uiSectionName); |
| 268 this._nameToSection.set(sectionName, sectionElement); |
| 269 } |
| 270 return sectionElement; |
| 271 } |
194 }; | 272 }; |
195 | 273 |
196 /** | 274 |
197 * @param {!Runtime.Extension} extension | 275 /** |
198 * @return {boolean} | 276 * @unrestricted |
199 */ | 277 */ |
200 WebInspector.GenericSettingsTab.isSettingVisible = function(extension) | 278 WebInspector.WorkspaceSettingsTab = class extends WebInspector.SettingsTab { |
201 { | 279 constructor() { |
202 var descriptor = extension.descriptor(); | 280 super(WebInspector.UIString('Workspace'), 'workspace-tab-content'); |
203 if (!("title" in descriptor)) | 281 WebInspector.isolatedFileSystemManager.addEventListener( |
204 return false; | 282 WebInspector.IsolatedFileSystemManager.Events.FileSystemAdded, this._fil
eSystemAdded, this); |
205 if (!("category" in descriptor)) | 283 WebInspector.isolatedFileSystemManager.addEventListener( |
206 return false; | 284 WebInspector.IsolatedFileSystemManager.Events.FileSystemRemoved, this._f
ileSystemRemoved, this); |
207 return true; | |
208 }; | |
209 | |
210 WebInspector.GenericSettingsTab.prototype = { | |
211 /** | |
212 * @param {!Runtime.Extension} extension | |
213 */ | |
214 _addSetting: function(extension) | |
215 { | |
216 if (!WebInspector.GenericSettingsTab.isSettingVisible(extension)) | |
217 return; | |
218 var descriptor = extension.descriptor(); | |
219 var sectionName = descriptor["category"]; | |
220 var settingName = descriptor["settingName"]; | |
221 var setting = WebInspector.moduleSetting(settingName); | |
222 var uiTitle = WebInspector.UIString(extension.title()); | |
223 | |
224 var sectionElement = this._sectionElement(sectionName); | |
225 var settingControl; | |
226 | |
227 switch (descriptor["settingType"]) { | |
228 case "boolean": | |
229 settingControl = WebInspector.SettingsUI.createSettingCheckbox(uiTit
le, setting); | |
230 break; | |
231 case "enum": | |
232 var descriptorOptions = descriptor["options"]; | |
233 var options = new Array(descriptorOptions.length); | |
234 for (var i = 0; i < options.length; ++i) { | |
235 // The "raw" flag indicates text is non-i18n-izable. | |
236 var optionName = descriptorOptions[i]["raw"] ? descriptorOptions
[i]["text"] : WebInspector.UIString(descriptorOptions[i]["text"]); | |
237 options[i] = [optionName, descriptorOptions[i]["value"]]; | |
238 } | |
239 settingControl = this._createSelectSetting(uiTitle, options, setting
); | |
240 break; | |
241 default: | |
242 console.error("Invalid setting type: " + descriptor["settingType"]); | |
243 return; | |
244 } | |
245 this._nameToSettingElement.set(settingName, settingControl); | |
246 sectionElement.appendChild(/** @type {!Element} */ (settingControl)); | |
247 }, | |
248 | |
249 /** | |
250 * @param {!Runtime.Extension} extension | |
251 */ | |
252 _addSettingUI: function(extension) | |
253 { | |
254 var descriptor = extension.descriptor(); | |
255 var sectionName = descriptor["category"] || ""; | |
256 extension.instance().then(appendCustomSetting.bind(this)); | |
257 | |
258 /** | |
259 * @param {!Object} object | |
260 * @this {WebInspector.GenericSettingsTab} | |
261 */ | |
262 function appendCustomSetting(object) | |
263 { | |
264 var settingUI = /** @type {!WebInspector.SettingUI} */ (object); | |
265 var element = settingUI.settingElement(); | |
266 if (element) | |
267 this._sectionElement(sectionName).appendChild(element); | |
268 } | |
269 }, | |
270 | |
271 /** | |
272 * @param {string} sectionName | |
273 * @return {!Element} | |
274 */ | |
275 _sectionElement: function(sectionName) | |
276 { | |
277 var sectionElement = this._nameToSection.get(sectionName); | |
278 if (!sectionElement) { | |
279 var uiSectionName = sectionName && WebInspector.UIString(sectionName
); | |
280 sectionElement = this._appendSection(uiSectionName); | |
281 this._nameToSection.set(sectionName, sectionElement); | |
282 } | |
283 return sectionElement; | |
284 }, | |
285 | |
286 __proto__: WebInspector.SettingsTab.prototype | |
287 }; | |
288 | |
289 /** | |
290 * @constructor | |
291 * @extends {WebInspector.SettingsTab} | |
292 */ | |
293 WebInspector.WorkspaceSettingsTab = function() | |
294 { | |
295 WebInspector.SettingsTab.call(this, WebInspector.UIString("Workspace"), "wor
kspace-tab-content"); | |
296 WebInspector.isolatedFileSystemManager.addEventListener(WebInspector.Isolate
dFileSystemManager.Events.FileSystemAdded, this._fileSystemAdded, this); | |
297 WebInspector.isolatedFileSystemManager.addEventListener(WebInspector.Isolate
dFileSystemManager.Events.FileSystemRemoved, this._fileSystemRemoved, this); | |
298 | 285 |
299 var folderExcludePatternInput = this._createFolderExcludePatternInput(); | 286 var folderExcludePatternInput = this._createFolderExcludePatternInput(); |
300 folderExcludePatternInput.classList.add("folder-exclude-pattern"); | 287 folderExcludePatternInput.classList.add('folder-exclude-pattern'); |
301 this.containerElement.appendChild(folderExcludePatternInput); | 288 this.containerElement.appendChild(folderExcludePatternInput); |
302 | 289 |
303 this._fileSystemsListContainer = this.containerElement.createChild("div", ""
); | 290 this._fileSystemsListContainer = this.containerElement.createChild('div', ''
); |
304 | 291 |
305 this.containerElement.appendChild(createTextButton(WebInspector.UIString("Ad
d folder\u2026"), this._addFileSystemClicked.bind(this))); | 292 this.containerElement.appendChild( |
| 293 createTextButton(WebInspector.UIString('Add folder\u2026'), this._addFil
eSystemClicked.bind(this))); |
306 | 294 |
307 /** @type {!Map<string, !Element>} */ | 295 /** @type {!Map<string, !Element>} */ |
308 this._elementByPath = new Map(); | 296 this._elementByPath = new Map(); |
309 | 297 |
310 /** @type {!Map<string, !WebInspector.EditFileSystemView>} */ | 298 /** @type {!Map<string, !WebInspector.EditFileSystemView>} */ |
311 this._mappingViewByPath = new Map(); | 299 this._mappingViewByPath = new Map(); |
312 | 300 |
313 var fileSystems = WebInspector.isolatedFileSystemManager.fileSystems(); | 301 var fileSystems = WebInspector.isolatedFileSystemManager.fileSystems(); |
314 for (var i = 0; i < fileSystems.length; ++i) | 302 for (var i = 0; i < fileSystems.length; ++i) |
315 this._addItem(fileSystems[i]); | 303 this._addItem(fileSystems[i]); |
316 }; | 304 } |
317 | 305 |
318 WebInspector.WorkspaceSettingsTab.prototype = { | 306 /** |
319 /** | 307 * @return {!Element} |
320 * @return {!Element} | 308 */ |
321 */ | 309 _createFolderExcludePatternInput() { |
322 _createFolderExcludePatternInput: function() | 310 var p = createElement('p'); |
323 { | 311 var labelElement = p.createChild('label'); |
324 var p = createElement("p"); | 312 labelElement.textContent = WebInspector.UIString('Folder exclude pattern'); |
325 var labelElement = p.createChild("label"); | 313 var inputElement = p.createChild('input'); |
326 labelElement.textContent = WebInspector.UIString("Folder exclude pattern
"); | 314 inputElement.type = 'text'; |
327 var inputElement = p.createChild("input"); | 315 inputElement.style.width = '270px'; |
328 inputElement.type = "text"; | 316 var folderExcludeSetting = WebInspector.isolatedFileSystemManager.workspaceF
olderExcludePatternSetting(); |
329 inputElement.style.width = "270px"; | 317 var setValue = WebInspector.bindInput( |
330 var folderExcludeSetting = WebInspector.isolatedFileSystemManager.worksp
aceFolderExcludePatternSetting(); | 318 inputElement, folderExcludeSetting.set.bind(folderExcludeSetting), regex
Validator, false); |
331 var setValue = WebInspector.bindInput(inputElement, folderExcludeSetting
.set.bind(folderExcludeSetting), regexValidator, false); | 319 folderExcludeSetting.addChangeListener(() => setValue.call(null, folderExclu
deSetting.get())); |
332 folderExcludeSetting.addChangeListener(() => setValue.call(null, folderE
xcludeSetting.get())); | 320 setValue(folderExcludeSetting.get()); |
333 setValue(folderExcludeSetting.get()); | 321 return p; |
334 return p; | 322 |
335 | 323 /** |
336 /** | 324 * @param {string} value |
337 * @param {string} value | 325 * @return {boolean} |
338 * @return {boolean} | 326 */ |
339 */ | 327 function regexValidator(value) { |
340 function regexValidator(value) | 328 var regex; |
341 { | 329 try { |
342 var regex; | 330 regex = new RegExp(value); |
343 try { | 331 } catch (e) { |
344 regex = new RegExp(value); | 332 } |
345 } catch (e) { | 333 return !!regex; |
346 } | 334 } |
347 return !!regex; | 335 } |
348 } | 336 |
349 }, | 337 /** |
350 | 338 * @param {!WebInspector.IsolatedFileSystem} fileSystem |
351 /** | 339 */ |
352 * @param {!WebInspector.IsolatedFileSystem} fileSystem | 340 _addItem(fileSystem) { |
353 */ | 341 var element = this._renderFileSystem(fileSystem); |
354 _addItem: function(fileSystem) | 342 this._elementByPath.set(fileSystem.path(), element); |
355 { | 343 |
356 var element = this._renderFileSystem(fileSystem); | 344 this._fileSystemsListContainer.appendChild(element); |
357 this._elementByPath.set(fileSystem.path(), element); | 345 |
358 | 346 var mappingView = new WebInspector.EditFileSystemView(fileSystem.path()); |
359 this._fileSystemsListContainer.appendChild(element); | 347 this._mappingViewByPath.set(fileSystem.path(), mappingView); |
360 | 348 mappingView.element.classList.add('file-system-mapping-view'); |
361 var mappingView = new WebInspector.EditFileSystemView(fileSystem.path())
; | 349 mappingView.show(element); |
362 this._mappingViewByPath.set(fileSystem.path(), mappingView); | 350 } |
363 mappingView.element.classList.add("file-system-mapping-view"); | 351 |
364 mappingView.show(element); | 352 /** |
365 }, | 353 * @param {!WebInspector.IsolatedFileSystem} fileSystem |
366 | 354 * @return {!Element} |
367 /** | 355 */ |
368 * @param {!WebInspector.IsolatedFileSystem} fileSystem | 356 _renderFileSystem(fileSystem) { |
369 * @return {!Element} | 357 var fileSystemPath = fileSystem.path(); |
370 */ | 358 var lastIndexOfSlash = fileSystemPath.lastIndexOf(WebInspector.isWin() ? '\\
' : '/'); |
371 _renderFileSystem: function(fileSystem) | 359 var folderName = fileSystemPath.substr(lastIndexOfSlash + 1); |
372 { | 360 |
373 var fileSystemPath = fileSystem.path(); | 361 var element = createElementWithClass('div', 'file-system-container'); |
374 var lastIndexOfSlash = fileSystemPath.lastIndexOf(WebInspector.isWin() ?
"\\" : "/"); | 362 var header = element.createChild('div', 'file-system-header'); |
375 var folderName = fileSystemPath.substr(lastIndexOfSlash + 1); | 363 |
376 | 364 header.createChild('div', 'file-system-name').textContent = folderName; |
377 var element = createElementWithClass("div", "file-system-container"); | 365 var path = header.createChild('div', 'file-system-path'); |
378 var header = element.createChild("div", "file-system-header"); | 366 path.textContent = fileSystemPath; |
379 | 367 path.title = fileSystemPath; |
380 header.createChild("div", "file-system-name").textContent = folderName; | 368 |
381 var path = header.createChild("div", "file-system-path"); | 369 var toolbar = new WebInspector.Toolbar(''); |
382 path.textContent = fileSystemPath; | 370 var button = new WebInspector.ToolbarButton(WebInspector.UIString('Remove'),
'delete-toolbar-item'); |
383 path.title = fileSystemPath; | 371 button.addEventListener('click', this._removeFileSystemClicked.bind(this, fi
leSystem)); |
384 | 372 toolbar.appendToolbarItem(button); |
385 var toolbar = new WebInspector.Toolbar(""); | 373 header.appendChild(toolbar.element); |
386 var button = new WebInspector.ToolbarButton(WebInspector.UIString("Remov
e"), "delete-toolbar-item"); | 374 |
387 button.addEventListener("click", this._removeFileSystemClicked.bind(this
, fileSystem)); | 375 return element; |
388 toolbar.appendToolbarItem(button); | 376 } |
389 header.appendChild(toolbar.element); | 377 |
390 | 378 /** |
391 return element; | 379 * @param {!WebInspector.IsolatedFileSystem} fileSystem |
392 }, | 380 */ |
393 | 381 _removeFileSystemClicked(fileSystem) { |
394 /** | 382 WebInspector.isolatedFileSystemManager.removeFileSystem(fileSystem); |
395 * @param {!WebInspector.IsolatedFileSystem} fileSystem | 383 } |
396 */ | 384 |
397 _removeFileSystemClicked: function(fileSystem) | 385 _addFileSystemClicked() { |
398 { | 386 WebInspector.isolatedFileSystemManager.addFileSystem(); |
399 WebInspector.isolatedFileSystemManager.removeFileSystem(fileSystem); | 387 } |
400 }, | 388 |
401 | 389 _fileSystemAdded(event) { |
402 _addFileSystemClicked: function() | 390 var fileSystem = /** @type {!WebInspector.IsolatedFileSystem} */ (event.data
); |
403 { | 391 this._addItem(fileSystem); |
404 WebInspector.isolatedFileSystemManager.addFileSystem(); | 392 } |
405 }, | 393 |
406 | 394 _fileSystemRemoved(event) { |
407 _fileSystemAdded: function(event) | 395 var fileSystem = /** @type {!WebInspector.IsolatedFileSystem} */ (event.data
); |
408 { | 396 |
409 var fileSystem = /** @type {!WebInspector.IsolatedFileSystem} */ (event.
data); | 397 var mappingView = this._mappingViewByPath.get(fileSystem.path()); |
410 this._addItem(fileSystem); | 398 if (mappingView) { |
411 }, | 399 mappingView.dispose(); |
412 | 400 this._mappingViewByPath.delete(fileSystem.path()); |
413 _fileSystemRemoved: function(event) | 401 } |
414 { | 402 |
415 var fileSystem = /** @type {!WebInspector.IsolatedFileSystem} */ (event.
data); | 403 var element = this._elementByPath.get(fileSystem.path()); |
416 | 404 if (element) { |
417 var mappingView = this._mappingViewByPath.get(fileSystem.path()); | 405 this._elementByPath.delete(fileSystem.path()); |
418 if (mappingView) { | 406 element.remove(); |
419 mappingView.dispose(); | 407 } |
420 this._mappingViewByPath.delete(fileSystem.path()); | 408 } |
421 } | 409 }; |
422 | |
423 var element = this._elementByPath.get(fileSystem.path()); | |
424 if (element) { | |
425 this._elementByPath.delete(fileSystem.path()); | |
426 element.remove(); | |
427 } | |
428 }, | |
429 | |
430 __proto__: WebInspector.SettingsTab.prototype | |
431 }; | |
432 | |
433 | 410 |
434 /** | 411 /** |
435 * @constructor | 412 * @unrestricted |
436 * @extends {WebInspector.SettingsTab} | |
437 */ | 413 */ |
438 WebInspector.ExperimentsSettingsTab = function() | 414 WebInspector.ExperimentsSettingsTab = class extends WebInspector.SettingsTab { |
439 { | 415 constructor() { |
440 WebInspector.SettingsTab.call(this, WebInspector.UIString("Experiments"), "e
xperiments-tab-content"); | 416 super(WebInspector.UIString('Experiments'), 'experiments-tab-content'); |
441 | 417 |
442 var experiments = Runtime.experiments.allConfigurableExperiments(); | 418 var experiments = Runtime.experiments.allConfigurableExperiments(); |
443 if (experiments.length) { | 419 if (experiments.length) { |
444 var experimentsSection = this._appendSection(); | 420 var experimentsSection = this._appendSection(); |
445 experimentsSection.appendChild(this._createExperimentsWarningSubsection(
)); | 421 experimentsSection.appendChild(this._createExperimentsWarningSubsection())
; |
446 for (var i = 0; i < experiments.length; ++i) | 422 for (var i = 0; i < experiments.length; ++i) |
447 experimentsSection.appendChild(this._createExperimentCheckbox(experi
ments[i])); | 423 experimentsSection.appendChild(this._createExperimentCheckbox(experiment
s[i])); |
448 } | 424 } |
449 }; | 425 } |
450 | 426 |
451 WebInspector.ExperimentsSettingsTab.prototype = { | 427 /** |
452 /** | 428 * @return {!Element} element |
453 * @return {!Element} element | 429 */ |
454 */ | 430 _createExperimentsWarningSubsection() { |
455 _createExperimentsWarningSubsection: function() | 431 var subsection = createElement('div'); |
456 { | 432 var warning = subsection.createChild('span', 'settings-experiments-warning-s
ubsection-warning'); |
457 var subsection = createElement("div"); | 433 warning.textContent = WebInspector.UIString('WARNING:'); |
458 var warning = subsection.createChild("span", "settings-experiments-warni
ng-subsection-warning"); | 434 subsection.createTextChild(' '); |
459 warning.textContent = WebInspector.UIString("WARNING:"); | 435 var message = subsection.createChild('span', 'settings-experiments-warning-s
ubsection-message'); |
460 subsection.createTextChild(" "); | 436 message.textContent = WebInspector.UIString('These experiments could be dang
erous and may require restart.'); |
461 var message = subsection.createChild("span", "settings-experiments-warni
ng-subsection-message"); | 437 return subsection; |
462 message.textContent = WebInspector.UIString("These experiments could be
dangerous and may require restart."); | 438 } |
463 return subsection; | 439 |
464 }, | 440 _createExperimentCheckbox(experiment) { |
465 | 441 var label = createCheckboxLabel(WebInspector.UIString(experiment.title), exp
eriment.isEnabled()); |
466 _createExperimentCheckbox: function(experiment) | 442 var input = label.checkboxElement; |
467 { | 443 input.name = experiment.name; |
468 var label = createCheckboxLabel(WebInspector.UIString(experiment.title),
experiment.isEnabled()); | 444 function listener() { |
469 var input = label.checkboxElement; | 445 experiment.setEnabled(input.checked); |
470 input.name = experiment.name; | 446 } |
471 function listener() | 447 input.addEventListener('click', listener, false); |
472 { | 448 |
473 experiment.setEnabled(input.checked); | 449 var p = createElement('p'); |
474 } | 450 p.className = experiment.hidden && !experiment.isEnabled() ? 'settings-exper
iment-hidden' : ''; |
475 input.addEventListener("click", listener, false); | 451 p.appendChild(label); |
476 | 452 return p; |
477 var p = createElement("p"); | 453 } |
478 p.className = experiment.hidden && !experiment.isEnabled() ? "settings-e
xperiment-hidden" : ""; | |
479 p.appendChild(label); | |
480 return p; | |
481 }, | |
482 | |
483 __proto__: WebInspector.SettingsTab.prototype | |
484 }; | 454 }; |
485 | 455 |
486 /** | 456 /** |
487 * @constructor | |
488 * @implements {WebInspector.ActionDelegate} | 457 * @implements {WebInspector.ActionDelegate} |
| 458 * @unrestricted |
489 */ | 459 */ |
490 WebInspector.SettingsScreen.ActionDelegate = function() { }; | 460 WebInspector.SettingsScreen.ActionDelegate = class { |
491 | 461 /** |
492 WebInspector.SettingsScreen.ActionDelegate.prototype = { | 462 * @override |
493 /** | 463 * @param {!WebInspector.Context} context |
494 * @override | 464 * @param {string} actionId |
495 * @param {!WebInspector.Context} context | 465 * @return {boolean} |
496 * @param {string} actionId | 466 */ |
497 * @return {boolean} | 467 handleAction(context, actionId) { |
498 */ | 468 switch (actionId) { |
499 handleAction: function(context, actionId) | 469 case 'settings.show': |
500 { | 470 WebInspector.SettingsScreen._showSettingsScreen(); |
501 switch (actionId) { | 471 return true; |
502 case "settings.show": | 472 case 'settings.help': |
503 WebInspector.SettingsScreen._showSettingsScreen(); | 473 InspectorFrontendHost.openInNewTab('https://developers.google.com/web/to
ols/chrome-devtools/'); |
504 return true; | 474 return true; |
505 case "settings.help": | 475 case 'settings.shortcuts': |
506 InspectorFrontendHost.openInNewTab("https://developers.google.com/we
b/tools/chrome-devtools/"); | 476 WebInspector.SettingsScreen._showSettingsScreen(WebInspector.UIString('S
hortcuts')); |
507 return true; | 477 return true; |
508 case "settings.shortcuts": | 478 } |
509 WebInspector.SettingsScreen._showSettingsScreen(WebInspector.UIStrin
g("Shortcuts")); | 479 return false; |
510 return true; | 480 } |
511 } | |
512 return false; | |
513 } | |
514 }; | 481 }; |
515 | 482 |
516 /** | 483 /** |
517 * @constructor | |
518 * @implements {WebInspector.Revealer} | 484 * @implements {WebInspector.Revealer} |
| 485 * @unrestricted |
519 */ | 486 */ |
520 WebInspector.SettingsScreen.Revealer = function() { }; | 487 WebInspector.SettingsScreen.Revealer = class { |
521 | 488 /** |
522 WebInspector.SettingsScreen.Revealer.prototype = { | 489 * @override |
523 /** | 490 * @param {!Object} object |
524 * @override | 491 * @return {!Promise} |
525 * @param {!Object} object | 492 */ |
526 * @return {!Promise} | 493 reveal(object) { |
527 */ | 494 console.assert(object instanceof WebInspector.Setting); |
528 reveal: function(object) | 495 var setting = /** @type {!WebInspector.Setting} */ (object); |
529 { | 496 var success = false; |
530 console.assert(object instanceof WebInspector.Setting); | 497 |
531 var setting = /** @type {!WebInspector.Setting} */ (object); | 498 self.runtime.extensions('setting').forEach(revealModuleSetting); |
532 var success = false; | 499 self.runtime.extensions(WebInspector.SettingUI).forEach(revealSettingUI); |
533 | 500 self.runtime.extensions('view').forEach(revealSettingsView); |
534 self.runtime.extensions("setting").forEach(revealModuleSetting); | 501 |
535 self.runtime.extensions(WebInspector.SettingUI).forEach(revealSettingUI)
; | 502 return success ? Promise.resolve() : Promise.reject(); |
536 self.runtime.extensions("view").forEach(revealSettingsView); | 503 |
537 | 504 /** |
538 return success ? Promise.resolve() : Promise.reject(); | 505 * @param {!Runtime.Extension} extension |
539 | 506 */ |
540 /** | 507 function revealModuleSetting(extension) { |
541 * @param {!Runtime.Extension} extension | 508 if (!WebInspector.GenericSettingsTab.isSettingVisible(extension)) |
542 */ | 509 return; |
543 function revealModuleSetting(extension) | 510 if (extension.descriptor()['settingName'] === setting.name) { |
544 { | 511 InspectorFrontendHost.bringToFront(); |
545 if (!WebInspector.GenericSettingsTab.isSettingVisible(extension)) | 512 WebInspector.SettingsScreen._showSettingsScreen(); |
546 return; | 513 success = true; |
547 if (extension.descriptor()["settingName"] === setting.name) { | 514 } |
548 InspectorFrontendHost.bringToFront(); | 515 } |
549 WebInspector.SettingsScreen._showSettingsScreen(); | 516 |
550 success = true; | 517 /** |
551 } | 518 * @param {!Runtime.Extension} extension |
552 } | 519 */ |
553 | 520 function revealSettingUI(extension) { |
554 /** | 521 var settings = extension.descriptor()['settings']; |
555 * @param {!Runtime.Extension} extension | 522 if (settings && settings.indexOf(setting.name) !== -1) { |
556 */ | 523 InspectorFrontendHost.bringToFront(); |
557 function revealSettingUI(extension) | 524 WebInspector.SettingsScreen._showSettingsScreen(); |
558 { | 525 success = true; |
559 var settings = extension.descriptor()["settings"]; | 526 } |
560 if (settings && settings.indexOf(setting.name) !== -1) { | 527 } |
561 InspectorFrontendHost.bringToFront(); | 528 |
562 WebInspector.SettingsScreen._showSettingsScreen(); | 529 /** |
563 success = true; | 530 * @param {!Runtime.Extension} extension |
564 } | 531 */ |
565 } | 532 function revealSettingsView(extension) { |
566 | 533 var location = extension.descriptor()['location']; |
567 /** | 534 if (location !== 'settings-view') |
568 * @param {!Runtime.Extension} extension | 535 return; |
569 */ | 536 var settings = extension.descriptor()['settings']; |
570 function revealSettingsView(extension) | 537 if (settings && settings.indexOf(setting.name) !== -1) { |
571 { | 538 InspectorFrontendHost.bringToFront(); |
572 var location = extension.descriptor()["location"]; | 539 WebInspector.SettingsScreen._showSettingsScreen(extension.descriptor()['
id']); |
573 if (location !== "settings-view") | 540 success = true; |
574 return; | 541 } |
575 var settings = extension.descriptor()["settings"]; | 542 } |
576 if (settings && settings.indexOf(setting.name) !== -1) { | 543 } |
577 InspectorFrontendHost.bringToFront(); | 544 }; |
578 WebInspector.SettingsScreen._showSettingsScreen(extension.descri
ptor()["id"]); | |
579 success = true; | |
580 } | |
581 } | |
582 } | |
583 }; | |
OLD | NEW |