Skip to content

Commit

Permalink
#1801 fix storing empty editor sate, fix javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgen Vidolob committed Oct 25, 2016
1 parent 8995de3 commit 9e13d77
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class EditorAgentImpl implements EditorAgent,
private final Map<EditorPartPresenter, String> openedEditorsToProviders;
private final Provider<EditorContentSynchronizer> editorContentSynchronizerProvider;
private final AppContext appContext;
private final PromiseProvider promiseProvider;
private final PromiseProvider promiseProvider;
private List<EditorPartPresenter> dirtyEditors;
private EditorPartPresenter activeEditor;

Expand Down Expand Up @@ -395,8 +395,11 @@ public EditorPartPresenter getPreviousFor(EditorPartPresenter editorPart) {
public JsonObject getState() {
JsonObject state = Json.createObject();


EditorMultiPartStackState stacks = editorMultiPartStack.getState();
EditorMultiPartStackState stacks = null;
try {
stacks = editorMultiPartStack.getState();
} catch (IllegalStateException ignore) {
}
if (stacks != null) {
state.put("FILES", storeEditors(stacks));
}
Expand Down Expand Up @@ -443,31 +446,34 @@ private JsonArray storeEditors(EditorPartStack partStack) {
@Override
@SuppressWarnings("unchecked")
public void loadState(@NotNull final JsonObject state) {
JsonObject files = state.getObject("FILES");
EditorPartStack partStack = editorMultiPartStack.createFirstPartStack();
final Map<EditorPartPresenter, EditorPartStack> activeEditors = new HashMap<>();
List<Promise<Void>> restore = restore(files, partStack, activeEditors);
Promise<ArrayOf<?>> promise = promiseProvider.all2(restore.toArray(new Promise[restore.size()]));
promise.then(new Operation() {
@Override
public void apply(Object arg) throws OperationException {
String activeFile = "";
if(state.hasKey("ACTIVE_EDITOR")){
activeFile = state.getString("ACTIVE_EDITOR");
}
EditorPartPresenter activeEditorPart = null;
for (Map.Entry<EditorPartPresenter, EditorPartStack> entry : activeEditors.entrySet()) {
entry.getValue().setActivePart(entry.getKey());
if (activeFile.equals(entry.getKey().getEditorInput().getFile().getLocation().toString())) {
activeEditorPart = entry.getKey();
if (state.hasKey("FILES")) {
JsonObject files = state.getObject("FILES");
EditorPartStack partStack = editorMultiPartStack.createFirstPartStack();
final Map<EditorPartPresenter, EditorPartStack> activeEditors = new HashMap<>();
List<Promise<Void>> restore = restore(files, partStack, activeEditors);
Promise<ArrayOf<?>> promise = promiseProvider.all2(restore.toArray(new Promise[restore.size()]));
promise.then(new Operation() {
@Override
public void apply(Object arg) throws OperationException {
String activeFile = "";
if (state.hasKey("ACTIVE_EDITOR")) {
activeFile = state.getString("ACTIVE_EDITOR");
}
EditorPartPresenter activeEditorPart = null;
for (Map.Entry<EditorPartPresenter, EditorPartStack> entry : activeEditors.entrySet()) {
entry.getValue().setActivePart(entry.getKey());
if (activeFile.equals(entry.getKey().getEditorInput().getFile().getLocation().toString())) {
activeEditorPart = entry.getKey();
}
}
workspaceAgent.setActivePart(activeEditorPart);
}
workspaceAgent.setActivePart(activeEditorPart);
}
});
});
}
}

private List<Promise<Void>> restore(JsonObject files, EditorPartStack editorPartStack, Map<EditorPartPresenter, EditorPartStack> activeEditors) {
private List<Promise<Void>> restore(JsonObject files, EditorPartStack editorPartStack,
Map<EditorPartPresenter, EditorPartStack> activeEditors) {

if (files.hasKey("FILES")) {
//plain
Expand All @@ -487,7 +493,8 @@ private List<Promise<Void>> restore(JsonObject files, EditorPartStack editorPart

}

private List<Promise<Void>> restoreSplit(JsonObject files, EditorPartStack editorPartStack, Map<EditorPartPresenter, EditorPartStack> activeEditors) {
private List<Promise<Void>> restoreSplit(JsonObject files, EditorPartStack editorPartStack,
Map<EditorPartPresenter, EditorPartStack> activeEditors) {
JsonObject splitFirst = files.getObject("SPLIT_FIRST");
List<Promise<Void>> restoreFirst = restore(splitFirst, editorPartStack, activeEditors);
String direction = files.getString("DIRECTION");
Expand All @@ -502,7 +509,7 @@ private List<Promise<Void>> restoreSplit(JsonObject files, EditorPartStack edito
}

private Promise<Void> openFile(final JsonObject file, final EditorPartStack editorPartStack,
final Map<EditorPartPresenter, EditorPartStack> activeEditors) {
final Map<EditorPartPresenter, EditorPartStack> activeEditors) {
return AsyncPromiseHelper.createFromAsyncRequest(new AsyncPromiseHelper.RequestCall<Void>() {
@Override
public void makeCall(final AsyncCallback<Void> callback) {
Expand All @@ -524,7 +531,8 @@ public void apply(final Optional<File> optionalFile) throws OperationException {
}

private void restoreCreateEditor(final File resourceFile, JsonObject file, final EditorPartStack editorPartStack,
final AsyncCallback<Void> openCallback, final Map<EditorPartPresenter, EditorPartStack> activeEditors) {
final AsyncCallback<Void> openCallback,
final Map<EditorPartPresenter, EditorPartStack> activeEditors) {
String providerId = file.getString("EDITOR_PROVIDER");
final OpenEditorCallback callback;
if (file.hasKey("CURSOR_OFFSET") && file.hasKey("TOP_VISIBLE_LINE")) {
Expand Down Expand Up @@ -560,7 +568,7 @@ public void apply(EditorPartPresenter arg) throws OperationException {
}

private void restoreInitEditor(final VirtualFile file, final OpenEditorCallback callback, FileType fileType,
final EditorPartPresenter editor, EditorProvider editorProvider, EditorPartStack editorPartStack) {
final EditorPartPresenter editor, EditorProvider editorProvider, EditorPartStack editorPartStack) {
editor.init(new EditorInputImpl(fileType, file), callback);
editor.addCloseHandler(this);

Expand All @@ -569,8 +577,7 @@ private void restoreInitEditor(final VirtualFile file, final OpenEditorCallback
}



private static class RestoreStateEditorCallBack extends OpenEditorCallbackImpl{
private static class RestoreStateEditorCallBack extends OpenEditorCallbackImpl {
private final int cursorOffset;
private final int topLine;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@ void addPartStack(@NotNull final EditorPartStack partStack, @Nullable final Edit
*/
void removePartStack(@NotNull final EditorPartStack partStack);

/**
* @return the editor multi part stack state
*/
EditorMultiPartStackState getState();
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,10 @@ public interface SplitEditorPartView extends IsWidget {
/** Removes this view from its parent widget */
void removeFromParent();

/**
* Get editor multi part stack state
* @param splitEditorParts split editor part view mapped to their part stack
* @return the editor multi part stack state
*/
EditorMultiPartStackState getState(BiMap<SplitEditorPartView, EditorPartStack> splitEditorParts);
}

0 comments on commit 9e13d77

Please sign in to comment.