WorkspaceImpl.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. export class ProjectSearchConfig{query(){}
  2. ignoreCase(){}
  3. isRegex(){}
  4. queries(){}
  5. filePathMatchesFileQuery(filePath){}}
  6. export class Project{workspace(){}
  7. id(){}
  8. type(){}
  9. isServiceProject(){}
  10. displayName(){}
  11. requestMetadata(uiSourceCode){}
  12. requestFileContent(uiSourceCode){}
  13. canSetFileContent(){}
  14. setFileContent(uiSourceCode,newContent,isBase64){}
  15. fullDisplayName(uiSourceCode){}
  16. mimeType(uiSourceCode){}
  17. canRename(){}
  18. rename(uiSourceCode,newName,callback){}
  19. excludeFolder(path){}
  20. canExcludeFolder(path){}
  21. createFile(path,name,content,isBase64){}
  22. canCreateFile(){}
  23. deleteFile(uiSourceCode){}
  24. remove(){}
  25. searchInFileContent(uiSourceCode,query,caseSensitive,isRegex){}
  26. findFilesMatchingSearchRequest(searchConfig,filesMathingFileQuery,progress){}
  27. indexContent(progress){}
  28. uiSourceCodeForURL(url){}
  29. uiSourceCodes(){}}
  30. export const projectTypes={Debugger:'debugger',Formatter:'formatter',Network:'network',FileSystem:'filesystem',ContentScripts:'contentscripts',Service:'service'};export class ProjectStore{constructor(workspace,id,type,displayName){this._workspace=workspace;this._id=id;this._type=type;this._displayName=displayName;this._uiSourceCodesMap=new Map();this._uiSourceCodesList=[];this._project=(this);}
  31. id(){return this._id;}
  32. type(){return this._type;}
  33. displayName(){return this._displayName;}
  34. workspace(){return this._workspace;}
  35. createUISourceCode(url,contentType){return new Workspace.UISourceCode(this._project,url,contentType);}
  36. addUISourceCode(uiSourceCode){const url=uiSourceCode.url();if(this.uiSourceCodeForURL(url)){return false;}
  37. this._uiSourceCodesMap.set(url,{uiSourceCode:uiSourceCode,index:this._uiSourceCodesList.length});this._uiSourceCodesList.push(uiSourceCode);this._workspace.dispatchEventToListeners(Events.UISourceCodeAdded,uiSourceCode);return true;}
  38. removeUISourceCode(url){const uiSourceCode=this.uiSourceCodeForURL(url);if(!uiSourceCode){return;}
  39. const entry=this._uiSourceCodesMap.get(url);const movedUISourceCode=this._uiSourceCodesList[this._uiSourceCodesList.length-1];this._uiSourceCodesList[entry.index]=movedUISourceCode;const movedEntry=this._uiSourceCodesMap.get(movedUISourceCode.url());movedEntry.index=entry.index;this._uiSourceCodesList.splice(this._uiSourceCodesList.length-1,1);this._uiSourceCodesMap.delete(url);this._workspace.dispatchEventToListeners(Events.UISourceCodeRemoved,entry.uiSourceCode);}
  40. removeProject(){this._workspace._removeProject(this._project);this._uiSourceCodesMap=new Map();this._uiSourceCodesList=[];}
  41. uiSourceCodeForURL(url){const entry=this._uiSourceCodesMap.get(url);return entry?entry.uiSourceCode:null;}
  42. uiSourceCodes(){return this._uiSourceCodesList;}
  43. renameUISourceCode(uiSourceCode,newName){const oldPath=uiSourceCode.url();const newPath=uiSourceCode.parentURL()?uiSourceCode.parentURL()+'/'+newName:newName;const value=(this._uiSourceCodesMap.get(oldPath));this._uiSourceCodesMap.set(newPath,value);this._uiSourceCodesMap.delete(oldPath);}}
  44. export default class WorkspaceImpl extends Common.Object{constructor(){super();this._projects=new Map();this._hasResourceContentTrackingExtensions=false;}
  45. uiSourceCode(projectId,url){const project=this._projects.get(projectId);return project?project.uiSourceCodeForURL(url):null;}
  46. uiSourceCodeForURL(url){for(const project of this._projects.values()){const uiSourceCode=project.uiSourceCodeForURL(url);if(uiSourceCode){return uiSourceCode;}}
  47. return null;}
  48. uiSourceCodesForProjectType(type){let result=[];for(const project of this._projects.values()){if(project.type()===type){result=result.concat(project.uiSourceCodes());}}
  49. return result;}
  50. addProject(project){console.assert(!this._projects.has(project.id()),`A project with id ${project.id()} already exists!`);this._projects.set(project.id(),project);this.dispatchEventToListeners(Events.ProjectAdded,project);}
  51. _removeProject(project){this._projects.delete(project.id());this.dispatchEventToListeners(Events.ProjectRemoved,project);}
  52. project(projectId){return this._projects.get(projectId)||null;}
  53. projects(){return this._projects.valuesArray();}
  54. projectsForType(type){function filterByType(project){return project.type()===type;}
  55. return this.projects().filter(filterByType);}
  56. uiSourceCodes(){let result=[];for(const project of this._projects.values()){result=result.concat(project.uiSourceCodes());}
  57. return result;}
  58. setHasResourceContentTrackingExtensions(hasExtensions){this._hasResourceContentTrackingExtensions=hasExtensions;}
  59. hasResourceContentTrackingExtensions(){return this._hasResourceContentTrackingExtensions;}}
  60. export const Events={UISourceCodeAdded:Symbol('UISourceCodeAdded'),UISourceCodeRemoved:Symbol('UISourceCodeRemoved'),UISourceCodeRenamed:Symbol('UISourceCodeRenamed'),WorkingCopyChanged:Symbol('WorkingCopyChanged'),WorkingCopyCommitted:Symbol('WorkingCopyCommitted'),WorkingCopyCommittedByUser:Symbol('WorkingCopyCommittedByUser'),ProjectAdded:Symbol('ProjectAdded'),ProjectRemoved:Symbol('ProjectRemoved')};self.Workspace=self.Workspace||{};Workspace=Workspace||{};Workspace.Workspace=WorkspaceImpl;Workspace.Workspace.Events=Events;Workspace.ProjectSearchConfig=ProjectSearchConfig;Workspace.Project=Project;Workspace.projectTypes=projectTypes;Workspace.ProjectStore=ProjectStore;Workspace.workspace;