public HttpFileEditor(@NotNull Project project, @NotNull HttpVirtualFile virtualFile) { super(project); myPanel = new RemoteFilePanel(project, virtualFile, this); RemoteFileInfo fileInfo = virtualFile.getFileInfo(); assert fileInfo != null; fileInfo.download() .done(new Consumer<VirtualFile>() { @Override public void consume(VirtualFile file) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { contentLoaded(); } }, myProject.getDisposed()); } }) .rejected(new Consumer<Throwable>() { @Override public void consume(Throwable throwable) { contentRejected(); } }); }
@Override public boolean canSelect(SelectInContext context) { Object selectorInFile = context.getSelectorInFile(); OpenInBrowserRequest request = selectorInFile instanceof PsiElement ? OpenInBrowserRequest.create((PsiElement) selectorInFile) : null; if(request == null) { return false; } WebBrowserUrlProvider urlProvider = WebBrowserServiceImpl.getProvider(request); if(urlProvider == null) { VirtualFile virtualFile = request.getVirtualFile(); return virtualFile instanceof HttpVirtualFile || (HtmlUtil.isHtmlFile(request.getFile()) && !(virtualFile instanceof LightVirtualFile)); } return true; }
@Override public boolean canHandleElement(@NotNull OpenInBrowserRequest request) { if (request.getVirtualFile() instanceof HttpVirtualFile) { return true; } // we must use base language because we serve file - not part of file, but the whole file // handlebars, for example, contains HTML and HBS psi trees, so, regardless of context, we should not handle such file FileViewProvider viewProvider = request.getFile().getViewProvider(); return viewProvider.isPhysical() && !(request.getVirtualFile() instanceof LightVirtualFile) && isMyLanguage(viewProvider.getBaseLanguage()); }
@Nullable @Override protected Url getUrl(@NotNull OpenInBrowserRequest request, @NotNull VirtualFile file) throws BrowserException { if (file instanceof HttpVirtualFile) { return Urls.newFromVirtualFile(file); } else { return ContainerUtil.getFirstItem(getUrls(file, request.getProject(), null)); } }
public static boolean mayShowToolbar(@Nullable final Document document) { if (document == null) { return false; } final VirtualFile file = FileDocumentManager.getInstance().getFile(document); return file != null && file.isValid() && (file.isInLocalFileSystem() || file instanceof HttpVirtualFile); }
/** * do not call this method from plugins, use {@link com.intellij.xdebugger.XDebuggerUtil#createPosition(com.intellij.openapi.vfs.VirtualFile, int)} instead */ @Nullable public static XSourcePositionImpl create(@Nullable VirtualFile file, int line) { if (file == null) { return null; } AccessToken lock = ApplicationManager.getApplication().acquireReadActionLock(); try { int offset; if (file instanceof LightVirtualFile || file instanceof HttpVirtualFile) { offset = -1; } else { Document document = file.isValid() ? FileDocumentManager.getInstance().getDocument(file) : null; if (document == null) { return null; } if (line < 0) { line = 0; } offset = line < document.getLineCount() ? document.getLineStartOffset(line) : -1; } return new XSourcePositionImpl(file, line, offset); } finally { lock.finish(); } }
@Nullable @Override public PsiFileSystemItem resolveFileReference(@NotNull FileReference reference, @NotNull String name) { VirtualFile file = getVirtualFile(); if (!(file instanceof HttpVirtualFile)) { return null; } VirtualFile parent = file; if (!parent.isDirectory()) { parent = parent.getParent(); if (parent == null) { parent = file; } } VirtualFile childFile = parent.findChild(name); HttpFileSystem fileSystem = (HttpFileSystem)parent.getFileSystem(); if (childFile == null) { childFile = fileSystem.createChild(parent, name, !reference.isLast()); } if (childFile.isDirectory()) { // pre create children VirtualFile childParent = childFile; FileReference[] references = reference.getFileReferenceSet().getAllReferences(); for (int i = reference.getIndex() + 1, n = references.length; i < n; i++) { FileReference childReference = references[i]; childParent = fileSystem.createChild(childParent, childReference.decode(childReference.getText()), i != (n - 1)); } return getManager().findDirectory(childFile); } else { return getManager().findFile(childFile); } }
private static boolean isSuitable(@NotNull Project project, @NotNull VirtualFile file) { if (file instanceof HttpVirtualFile) { return false; } final FileViewProvider provider = PsiManager.getInstance(project).findViewProvider(file); return provider != null && BreadcrumbsXmlWrapper.findInfoProvider(provider) != null; }
@Override public boolean canSelect(SelectInContext context) { Object selectorInFile = context.getSelectorInFile(); OpenInBrowserRequest request = selectorInFile instanceof PsiElement ? OpenInBrowserRequest.create((PsiElement)selectorInFile) : null; if (request == null) { return false; } WebBrowserUrlProvider urlProvider = WebBrowserServiceImpl.getProvider(request); if (urlProvider == null) { VirtualFile virtualFile = request.getVirtualFile(); return virtualFile instanceof HttpVirtualFile || (HtmlUtil.isHtmlFile(request.getFile()) && !(virtualFile instanceof LightVirtualFile)); } return true; }
public static boolean mayShowToolbar(@Nullable final Document document) { if (document == null) { return false; } final VirtualFile file = FileDocumentManager.getInstance().getFile(document); return file != null && file.isValid() && (file.getFileSystem() == LocalFileSystem.getInstance() || file instanceof HttpVirtualFile); }
private static boolean isSuitable(final Project project, final VirtualFile file) { if (file instanceof HttpVirtualFile) { return false; } final FileViewProvider provider = PsiManager.getInstance(project).findViewProvider(file); return provider != null && BreadcrumbsXmlWrapper.findInfoProvider(provider) != null; }
@Override @Nullable public Url getUrlToOpen(@NotNull PsiElement psiElement, boolean preferLocalUrl) throws WebBrowserUrlProvider.BrowserException { final PsiFile psiFile = psiElement instanceof PsiFile ? (PsiFile)psiElement : psiElement.getContainingFile(); if (psiFile == null) { return null; } VirtualFile virtualFile = psiFile.getVirtualFile(); if (virtualFile == null) { return null; } if (virtualFile instanceof HttpVirtualFile) { return Urls.newFromVirtualFile(virtualFile); } if (!(preferLocalUrl && HtmlUtil.isHtmlFile(psiFile))) { Pair<WebBrowserUrlProvider, Url> provider = getProvider(psiElement); if (provider != null) { if (provider.second != null) { return provider.second; } try { Url url = provider.first.getUrl(psiElement, psiFile, virtualFile); if (url != null) { return url; } } catch (WebBrowserUrlProvider.BrowserException e) { if (!HtmlUtil.isHtmlFile(psiFile)) { throw e; } } } } return virtualFile instanceof LightVirtualFile ? null : Urls.newFromVirtualFile(virtualFile); }
private static boolean isSuitable(@Nonnull TextEditor editor, @Nonnull VirtualFile file) { if (file instanceof HttpVirtualFile) { return false; } return editor.isValid() && BreadcrumbsWrapper.findInfoProvider(editor.getEditor(), file) != null; }
@NotNull @Override public Collection<Url> getUrlsToOpen(@NotNull OpenInBrowserRequest request, boolean preferLocalUrl) throws WebBrowserUrlProvider.BrowserException { VirtualFile virtualFile = request.getVirtualFile(); if(virtualFile instanceof HttpVirtualFile) { return Collections.singleton(Urls.newFromVirtualFile(virtualFile)); } if(!preferLocalUrl || !HtmlUtil.isHtmlFile(request.getFile())) { WebBrowserUrlProvider provider = getProvider(request); if(provider != null) { if(request.getResult() != null) { return request.getResult(); } try { Collection<Url> urls = provider.getUrls(request); if(!urls.isEmpty()) { return urls; } } catch(WebBrowserUrlProvider.BrowserException e) { if(!HtmlUtil.isHtmlFile(request.getFile())) { throw e; } } } } return virtualFile instanceof LightVirtualFile || !request.getFile().getViewProvider().isPhysical() ? Collections.<Url>emptySet() : Collections.singleton(Urls.newFromVirtualFile(virtualFile)); }
public RemoteFilePanel(final Project project, final HttpVirtualFile virtualFile, @NotNull PropertyChangeListener propertyChangeListener) { myProject = project; myVirtualFile = virtualFile; myPropertyChangeListener = propertyChangeListener; myErrorLabel.setIcon(AllIcons.RunConfigurations.ConfigurationWarning); myUrlTextField.setText(virtualFile.getUrl()); myProgressUpdatesQueue = new MergingUpdateQueue("downloading progress updates", 300, false, myMainPanel); initToolbar(project); final RemoteFileInfo remoteFileInfo = virtualFile.getFileInfo(); myDownloadingListener = new MyDownloadingListener(); assert remoteFileInfo != null; remoteFileInfo.addDownloadingListener(myDownloadingListener); myCancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(@NotNull final ActionEvent e) { remoteFileInfo.cancelDownloading(); } }); myTryAgainButton.addActionListener(new ActionListener() { @Override public void actionPerformed(@NotNull final ActionEvent e) { showCard(DOWNLOADING_CARD); remoteFileInfo.restartDownloading(); } }); myChangeProxySettingsButton.addActionListener(new ActionListener() { @Override public void actionPerformed(@NotNull ActionEvent e) { HttpConfigurable.editConfigurable(myMainPanel); } }); if (remoteFileInfo.getState() != RemoteFileState.DOWNLOADED) { showCard(DOWNLOADING_CARD); remoteFileInfo.startDownloading(); } // file could be from cache if (remoteFileInfo.getState() == RemoteFileState.DOWNLOADED) { switchEditor(); } else { String errorMessage = remoteFileInfo.getErrorMessage(); if (errorMessage != null) { myDownloadingListener.errorOccurred(errorMessage); } } }
@NotNull public abstract AnAction[] createToolbarActions(@NotNull Project project, @NotNull HttpVirtualFile file);
@Override public boolean accept(@NotNull final Project project, @NotNull final VirtualFile file) { return file instanceof HttpVirtualFile && !file.isDirectory(); }
@Override @NotNull public FileEditor createEditor(@NotNull final Project project, @NotNull final VirtualFile file) { return new HttpFileEditor(project, (HttpVirtualFile)file); }
public RefreshRemoteFileAction(HttpVirtualFile file) { super("Reload File", "", AllIcons.Actions.Refresh); myFile = file; }
public JumpFromRemoteFileToLocalAction(HttpVirtualFile file, Project project) { super("Find Local File", "", AllIcons.General.AutoscrollToSource); myFile = file; myProject = project; }
@NotNull @Override public AnAction[] createToolbarActions(@NotNull Project project, @NotNull HttpVirtualFile file) { return new AnAction[] {new JumpFromRemoteFileToLocalAction(file, project)}; }
@Override public boolean isMine(Project project, @NotNull VirtualFile file) { return file instanceof HttpVirtualFile; }
public boolean accept(@NotNull final Project project, @NotNull final VirtualFile file) { return file instanceof HttpVirtualFile && !file.isDirectory(); }
@NotNull public FileEditor createEditor(@NotNull final Project project, @NotNull final VirtualFile file) { return new HttpFileEditor(project, (HttpVirtualFile)file); }
public HttpFileEditor(final Project project, final HttpVirtualFile virtualFile) { myProject = project; myPanel = new RemoteFilePanel(project, virtualFile); }
@Nonnull public abstract AnAction[] createToolbarActions(@Nonnull Project project, @Nonnull HttpVirtualFile file);
public boolean accept(@Nonnull final Project project, @Nonnull final VirtualFile file) { return file instanceof HttpVirtualFile && !file.isDirectory(); }
@Nonnull public FileEditor createEditor(@Nonnull final Project project, @Nonnull final VirtualFile file) { return new HttpFileEditor(project, (HttpVirtualFile)file); }
@Nonnull @Override public AnAction[] createToolbarActions(@Nonnull Project project, @Nonnull HttpVirtualFile file) { return new AnAction[] {new JumpFromRemoteFileToLocalAction(file, project)}; }
@Override public boolean isMine(Project project, @Nonnull VirtualFile file) { return file instanceof HttpVirtualFile; }