CHE-5777. Fix editor initialization
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>6.19.x
parent
2d70311901
commit
ef9d42dfea
|
|
@ -137,6 +137,8 @@ public class CommandEditor extends AbstractEditorPresenter implements CommandEdi
|
|||
initializePages();
|
||||
|
||||
pages.forEach(page -> view.addPage(page.getView(), page.getTitle()));
|
||||
|
||||
callback.onEditorOpened(this);
|
||||
} else {
|
||||
callback.onInitializationFailed();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -280,41 +280,45 @@ public class EditorAgentImpl implements EditorAgent,
|
|||
initEditor(file, callback, fileType, editor, constraints, editorProvider);
|
||||
}
|
||||
|
||||
private void initEditor(final VirtualFile file, final OpenEditorCallback callback, FileType fileType,
|
||||
private void initEditor(final VirtualFile file, final OpenEditorCallback openEditorCallback, FileType fileType,
|
||||
final EditorPartPresenter editor, final Constraints constraints, EditorProvider editorProvider) {
|
||||
editor.init(new EditorInputImpl(fileType, file), callback);
|
||||
editor.addCloseHandler(this);
|
||||
OpenEditorCallback initializeCallback = new OpenEditorCallbackImpl() {
|
||||
@Override
|
||||
public void onEditorOpened(EditorPartPresenter editor) {
|
||||
workspaceAgent.openPart(editor, EDITING, constraints);
|
||||
workspaceAgent.setActivePart(editor);
|
||||
|
||||
workspaceAgent.openPart(editor, EDITING, constraints);
|
||||
finalizeInit(file, callback, editor, editorProvider).then(arg -> {
|
||||
workspaceAgent.setActivePart(editor);
|
||||
});
|
||||
openEditorCallback.onEditorOpened(editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitializationFailed() {
|
||||
openEditorCallback.onInitializationFailed();
|
||||
}
|
||||
};
|
||||
|
||||
editor.init(new EditorInputImpl(fileType, file), initializeCallback);
|
||||
finalizeInit(file, editor, editorProvider);
|
||||
}
|
||||
|
||||
private Promise<Void> finalizeInit(final VirtualFile file,
|
||||
final OpenEditorCallback openEditorCallback,
|
||||
final EditorPartPresenter editor,
|
||||
EditorProvider editorProvider) {
|
||||
return AsyncPromiseHelper.createFromAsyncRequest(promiseCallback -> {
|
||||
openedEditors.add(editor);
|
||||
openedEditorsToProviders.put(editor, editorProvider.getId());
|
||||
private void finalizeInit(VirtualFile file, EditorPartPresenter editor, EditorProvider editorProvider) {
|
||||
openedEditors.add(editor);
|
||||
openedEditorsToProviders.put(editor, editorProvider.getId());
|
||||
|
||||
editor.addPropertyListener((source, propId) -> {
|
||||
if (propId == EditorPartPresenter.PROP_INPUT) {
|
||||
promiseCallback.onSuccess(null);
|
||||
|
||||
if (editor instanceof HasReadOnlyProperty) {
|
||||
((HasReadOnlyProperty)editor).setReadOnly(file.isReadOnly());
|
||||
}
|
||||
|
||||
if (editor instanceof TextEditor) {
|
||||
editorContentSynchronizer.trackEditor(editor);
|
||||
}
|
||||
openEditorCallback.onEditorOpened(editor);
|
||||
eventBus.fireEvent(FileEvent.createFileOpenedEvent(file));
|
||||
eventBus.fireEvent(new EditorOpenedEvent(file, editor));
|
||||
editor.addCloseHandler(this);
|
||||
editor.addPropertyListener((source, propId) -> {
|
||||
if (propId == EditorPartPresenter.PROP_INPUT) {
|
||||
if (editor instanceof HasReadOnlyProperty) {
|
||||
((HasReadOnlyProperty)editor).setReadOnly(file.isReadOnly());
|
||||
}
|
||||
});
|
||||
|
||||
if (editor instanceof TextEditor) {
|
||||
editorContentSynchronizer.trackEditor(editor);
|
||||
}
|
||||
|
||||
eventBus.fireEvent(FileEvent.createFileOpenedEvent(file));
|
||||
eventBus.fireEvent(new EditorOpenedEvent(file, editor));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -580,14 +584,29 @@ public class EditorAgentImpl implements EditorAgent,
|
|||
}
|
||||
}
|
||||
|
||||
private Promise<Void> restoreInitEditor(final VirtualFile file, final OpenEditorCallback callback, FileType fileType,
|
||||
private Promise<Void> restoreInitEditor(final VirtualFile file, final OpenEditorCallback openEditorCallback, FileType fileType,
|
||||
final EditorPartPresenter editor, EditorProvider editorProvider,
|
||||
EditorPartStack editorPartStack) {
|
||||
editor.init(new EditorInputImpl(fileType, file), callback);
|
||||
editor.addCloseHandler(this);
|
||||
return AsyncPromiseHelper.createFromAsyncRequest((AsyncCallback<Void> promiseCallback) -> {
|
||||
OpenEditorCallback initializeCallback = new OpenEditorCallbackImpl() {
|
||||
@Override
|
||||
public void onEditorOpened(EditorPartPresenter editor) {
|
||||
editorPartStack.addPart(editor);
|
||||
|
||||
editorPartStack.addPart(editor);
|
||||
return finalizeInit(file, callback, editor, editorProvider);
|
||||
promiseCallback.onSuccess(null);
|
||||
openEditorCallback.onEditorOpened(editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitializationFailed() {
|
||||
promiseCallback.onFailure(new Exception("Can not initialize editor for " + file.getLocation()));
|
||||
openEditorCallback.onInitializationFailed();
|
||||
}
|
||||
};
|
||||
|
||||
editor.init(new EditorInputImpl(fileType, file), initializeCallback);
|
||||
finalizeInit(file, editor, editorProvider);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -164,6 +164,7 @@ public class ImageViewer extends AbstractEditorPresenter implements FileEventHan
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected void initializeEditor(OpenEditorCallback callback) {
|
||||
callback.onEditorOpened(this);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import org.eclipse.che.ide.api.dialogs.ConfirmCallback;
|
|||
import org.eclipse.che.ide.api.dialogs.DialogFactory;
|
||||
import org.eclipse.che.ide.api.editor.AbstractEditorPresenter;
|
||||
import org.eclipse.che.ide.api.editor.EditorAgent;
|
||||
import org.eclipse.che.ide.api.editor.EditorAgent.OpenEditorCallback;
|
||||
import org.eclipse.che.ide.api.editor.EditorInput;
|
||||
import org.eclipse.che.ide.api.editor.EditorLocalizationConstants;
|
||||
import org.eclipse.che.ide.api.editor.EditorWithAutoSave;
|
||||
|
|
@ -257,7 +258,7 @@ public class OrionEditorPresenter extends AbstractEditorPresenter implements Tex
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void initializeEditor(final EditorAgent.OpenEditorCallback callback) {
|
||||
protected void initializeEditor(final OpenEditorCallback callback) {
|
||||
QuickAssistProcessor processor = configuration.getQuickAssistProcessor();
|
||||
if (quickAssistantFactory != null && processor != null) {
|
||||
quickAssistant = quickAssistantFactory.createQuickAssistant(this);
|
||||
|
|
@ -285,7 +286,7 @@ public class OrionEditorPresenter extends AbstractEditorPresenter implements Tex
|
|||
}).then(new Operation<String>() {
|
||||
@Override
|
||||
public void apply(String content) throws OperationException {
|
||||
createEditor(content);
|
||||
createEditor(content, callback);
|
||||
}
|
||||
}).catchError(new Operation<PromiseError>() {
|
||||
@Override
|
||||
|
|
@ -297,9 +298,9 @@ public class OrionEditorPresenter extends AbstractEditorPresenter implements Tex
|
|||
|
||||
}
|
||||
|
||||
private void createEditor(final String content) {
|
||||
private void createEditor(final String content, OpenEditorCallback openEditorCallback) {
|
||||
this.fileTypes = detectFileType(getEditorInput().getFile());
|
||||
editorWidgetFactory.createEditorWidget(fileTypes, new EditorWidgetInitializedCallback(content));
|
||||
editorWidgetFactory.createEditorWidget(fileTypes, new EditorWidgetInitializedCallback(content, openEditorCallback));
|
||||
}
|
||||
|
||||
private void setupEventHandlers() {
|
||||
|
|
@ -999,12 +1000,13 @@ public class OrionEditorPresenter extends AbstractEditorPresenter implements Tex
|
|||
}
|
||||
|
||||
private class EditorWidgetInitializedCallback implements EditorWidget.WidgetInitializedCallback {
|
||||
private final String content;
|
||||
private final String content;
|
||||
private boolean isInitialized;
|
||||
private OpenEditorCallback openEditorCallback;
|
||||
|
||||
private boolean isInitialized;
|
||||
|
||||
private EditorWidgetInitializedCallback(String content) {
|
||||
private EditorWidgetInitializedCallback(String content, OpenEditorCallback openEditorCallback) {
|
||||
this.content = content;
|
||||
this.openEditorCallback = openEditorCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -1057,6 +1059,7 @@ public class OrionEditorPresenter extends AbstractEditorPresenter implements Tex
|
|||
setupFileContentUpdateHandler();
|
||||
|
||||
isInitialized = true;
|
||||
openEditorCallback.onEditorOpened(OrionEditorPresenter.this);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue