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;
}
}
}
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();
}
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()]);
}
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);
}
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;
}
Aggregations