Skip to content

Commit

Permalink
Fix issue in editorpane
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmanusta committed Dec 4, 2015
1 parent 612f279 commit f9786d8
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/main/java/com/kodcu/component/EditorPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.scene.Node;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.input.Dragboard;
Expand Down Expand Up @@ -88,26 +88,20 @@ public EditorPane(ApplicationController controller, ThreadService threadService,
this.handleReadyTasks = FXCollections.observableArrayList();
this.parserService = parserService;
this.webView = new WebView();
this.ready.addListener(this::afterEditorReady);
webEngine().setConfirmHandler(this::handleConfirm);
initializeMargins();
initializeEditorContextMenus();
}

private Boolean handleConfirm(String param) {
if ("command:ready".equals(param)) {
handleEditorReady();
ObservableList<Runnable> runnables = FXCollections.observableArrayList(handleReadyTasks);
handleReadyTasks.clear();
for (Runnable runnable : runnables) {
runnable.run();
}
ready.setValue(true);
updatePreviewUrl();
afterEditorLoaded();
}
return false;
}

private void handleEditorReady() {
private void afterEditorLoaded() {
getWindow().setMember("afx", controller);
updateOptions();

Expand All @@ -120,18 +114,34 @@ private void handleEditorReady() {
setInitialized();
setEditorValue(content);
resetUndoManager();
ready.setValue(true);
});
});
} else {
setInitialized();
setEditorValue(initialEditorValue);
resetUndoManager();
ready.setValue(true);
}

this.getChildren().add(webView);
webView.requestFocus();
}

private void afterEditorReady(ObservableValue observable, boolean oldValue, boolean newValue) {
if (newValue) {
ObservableList<Runnable> runnables = FXCollections.observableArrayList(handleReadyTasks);
handleReadyTasks.clear();
for (Runnable runnable : runnables) {
runnable.run();
}

updatePreviewUrl();
}
}

;

public void updatePreviewUrl() {
threadService.runActionLater(() -> {
if (is("asciidoc") || is("markdown")) {
Expand Down

0 comments on commit f9786d8

Please sign in to comment.