ContentProviderBasedProject.js 3.6 KB

123456789101112131415161718192021222324252627282930
  1. export default class ContentProviderBasedProject extends Workspace.ProjectStore{constructor(workspace,id,type,displayName,isServiceProject){super(workspace,id,type,displayName);this._contentProviders={};this._isServiceProject=isServiceProject;workspace.addProject(this);}
  2. async requestFileContent(uiSourceCode){const contentProvider=this._contentProviders[uiSourceCode.url()];try{const[content,isEncoded]=await Promise.all([contentProvider.requestContent(),contentProvider.contentEncoded()]);return{content:content.content,isEncoded,error:content.error};}catch(err){return{isEncoded:false,error:err?String(err):ls`Unknown error loading file`};}}
  3. isServiceProject(){return this._isServiceProject;}
  4. requestMetadata(uiSourceCode){return Promise.resolve(uiSourceCode[_metadata]);}
  5. canSetFileContent(){return false;}
  6. async setFileContent(uiSourceCode,newContent,isBase64){}
  7. fullDisplayName(uiSourceCode){let parentPath=uiSourceCode.parentURL().replace(/^(?:https?|file)\:\/\//,'');try{parentPath=decodeURI(parentPath);}catch(e){}
  8. return parentPath+'/'+uiSourceCode.displayName(true);}
  9. mimeType(uiSourceCode){return(uiSourceCode[_mimeType]);}
  10. canRename(){return false;}
  11. rename(uiSourceCode,newName,callback){const path=uiSourceCode.url();this.performRename(path,newName,innerCallback.bind(this));function innerCallback(success,newName){if(success&&newName){const copyOfPath=path.split('/');copyOfPath[copyOfPath.length-1]=newName;const newPath=copyOfPath.join('/');this._contentProviders[newPath]=this._contentProviders[path];delete this._contentProviders[path];this.renameUISourceCode(uiSourceCode,newName);}
  12. callback(success,newName);}}
  13. excludeFolder(path){}
  14. canExcludeFolder(path){return false;}
  15. createFile(path,name,content,isBase64){}
  16. canCreateFile(){return false;}
  17. deleteFile(uiSourceCode){}
  18. remove(){}
  19. performRename(path,newName,callback){callback(false);}
  20. searchInFileContent(uiSourceCode,query,caseSensitive,isRegex){const contentProvider=this._contentProviders[uiSourceCode.url()];return contentProvider.searchInContent(query,caseSensitive,isRegex);}
  21. async findFilesMatchingSearchRequest(searchConfig,filesMathingFileQuery,progress){const result=[];progress.setTotalWork(filesMathingFileQuery.length);await Promise.all(filesMathingFileQuery.map(searchInContent.bind(this)));progress.done();return result;async function searchInContent(path){const provider=this._contentProviders[path];let allMatchesFound=true;for(const query of searchConfig.queries().slice()){const searchMatches=await provider.searchInContent(query,!searchConfig.ignoreCase(),searchConfig.isRegex());if(!searchMatches.length){allMatchesFound=false;break;}}
  22. if(allMatchesFound){result.push(path);}
  23. progress.worked(1);}}
  24. indexContent(progress){setImmediate(progress.done.bind(progress));}
  25. addUISourceCodeWithProvider(uiSourceCode,contentProvider,metadata,mimeType){uiSourceCode[_mimeType]=mimeType;this._contentProviders[uiSourceCode.url()]=contentProvider;uiSourceCode[_metadata]=metadata;this.addUISourceCode(uiSourceCode);}
  26. addContentProvider(url,contentProvider,mimeType){const uiSourceCode=this.createUISourceCode(url,contentProvider.contentType());this.addUISourceCodeWithProvider(uiSourceCode,contentProvider,null,mimeType);return uiSourceCode;}
  27. removeFile(path){delete this._contentProviders[path];this.removeUISourceCode(path);}
  28. reset(){this._contentProviders={};this.removeProject();this.workspace().addProject(this);}
  29. dispose(){this._contentProviders={};this.removeProject();}}
  30. const _metadata=Symbol('ContentProviderBasedProject.Metadata');const _mimeType=Symbol('ContentProviderBasedProject.MimeType');self.Bindings=self.Bindings||{};Bindings=Bindings||{};Bindings.ContentProviderBasedProject=ContentProviderBasedProject;