Search in sources :

Example 1 with FileEditorProvider

use of com.intellij.openapi.fileEditor.FileEditorProvider in project intellij-community by JetBrains.

the class ImplementationViewComponent method updateEditorText.

private void updateEditorText() {
    disposeNonTextEditor();
    final PsiElement foundElement = myElements[myIndex];
    final PsiElement elt = foundElement.getNavigationElement();
    LOG.assertTrue(elt != null, foundElement);
    final Project project = foundElement.getProject();
    final PsiFile psiFile = getContainingFile(elt);
    final VirtualFile vFile = psiFile != null ? psiFile.getVirtualFile() : null;
    if (vFile == null)
        return;
    final FileEditorProvider[] providers = FileEditorProviderManager.getInstance().getProviders(project, vFile);
    for (FileEditorProvider provider : providers) {
        if (provider instanceof TextEditorProvider) {
            updateTextElement(elt);
            myBinarySwitch.show(myViewingPanel, TEXT_PAGE_KEY);
            break;
        } else if (provider.accept(project, vFile)) {
            myCurrentNonTextEditorProvider = provider;
            myNonTextEditor = myCurrentNonTextEditorProvider.createEditor(project, vFile);
            myBinaryPanel.removeAll();
            myBinaryPanel.add(myNonTextEditor.getComponent());
            myBinarySwitch.show(myViewingPanel, BINARY_PAGE_KEY);
            break;
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileEditorProvider(com.intellij.openapi.fileEditor.FileEditorProvider) TextEditorProvider(com.intellij.openapi.fileEditor.impl.text.TextEditorProvider)

Example 2 with FileEditorProvider

use of com.intellij.openapi.fileEditor.FileEditorProvider in project intellij-community by JetBrains.

the class EditorPlaceHolder method setContent.

public void setContent(final DiffContent content) {
    runRegisteredDisposables();
    myContent = content;
    if (myContent != null) {
        Document document = myContent.getDocument();
        if (myContent.isBinary() || document == null || myContent.getContentType() instanceof UIBasedFileType) {
            final VirtualFile file = myContent.getFile();
            if (file != null) {
                final FileEditorProvider[] providers = FileEditorProviderManager.getInstance().getProviders(getProject(), file);
                if (providers.length > 0) {
                    myFileEditor = providers[0].createEditor(getProject(), file);
                    if (myFileEditor instanceof TextEditor) {
                        myEditor = (EditorEx) ((TextEditor) myFileEditor).getEditor();
                        ContentDocumentListener.install(myContent, this);
                    }
                    myFileEditorProvider = providers[0];
                    addDisposable(new Disposable() {

                        @Override
                        public void dispose() {
                            myFileEditorProvider.disposeEditor(myFileEditor);
                            myFileEditor = null;
                            myFileEditorProvider = null;
                            myEditor = null;
                        }
                    });
                } else {
                    document = new DocumentImpl("Can not show", true);
                    final EditorFactory editorFactory = EditorFactory.getInstance();
                    myEditor = DiffUtil.createEditor(document, getProject(), true, content.getContentType());
                    addDisposable(new Disposable() {

                        public void dispose() {
                            editorFactory.releaseEditor(myEditor);
                            myEditor = null;
                        }
                    });
                }
            }
        } else {
            final EditorFactory editorFactory = EditorFactory.getInstance();
            myEditor = DiffUtil.createEditor(document, getProject(), false, content.getContentType());
            addDisposable(new Disposable() {

                public void dispose() {
                    editorFactory.releaseEditor(myEditor);
                    myEditor = null;
                }
            });
            ContentDocumentListener.install(myContent, this);
        }
    }
    fireContentChanged();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Disposable(com.intellij.openapi.Disposable) UIBasedFileType(com.intellij.openapi.fileTypes.UIBasedFileType) EditorFactory(com.intellij.openapi.editor.EditorFactory) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditorProvider(com.intellij.openapi.fileEditor.FileEditorProvider) Document(com.intellij.openapi.editor.Document) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl)

Example 3 with FileEditorProvider

use of com.intellij.openapi.fileEditor.FileEditorProvider in project intellij-community by JetBrains.

the class FileEditorProviderManagerImpl method getProviders.

@Override
@NotNull
public FileEditorProvider[] getProviders(@NotNull final Project project, @NotNull final VirtualFile file) {
    // Collect all possible editors
    List<FileEditorProvider> sharedProviders = new ArrayList<>();
    boolean doNotShowTextEditor = false;
    for (final FileEditorProvider provider : myProviders) {
        if (ReadAction.compute(() -> {
            if (DumbService.isDumb(project) && !DumbService.isDumbAware(provider)) {
                return false;
            }
            return provider.accept(project, file);
        })) {
            sharedProviders.add(provider);
            doNotShowTextEditor |= provider.getPolicy() == FileEditorPolicy.HIDE_DEFAULT_EDITOR;
        }
    }
    // Throw out default editors provider if necessary
    if (doNotShowTextEditor) {
        ContainerUtil.retainAll(sharedProviders, provider -> !(provider instanceof TextEditorProvider));
    }
    // Sort editors according policies
    Collections.sort(sharedProviders, MyComparator.ourInstance);
    return sharedProviders.toArray(new FileEditorProvider[sharedProviders.size()]);
}
Also used : WeighedFileEditorProvider(com.intellij.openapi.fileEditor.WeighedFileEditorProvider) FileEditorProvider(com.intellij.openapi.fileEditor.FileEditorProvider) TextEditorProvider(com.intellij.openapi.fileEditor.impl.text.TextEditorProvider) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with FileEditorProvider

use of com.intellij.openapi.fileEditor.FileEditorProvider in project intellij-community by JetBrains.

the class FileEditorProviderManagerImpl method getSelectedFileEditorProvider.

@Nullable
FileEditorProvider getSelectedFileEditorProvider(EditorHistoryManager editorHistoryManager, VirtualFile file, FileEditorProvider[] providers) {
    FileEditorProvider provider = editorHistoryManager.getSelectedProvider(file);
    if (provider != null || providers.length < 2) {
        return provider;
    }
    String id = mySelectedProviders.get(computeKey(providers));
    return id == null ? null : getProvider(id);
}
Also used : WeighedFileEditorProvider(com.intellij.openapi.fileEditor.WeighedFileEditorProvider) FileEditorProvider(com.intellij.openapi.fileEditor.FileEditorProvider) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with FileEditorProvider

use of com.intellij.openapi.fileEditor.FileEditorProvider in project intellij-community by JetBrains.

the class HistoryEntry method createHeavy.

@NotNull
static HistoryEntry createHeavy(@NotNull Project project, @NotNull Element e) throws InvalidDataException {
    if (project.isDisposed())
        return createLight(project, e);
    EntryData entryData = parseEntry(project, e);
    Disposable disposable = Disposer.newDisposable();
    VirtualFilePointer pointer = VirtualFilePointerManager.getInstance().create(entryData.url, disposable, null);
    HistoryEntry entry = new HistoryEntry(pointer, entryData.selectedProvider, disposable);
    for (Pair<FileEditorProvider, FileEditorState> state : entryData.providerStates) {
        entry.putState(state.first, state.second);
    }
    return entry;
}
Also used : Disposable(com.intellij.openapi.Disposable) FileEditorProvider(com.intellij.openapi.fileEditor.FileEditorProvider) FileEditorState(com.intellij.openapi.fileEditor.FileEditorState) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FileEditorProvider (com.intellij.openapi.fileEditor.FileEditorProvider)14 NotNull (org.jetbrains.annotations.NotNull)6 FileEditorState (com.intellij.openapi.fileEditor.FileEditorState)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 Disposable (com.intellij.openapi.Disposable)3 VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)3 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 WeighedFileEditorProvider (com.intellij.openapi.fileEditor.WeighedFileEditorProvider)2 TextEditorProvider (com.intellij.openapi.fileEditor.impl.text.TextEditorProvider)2 Project (com.intellij.openapi.project.Project)2 Element (org.jdom.Element)2 Nullable (org.jetbrains.annotations.Nullable)2 TabularLayout (com.android.tools.adtui.TabularLayout)1 Document (com.intellij.openapi.editor.Document)1 EditorFactory (com.intellij.openapi.editor.EditorFactory)1 DocumentImpl (com.intellij.openapi.editor.impl.DocumentImpl)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 TextEditor (com.intellij.openapi.fileEditor.TextEditor)1 FileEditorProviderManager (com.intellij.openapi.fileEditor.ex.FileEditorProviderManager)1 UIBasedFileType (com.intellij.openapi.fileTypes.UIBasedFileType)1