PersistenceActions.js 1.6 KB

1234567
  1. export class ContextMenuProvider{appendApplicableItems(event,contextMenu,target){const contentProvider=(target);async function saveAs(){if(contentProvider instanceof Workspace.UISourceCode){(contentProvider).commitWorkingCopy();}
  2. let content=(await contentProvider.requestContent()).content||'';if(await contentProvider.contentEncoded()){content=window.atob(content);}
  3. const url=contentProvider.contentURL();Workspace.fileManager.save(url,(content),true);Workspace.fileManager.close(url);}
  4. if(contentProvider.contentType().isDocumentOrScriptOrStyleSheet()){contextMenu.saveSection().appendItem(Common.UIString('Save as...'),saveAs);}
  5. const uiSourceCode=Workspace.workspace.uiSourceCodeForURL(contentProvider.contentURL());if(uiSourceCode&&Persistence.networkPersistenceManager.canSaveUISourceCodeForOverrides(uiSourceCode)){contextMenu.saveSection().appendItem(Common.UIString('Save for overrides'),()=>{uiSourceCode.commitWorkingCopy();Persistence.networkPersistenceManager.saveUISourceCodeForOverrides((uiSourceCode));Common.Revealer.reveal(uiSourceCode);});}
  6. const binding=uiSourceCode&&Persistence.persistence.binding(uiSourceCode);const fileURL=binding?binding.fileSystem.contentURL():contentProvider.contentURL();if(fileURL.startsWith('file://')){const path=Common.ParsedURL.urlToPlatformPath(fileURL,Host.isWin());contextMenu.revealSection().appendItem(Common.UIString('Open in containing folder'),()=>Host.InspectorFrontendHost.showItemInFolder(path));}}}
  7. self.Persistence=self.Persistence||{};Persistence=Persistence||{};Persistence.PersistenceActions={};Persistence.PersistenceActions.ContextMenuProvider=ContextMenuProvider;