优化注释
This commit is contained in:
parent
f424584caa
commit
ac028ee3fb
@ -206,10 +206,10 @@ public class JNotepad extends Application {
|
|||||||
if (selectedTab != null) {
|
if (selectedTab != null) {
|
||||||
File file = (File) selectedTab.getUserData(); // 获取当前Tab页对应的文件对象
|
File file = (File) selectedTab.getUserData(); // 获取当前Tab页对应的文件对象
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
// If no file is associated (newly created tab), perform Save As logic
|
// 如果没有关联文件(新创建的选项卡),执行另存为逻辑
|
||||||
saveAsFile();
|
saveAsFile();
|
||||||
} else {
|
} else {
|
||||||
// File is associated, proceed with regular save logic
|
// 文件已关联,继续使用常规保存逻辑
|
||||||
try {
|
try {
|
||||||
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
|
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
|
||||||
TextArea textArea = (TextArea) selectedTab.getContent(); // 获取当前Tab页的文本编辑区
|
TextArea textArea = (TextArea) selectedTab.getContent(); // 获取当前Tab页的文本编辑区
|
||||||
@ -307,13 +307,12 @@ public class JNotepad extends Application {
|
|||||||
|
|
||||||
private void updateEncodingLabel(String text) {
|
private void updateEncodingLabel(String text) {
|
||||||
String encoding = detectEncoding(text);
|
String encoding = detectEncoding(text);
|
||||||
// 假设您有一个名为"encodingLabel"的标签控件来显示编码信息
|
|
||||||
encodingLabel.setText("\t编码: " + encoding);
|
encodingLabel.setText("\t编码: " + encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEncodingValid(String text, String encoding) {
|
private boolean isEncodingValid(String text, String encoding) {
|
||||||
// 在这里实现您的编码有效性检查逻辑
|
// 编码有效性检查
|
||||||
// 比如,您可以尝试使用指定的编码解码文本,并检查是否出现异常来判断编码是否有效
|
// 使用指定的编码解码文本,并检查是否出现异常来判断编码是否有效
|
||||||
try {
|
try {
|
||||||
byte[] bytes = text.getBytes(encoding);
|
byte[] bytes = text.getBytes(encoding);
|
||||||
String decodedText = new String(bytes, encoding);
|
String decodedText = new String(bytes, encoding);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user