Skip to content

Commit

Permalink
优化操作体验
Browse files Browse the repository at this point in the history
  • Loading branch information
GGXBoo committed Jun 23, 2018
1 parent 3bfa471 commit a6a1207
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ jfx {

// gradle jfxNative
identifier = null // String - setting this for windows-bundlers makes it possible to generate upgradeable installers (using same GUID)
vendor = "some serious business corp."
vendor = "ggx.org"
nativeOutputDir = "build/jfx/native"
bundler = "windows.app" // set this to some specific, if your don't want all bundlers running, examples "windows.app", "jnlp", ...
bundler = "all" // set this to some specific, if your don't want all bundlers running, examples "windows.app", "jnlp", ...
jvmProperties = null // Map<String, String>
jvmArgs = null // List<String>
userJvmArgs = null // Map<String, String>
Expand All @@ -85,8 +85,8 @@ jfx {
needMenu = false
bundleArguments = [
// dont bundle JRE (not recommended, but increases build-size/-speed)
runtime: "D:\\Program Files\\Java\\jre1.8.0_131"
// runtime: "/usr/lib/jvm/java-8-oracle/jre"
// runtime: "D:\\Program Files\\Java\\jre1.8.0_131"
runtime: "/usr/lib/jvm/java-8-oracle/jre"
]
appName = "GMarkdownEditor" // this is used for files below "src/main/deploy", e.g. "src/main/deploy/package/windows/project.ico"
additionalBundlerResources = null // path to some additional resources for the bundlers when creating application-bundle
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ggx/editor/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void start(Stage primaryStage) throws Exception {
main=primaryStage;
executor=Executors.newSingleThreadExecutor();
primaryStage.getIcons().add(new Image("icons/markdownwriterfx32.png"));
primaryStage.setTitle("Editor");
primaryStage.setTitle("MarkBook");
FXMLLoader loader=new FXMLLoader(ClassLoader.getSystemResource("fxml/main.fxml"));
Parent root=loader.load();
Scene scene=new Scene(root);
Expand Down
52 changes: 34 additions & 18 deletions src/main/java/com/ggx/editor/controller/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Rectangle2D;
import javafx.scene.Cursor;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
Expand All @@ -36,7 +37,9 @@
import java.text.DateFormat;
import java.util.Arrays;
import java.util.Locale;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;

public class MainController implements Initializable, TreeListAction,Runnable {
Expand Down Expand Up @@ -194,31 +197,44 @@ public void openFile(File file) {
if(!file.exists()){
return;
}
if(currentFile==file){
return;
}
currentFile = file;
initOpenFile();
changeTextType(file);
BufferedReader br = null;
try {
StringBuilder sb = new StringBuilder();
br = new BufferedReader(new FileReader(file));
br.lines().map(s -> s + "\n").forEach(sb::append);
markDownEditorPane.setNewFileContent(sb.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
rootPane.setCursor(Cursor.WAIT);
if (fileContainer.getChildren().size() == 2) {
fileContainer.getChildren().remove(1);
}
fileContainer.getChildren().add(markDownEditorPane.getScrollPane());
markDownEditorPane.getScrollPane().scrollYToPixel(0);
CompletableFuture.supplyAsync(()->{
BufferedReader br = null;
StringBuilder sb = new StringBuilder();
try {
br = new BufferedReader(new FileReader(file));
br.lines().map(s -> s + "\n").forEach(sb::append);
// markDownEditorPane.setNewFileContent(sb.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
return "";
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return sb.toString();
}).thenAccept(s -> Platform.runLater(()-> {
markDownEditorPane.setNewFileContent(s);
markDownEditorPane.getScrollPane().scrollYToPixel(0);
rootPane.setCursor(Cursor.DEFAULT);
}));




}
Expand Down

0 comments on commit a6a1207

Please sign in to comment.