Search in sources :

Example 1 with FileEditorState

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

the class UndoRedo method restore.

private boolean restore(EditorAndState pair, boolean onlyIfDiffers) {
    if (myEditor == null || // editor can be invalid if underlying file is deleted during undo (e.g. after undoing scratch file creation)
    !myEditor.isValid() || pair == null || pair.getEditor() == null) {
        return false;
    }
    // 5. undo -> position is not affected, because instance created in step 4 is not the same!!!
    if (!myEditor.getClass().equals(pair.getEditor().getClass())) {
        return false;
    }
    // If current editor state isn't equals to remembered state then
    // we have to try to restore previous state. But sometime it's
    // not possible to restore it. For example, it's not possible to
    // restore scroll proportion if editor doesn not have scrolling any more.
    FileEditorState currentState = myEditor.getState(FileEditorStateLevel.UNDO);
    if (onlyIfDiffers && currentState.equals(pair.getState())) {
        return false;
    }
    myEditor.setState(pair.getState());
    return true;
}
Also used : FileEditorState(com.intellij.openapi.fileEditor.FileEditorState)

Example 2 with FileEditorState

use of com.intellij.openapi.fileEditor.FileEditorState 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)

Example 3 with FileEditorState

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

the class HistoryEntry method createHeavy.

@NotNull
static HistoryEntry createHeavy(@NotNull Project project, @NotNull VirtualFile file, @NotNull FileEditorProvider[] providers, @NotNull FileEditorState[] states, @NotNull FileEditorProvider selectedProvider) {
    if (project.isDisposed())
        return createLight(file, providers, states, selectedProvider);
    Disposable disposable = Disposer.newDisposable();
    VirtualFilePointer pointer = VirtualFilePointerManager.getInstance().create(file, disposable, null);
    HistoryEntry entry = new HistoryEntry(pointer, selectedProvider, disposable);
    for (int i = 0; i < providers.length; i++) {
        FileEditorProvider provider = providers[i];
        FileEditorState state = states[i];
        if (provider != null && state != null) {
            entry.putState(provider, state);
        }
    }
    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)

Example 4 with FileEditorState

use of com.intellij.openapi.fileEditor.FileEditorState 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 5 with FileEditorState

use of com.intellij.openapi.fileEditor.FileEditorState 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)

Aggregations

FileEditorState (com.intellij.openapi.fileEditor.FileEditorState)6 FileEditorProvider (com.intellij.openapi.fileEditor.FileEditorProvider)5 NotNull (org.jetbrains.annotations.NotNull)4 VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)3 Disposable (com.intellij.openapi.Disposable)2 Element (org.jdom.Element)2 InvalidDataException (com.intellij.openapi.util.InvalidDataException)1 Pair (com.intellij.openapi.util.Pair)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 LightFilePointer (com.intellij.openapi.vfs.impl.LightFilePointer)1 HashMap (com.intellij.util.containers.HashMap)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1