Search in sources :

Example 11 with FileEditorProvider

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

the class StructureViewWrapperImpl method createTempFileEditor.

@Nullable
private FileEditor createTempFileEditor(@NotNull VirtualFile file) {
    if (file.getLength() > PersistentFSConstants.getMaxIntellisenseFileSize())
        return null;
    FileEditorProviderManager editorProviderManager = FileEditorProviderManager.getInstance();
    final FileEditorProvider[] providers = editorProviderManager.getProviders(myProject, file);
    return providers.length == 0 ? null : providers[0].createEditor(myProject, file);
}
Also used : FileEditorProvider(com.intellij.openapi.fileEditor.FileEditorProvider) FileEditorProviderManager(com.intellij.openapi.fileEditor.ex.FileEditorProviderManager) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with FileEditorProvider

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

the class HistoryEntry method createLight.

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

Example 13 with FileEditorProvider

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

the class HistoryEntry method parseEntry.

@NotNull
private static EntryData parseEntry(@NotNull Project project, @NotNull Element e) throws InvalidDataException {
    if (!e.getName().equals(TAG)) {
        throw new IllegalArgumentException("unexpected tag: " + e);
    }
    String url = e.getAttributeValue(FILE_ATTR);
    List<Pair<FileEditorProvider, FileEditorState>> providerStates = new ArrayList<>();
    FileEditorProvider selectedProvider = null;
    VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url);
    for (Element _e : e.getChildren(PROVIDER_ELEMENT)) {
        String typeId = _e.getAttributeValue(EDITOR_TYPE_ID_ATTR);
        FileEditorProvider provider = FileEditorProviderManager.getInstance().getProvider(typeId);
        if (provider == null) {
            continue;
        }
        if (Boolean.valueOf(_e.getAttributeValue(SELECTED_ATTR_VALUE))) {
            selectedProvider = provider;
        }
        Element stateElement = _e.getChild(STATE_ELEMENT);
        if (stateElement == null) {
            throw new InvalidDataException();
        }
        if (file != null) {
            FileEditorState state = provider.readState(stateElement, project, file);
            providerStates.add(Pair.create(provider, state));
        }
    }
    return new EntryData(url, providerStates, selectedProvider);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorProvider(com.intellij.openapi.fileEditor.FileEditorProvider) Element(org.jdom.Element) ArrayList(java.util.ArrayList) InvalidDataException(com.intellij.openapi.util.InvalidDataException) FileEditorState(com.intellij.openapi.fileEditor.FileEditorState) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with FileEditorProvider

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

the class HistoryEntry method writeExternal.

/**
   * @return element that was added to the {@code element}.
   * Returned element has tag {@link #TAG}. Never null.
   */
public Element writeExternal(Element element, Project project) {
    Element e = new Element(TAG);
    element.addContent(e);
    e.setAttribute(FILE_ATTR, myFilePointer.getUrl());
    for (final Map.Entry<FileEditorProvider, FileEditorState> entry : myProvider2State.entrySet()) {
        FileEditorProvider provider = entry.getKey();
        Element providerElement = new Element(PROVIDER_ELEMENT);
        if (provider.equals(mySelectedProvider)) {
            providerElement.setAttribute(SELECTED_ATTR_VALUE, Boolean.TRUE.toString());
        }
        providerElement.setAttribute(EDITOR_TYPE_ID_ATTR, provider.getEditorTypeId());
        Element stateElement = new Element(STATE_ELEMENT);
        providerElement.addContent(stateElement);
        provider.writeState(entry.getValue(), project, stateElement);
        e.addContent(providerElement);
    }
    return e;
}
Also used : FileEditorProvider(com.intellij.openapi.fileEditor.FileEditorProvider) Element(org.jdom.Element) HashMap(com.intellij.util.containers.HashMap) Map(java.util.Map) FileEditorState(com.intellij.openapi.fileEditor.FileEditorState)

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