| 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 | |
| 31 /** | 30 /** |
| 32 * @constructor | |
| 33 * @extends {WebInspector.VBox} | |
| 34 * @implements {WebInspector.ListWidget.Delegate} | 31 * @implements {WebInspector.ListWidget.Delegate} |
| 35 * @param {string} fileSystemPath | 32 * @unrestricted |
| 36 */ | 33 */ |
| 37 WebInspector.EditFileSystemView = function(fileSystemPath) | 34 WebInspector.EditFileSystemView = class extends WebInspector.VBox { |
| 38 { | 35 /** |
| 39 WebInspector.VBox.call(this, true); | 36 * @param {string} fileSystemPath |
| 40 this.registerRequiredCSS("settings/editFileSystemView.css"); | 37 */ |
| 38 constructor(fileSystemPath) { |
| 39 super(true); |
| 40 this.registerRequiredCSS('settings/editFileSystemView.css'); |
| 41 this._fileSystemPath = fileSystemPath; | 41 this._fileSystemPath = fileSystemPath; |
| 42 | 42 |
| 43 this._eventListeners = [ | 43 this._eventListeners = [ |
| 44 WebInspector.fileSystemMapping.addEventListener(WebInspector.FileSystemM
apping.Events.FileMappingAdded, this._update, this), | 44 WebInspector.fileSystemMapping.addEventListener( |
| 45 WebInspector.fileSystemMapping.addEventListener(WebInspector.FileSystemM
apping.Events.FileMappingRemoved, this._update, this), | 45 WebInspector.FileSystemMapping.Events.FileMappingAdded, this._update,
this), |
| 46 WebInspector.isolatedFileSystemManager.addEventListener(WebInspector.Iso
latedFileSystemManager.Events.ExcludedFolderAdded, this._update, this), | 46 WebInspector.fileSystemMapping.addEventListener( |
| 47 WebInspector.isolatedFileSystemManager.addEventListener(WebInspector.Iso
latedFileSystemManager.Events.ExcludedFolderRemoved, this._update, this) | 47 WebInspector.FileSystemMapping.Events.FileMappingRemoved, this._update
, this), |
| 48 WebInspector.isolatedFileSystemManager.addEventListener( |
| 49 WebInspector.IsolatedFileSystemManager.Events.ExcludedFolderAdded, thi
s._update, this), |
| 50 WebInspector.isolatedFileSystemManager.addEventListener( |
| 51 WebInspector.IsolatedFileSystemManager.Events.ExcludedFolderRemoved, t
his._update, this) |
| 48 ]; | 52 ]; |
| 49 | 53 |
| 50 this._mappingsList = new WebInspector.ListWidget(this); | 54 this._mappingsList = new WebInspector.ListWidget(this); |
| 51 this._mappingsList.element.classList.add("file-system-list"); | 55 this._mappingsList.element.classList.add('file-system-list'); |
| 52 this._mappingsList.registerRequiredCSS("settings/editFileSystemView.css"); | 56 this._mappingsList.registerRequiredCSS('settings/editFileSystemView.css'); |
| 53 var mappingsPlaceholder = createElementWithClass("div", "file-system-list-em
pty"); | 57 var mappingsPlaceholder = createElementWithClass('div', 'file-system-list-em
pty'); |
| 54 var mappingsHeader = this.contentElement.createChild("div", "file-system-hea
der"); | 58 var mappingsHeader = this.contentElement.createChild('div', 'file-system-hea
der'); |
| 55 mappingsHeader.createChild("div", "file-system-header-text").textContent = W
ebInspector.UIString("Mappings"); | 59 mappingsHeader.createChild('div', 'file-system-header-text').textContent = W
ebInspector.UIString('Mappings'); |
| 56 if (Runtime.experiments.isEnabled("persistence2")) { | 60 if (Runtime.experiments.isEnabled('persistence2')) { |
| 57 mappingsPlaceholder.textContent = WebInspector.UIString("Mappings are in
ferred automatically via the 'Persistence 2.0' experiment."); | 61 mappingsPlaceholder.textContent = |
| 58 } else { | 62 WebInspector.UIString('Mappings are inferred automatically via the \'P
ersistence 2.0\' experiment.'); |
| 59 mappingsPlaceholder.textContent = WebInspector.UIString("No mappings"); | 63 } else { |
| 60 mappingsHeader.appendChild(createTextButton(WebInspector.UIString("Add")
, this._addMappingButtonClicked.bind(this), "add-button")); | 64 mappingsPlaceholder.textContent = WebInspector.UIString('No mappings'); |
| 65 mappingsHeader.appendChild( |
| 66 createTextButton(WebInspector.UIString('Add'), this._addMappingButtonC
licked.bind(this), 'add-button')); |
| 61 } | 67 } |
| 62 this._mappingsList.setEmptyPlaceholder(mappingsPlaceholder); | 68 this._mappingsList.setEmptyPlaceholder(mappingsPlaceholder); |
| 63 this._mappingsList.show(this.contentElement); | 69 this._mappingsList.show(this.contentElement); |
| 64 | 70 |
| 65 var excludedFoldersHeader = this.contentElement.createChild("div", "file-sys
tem-header"); | 71 var excludedFoldersHeader = this.contentElement.createChild('div', 'file-sys
tem-header'); |
| 66 excludedFoldersHeader.createChild("div", "file-system-header-text").textCont
ent = WebInspector.UIString("Excluded folders"); | 72 excludedFoldersHeader.createChild('div', 'file-system-header-text').textCont
ent = |
| 67 excludedFoldersHeader.appendChild(createTextButton(WebInspector.UIString("Ad
d"), this._addExcludedFolderButtonClicked.bind(this), "add-button")); | 73 WebInspector.UIString('Excluded folders'); |
| 74 excludedFoldersHeader.appendChild( |
| 75 createTextButton(WebInspector.UIString('Add'), this._addExcludedFolderBu
ttonClicked.bind(this), 'add-button')); |
| 68 this._excludedFoldersList = new WebInspector.ListWidget(this); | 76 this._excludedFoldersList = new WebInspector.ListWidget(this); |
| 69 this._excludedFoldersList.element.classList.add("file-system-list"); | 77 this._excludedFoldersList.element.classList.add('file-system-list'); |
| 70 this._excludedFoldersList.registerRequiredCSS("settings/editFileSystemView.c
ss"); | 78 this._excludedFoldersList.registerRequiredCSS('settings/editFileSystemView.c
ss'); |
| 71 var excludedFoldersPlaceholder = createElementWithClass("div", "file-system-
list-empty"); | 79 var excludedFoldersPlaceholder = createElementWithClass('div', 'file-system-
list-empty'); |
| 72 excludedFoldersPlaceholder.textContent = WebInspector.UIString("No excluded
folders"); | 80 excludedFoldersPlaceholder.textContent = WebInspector.UIString('No excluded
folders'); |
| 73 this._excludedFoldersList.setEmptyPlaceholder(excludedFoldersPlaceholder); | 81 this._excludedFoldersList.setEmptyPlaceholder(excludedFoldersPlaceholder); |
| 74 this._excludedFoldersList.show(this.contentElement); | 82 this._excludedFoldersList.show(this.contentElement); |
| 75 | 83 |
| 76 this.contentElement.tabIndex = 0; | 84 this.contentElement.tabIndex = 0; |
| 77 this._update(); | 85 this._update(); |
| 78 }; | 86 } |
| 79 | 87 |
| 80 WebInspector.EditFileSystemView.prototype = { | 88 dispose() { |
| 81 dispose: function() | 89 WebInspector.EventTarget.removeEventListeners(this._eventListeners); |
| 82 { | 90 } |
| 83 WebInspector.EventTarget.removeEventListeners(this._eventListeners); | 91 |
| 84 }, | 92 _update() { |
| 85 | 93 if (this._muteUpdate) |
| 86 _update: function() | 94 return; |
| 87 { | 95 |
| 88 if (this._muteUpdate) | 96 this._mappingsList.clear(); |
| 89 return; | 97 this._mappings = []; |
| 90 | 98 if (Runtime.experiments.isEnabled('persistence2')) |
| 91 this._mappingsList.clear(); | 99 return; |
| 92 this._mappings = []; | 100 var mappings = WebInspector.fileSystemMapping.mappingEntries(this._fileSyste
mPath); |
| 93 if (Runtime.experiments.isEnabled("persistence2")) | 101 for (var entry of mappings) { |
| 94 return; | 102 if (entry.configurable) { |
| 95 var mappings = WebInspector.fileSystemMapping.mappingEntries(this._fileS
ystemPath); | 103 this._mappingsList.appendItem(entry, true); |
| 96 for (var entry of mappings) { | 104 this._mappings.push(entry); |
| 97 if (entry.configurable) { | 105 } |
| 98 this._mappingsList.appendItem(entry, true); | 106 } |
| 99 this._mappings.push(entry); | 107 for (var entry of mappings) { |
| 100 } | 108 if (!entry.configurable) { |
| 101 } | 109 this._mappingsList.appendItem(entry, false); |
| 102 for (var entry of mappings) { | 110 this._mappings.push(entry); |
| 103 if (!entry.configurable) { | 111 } |
| 104 this._mappingsList.appendItem(entry, false); | 112 } |
| 105 this._mappings.push(entry); | 113 |
| 106 } | 114 this._excludedFoldersList.clear(); |
| 107 } | 115 this._excludedFolders = []; |
| 108 | 116 for (var folder of WebInspector.isolatedFileSystemManager.fileSystem(this._f
ileSystemPath) |
| 109 this._excludedFoldersList.clear(); | 117 .excludedFolders() |
| 110 this._excludedFolders = []; | 118 .values()) { |
| 111 for (var folder of WebInspector.isolatedFileSystemManager.fileSystem(thi
s._fileSystemPath).excludedFolders().values()) { | 119 this._excludedFolders.push(folder); |
| 112 this._excludedFolders.push(folder); | 120 this._excludedFoldersList.appendItem(folder, true); |
| 113 this._excludedFoldersList.appendItem(folder, true); | 121 } |
| 114 } | 122 for (var folder of WebInspector.isolatedFileSystemManager.fileSystem(this._f
ileSystemPath) |
| 115 for (var folder of WebInspector.isolatedFileSystemManager.fileSystem(thi
s._fileSystemPath).nonConfigurableExcludedFolders().values()) { | 123 .nonConfigurableExcludedFolders() |
| 116 this._excludedFolders.push(folder); | 124 .values()) { |
| 117 this._excludedFoldersList.appendItem(folder, false); | 125 this._excludedFolders.push(folder); |
| 118 } | 126 this._excludedFoldersList.appendItem(folder, false); |
| 119 }, | 127 } |
| 120 | 128 } |
| 121 _addMappingButtonClicked: function() | 129 |
| 122 { | 130 _addMappingButtonClicked() { |
| 123 var entry = new WebInspector.FileSystemMapping.Entry(this._fileSystemPat
h, "", "", true); | 131 var entry = new WebInspector.FileSystemMapping.Entry(this._fileSystemPath, '
', '', true); |
| 124 this._mappingsList.addNewItem(0, entry); | 132 this._mappingsList.addNewItem(0, entry); |
| 125 }, | 133 } |
| 126 | 134 |
| 127 _addExcludedFolderButtonClicked: function() | 135 _addExcludedFolderButtonClicked() { |
| 128 { | 136 this._excludedFoldersList.addNewItem(0, ''); |
| 129 this._excludedFoldersList.addNewItem(0, ""); | 137 } |
| 130 }, | 138 |
| 139 /** |
| 140 * @override |
| 141 * @param {*} item |
| 142 * @param {boolean} editable |
| 143 * @return {!Element} |
| 144 */ |
| 145 renderItem(item, editable) { |
| 146 var element = createElementWithClass('div', 'file-system-list-item'); |
| 147 if (!editable) |
| 148 element.classList.add('locked'); |
| 149 if (item instanceof WebInspector.FileSystemMapping.Entry) { |
| 150 var entry = /** @type {!WebInspector.FileSystemMapping.Entry} */ (item); |
| 151 var urlPrefix = |
| 152 entry.configurable ? entry.urlPrefix : WebInspector.UIString('%s (via
.devtools)', entry.urlPrefix); |
| 153 var urlPrefixElement = element.createChild('div', 'file-system-value'); |
| 154 urlPrefixElement.textContent = urlPrefix; |
| 155 urlPrefixElement.title = urlPrefix; |
| 156 element.createChild('div', 'file-system-separator'); |
| 157 var pathPrefixElement = element.createChild('div', 'file-system-value'); |
| 158 pathPrefixElement.textContent = entry.pathPrefix; |
| 159 pathPrefixElement.title = entry.pathPrefix; |
| 160 } else { |
| 161 var pathPrefix = /** @type {string} */ (editable ? item : WebInspector.UIS
tring('%s (via .devtools)', item)); |
| 162 var pathPrefixElement = element.createChild('div', 'file-system-value'); |
| 163 pathPrefixElement.textContent = pathPrefix; |
| 164 pathPrefixElement.title = pathPrefix; |
| 165 } |
| 166 element.createChild('div', 'file-system-locked').title = WebInspector.UIStri
ng('From .devtools file'); |
| 167 return element; |
| 168 } |
| 169 |
| 170 /** |
| 171 * @override |
| 172 * @param {*} item |
| 173 * @param {number} index |
| 174 */ |
| 175 removeItemRequested(item, index) { |
| 176 if (item instanceof WebInspector.FileSystemMapping.Entry) { |
| 177 var entry = this._mappings[index]; |
| 178 WebInspector.fileSystemMapping.removeFileMapping(entry.fileSystemPath, ent
ry.urlPrefix, entry.pathPrefix); |
| 179 } else { |
| 180 WebInspector.isolatedFileSystemManager.fileSystem(this._fileSystemPath) |
| 181 .removeExcludedFolder(this._excludedFolders[index]); |
| 182 } |
| 183 } |
| 184 |
| 185 /** |
| 186 * @override |
| 187 * @param {*} item |
| 188 * @param {!WebInspector.ListWidget.Editor} editor |
| 189 * @param {boolean} isNew |
| 190 */ |
| 191 commitEdit(item, editor, isNew) { |
| 192 this._muteUpdate = true; |
| 193 if (item instanceof WebInspector.FileSystemMapping.Entry) { |
| 194 var entry = /** @type {!WebInspector.FileSystemMapping.Entry} */ (item); |
| 195 if (!isNew) |
| 196 WebInspector.fileSystemMapping.removeFileMapping(this._fileSystemPath, e
ntry.urlPrefix, entry.pathPrefix); |
| 197 WebInspector.fileSystemMapping.addFileMapping( |
| 198 this._fileSystemPath, this._normalizePrefix(editor.control('urlPrefix'
).value), |
| 199 this._normalizePrefix(editor.control('pathPrefix').value)); |
| 200 } else { |
| 201 if (!isNew) |
| 202 WebInspector.isolatedFileSystemManager.fileSystem(this._fileSystemPath) |
| 203 .removeExcludedFolder(/** @type {string} */ (item)); |
| 204 WebInspector.isolatedFileSystemManager.fileSystem(this._fileSystemPath) |
| 205 .addExcludedFolder(this._normalizePrefix(editor.control('pathPrefix').
value)); |
| 206 } |
| 207 this._muteUpdate = false; |
| 208 this._update(); |
| 209 } |
| 210 |
| 211 /** |
| 212 * @override |
| 213 * @param {*} item |
| 214 * @return {!WebInspector.ListWidget.Editor} |
| 215 */ |
| 216 beginEdit(item) { |
| 217 if (item instanceof WebInspector.FileSystemMapping.Entry) { |
| 218 var entry = /** @type {!WebInspector.FileSystemMapping.Entry} */ (item); |
| 219 var editor = this._createMappingEditor(); |
| 220 editor.control('urlPrefix').value = entry.urlPrefix; |
| 221 editor.control('pathPrefix').value = entry.pathPrefix; |
| 222 return editor; |
| 223 } else { |
| 224 var editor = this._createExcludedFolderEditor(); |
| 225 editor.control('pathPrefix').value = item; |
| 226 return editor; |
| 227 } |
| 228 } |
| 229 |
| 230 /** |
| 231 * @return {!WebInspector.ListWidget.Editor} |
| 232 */ |
| 233 _createMappingEditor() { |
| 234 if (this._mappingEditor) |
| 235 return this._mappingEditor; |
| 236 |
| 237 var editor = new WebInspector.ListWidget.Editor(); |
| 238 this._mappingEditor = editor; |
| 239 var content = editor.contentElement(); |
| 240 |
| 241 var titles = content.createChild('div', 'file-system-edit-row'); |
| 242 titles.createChild('div', 'file-system-value').textContent = WebInspector.UI
String('URL prefix'); |
| 243 titles.createChild('div', 'file-system-separator file-system-separator-invis
ible'); |
| 244 titles.createChild('div', 'file-system-value').textContent = WebInspector.UI
String('Folder path'); |
| 245 |
| 246 var fields = content.createChild('div', 'file-system-edit-row'); |
| 247 fields.createChild('div', 'file-system-value') |
| 248 .appendChild( |
| 249 editor.createInput('urlPrefix', 'text', 'http://localhost:8000/url',
urlPrefixValidator.bind(this))); |
| 250 fields.createChild('div', 'file-system-separator file-system-separator-invis
ible'); |
| 251 fields.createChild('div', 'file-system-value') |
| 252 .appendChild(editor.createInput('pathPrefix', 'text', '/path/to/folder/'
, pathPrefixValidator.bind(this))); |
| 253 |
| 254 return editor; |
| 131 | 255 |
| 132 /** | 256 /** |
| 133 * @override | |
| 134 * @param {*} item | |
| 135 * @param {boolean} editable | |
| 136 * @return {!Element} | |
| 137 */ | |
| 138 renderItem: function(item, editable) | |
| 139 { | |
| 140 var element = createElementWithClass("div", "file-system-list-item"); | |
| 141 if (!editable) | |
| 142 element.classList.add("locked"); | |
| 143 if (item instanceof WebInspector.FileSystemMapping.Entry) { | |
| 144 var entry = /** @type {!WebInspector.FileSystemMapping.Entry} */ (it
em); | |
| 145 var urlPrefix = entry.configurable ? entry.urlPrefix : WebInspector.
UIString("%s (via .devtools)", entry.urlPrefix); | |
| 146 var urlPrefixElement = element.createChild("div", "file-system-value
"); | |
| 147 urlPrefixElement.textContent = urlPrefix; | |
| 148 urlPrefixElement.title = urlPrefix; | |
| 149 element.createChild("div", "file-system-separator"); | |
| 150 var pathPrefixElement = element.createChild("div", "file-system-valu
e"); | |
| 151 pathPrefixElement.textContent = entry.pathPrefix; | |
| 152 pathPrefixElement.title = entry.pathPrefix; | |
| 153 } else { | |
| 154 var pathPrefix = /** @type {string} */ (editable ? item : WebInspect
or.UIString("%s (via .devtools)", item)); | |
| 155 var pathPrefixElement = element.createChild("div", "file-system-valu
e"); | |
| 156 pathPrefixElement.textContent = pathPrefix; | |
| 157 pathPrefixElement.title = pathPrefix; | |
| 158 } | |
| 159 element.createChild("div", "file-system-locked").title = WebInspector.UI
String("From .devtools file"); | |
| 160 return element; | |
| 161 }, | |
| 162 | |
| 163 /** | |
| 164 * @override | |
| 165 * @param {*} item | 257 * @param {*} item |
| 166 * @param {number} index | 258 * @param {number} index |
| 259 * @param {!HTMLInputElement|!HTMLSelectElement} input |
| 260 * @return {boolean} |
| 261 * @this {WebInspector.EditFileSystemView} |
| 167 */ | 262 */ |
| 168 removeItemRequested: function(item, index) | 263 function urlPrefixValidator(item, index, input) { |
| 169 { | 264 var prefix = this._normalizePrefix(input.value); |
| 170 if (item instanceof WebInspector.FileSystemMapping.Entry) { | 265 for (var i = 0; i < this._mappings.length; ++i) { |
| 171 var entry = this._mappings[index]; | 266 if (i !== index && this._mappings[i].configurable && this._mappings[i].u
rlPrefix === prefix) |
| 172 WebInspector.fileSystemMapping.removeFileMapping(entry.fileSystemPat
h, entry.urlPrefix, entry.pathPrefix); | 267 return false; |
| 173 } else { | 268 } |
| 174 WebInspector.isolatedFileSystemManager.fileSystem(this._fileSystemPa
th).removeExcludedFolder(this._excludedFolders[index]); | 269 return !!prefix; |
| 175 } | 270 } |
| 176 }, | |
| 177 | 271 |
| 178 /** | 272 /** |
| 179 * @override | |
| 180 * @param {*} item | 273 * @param {*} item |
| 181 * @param {!WebInspector.ListWidget.Editor} editor | 274 * @param {number} index |
| 182 * @param {boolean} isNew | 275 * @param {!HTMLInputElement|!HTMLSelectElement} input |
| 276 * @return {boolean} |
| 277 * @this {WebInspector.EditFileSystemView} |
| 183 */ | 278 */ |
| 184 commitEdit: function(item, editor, isNew) | 279 function pathPrefixValidator(item, index, input) { |
| 185 { | 280 var prefix = this._normalizePrefix(input.value); |
| 186 this._muteUpdate = true; | 281 for (var i = 0; i < this._mappings.length; ++i) { |
| 187 if (item instanceof WebInspector.FileSystemMapping.Entry) { | 282 if (i !== index && this._mappings[i].configurable && this._mappings[i].p
athPrefix === prefix) |
| 188 var entry = /** @type {!WebInspector.FileSystemMapping.Entry} */ (it
em); | 283 return false; |
| 189 if (!isNew) | 284 } |
| 190 WebInspector.fileSystemMapping.removeFileMapping(this._fileSyste
mPath, entry.urlPrefix, entry.pathPrefix); | 285 return !!prefix; |
| 191 WebInspector.fileSystemMapping.addFileMapping(this._fileSystemPath,
this._normalizePrefix(editor.control("urlPrefix").value), this._normalizePrefix(
editor.control("pathPrefix").value)); | 286 } |
| 192 } else { | 287 } |
| 193 if (!isNew) | 288 |
| 194 WebInspector.isolatedFileSystemManager.fileSystem(this._fileSyst
emPath).removeExcludedFolder(/** @type {string} */ (item)); | 289 /** |
| 195 WebInspector.isolatedFileSystemManager.fileSystem(this._fileSystemPa
th).addExcludedFolder(this._normalizePrefix(editor.control("pathPrefix").value))
; | 290 * @return {!WebInspector.ListWidget.Editor} |
| 196 } | 291 */ |
| 197 this._muteUpdate = false; | 292 _createExcludedFolderEditor() { |
| 198 this._update(); | 293 if (this._excludedFolderEditor) |
| 199 }, | 294 return this._excludedFolderEditor; |
| 295 |
| 296 var editor = new WebInspector.ListWidget.Editor(); |
| 297 this._excludedFolderEditor = editor; |
| 298 var content = editor.contentElement(); |
| 299 |
| 300 var titles = content.createChild('div', 'file-system-edit-row'); |
| 301 titles.createChild('div', 'file-system-value').textContent = WebInspector.UI
String('Folder path'); |
| 302 |
| 303 var fields = content.createChild('div', 'file-system-edit-row'); |
| 304 fields.createChild('div', 'file-system-value') |
| 305 .appendChild(editor.createInput('pathPrefix', 'text', '/path/to/folder/'
, pathPrefixValidator.bind(this))); |
| 306 |
| 307 return editor; |
| 200 | 308 |
| 201 /** | 309 /** |
| 202 * @override | |
| 203 * @param {*} item | 310 * @param {*} item |
| 204 * @return {!WebInspector.ListWidget.Editor} | 311 * @param {number} index |
| 312 * @param {!HTMLInputElement|!HTMLSelectElement} input |
| 313 * @return {boolean} |
| 314 * @this {WebInspector.EditFileSystemView} |
| 205 */ | 315 */ |
| 206 beginEdit: function(item) | 316 function pathPrefixValidator(item, index, input) { |
| 207 { | 317 var prefix = this._normalizePrefix(input.value); |
| 208 if (item instanceof WebInspector.FileSystemMapping.Entry) { | 318 var configurableCount = |
| 209 var entry = /** @type {!WebInspector.FileSystemMapping.Entry} */ (it
em); | 319 WebInspector.isolatedFileSystemManager.fileSystem(this._fileSystemPath
).excludedFolders().size; |
| 210 var editor = this._createMappingEditor(); | 320 for (var i = 0; i < configurableCount; ++i) { |
| 211 editor.control("urlPrefix").value = entry.urlPrefix; | 321 if (i !== index && this._excludedFolders[i] === prefix) |
| 212 editor.control("pathPrefix").value = entry.pathPrefix; | 322 return false; |
| 213 return editor; | 323 } |
| 214 } else { | 324 return !!prefix; |
| 215 var editor = this._createExcludedFolderEditor(); | 325 } |
| 216 editor.control("pathPrefix").value = item; | 326 } |
| 217 return editor; | 327 |
| 218 } | 328 /** |
| 219 }, | 329 * @param {string} prefix |
| 220 | 330 * @return {string} |
| 221 /** | 331 */ |
| 222 * @return {!WebInspector.ListWidget.Editor} | 332 _normalizePrefix(prefix) { |
| 223 */ | 333 if (!prefix) |
| 224 _createMappingEditor: function() | 334 return ''; |
| 225 { | 335 return prefix + (prefix[prefix.length - 1] === '/' ? '' : '/'); |
| 226 if (this._mappingEditor) | 336 } |
| 227 return this._mappingEditor; | |
| 228 | |
| 229 var editor = new WebInspector.ListWidget.Editor(); | |
| 230 this._mappingEditor = editor; | |
| 231 var content = editor.contentElement(); | |
| 232 | |
| 233 var titles = content.createChild("div", "file-system-edit-row"); | |
| 234 titles.createChild("div", "file-system-value").textContent = WebInspecto
r.UIString("URL prefix"); | |
| 235 titles.createChild("div", "file-system-separator file-system-separator-i
nvisible"); | |
| 236 titles.createChild("div", "file-system-value").textContent = WebInspecto
r.UIString("Folder path"); | |
| 237 | |
| 238 var fields = content.createChild("div", "file-system-edit-row"); | |
| 239 fields.createChild("div", "file-system-value").appendChild(editor.create
Input("urlPrefix", "text", "http://localhost:8000/url", urlPrefixValidator.bind(
this))); | |
| 240 fields.createChild("div", "file-system-separator file-system-separator-i
nvisible"); | |
| 241 fields.createChild("div", "file-system-value").appendChild(editor.create
Input("pathPrefix", "text", "/path/to/folder/", pathPrefixValidator.bind(this)))
; | |
| 242 | |
| 243 return editor; | |
| 244 | |
| 245 /** | |
| 246 * @param {*} item | |
| 247 * @param {number} index | |
| 248 * @param {!HTMLInputElement|!HTMLSelectElement} input | |
| 249 * @return {boolean} | |
| 250 * @this {WebInspector.EditFileSystemView} | |
| 251 */ | |
| 252 function urlPrefixValidator(item, index, input) | |
| 253 { | |
| 254 var prefix = this._normalizePrefix(input.value); | |
| 255 for (var i = 0; i < this._mappings.length; ++i) { | |
| 256 if (i !== index && this._mappings[i].configurable && this._mappi
ngs[i].urlPrefix === prefix) | |
| 257 return false; | |
| 258 } | |
| 259 return !!prefix; | |
| 260 } | |
| 261 | |
| 262 /** | |
| 263 * @param {*} item | |
| 264 * @param {number} index | |
| 265 * @param {!HTMLInputElement|!HTMLSelectElement} input | |
| 266 * @return {boolean} | |
| 267 * @this {WebInspector.EditFileSystemView} | |
| 268 */ | |
| 269 function pathPrefixValidator(item, index, input) | |
| 270 { | |
| 271 var prefix = this._normalizePrefix(input.value); | |
| 272 for (var i = 0; i < this._mappings.length; ++i) { | |
| 273 if (i !== index && this._mappings[i].configurable && this._mappi
ngs[i].pathPrefix === prefix) | |
| 274 return false; | |
| 275 } | |
| 276 return !!prefix; | |
| 277 } | |
| 278 }, | |
| 279 | |
| 280 /** | |
| 281 * @return {!WebInspector.ListWidget.Editor} | |
| 282 */ | |
| 283 _createExcludedFolderEditor: function() | |
| 284 { | |
| 285 if (this._excludedFolderEditor) | |
| 286 return this._excludedFolderEditor; | |
| 287 | |
| 288 var editor = new WebInspector.ListWidget.Editor(); | |
| 289 this._excludedFolderEditor = editor; | |
| 290 var content = editor.contentElement(); | |
| 291 | |
| 292 var titles = content.createChild("div", "file-system-edit-row"); | |
| 293 titles.createChild("div", "file-system-value").textContent = WebInspecto
r.UIString("Folder path"); | |
| 294 | |
| 295 var fields = content.createChild("div", "file-system-edit-row"); | |
| 296 fields.createChild("div", "file-system-value").appendChild(editor.create
Input("pathPrefix", "text", "/path/to/folder/", pathPrefixValidator.bind(this)))
; | |
| 297 | |
| 298 return editor; | |
| 299 | |
| 300 /** | |
| 301 * @param {*} item | |
| 302 * @param {number} index | |
| 303 * @param {!HTMLInputElement|!HTMLSelectElement} input | |
| 304 * @return {boolean} | |
| 305 * @this {WebInspector.EditFileSystemView} | |
| 306 */ | |
| 307 function pathPrefixValidator(item, index, input) | |
| 308 { | |
| 309 var prefix = this._normalizePrefix(input.value); | |
| 310 var configurableCount = WebInspector.isolatedFileSystemManager.fileS
ystem(this._fileSystemPath).excludedFolders().size; | |
| 311 for (var i = 0; i < configurableCount; ++i) { | |
| 312 if (i !== index && this._excludedFolders[i] === prefix) | |
| 313 return false; | |
| 314 } | |
| 315 return !!prefix; | |
| 316 } | |
| 317 }, | |
| 318 | |
| 319 /** | |
| 320 * @param {string} prefix | |
| 321 * @return {string} | |
| 322 */ | |
| 323 _normalizePrefix: function(prefix) | |
| 324 { | |
| 325 if (!prefix) | |
| 326 return ""; | |
| 327 return prefix + (prefix[prefix.length - 1] === "/" ? "" : "/"); | |
| 328 }, | |
| 329 | |
| 330 __proto__: WebInspector.VBox.prototype | |
| 331 }; | 337 }; |
| OLD | NEW |