diff --git a/src/main/java/org/jcnc/jnotepad/JNotepad.java b/src/main/java/org/jcnc/jnotepad/JNotepad.java index 5c1775e..5c702d4 100644 --- a/src/main/java/org/jcnc/jnotepad/JNotepad.java +++ b/src/main/java/org/jcnc/jnotepad/JNotepad.java @@ -124,7 +124,6 @@ public class JNotepad extends Application { } } } - // 保存文件事件处理器 private class SaveFileEventHandler implements EventHandler { @Override @@ -132,7 +131,11 @@ public class JNotepad extends Application { Tab selectedTab = tabPane.getSelectionModel().getSelectedItem(); if (selectedTab != null) { File file = (File) selectedTab.getUserData(); // 获取当前Tab页对应的文件对象 - if (file.exists()) { + if (file == null) { + // If no file is associated (newly created tab), perform Save As logic + saveAsFile(); + } else { + // File is associated, proceed with regular save logic try { BufferedWriter writer = new BufferedWriter(new FileWriter(file)); TextArea textArea = (TextArea) selectedTab.getContent(); // 获取当前Tab页的文本编辑区 @@ -143,14 +146,12 @@ public class JNotepad extends Application { } catch (IOException e) { e.printStackTrace(); } - - } else { - saveAsFile(); } } } } + // 另存为文件事件处理器 private class SaveAsFileEventHandler implements EventHandler { @Override diff --git a/打包.txt b/打包.txt index 845c158..227b190 100644 --- a/打包.txt +++ b/打包.txt @@ -4,5 +4,5 @@ jpackage ` -m org.jcnc.jnotepad/org.jcnc.jnotepad.JNotepad ` --runtime-image .\target\JNotepad\ ` --icon src/main/resources/img/icon.ico ` - --app-version 1.1.1 ` + --app-version 1.1.2 ` --vendor "JCNC" `