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