Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit ad76c59

Browse files
committed
refactor: optimize hutool cmd
1 parent 91a6e41 commit ad76c59

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/main/java/org/code4everything/wetool/controller/MainController.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javafx.scene.layout.VBox;
2626
import lombok.extern.slf4j.Slf4j;
2727
import org.code4everything.boot.base.FileUtils;
28+
import org.code4everything.boot.base.constant.StringConsts;
2829
import org.code4everything.wetool.WeApplication;
2930
import org.code4everything.wetool.constant.FileConsts;
3031
import org.code4everything.wetool.constant.TipConsts;
@@ -119,7 +120,7 @@ public static void registerAction(String name, EventHandler<ActionEvent> eventHa
119120
name = StrUtil.trim(name);
120121
Preconditions.checkArgument(StrUtil.isNotBlank(name), "action name must not be blank");
121122
ACTION_MAP.put(name, eventHandler);
122-
if (name.endsWith("*")) {
123+
if (name.endsWith(StringConsts.Sign.STAR)) {
123124
return;
124125
}
125126
String pinyin = PinyinUtil.getPinyin(name);
@@ -185,7 +186,9 @@ public void handleEvent0(String s, Date date) {
185186
registerAction("插件仓库-pluginrepository", actionEvent -> FxUtils.openLink(TipConsts.REPO_LINK));
186187

187188
// 注册模式匹配动作
188-
registerAction("hutool*", this::runHutoolCmd);
189+
EventHandler<ActionEvent> runHutoolCmd = this::runHutoolCmd;
190+
registerAction("hutool*", runHutoolCmd);
191+
registerAction("*", runHutoolCmd);
189192
registerAction("file-browser*", HttpFileBrowserService.getInstance());
190193
registerAction("env*", a -> {
191194
String name = StrUtil.removePrefix(a.getSource().toString(), "env").trim();
@@ -579,7 +582,7 @@ public void toolBoxKeyReleased(KeyEvent keyEvent) {
579582
toolSearchBox.getItems().clear();
580583
String[] tokenizer = StrUtil.splitTrim(keyword, " ").toArray(new String[0]);
581584
ACTION_MAP.forEach((k, v) -> {
582-
if (k.endsWith("*")) {
585+
if (k.endsWith(StringConsts.Sign.STAR)) {
583586
// 模式匹配,不适用下拉框提示
584587
return;
585588
}
@@ -605,21 +608,24 @@ private EventHandler<ActionEvent> getActionEventEventHandler(String keyword, Str
605608

606609
// 模式匹配
607610
return actionCache.get(keyword, () -> {
611+
EventHandler<ActionEvent> handler = null;
608612
for (Map.Entry<String, EventHandler<ActionEvent>> entry : ACTION_MAP.entrySet()) {
609613
String key = entry.getKey();
610-
if (!key.endsWith("*")) {
614+
if (!key.endsWith(StringConsts.Sign.STAR)) {
615+
continue;
616+
}
617+
618+
if (key.equals(StringConsts.Sign.STAR)) {
619+
handler = entry.getValue();
611620
continue;
612621
}
613622

614623
key = key.substring(0, key.length() - 1);
615-
if (keyword.startsWith(key)) {
616-
EventHandler<ActionEvent> handler = entry.getValue();
617-
if (Objects.nonNull(handler)) {
618-
return handler;
619-
}
624+
if (keyword.startsWith(key) && Objects.nonNull(entry.getValue())) {
625+
return entry.getValue();
620626
}
621627
}
622-
return null;
628+
return handler;
623629
});
624630
}
625631

we-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
/*windows虚拟桌面触发角:LEFT_TOP, LEFT_BOTTOM, RIGHT_TOP, RIGHT_BOTTOM*/
7171
"winVirtualDesktopHotCorner": "RIGHT_TOP",
7272
/*是否关闭鼠标键盘监听器*/
73-
"disableKeyboardMouseListener": false,
73+
"disableKeyboardMouseListener": true,
7474
/*是否关闭暗黑模式*/
7575
"disableDarkMode": false,
7676
/*自动移除未加载的插件*/

0 commit comments

Comments
 (0)