OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
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. | |
29 */ | |
30 | |
31 /** | |
32 * @constructor | |
33 * @extends {WebInspector.DialogDelegate} | |
34 * @param {string} fileSystemPath | |
35 */ | |
36 WebInspector.EditFileSystemDialog = function(fileSystemPath) | |
37 { | |
38 WebInspector.DialogDelegate.call(this); | |
39 this._fileSystemPath = fileSystemPath; | |
40 | |
41 this.element = document.createElement("div"); | |
42 this.element.className = "edit-file-system-dialog"; | |
43 | |
44 var header = this.element.createChild("div", "header"); | |
45 var headerText = header.createChild("span"); | |
46 headerText.textContent = WebInspector.UIString("Edit file system"); | |
47 | |
48 var closeButton = header.createChild("div", "close-button-gray done-button")
; | |
49 closeButton.addEventListener("click", this._onDoneClick.bind(this), false); | |
50 | |
51 var contents = this.element.createChild("div", "contents"); | |
52 | |
53 WebInspector.isolatedFileSystemManager.mapping().addEventListener(WebInspect
or.FileSystemMapping.Events.FileMappingAdded, this._fileMappingAdded, this); | |
54 WebInspector.isolatedFileSystemManager.mapping().addEventListener(WebInspect
or.FileSystemMapping.Events.FileMappingRemoved, this._fileMappingRemoved, this); | |
55 WebInspector.isolatedFileSystemManager.mapping().addEventListener(WebInspect
or.FileSystemMapping.Events.ExcludedFolderAdded, this._excludedFolderAdded, this
); | |
56 WebInspector.isolatedFileSystemManager.mapping().addEventListener(WebInspect
or.FileSystemMapping.Events.ExcludedFolderRemoved, this._excludedFolderRemoved,
this); | |
57 | |
58 var blockHeader = contents.createChild("div", "block-header"); | |
59 blockHeader.textContent = WebInspector.UIString("Mappings"); | |
60 this._fileMappingsSection = contents.createChild("div", "section file-mappin
gs-section"); | |
61 this._fileMappingsListContainer = this._fileMappingsSection.createChild("div
", "settings-list-container"); | |
62 var entries = WebInspector.isolatedFileSystemManager.mapping().mappingEntrie
s(this._fileSystemPath); | |
63 | |
64 this._fileMappingsList = new WebInspector.EditableSettingsList(["url", "path
"], this._fileMappingValuesProvider.bind(this), this._fileMappingValidate.bind(t
his), this._fileMappingEdit.bind(this)); | |
65 this._fileMappingsList.addEventListener(WebInspector.SettingsList.Events.Rem
oved, this._fileMappingRemovedfromList.bind(this)); | |
66 | |
67 this._fileMappingsList.element.classList.add("file-mappings-list"); | |
68 this._fileMappingsListContainer.appendChild(this._fileMappingsList.element); | |
69 | |
70 this._entries = {}; | |
71 for (var i = 0; i < entries.length; ++i) | |
72 this._addMappingRow(entries[i]); | |
73 | |
74 blockHeader = contents.createChild("div", "block-header"); | |
75 blockHeader.textContent = WebInspector.UIString("Excluded folders"); | |
76 this._excludedFolderListSection = contents.createChild("div", "section exclu
ded-folders-section"); | |
77 this._excludedFolderListContainer = this._excludedFolderListSection.createCh
ild("div", "settings-list-container"); | |
78 var excludedFolderEntries = WebInspector.isolatedFileSystemManager.mapping()
.excludedFolders(fileSystemPath); | |
79 | |
80 this._excludedFolderList = new WebInspector.EditableSettingsList(["path"], t
his._excludedFolderValueProvider.bind(this), this._excludedFolderValidate.bind(t
his), this._excludedFolderEdit.bind(this)); | |
81 this._excludedFolderList.addEventListener(WebInspector.SettingsList.Events.R
emoved, this._excludedFolderRemovedfromList.bind(this)); | |
82 this._excludedFolderList.element.classList.add("excluded-folders-list"); | |
83 this._excludedFolderListContainer.appendChild(this._excludedFolderList.eleme
nt); | |
84 this._excludedFolderEntries = new StringMap(); | |
85 for (var i = 0; i < excludedFolderEntries.length; ++i) | |
86 this._addExcludedFolderRow(excludedFolderEntries[i]); | |
87 | |
88 this.element.tabIndex = 0; | |
89 } | |
90 | |
91 WebInspector.EditFileSystemDialog.show = function(element, fileSystemPath) | |
92 { | |
93 WebInspector.Dialog.show(element, new WebInspector.EditFileSystemDialog(file
SystemPath)); | |
94 var glassPane = document.getElementById("glass-pane"); | |
95 glassPane.classList.add("settings-glass-pane"); | |
96 } | |
97 | |
98 WebInspector.EditFileSystemDialog.prototype = { | |
99 /** | |
100 * @param {!Element} element | |
101 */ | |
102 show: function(element) | |
103 { | |
104 element.appendChild(this.element); | |
105 this.element.classList.add("dialog-contents"); | |
106 element.classList.add("settings-dialog"); | |
107 element.classList.add("settings-tab"); | |
108 this._dialogElement = element; | |
109 }, | |
110 | |
111 _resize: function() | |
112 { | |
113 if (!this._dialogElement || !this._relativeToElement) | |
114 return; | |
115 | |
116 const minWidth = 200; | |
117 const minHeight = 150; | |
118 var maxHeight = this._relativeToElement.offsetHeight - 10; | |
119 maxHeight = Math.max(minHeight, maxHeight); | |
120 var maxWidth = Math.min(540, this._relativeToElement.offsetWidth - 10); | |
121 maxWidth = Math.max(minWidth, maxWidth); | |
122 this._dialogElement.style.maxHeight = maxHeight + "px"; | |
123 this._dialogElement.style.width = maxWidth + "px"; | |
124 | |
125 WebInspector.DialogDelegate.prototype.position(this._dialogElement, this
._relativeToElement); | |
126 }, | |
127 | |
128 /** | |
129 * @param {!Element} element | |
130 * @param {!Element} relativeToElement | |
131 */ | |
132 position: function(element, relativeToElement) | |
133 { | |
134 this._relativeToElement = relativeToElement; | |
135 this._resize(); | |
136 }, | |
137 | |
138 willHide: function(event) | |
139 { | |
140 }, | |
141 | |
142 _fileMappingAdded: function(event) | |
143 { | |
144 var entry = /** @type {!WebInspector.FileSystemMapping.Entry} */ (event.
data); | |
145 this._addMappingRow(entry); | |
146 }, | |
147 | |
148 _fileMappingRemoved: function(event) | |
149 { | |
150 var entry = /** @type {!WebInspector.FileSystemMapping.Entry} */ (event.
data); | |
151 if (this._fileSystemPath !== entry.fileSystemPath) | |
152 return; | |
153 delete this._entries[entry.urlPrefix]; | |
154 if (this._fileMappingsList.itemForId(entry.urlPrefix)) | |
155 this._fileMappingsList.removeItem(entry.urlPrefix); | |
156 this._resize(); | |
157 }, | |
158 | |
159 _fileMappingValuesProvider: function(itemId, columnId) | |
160 { | |
161 if (!itemId) | |
162 return ""; | |
163 var entry = this._entries[itemId]; | |
164 switch (columnId) { | |
165 case "url": | |
166 return entry.urlPrefix; | |
167 case "path": | |
168 return entry.pathPrefix; | |
169 default: | |
170 console.assert("Should not be reached."); | |
171 } | |
172 return ""; | |
173 }, | |
174 | |
175 /** | |
176 * @param {?string} itemId | |
177 * @param {!Object} data | |
178 */ | |
179 _fileMappingValidate: function(itemId, data) | |
180 { | |
181 var oldPathPrefix = itemId ? this._entries[itemId].pathPrefix : null; | |
182 return this._validateMapping(data["url"], itemId, data["path"], oldPathP
refix); | |
183 }, | |
184 | |
185 /** | |
186 * @param {?string} itemId | |
187 * @param {!Object} data | |
188 */ | |
189 _fileMappingEdit: function(itemId, data) | |
190 { | |
191 if (itemId) { | |
192 var urlPrefix = itemId; | |
193 var pathPrefix = this._entries[itemId].pathPrefix; | |
194 var fileSystemPath = this._entries[itemId].fileSystemPath; | |
195 WebInspector.isolatedFileSystemManager.mapping().removeFileMapping(f
ileSystemPath, urlPrefix, pathPrefix); | |
196 } | |
197 this._addFileMapping(data["url"], data["path"]); | |
198 }, | |
199 | |
200 /** | |
201 * @param {string} urlPrefix | |
202 * @param {?string} allowedURLPrefix | |
203 * @param {string} path | |
204 * @param {?string} allowedPathPrefix | |
205 */ | |
206 _validateMapping: function(urlPrefix, allowedURLPrefix, path, allowedPathPre
fix) | |
207 { | |
208 var columns = []; | |
209 if (!this._checkURLPrefix(urlPrefix, allowedURLPrefix)) | |
210 columns.push("url"); | |
211 if (!this._checkPathPrefix(path, allowedPathPrefix)) | |
212 columns.push("path"); | |
213 return columns; | |
214 }, | |
215 | |
216 /** | |
217 * @param {!WebInspector.Event} event | |
218 */ | |
219 _fileMappingRemovedfromList: function(event) | |
220 { | |
221 var urlPrefix = /** @type{?string} */ (event.data); | |
222 if (!urlPrefix) | |
223 return; | |
224 | |
225 var entry = this._entries[urlPrefix]; | |
226 WebInspector.isolatedFileSystemManager.mapping().removeFileMapping(entry
.fileSystemPath, entry.urlPrefix, entry.pathPrefix); | |
227 }, | |
228 | |
229 /** | |
230 * @param {string} urlPrefix | |
231 * @param {string} pathPrefix | |
232 * @return {boolean} | |
233 */ | |
234 _addFileMapping: function(urlPrefix, pathPrefix) | |
235 { | |
236 var normalizedURLPrefix = this._normalizePrefix(urlPrefix); | |
237 var normalizedPathPrefix = this._normalizePrefix(pathPrefix); | |
238 WebInspector.isolatedFileSystemManager.mapping().addFileMapping(this._fi
leSystemPath, normalizedURLPrefix, normalizedPathPrefix); | |
239 this._fileMappingsList.selectItem(normalizedURLPrefix); | |
240 return true; | |
241 }, | |
242 | |
243 /** | |
244 * @param {string} prefix | |
245 * @return {string} | |
246 */ | |
247 _normalizePrefix: function(prefix) | |
248 { | |
249 if (!prefix) | |
250 return ""; | |
251 return prefix + (prefix[prefix.length - 1] === "/" ? "" : "/"); | |
252 }, | |
253 | |
254 _addMappingRow: function(entry) | |
255 { | |
256 var fileSystemPath = entry.fileSystemPath; | |
257 var urlPrefix = entry.urlPrefix; | |
258 if (!this._fileSystemPath || this._fileSystemPath !== fileSystemPath) | |
259 return; | |
260 | |
261 this._entries[urlPrefix] = entry; | |
262 var fileMappingListItem = this._fileMappingsList.addItem(urlPrefix, null
); | |
263 this._resize(); | |
264 }, | |
265 | |
266 _excludedFolderAdded: function(event) | |
267 { | |
268 var entry = /** @type {!WebInspector.FileSystemMapping.ExcludedFolderEnt
ry} */ (event.data); | |
269 this._addExcludedFolderRow(entry); | |
270 }, | |
271 | |
272 _excludedFolderRemoved: function(event) | |
273 { | |
274 var entry = /** @type {!WebInspector.FileSystemMapping.ExcludedFolderEnt
ry} */ (event.data); | |
275 var fileSystemPath = entry.fileSystemPath; | |
276 if (!fileSystemPath || this._fileSystemPath !== fileSystemPath) | |
277 return; | |
278 delete this._excludedFolderEntries[entry.path]; | |
279 if (this._excludedFolderList.itemForId(entry.path)) | |
280 this._excludedFolderList.removeItem(entry.path); | |
281 }, | |
282 | |
283 _excludedFolderValueProvider: function(itemId, columnId) | |
284 { | |
285 return itemId; | |
286 }, | |
287 | |
288 /** | |
289 * @param {?string} itemId | |
290 * @param {!Object} data | |
291 */ | |
292 _excludedFolderValidate: function(itemId, data) | |
293 { | |
294 var fileSystemPath = this._fileSystemPath; | |
295 var columns = []; | |
296 if (!this._validateExcludedFolder(data["path"], itemId)) | |
297 columns.push("path"); | |
298 return columns; | |
299 }, | |
300 | |
301 /** | |
302 * @param {string} path | |
303 * @param {?string} allowedPath | |
304 * @return {boolean} | |
305 */ | |
306 _validateExcludedFolder: function(path, allowedPath) | |
307 { | |
308 return !!path && (path === allowedPath || !this._excludedFolderEntries.c
ontains(path)); | |
309 }, | |
310 | |
311 /** | |
312 * @param {?string} itemId | |
313 * @param {!Object} data | |
314 */ | |
315 _excludedFolderEdit: function(itemId, data) | |
316 { | |
317 var fileSystemPath = this._fileSystemPath; | |
318 if (itemId) | |
319 WebInspector.isolatedFileSystemManager.mapping().removeExcludedFolde
r(fileSystemPath, itemId); | |
320 var excludedFolderPath = data["path"]; | |
321 WebInspector.isolatedFileSystemManager.mapping().addExcludedFolder(fileS
ystemPath, excludedFolderPath); | |
322 }, | |
323 | |
324 /** | |
325 * @param {!WebInspector.Event} event | |
326 */ | |
327 _excludedFolderRemovedfromList: function(event) | |
328 { | |
329 var itemId = /** @type{?string} */ (event.data); | |
330 if (!itemId) | |
331 return; | |
332 WebInspector.isolatedFileSystemManager.mapping().removeExcludedFolder(th
is._fileSystemPath, itemId); | |
333 }, | |
334 | |
335 /** | |
336 * @param {!WebInspector.FileSystemMapping.ExcludedFolderEntry} entry | |
337 */ | |
338 _addExcludedFolderRow: function(entry) | |
339 { | |
340 var fileSystemPath = entry.fileSystemPath; | |
341 if (!fileSystemPath || this._fileSystemPath !== fileSystemPath) | |
342 return; | |
343 var path = entry.path; | |
344 this._excludedFolderEntries.put(path, entry); | |
345 this._excludedFolderList.addItem(path, null); | |
346 this._resize(); | |
347 }, | |
348 | |
349 /** | |
350 * @param {string} value | |
351 * @param {?string} allowedPrefix | |
352 * @return {boolean} | |
353 */ | |
354 _checkURLPrefix: function(value, allowedPrefix) | |
355 { | |
356 var prefix = this._normalizePrefix(value); | |
357 return !!prefix && (prefix === allowedPrefix || !this._entries[prefix]); | |
358 }, | |
359 | |
360 /** | |
361 * @param {string} value | |
362 * @param {?string} allowedPrefix | |
363 * @return {boolean} | |
364 */ | |
365 _checkPathPrefix: function(value, allowedPrefix) | |
366 { | |
367 var prefix = this._normalizePrefix(value); | |
368 if (!prefix) | |
369 return false; | |
370 if (prefix === allowedPrefix) | |
371 return true; | |
372 for (var urlPrefix in this._entries) { | |
373 var entry = this._entries[urlPrefix]; | |
374 if (urlPrefix && entry.pathPrefix === prefix) | |
375 return false; | |
376 } | |
377 return true; | |
378 }, | |
379 | |
380 focus: function() | |
381 { | |
382 WebInspector.setCurrentFocusElement(this.element); | |
383 }, | |
384 | |
385 _onDoneClick: function() | |
386 { | |
387 WebInspector.Dialog.hide(); | |
388 }, | |
389 | |
390 onEnter: function() | |
391 { | |
392 }, | |
393 | |
394 __proto__: WebInspector.DialogDelegate.prototype | |
395 } | |
OLD | NEW |