2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
33 * @extends {WebInspector.DialogDelegate}
34 * @param {string} fileSystemPath
36 WebInspector
.EditFileSystemDialog = function(fileSystemPath
)
38 WebInspector
.DialogDelegate
.call(this);
39 this.element
.classList
.add("dialog-contents");
40 this._fileSystemPath
= fileSystemPath
;
42 var header
= this.element
.createChild("div", "header");
43 var headerText
= header
.createChild("span");
44 headerText
.textContent
= WebInspector
.UIString("Edit file system");
46 var closeButton
= header
.createChild("div", "done-button", "dt-close-button");
47 closeButton
.gray
= true;
48 closeButton
.addEventListener("click", this._onDoneClick
.bind(this), false);
50 var contents
= this.element
.createChild("div", "contents");
52 WebInspector
.isolatedFileSystemManager
.mapping().addEventListener(WebInspector
.FileSystemMapping
.Events
.FileMappingAdded
, this._fileMappingAdded
, this);
53 WebInspector
.isolatedFileSystemManager
.mapping().addEventListener(WebInspector
.FileSystemMapping
.Events
.FileMappingRemoved
, this._fileMappingRemoved
, this);
54 WebInspector
.isolatedFileSystemManager
.excludedFolderManager().addEventListener(WebInspector
.ExcludedFolderManager
.Events
.ExcludedFolderAdded
, this._excludedFolderAdded
, this);
55 WebInspector
.isolatedFileSystemManager
.excludedFolderManager().addEventListener(WebInspector
.ExcludedFolderManager
.Events
.ExcludedFolderRemoved
, this._excludedFolderRemoved
, this);
57 var blockHeader
= contents
.createChild("div", "block-header");
58 blockHeader
.textContent
= WebInspector
.UIString("Mappings");
59 this._fileMappingsSection
= contents
.createChild("div", "section");
60 this._fileMappingsListContainer
= this._fileMappingsSection
.createChild("div", "settings-list-container");
61 var entries
= WebInspector
.isolatedFileSystemManager
.mapping().mappingEntries(this._fileSystemPath
);
63 var urlColumn
= { id
: "url", placeholder
: WebInspector
.UIString("URL prefix") };
64 var pathColumn
= { id
: "path", placeholder
: WebInspector
.UIString("Folder path") };
66 this._fileMappingsList
= new WebInspector
.EditableSettingsList([urlColumn
, pathColumn
], this._fileMappingValuesProvider
.bind(this), this._fileMappingValidate
.bind(this), this._fileMappingEdit
.bind(this));
67 this._fileMappingsList
.addEventListener(WebInspector
.SettingsList
.Events
.Removed
, this._fileMappingRemovedfromList
.bind(this));
69 this._fileMappingsList
.element
.classList
.add("file-mappings-list");
70 this._fileMappingsListContainer
.appendChild(this._fileMappingsList
.element
);
73 for (var i
= 0; i
< entries
.length
; ++i
)
74 this._addMappingRow(entries
[i
]);
76 blockHeader
= contents
.createChild("div", "block-header");
77 blockHeader
.textContent
= WebInspector
.UIString("Excluded folders");
78 this._excludedFolderListSection
= contents
.createChild("div", "section excluded-folders-section");
79 this._excludedFolderListContainer
= this._excludedFolderListSection
.createChild("div", "settings-list-container");
80 var excludedFolderEntries
= WebInspector
.isolatedFileSystemManager
.excludedFolderManager().excludedFolders(fileSystemPath
);
82 this._excludedFolderList
= new WebInspector
.EditableSettingsList([pathColumn
], this._excludedFolderValueProvider
.bind(this), this._excludedFolderValidate
.bind(this), this._excludedFolderEdit
.bind(this));
83 this._excludedFolderList
.addEventListener(WebInspector
.SettingsList
.Events
.Removed
, this._excludedFolderRemovedfromList
.bind(this));
84 this._excludedFolderList
.element
.classList
.add("excluded-folders-list");
85 this._excludedFolderListContainer
.appendChild(this._excludedFolderList
.element
);
86 this._excludedFolderEntries
= new Map();
87 for (var i
= 0; i
< excludedFolderEntries
.length
; ++i
)
88 this._addExcludedFolderRow(excludedFolderEntries
[i
]);
90 this.element
.tabIndex
= 0;
91 this._hasMappingChanges
= false;
94 WebInspector
.EditFileSystemDialog
.show = function(element
, fileSystemPath
)
96 var dialog
= new WebInspector
.EditFileSystemDialog(fileSystemPath
);
97 WebInspector
.Dialog
.show(element
, dialog
);
98 var glassPane
= dialog
.element
.ownerDocument
.getElementById("glass-pane");
99 glassPane
.classList
.add("settings-glass-pane");
102 WebInspector
.EditFileSystemDialog
.prototype = {
105 * @param {!Element} element
107 show: function(element
)
109 this._dialogElement
= element
;
110 element
.appendChild(this.element
);
111 element
.classList
.add("settings-dialog", "settings-tab");
116 if (!this._dialogElement
|| !this._relativeToElement
)
119 const minWidth
= 200;
120 const minHeight
= 150;
121 var maxHeight
= this._relativeToElement
.offsetHeight
- 10;
122 maxHeight
= Math
.max(minHeight
, maxHeight
);
123 var maxWidth
= Math
.min(540, this._relativeToElement
.offsetWidth
- 10);
124 maxWidth
= Math
.max(minWidth
, maxWidth
);
125 this._dialogElement
.style
.maxHeight
= maxHeight
+ "px";
126 this._dialogElement
.style
.width
= maxWidth
+ "px";
128 WebInspector
.DialogDelegate
.prototype.position(this._dialogElement
, this._relativeToElement
);
133 * @param {!Element} element
134 * @param {!Element} relativeToElement
136 position: function(element
, relativeToElement
)
138 this._relativeToElement
= relativeToElement
;
142 willHide: function(event
)
144 if (!this._hasMappingChanges
)
146 if (window
.confirm(WebInspector
.UIString("It is recommended to restart DevTools after making these changes. Would you like to restart it?")))
147 WebInspector
.reload();
150 _fileMappingAdded: function(event
)
152 var entry
= /** @type {!WebInspector.FileSystemMapping.Entry} */ (event
.data
);
153 this._addMappingRow(entry
);
156 _fileMappingRemoved: function(event
)
158 var entry
= /** @type {!WebInspector.FileSystemMapping.Entry} */ (event
.data
);
159 if (this._fileSystemPath
!== entry
.fileSystemPath
)
161 delete this._entries
[entry
.urlPrefix
];
162 if (this._fileMappingsList
.itemForId(entry
.urlPrefix
))
163 this._fileMappingsList
.removeItem(entry
.urlPrefix
);
168 * @param {string} itemId
169 * @param {string} columnId
172 _fileMappingValuesProvider: function(itemId
, columnId
)
176 var entry
= this._entries
[itemId
];
179 return entry
.urlPrefix
;
181 return entry
.pathPrefix
;
183 console
.assert("Should not be reached.");
189 * @param {?string} itemId
190 * @param {!Object} data
192 _fileMappingValidate: function(itemId
, data
)
194 var oldPathPrefix
= itemId
? this._entries
[itemId
].pathPrefix
: null;
195 return this._validateMapping(data
["url"], itemId
, data
["path"], oldPathPrefix
);
199 * @param {?string} itemId
200 * @param {!Object} data
202 _fileMappingEdit: function(itemId
, data
)
205 var urlPrefix
= itemId
;
206 var pathPrefix
= this._entries
[itemId
].pathPrefix
;
207 var fileSystemPath
= this._entries
[itemId
].fileSystemPath
;
208 WebInspector
.isolatedFileSystemManager
.mapping().removeFileMapping(fileSystemPath
, urlPrefix
, pathPrefix
);
210 this._addFileMapping(data
["url"], data
["path"]);
214 * @param {string} urlPrefix
215 * @param {?string} allowedURLPrefix
216 * @param {string} path
217 * @param {?string} allowedPathPrefix
219 _validateMapping: function(urlPrefix
, allowedURLPrefix
, path
, allowedPathPrefix
)
222 if (!this._checkURLPrefix(urlPrefix
, allowedURLPrefix
))
224 if (!this._checkPathPrefix(path
, allowedPathPrefix
))
225 columns
.push("path");
230 * @param {!WebInspector.Event} event
232 _fileMappingRemovedfromList: function(event
)
234 var urlPrefix
= /** @type{?string} */ (event
.data
);
238 var entry
= this._entries
[urlPrefix
];
239 WebInspector
.isolatedFileSystemManager
.mapping().removeFileMapping(entry
.fileSystemPath
, entry
.urlPrefix
, entry
.pathPrefix
);
240 this._hasMappingChanges
= true;
244 * @param {string} urlPrefix
245 * @param {string} pathPrefix
248 _addFileMapping: function(urlPrefix
, pathPrefix
)
250 var normalizedURLPrefix
= this._normalizePrefix(urlPrefix
);
251 var normalizedPathPrefix
= this._normalizePrefix(pathPrefix
);
252 WebInspector
.isolatedFileSystemManager
.mapping().addFileMapping(this._fileSystemPath
, normalizedURLPrefix
, normalizedPathPrefix
);
253 this._hasMappingChanges
= true;
254 this._fileMappingsList
.selectItem(normalizedURLPrefix
);
259 * @param {string} prefix
262 _normalizePrefix: function(prefix
)
266 return prefix
+ (prefix
[prefix
.length
- 1] === "/" ? "" : "/");
269 _addMappingRow: function(entry
)
271 var fileSystemPath
= entry
.fileSystemPath
;
272 var urlPrefix
= entry
.urlPrefix
;
273 if (!this._fileSystemPath
|| this._fileSystemPath
!== fileSystemPath
)
276 this._entries
[urlPrefix
] = entry
;
277 this._fileMappingsList
.addItem(urlPrefix
, null);
281 _excludedFolderAdded: function(event
)
283 var entry
= /** @type {!WebInspector.ExcludedFolderManager.Entry} */ (event
.data
);
284 this._addExcludedFolderRow(entry
);
287 _excludedFolderRemoved: function(event
)
289 var entry
= /** @type {!WebInspector.ExcludedFolderManager.Entry} */ (event
.data
);
290 var fileSystemPath
= entry
.fileSystemPath
;
291 if (!fileSystemPath
|| this._fileSystemPath
!== fileSystemPath
)
293 delete this._excludedFolderEntries
[entry
.path
];
294 if (this._excludedFolderList
.itemForId(entry
.path
))
295 this._excludedFolderList
.removeItem(entry
.path
);
299 * @param {string} itemId
300 * @param {string} columnId
303 _excludedFolderValueProvider: function(itemId
, columnId
)
309 * @param {?string} itemId
310 * @param {!Object} data
312 _excludedFolderValidate: function(itemId
, data
)
315 if (!this._validateExcludedFolder(data
["path"], itemId
))
316 columns
.push("path");
321 * @param {string} path
322 * @param {?string} allowedPath
325 _validateExcludedFolder: function(path
, allowedPath
)
327 return !!path
&& (path
=== allowedPath
|| !this._excludedFolderEntries
.has(path
));
331 * @param {?string} itemId
332 * @param {!Object} data
334 _excludedFolderEdit: function(itemId
, data
)
336 var fileSystemPath
= this._fileSystemPath
;
338 WebInspector
.isolatedFileSystemManager
.excludedFolderManager().removeExcludedFolder(fileSystemPath
, itemId
);
339 var excludedFolderPath
= data
["path"];
340 WebInspector
.isolatedFileSystemManager
.excludedFolderManager().addExcludedFolder(fileSystemPath
, excludedFolderPath
);
344 * @param {!WebInspector.Event} event
346 _excludedFolderRemovedfromList: function(event
)
348 var itemId
= /** @type{?string} */ (event
.data
);
351 WebInspector
.isolatedFileSystemManager
.excludedFolderManager().removeExcludedFolder(this._fileSystemPath
, itemId
);
355 * @param {!WebInspector.ExcludedFolderManager.Entry} entry
357 _addExcludedFolderRow: function(entry
)
359 var fileSystemPath
= entry
.fileSystemPath
;
360 if (!fileSystemPath
|| this._fileSystemPath
!== fileSystemPath
)
362 var path
= entry
.path
;
363 this._excludedFolderEntries
.set(path
, entry
);
364 this._excludedFolderList
.addItem(path
, null);
369 * @param {string} value
370 * @param {?string} allowedPrefix
373 _checkURLPrefix: function(value
, allowedPrefix
)
375 var prefix
= this._normalizePrefix(value
);
376 return !!prefix
&& (prefix
=== allowedPrefix
|| !this._entries
[prefix
]);
380 * @param {string} value
381 * @param {?string} allowedPrefix
384 _checkPathPrefix: function(value
, allowedPrefix
)
386 var prefix
= this._normalizePrefix(value
);
389 if (prefix
=== allowedPrefix
)
391 for (var urlPrefix
in this._entries
) {
392 var entry
= this._entries
[urlPrefix
];
393 if (urlPrefix
&& entry
.pathPrefix
=== prefix
)
401 WebInspector
.setCurrentFocusElement(this.element
);
404 _onDoneClick: function()
406 WebInspector
.Dialog
.hide();
413 __proto__
: WebInspector
.DialogDelegate
.prototype