From a6a120725bb99a32d78eb34580d148116a34b800 Mon Sep 17 00:00:00 2001 From: ggx Date: Sat, 23 Jun 2018 15:51:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=93=8D=E4=BD=9C=E4=BD=93?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 8 +-- src/main/java/com/ggx/editor/Main.java | 2 +- .../ggx/editor/controller/MainController.java | 52 ++++++++++++------- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/build.gradle b/build.gradle index 85047fd..17e02b3 100644 --- a/build.gradle +++ b/build.gradle @@ -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 jvmArgs = null // List userJvmArgs = null // Map @@ -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 diff --git a/src/main/java/com/ggx/editor/Main.java b/src/main/java/com/ggx/editor/Main.java index 699dadb..b1d2472 100644 --- a/src/main/java/com/ggx/editor/Main.java +++ b/src/main/java/com/ggx/editor/Main.java @@ -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); diff --git a/src/main/java/com/ggx/editor/controller/MainController.java b/src/main/java/com/ggx/editor/controller/MainController.java index 13bbfeb..517d5d6 100644 --- a/src/main/java/com/ggx/editor/controller/MainController.java +++ b/src/main/java/com/ggx/editor/controller/MainController.java @@ -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; @@ -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 { @@ -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); + })); + + }