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