2023年10月8日17:52:04
parent
7a6ab44ee3
commit
bc5629b251
|
|
@ -4,7 +4,13 @@ package com.zhangmeng.tools.editors.ace;
|
||||||
import com.zhangmeng.tools.utils.AlertUtils;
|
import com.zhangmeng.tools.utils.AlertUtils;
|
||||||
import com.zhangmeng.tools.utils.ClipboardUtils;
|
import com.zhangmeng.tools.utils.ClipboardUtils;
|
||||||
import javafx.beans.property.*;
|
import javafx.beans.property.*;
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
import javafx.concurrent.Worker;
|
import javafx.concurrent.Worker;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.ComboBox;
|
||||||
|
import javafx.scene.control.SingleSelectionModel;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
|
|
@ -22,6 +28,9 @@ import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zhangmeng
|
* @author zhangmeng
|
||||||
|
|
@ -219,6 +228,30 @@ public class AceEditor extends AnchorPane {
|
||||||
event.consume();
|
event.consume();
|
||||||
ClipboardUtils.setString(selectedText());
|
ClipboardUtils.setString(selectedText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.isControlDown() && event.getCode() == KeyCode.T) {
|
||||||
|
event.consume();
|
||||||
|
|
||||||
|
List<AceTheme> list = Arrays.stream(AceTheme.values()).collect(Collectors.toList());
|
||||||
|
|
||||||
|
ComboBox<AceTheme> comboBox = new ComboBox<>();
|
||||||
|
comboBox.setItems(FXCollections.observableArrayList(list));
|
||||||
|
|
||||||
|
AnchorPane anchorPane = new AnchorPane();
|
||||||
|
anchorPane.getChildren().add(comboBox);
|
||||||
|
anchorPane.setPrefWidth(200);
|
||||||
|
anchorPane.setPrefHeight(400);
|
||||||
|
Stage stage = new Stage();
|
||||||
|
stage.setScene(new Scene(anchorPane));
|
||||||
|
stage.show();
|
||||||
|
|
||||||
|
comboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
|
if (newValue != null){
|
||||||
|
setAceTheme(newValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (event.isControlDown() && event.getCode() == KeyCode.X) {
|
if (event.isControlDown() && event.getCode() == KeyCode.X) {
|
||||||
event.consume();
|
event.consume();
|
||||||
ClipboardUtils.setString(selectedText());
|
ClipboardUtils.setString(selectedText());
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ public class AceHelper {
|
||||||
InputStream aceJsStream = AceHelper.class.getResourceAsStream(ace_js);
|
InputStream aceJsStream = AceHelper.class.getResourceAsStream(ace_js);
|
||||||
InputStream ext_language_tools = AceHelper.class.getResourceAsStream(ext_language_tools_js);
|
InputStream ext_language_tools = AceHelper.class.getResourceAsStream(ext_language_tools_js);
|
||||||
InputStream modelJsStream = AceHelper.class.getResourceAsStream(model_js);
|
InputStream modelJsStream = AceHelper.class.getResourceAsStream(model_js);
|
||||||
InputStream themeJsStream = AceHelper.class.getResourceAsStream(theme_js);
|
// InputStream themeJsStream = AceHelper.class.getResourceAsStream(theme_js);
|
||||||
) {
|
) {
|
||||||
String html = """
|
String html = """
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
|
@ -40,7 +40,7 @@ public class AceHelper {
|
||||||
#editor-container{
|
#editor-container{
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background: white;
|
|
||||||
}
|
}
|
||||||
.ace_editor.ace_autocomplete {
|
.ace_editor.ace_autocomplete {
|
||||||
width: 415px;
|
width: 415px;
|
||||||
|
|
@ -61,8 +61,16 @@ public class AceHelper {
|
||||||
|
|
||||||
html += "<script>" + new String(Objects.requireNonNull(aceJsStream).readAllBytes(), StandardCharsets.UTF_8) + "</script>\n" +
|
html += "<script>" + new String(Objects.requireNonNull(aceJsStream).readAllBytes(), StandardCharsets.UTF_8) + "</script>\n" +
|
||||||
"<!--要更改主题,只需包含主题的JavaScript文件-->\n" +
|
"<!--要更改主题,只需包含主题的JavaScript文件-->\n" +
|
||||||
"\n" +
|
"\n" ;
|
||||||
"<script>" + new String(Objects.requireNonNull(themeJsStream).readAllBytes(), StandardCharsets.UTF_8) + "</script>\n" +
|
|
||||||
|
//加载所有主题
|
||||||
|
for (AceTheme value : AceTheme.values()) {
|
||||||
|
String theme_path = "/static/editors/ace-builds/src-min/" + value.getName();
|
||||||
|
InputStream themeStream = AceHelper.class.getResourceAsStream(theme_path);
|
||||||
|
html += "<script>" + new String(Objects.requireNonNull(themeStream).readAllBytes(), StandardCharsets.UTF_8) + "</script>\n" ;
|
||||||
|
}
|
||||||
|
|
||||||
|
html+=
|
||||||
"<!--默认情况下,编辑器只支持纯文本模式;许多其他语言作为单独的模块可用。在包含该模式的JavaScript文件后:-->\n" +
|
"<!--默认情况下,编辑器只支持纯文本模式;许多其他语言作为单独的模块可用。在包含该模式的JavaScript文件后:-->\n" +
|
||||||
"<script>" + new String(Objects.requireNonNull(modelJsStream).readAllBytes(), StandardCharsets.UTF_8) + "</script>\n" +
|
"<script>" + new String(Objects.requireNonNull(modelJsStream).readAllBytes(), StandardCharsets.UTF_8) + "</script>\n" +
|
||||||
"<script>" + new String(Objects.requireNonNull(ext_language_tools).readAllBytes(), StandardCharsets.UTF_8) +"</script>\n";
|
"<script>" + new String(Objects.requireNonNull(ext_language_tools).readAllBytes(), StandardCharsets.UTF_8) +"</script>\n";
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,35 @@ package com.zhangmeng.tools.editors.ace;
|
||||||
|
|
||||||
public enum AceTheme {
|
public enum AceTheme {
|
||||||
|
|
||||||
|
ambiance("theme-ambiance.js", "ace/theme/ambiance"),
|
||||||
|
chaos("theme-chaos.js", "ace/theme/chaos"),
|
||||||
CHROME("theme-chrome.js", "ace/theme/chrome"),
|
CHROME("theme-chrome.js", "ace/theme/chrome"),
|
||||||
|
cloud9_day("theme-cloud9_day.js", "ace/theme/cloud9_day"),
|
||||||
|
cloud9_night("theme-cloud9_night.js", "ace/theme/cloud9_night"),
|
||||||
|
cloud9_night_low_color("theme-cloud9_night_low_color.js", "ace/theme/cloud9_night_low_color"),
|
||||||
|
clouds("theme-clouds.js", "ace/theme/clouds"),
|
||||||
|
clouds_midnight("theme-clouds_midnight.js", "ace/theme/clouds_midnight"),
|
||||||
|
cobalt("theme-cobalt.js", "ace/theme/cobalt"),
|
||||||
|
crimson_editor("theme-crimson_editor.js", "ace/theme/crimson_editor"),
|
||||||
|
dawn("theme-dawn.js", "ace/theme/dawn"),
|
||||||
|
dracula("theme-dracula.js", "ace/theme/dracula"),
|
||||||
|
dreamweaver("theme-dreamweaver.js", "ace/theme/dreamweaver"),
|
||||||
|
eclipse("theme-eclipse.js", "ace/theme/eclipse"),
|
||||||
|
github("theme-github.js", "ace/theme/github"),
|
||||||
|
github_dark("theme-github_dark.js", "ace/theme/github_dark"),
|
||||||
|
gob("theme-gob.js", "ace/theme/gob"),
|
||||||
|
gruvbox("theme-gruvbox.js", "ace/theme/gruvbox"),
|
||||||
|
gruvbox_dark_hard("theme-gruvbox_dark_hard.js", "ace/theme/gruvbox_dark_hard"),
|
||||||
|
gruvbox_light_hard("theme-gruvbox_light_hard.js", "ace/theme/gruvbox_light_hard"),
|
||||||
|
idle_fingers("theme-idle_fingers.js", "ace/theme/idle_fingers"),
|
||||||
|
iplastic("theme-iplastic.js", "ace/theme/iplastic"),
|
||||||
|
katzenmilch("theme-katzenmilch.js", "ace/theme/katzenmilch"),
|
||||||
|
kr_theme("theme-kr_theme.js", "ace/theme/kr_theme"),
|
||||||
|
kuroir("theme-kuroir.js", "ace/theme/kuroir"),
|
||||||
|
merbivore("theme-merbivore.js", "ace/theme/merbivore"),
|
||||||
XCODE_JS("theme-xcode.js", "ace/theme/theme-xcode"),
|
XCODE_JS("theme-xcode.js", "ace/theme/theme-xcode"),
|
||||||
TOMORROW_NIGHT("theme-tomorrow_night.js", "ace/theme/tomorrow_night");
|
TOMORROW_NIGHT("theme-tomorrow_night.js", "ace/theme/tomorrow_night"),
|
||||||
|
;
|
||||||
|
|
||||||
AceTheme(String name, String value) {
|
AceTheme(String name, String value) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue