From 8f0616d8f3e284264d6ac737e3e4018573d195f0 Mon Sep 17 00:00:00 2001 From: zhangmeng <1334717033@qq.com> Date: Tue, 10 Oct 2023 17:06:40 +0800 Subject: [PATCH] =?UTF-8?q?2023=E5=B9=B410=E6=9C=8810=E6=97=A517:06:31?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/EditorListImplController.java | 63 +++++++++++++++++-- .../com/zhangmeng/tools/utils/AlertUtils.java | 1 + src/main/resources/fxml/editor-list-impl.fxml | 12 +++- src/main/resources/fxml/home.fxml | 6 +- src/main/resources/mystyle-java-fx-tools.ini | 2 +- 5 files changed, 71 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/zhangmeng/tools/controller/EditorListImplController.java b/src/main/java/com/zhangmeng/tools/controller/EditorListImplController.java index 6358781..06e1685 100644 --- a/src/main/java/com/zhangmeng/tools/controller/EditorListImplController.java +++ b/src/main/java/com/zhangmeng/tools/controller/EditorListImplController.java @@ -5,13 +5,11 @@ import com.zhangmeng.tools.components.RecursiveFileList; import com.zhangmeng.tools.dto.FileTreeView; import com.zhangmeng.tools.editors.ace.AceEditor; import com.zhangmeng.tools.editors.ace.AceMode; +import com.zhangmeng.tools.editors.ace.AceTheme; import com.zhangmeng.tools.editors.codemirr.CodeMirrWebView; import com.zhangmeng.tools.editors.monaco.*; import com.zhangmeng.tools.editors.timifx.TimiFxEditor; -import com.zhangmeng.tools.utils.AlertUtils; -import com.zhangmeng.tools.utils.ClipboardUtils; -import com.zhangmeng.tools.utils.ImagePath; -import com.zhangmeng.tools.utils.ResourcesUtils; +import com.zhangmeng.tools.utils.*; import eu.mihosoft.monacofx.Editor; import eu.mihosoft.monacofx.MonacoFX; import javafx.application.Platform; @@ -46,6 +44,8 @@ import javafx.stage.Stage; import javafx.util.Callback; import lombok.extern.slf4j.Slf4j; import net.imyeyu.timifx.service.RunAsync; +import net.imyeyu.timijava.config.Config; +import net.imyeyu.timijava.config.ConfigManager; import org.apache.commons.io.FilenameUtils; import org.fxmisc.flowless.VirtualizedScrollPane; import org.fxmisc.richtext.CodeArea; @@ -76,6 +76,9 @@ public class EditorListImplController { @FXML public MenuItem save; + @FXML + public Menu them_list; + public enum Type { JAVA, HTML, GO, JS, CSS, SQL, XML, YML, MARKDOWN @@ -92,6 +95,7 @@ public class EditorListImplController { private AnchorPane timiFx; private SimpleObjectProperty choose_file = new SimpleObjectProperty<>(null); + private SimpleObjectProperty choose_them = new SimpleObjectProperty<>(null); private final ObservableList filePaths_list = FXCollections.observableArrayList(); public static final String color_cell = "#f4f4f4"; @@ -270,6 +274,8 @@ public class EditorListImplController { @FXML public void initialize() { + String local = ConfigManager.getConfig(Resources.CONFIG_PATH).getString(Config.section("Main").key("AceJsThem")); + choose_them.setValue(AceTheme.valueOf(local)); init(); listView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { if (newValue != null) { @@ -369,10 +375,55 @@ public class EditorListImplController { tabPane = new TabPane(); //添加菜单 addMenu(); + + //加载菜单 +// for (AceTheme value : AceTheme.values()) { +// String them_string = value.toString(); +// MenuItem menuItem = new MenuItem(them_string); +// menuItem.setOnAction(event -> { +// AceEditor aceEditor = (AceEditor) tabPane.getSelectionModel().getSelectedItem().getContent(); +// MenuItem source = (MenuItem) event.getSource(); +// aceEditor.setAceTheme(AceTheme.valueOf(source.getText())); +// }); +// them_list.getItems().add(menuItem); +// } + ListView listView = new ListView<>(); + + ObservableList objects = FXCollections.observableArrayList(); + for (AceTheme value : AceTheme.values()) { + String them_string = value.toString(); + objects.add(them_string); + } + listView.setItems(objects); + + listView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, String oldValue, String newValue) { + if (newValue!= null){ + if (tabPane.getSelectionModel().getSelectedItem() == null){ + choose_them.setValue(AceTheme.valueOf(newValue)); + AlertUtils.alert_warning("主题选择成功!"); + return; + } + AceEditor aceEditor = (AceEditor) tabPane.getSelectionModel().getSelectedItem().getContent(); + aceEditor.setAceTheme(AceTheme.valueOf(newValue)); + } + } + }); + MenuItem menuItem = new MenuItem("设置主题"); + them_list.getItems().add(menuItem); + menuItem.setOnAction(event -> { + AnchorPane them_choose = new AnchorPane(); + them_choose.setPrefWidth(200); + them_choose.setPrefHeight(400); + them_choose.getChildren().add(listView); + Stage primaryStage = (Stage) EditorListImplController.this.splitPane.getScene().getWindow(); + AlertUtils.alert("设置", them_choose,200,400, primaryStage); + }); + File file = null; FileTreeView fileTreeView = new FileTreeView(file); fileTreeView.setBorder(BORDER_EXLEFT); - fileTreeView.setFixedCellSize(40); splitPane.getItems().clear(); splitPane.getItems().add(0, fileTreeView); splitPane.getItems().add(1, tabPane); @@ -651,7 +702,7 @@ public class EditorListImplController { case MARKDOWN -> mode = AceMode.MARKDOWN; } //新建编辑器 - AceEditor editor = new AceEditor(choose_file.getValue(),mode,null); + AceEditor editor = new AceEditor(choose_file.getValue(), mode, EditorListImplController.this.choose_them.get()); WebView view = editor.getWebView(); AnchorPane.setTopAnchor(view, 0.0); AnchorPane.setBottomAnchor(view, 0.0); diff --git a/src/main/java/com/zhangmeng/tools/utils/AlertUtils.java b/src/main/java/com/zhangmeng/tools/utils/AlertUtils.java index eba0e64..e77a93c 100644 --- a/src/main/java/com/zhangmeng/tools/utils/AlertUtils.java +++ b/src/main/java/com/zhangmeng/tools/utils/AlertUtils.java @@ -104,6 +104,7 @@ public class AlertUtils { stage.initStyle(StageStyle.UTILITY); stage.initOwner(primaryStage); stage.initModality(Modality.APPLICATION_MODAL); + stage.setResizable(false); stage.show(); } } diff --git a/src/main/resources/fxml/editor-list-impl.fxml b/src/main/resources/fxml/editor-list-impl.fxml index be1f21b..74aecf6 100644 --- a/src/main/resources/fxml/editor-list-impl.fxml +++ b/src/main/resources/fxml/editor-list-impl.fxml @@ -7,6 +7,9 @@ + + + @@ -112,9 +115,9 @@ - - - + + + @@ -138,6 +141,9 @@ + + + diff --git a/src/main/resources/fxml/home.fxml b/src/main/resources/fxml/home.fxml index b24e307..07078d1 100644 --- a/src/main/resources/fxml/home.fxml +++ b/src/main/resources/fxml/home.fxml @@ -115,9 +115,9 @@ - - - + + + diff --git a/src/main/resources/mystyle-java-fx-tools.ini b/src/main/resources/mystyle-java-fx-tools.ini index 40f1200..6ee7b02 100644 --- a/src/main/resources/mystyle-java-fx-tools.ini +++ b/src/main/resources/mystyle-java-fx-tools.ini @@ -14,7 +14,7 @@ Width=1300 Height=850 # 编辑器主题 -AceJsThem=kr_theme +AceJsThem=monokai [Interpolator]