EditFileSystemView.js 3.9 KB

1234567891011121314151617
  1. export default class EditFileSystemView extends UI.VBox{constructor(fileSystemPath){super(true);this.registerRequiredCSS('persistence/editFileSystemView.css');this._fileSystemPath=fileSystemPath;this._eventListeners=[Persistence.isolatedFileSystemManager.addEventListener(Persistence.IsolatedFileSystemManager.Events.ExcludedFolderAdded,this._update,this),Persistence.isolatedFileSystemManager.addEventListener(Persistence.IsolatedFileSystemManager.Events.ExcludedFolderRemoved,this._update,this)];const excludedFoldersHeader=this.contentElement.createChild('div','file-system-header');excludedFoldersHeader.createChild('div','file-system-header-text').textContent=Common.UIString('Excluded folders');excludedFoldersHeader.appendChild(UI.createTextButton(Common.UIString('Add'),this._addExcludedFolderButtonClicked.bind(this),'add-button'));this._excludedFoldersList=new UI.ListWidget(this);this._excludedFoldersList.element.classList.add('file-system-list');this._excludedFoldersList.registerRequiredCSS('persistence/editFileSystemView.css');const excludedFoldersPlaceholder=createElementWithClass('div','file-system-list-empty');excludedFoldersPlaceholder.textContent=Common.UIString('None');this._excludedFoldersList.setEmptyPlaceholder(excludedFoldersPlaceholder);this._excludedFoldersList.show(this.contentElement);this._update();}
  2. dispose(){Common.EventTarget.removeEventListeners(this._eventListeners);}
  3. _update(){if(this._muteUpdate){return;}
  4. this._excludedFoldersList.clear();this._excludedFolders=[];for(const folder of Persistence.isolatedFileSystemManager.fileSystem(this._fileSystemPath).excludedFolders().values()){this._excludedFolders.push(folder);this._excludedFoldersList.appendItem(folder,true);}}
  5. _addExcludedFolderButtonClicked(){this._excludedFoldersList.addNewItem(0,'');}
  6. renderItem(item,editable){const element=createElementWithClass('div','file-system-list-item');const pathPrefix=(editable?item:Common.UIString('%s (via .devtools)',item));const pathPrefixElement=element.createChild('div','file-system-value');pathPrefixElement.textContent=pathPrefix;pathPrefixElement.title=pathPrefix;return element;}
  7. removeItemRequested(item,index){Persistence.isolatedFileSystemManager.fileSystem(this._fileSystemPath).removeExcludedFolder(this._excludedFolders[index]);}
  8. commitEdit(item,editor,isNew){this._muteUpdate=true;if(!isNew){Persistence.isolatedFileSystemManager.fileSystem(this._fileSystemPath).removeExcludedFolder((item));}
  9. Persistence.isolatedFileSystemManager.fileSystem(this._fileSystemPath).addExcludedFolder(this._normalizePrefix(editor.control('pathPrefix').value));this._muteUpdate=false;this._update();}
  10. beginEdit(item){const editor=this._createExcludedFolderEditor();editor.control('pathPrefix').value=item;return editor;}
  11. _createExcludedFolderEditor(){if(this._excludedFolderEditor){return this._excludedFolderEditor;}
  12. const editor=new UI.ListWidget.Editor();this._excludedFolderEditor=editor;const content=editor.contentElement();const titles=content.createChild('div','file-system-edit-row');titles.createChild('div','file-system-value').textContent=Common.UIString('Folder path');const fields=content.createChild('div','file-system-edit-row');fields.createChild('div','file-system-value').appendChild(editor.createInput('pathPrefix','text','/path/to/folder/',pathPrefixValidator.bind(this)));return editor;function pathPrefixValidator(item,index,input){const prefix=this._normalizePrefix(input.value.trim());if(!prefix){return{valid:false,errorMessage:ls`Enter a path`};}
  13. const configurableCount=Persistence.isolatedFileSystemManager.fileSystem(this._fileSystemPath).excludedFolders().size;for(let i=0;i<configurableCount;++i){if(i!==index&&this._excludedFolders[i]===prefix){return{valid:false,errorMessage:ls`Enter a unique path`};}}
  14. return{valid:true};}}
  15. _normalizePrefix(prefix){if(!prefix){return'';}
  16. return prefix+(prefix[prefix.length-1]==='/'?'':'/');}}
  17. self.Persistence=self.Persistence||{};Persistence=Persistence||{};Persistence.EditFileSystemView=EditFileSystemView;