// 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>
<version>1.4.11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20230618</version>
</dependency>
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>

View File

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

View File

@ -2,7 +2,8 @@ package org.jcnc.jnotepad.constants;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
/**
* 文本常量
* <p>
@ -65,44 +66,57 @@ public class TextConstants {
/**
* 内置配置文件
*/
public static final String JNOTEPAD_CONFIG =
"""
{
"language":"chinese",
"shortcutKey":[
{
"buttonName": "newItem",
"shortcutKeyValue": "ctrl+n"
},
{
"buttonName": "openItem",
"shortcutKeyValue": "ctrl+o"
},
{
"buttonName": "saveItem",
"shortcutKeyValue": "ctrl+s"
},
{
"buttonName": "saveAsItem",
"shortcutKeyValue": "ctrl+alt+s"
},
{
"buttonName": "lineFeedItem",
"shortcutKeyValue": ""
},
{
"buttonName": "openConfigItem",
"shortcutKeyValue": "alt+s"
},
{
"buttonName": "addItem",
"shortcutKeyValue": ""
},
{
"buttonName": "countItem",
"shortcutKeyValue": ""
public static final String JNOTEPAD_CONFIG = createShortcutKeyJson().toString(4);
public static JSONObject createShortcutKeyJson() {
JSONObject json = new JSONObject();
json.put("language", "chinese");
JSONArray shortcutKeyArray = new JSONArray();
JSONObject newItem = new JSONObject();
newItem.put("buttonName", "newItem");
newItem.put("shortcutKeyValue", "ctrl+n");
shortcutKeyArray.put(newItem);
JSONObject openItem = new JSONObject();
openItem.put("buttonName", "openItem");
openItem.put("shortcutKeyValue", "ctrl+o");
shortcutKeyArray.put(openItem);
JSONObject saveItem = new JSONObject();
saveItem.put("buttonName", "saveItem");
saveItem.put("shortcutKeyValue", "ctrl+s");
shortcutKeyArray.put(saveItem);
JSONObject saveAsItem = new JSONObject();
saveAsItem.put("buttonName", "saveAsItem");
saveAsItem.put("shortcutKeyValue", "ctrl+alt+s");
shortcutKeyArray.put(saveAsItem);
JSONObject lineFeedItem = new JSONObject();
lineFeedItem.put("buttonName", "lineFeedItem");
lineFeedItem.put("shortcutKeyValue", "");
shortcutKeyArray.put(lineFeedItem);
JSONObject openConfigItem = new JSONObject();
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.tab.JNotepadTab;
import org.jcnc.jnotepad.ui.tab.JNotepadTabPane;
import org.json.JSONObject;
import org.slf4j.Logger;
import java.util.HashMap;
import java.util.Map;
import static org.jcnc.jnotepad.constants.TextConstants.CHINESE;
import static org.jcnc.jnotepad.constants.TextConstants.ENGLISH;
import static org.jcnc.jnotepad.constants.TextConstants.*;
/**
* 封装菜单栏组件
@ -246,11 +246,21 @@ public class JNotepadMenuBar extends MenuBar {
// 设置窗口为置顶
primaryStage.setAlwaysOnTop(after);
});
// todo 切换语言并将语言修改设置回本地
// todo 切换语言并将语言修改设置回本地,
// 1.只更新json的language为english,没有保存
englishItem.setOnAction(new OpenHandler() {
@Override
public void handle(ActionEvent actionEvent) {
// 获取当前的语言值
JSONObject json = createShortcutKeyJson();
// 更新语言值为 "english"
json.put("language", "english");
// 打印更新后的配置
System.out.println(json.toString(4)); // 使用四个空格缩进
}
});
chineseItem.setOnAction(new OpenHandler() {