// todo 切换语言并将语言修改设置回本地,

//  1.只更新json的language为english,没有保存
This commit is contained in:
许轲 2023-08-26 15:18:01 +08:00
parent 0a4fb7150d
commit c7d36438e1
4 changed files with 75 additions and 45 deletions

View File

@ -56,7 +56,12 @@
<artifactId>logback-classic</artifactId> <artifactId>logback-classic</artifactId>
<version>1.4.11</version> <version>1.4.11</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20230618</version>
</dependency>
<dependency> <dependency>
<groupId>com.ibm.icu</groupId> <groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId> <artifactId>icu4j</artifactId>

View File

@ -12,6 +12,7 @@ module org.jcnc.jnotepad {
requires ch.qos.logback.core; requires ch.qos.logback.core;
requires ch.qos.logback.classic; requires ch.qos.logback.classic;
requires com.ibm.icu; requires com.ibm.icu;
requires org.json;
exports org.jcnc.jnotepad.app.config; exports org.jcnc.jnotepad.app.config;
exports org.jcnc.jnotepad; exports org.jcnc.jnotepad;
exports org.jcnc.jnotepad.tool; exports org.jcnc.jnotepad.tool;

View File

@ -2,7 +2,8 @@ package org.jcnc.jnotepad.constants;
import java.util.Map; import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
/** /**
* 文本常量 * 文本常量
* <p> * <p>
@ -65,44 +66,57 @@ public class TextConstants {
/** /**
* 内置配置文件 * 内置配置文件
*/ */
public static final String JNOTEPAD_CONFIG = public static final String JNOTEPAD_CONFIG = createShortcutKeyJson().toString(4);
"""
{ public static JSONObject createShortcutKeyJson() {
"language":"chinese", JSONObject json = new JSONObject();
"shortcutKey":[
{ json.put("language", "chinese");
"buttonName": "newItem",
"shortcutKeyValue": "ctrl+n" JSONArray shortcutKeyArray = new JSONArray();
},
{ JSONObject newItem = new JSONObject();
"buttonName": "openItem", newItem.put("buttonName", "newItem");
"shortcutKeyValue": "ctrl+o" newItem.put("shortcutKeyValue", "ctrl+n");
}, shortcutKeyArray.put(newItem);
{
"buttonName": "saveItem", JSONObject openItem = new JSONObject();
"shortcutKeyValue": "ctrl+s" openItem.put("buttonName", "openItem");
}, openItem.put("shortcutKeyValue", "ctrl+o");
{ shortcutKeyArray.put(openItem);
"buttonName": "saveAsItem",
"shortcutKeyValue": "ctrl+alt+s" JSONObject saveItem = new JSONObject();
}, saveItem.put("buttonName", "saveItem");
{ saveItem.put("shortcutKeyValue", "ctrl+s");
"buttonName": "lineFeedItem", shortcutKeyArray.put(saveItem);
"shortcutKeyValue": ""
}, JSONObject saveAsItem = new JSONObject();
{ saveAsItem.put("buttonName", "saveAsItem");
"buttonName": "openConfigItem", saveAsItem.put("shortcutKeyValue", "ctrl+alt+s");
"shortcutKeyValue": "alt+s" shortcutKeyArray.put(saveAsItem);
},
{ JSONObject lineFeedItem = new JSONObject();
"buttonName": "addItem", lineFeedItem.put("buttonName", "lineFeedItem");
"shortcutKeyValue": "" lineFeedItem.put("shortcutKeyValue", "");
}, shortcutKeyArray.put(lineFeedItem);
{
"buttonName": "countItem", JSONObject openConfigItem = new JSONObject();
"shortcutKeyValue": "" openConfigItem.put("buttonName", "openConfigItem");
openConfigItem.put("shortcutKeyValue", "alt+s");
shortcutKeyArray.put(openConfigItem);
JSONObject addItem = new JSONObject();
addItem.put("buttonName", "addItem");
addItem.put("shortcutKeyValue", "");
shortcutKeyArray.put(addItem);
JSONObject countItem = new JSONObject();
countItem.put("buttonName", "countItem");
countItem.put("shortcutKeyValue", "");
shortcutKeyArray.put(countItem);
json.put("shortcutKey", shortcutKeyArray);
return json;
} }
]
}
""";
} }

View File

@ -10,13 +10,13 @@ import org.jcnc.jnotepad.tool.LogUtil;
import org.jcnc.jnotepad.ui.status.JNotepadStatusBox; import org.jcnc.jnotepad.ui.status.JNotepadStatusBox;
import org.jcnc.jnotepad.ui.tab.JNotepadTab; import org.jcnc.jnotepad.ui.tab.JNotepadTab;
import org.jcnc.jnotepad.ui.tab.JNotepadTabPane; import org.jcnc.jnotepad.ui.tab.JNotepadTabPane;
import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.jcnc.jnotepad.constants.TextConstants.CHINESE; import static org.jcnc.jnotepad.constants.TextConstants.*;
import static org.jcnc.jnotepad.constants.TextConstants.ENGLISH;
/** /**
* 封装菜单栏组件 * 封装菜单栏组件
@ -246,11 +246,21 @@ public class JNotepadMenuBar extends MenuBar {
// 设置窗口为置顶 // 设置窗口为置顶
primaryStage.setAlwaysOnTop(after); primaryStage.setAlwaysOnTop(after);
}); });
// todo 切换语言并将语言修改设置回本地 // todo 切换语言并将语言修改设置回本地,
// 1.只更新json的language为english,没有保存
englishItem.setOnAction(new OpenHandler() { englishItem.setOnAction(new OpenHandler() {
@Override @Override
public void handle(ActionEvent actionEvent) { public void handle(ActionEvent actionEvent) {
// 获取当前的语言值
JSONObject json = createShortcutKeyJson();
// 更新语言值为 "english"
json.put("language", "english");
// 打印更新后的配置
System.out.println(json.toString(4)); // 使用四个空格缩进
} }
}); });
chineseItem.setOnAction(new OpenHandler() { chineseItem.setOnAction(new OpenHandler() {