FileManager.js 1.4 KB

12345678
  1. export default class FileManager extends Common.Object{constructor(){super();this._saveCallbacks=new Map();Host.InspectorFrontendHost.events.addEventListener(Host.InspectorFrontendHostAPI.Events.SavedURL,this._savedURL,this);Host.InspectorFrontendHost.events.addEventListener(Host.InspectorFrontendHostAPI.Events.CanceledSaveURL,this._canceledSavedURL,this);Host.InspectorFrontendHost.events.addEventListener(Host.InspectorFrontendHostAPI.Events.AppendedToURL,this._appendedToURL,this);}
  2. save(url,content,forceSaveAs){const result=new Promise(resolve=>this._saveCallbacks.set(url,resolve));Host.InspectorFrontendHost.save(url,content,forceSaveAs);return result;}
  3. _savedURL(event){const url=(event.data.url);const callback=this._saveCallbacks.get(url);this._saveCallbacks.delete(url);if(callback){callback({fileSystemPath:(event.data.fileSystemPath)});}}
  4. _canceledSavedURL(event){const url=(event.data);const callback=this._saveCallbacks.get(url);this._saveCallbacks.delete(url);if(callback){callback(null);}}
  5. append(url,content){Host.InspectorFrontendHost.append(url,content);}
  6. close(url){Host.InspectorFrontendHost.close(url);}
  7. _appendedToURL(event){const url=(event.data);this.dispatchEventToListeners(Events.AppendedToURL,url);}}
  8. export const Events={AppendedToURL:Symbol('AppendedToURL')};self.Workspace=self.Workspace||{};Workspace=Workspace||{};Workspace.FileManager=FileManager;Workspace.FileManager.Events=Events;Workspace.fileManager;