2023年10月10日17:53:23

master
zhangmeng 2023-10-10 17:53:35 +08:00
parent 11d451f229
commit 2135cf6d72
3 changed files with 34 additions and 67 deletions

View File

@ -58,9 +58,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import static net.imyeyu.timifx.TimiFX.BORDER_EXLEFT;
@ -99,6 +97,8 @@ public class EditorListImplController {
private final ObservableList<Path> filePaths_list = FXCollections.observableArrayList();
public static final String color_cell = "#f4f4f4";
public static final Set<Tab> remove_set = new HashSet<>();
@FXML
private ListView<ResourcesUtils.EditorList> listView;
@ -620,6 +620,21 @@ public class EditorListImplController {
}
}
public String read_content(File file){
String file_content = null;
try {
file_content = Files.readString(file.toPath(), StandardCharsets.UTF_8);
} catch (IOException e) {
try {
file_content = Files.readString(file.toPath(), Charset.forName("GBK"));
} catch (IOException ex) {
ex.printStackTrace();
}
}
return file_content;
}
public void open_file(File file, Type type, int open_type) {
//打开文件
@ -635,6 +650,13 @@ public class EditorListImplController {
//切换到一打开的tab
Tab tab = map.get(path);
if (!tabPane.getTabs().contains(tab)) {
if (remove_set.contains(tab)){
//重新加载内容
AceEditor aceEditor = (AceEditor) tab.getContent();
aceEditor.setAceText(read_content(file));
tab.setContent(aceEditor);
}
tabPane.getTabs().add(tab);
}
tabPane.getSelectionModel().select(tab);
@ -643,18 +665,7 @@ public class EditorListImplController {
//异步加载
RunAsync.runback(() -> {
String file_content = null;
try {
file_content = Files.readString(choose_file.get().toPath(), StandardCharsets.UTF_8);
} catch (IOException e) {
try {
file_content = Files.readString(choose_file.get().toPath(), Charset.forName("GBK"));
} catch (IOException ex) {
ex.printStackTrace();
}
}
return file_content;
return read_content(choose_file.getValue());
}, file_content -> {
Tab tab = new Tab(file.getName());
@ -663,7 +674,11 @@ public class EditorListImplController {
MenuItem close_other_tabs = new MenuItem("close other tabs");
MenuItem close_all = new MenuItem("close all");
close_all.setOnAction(event -> {
for (Tab tabPaneTab : tabPane.getTabs()) {
remove_set.add(tabPaneTab);
}
tabPane.getTabs().clear();
});
close_other_tabs.setOnAction(event -> {
ObservableList<Tab> tabs = tabPane.getTabs();
@ -672,6 +687,7 @@ public class EditorListImplController {
for (Tab tabPaneTab : list) {
if (tabPaneTab != tabPane.getSelectionModel().getSelectedItem()) {
tabs.remove(tabPaneTab);
remove_set.add(tabPaneTab);
}
}
});
@ -679,6 +695,7 @@ public class EditorListImplController {
//关闭当前窗口
Tab selectedItem = tabPane.getSelectionModel().getSelectedItem();
tabPane.getTabs().remove(selectedItem);
remove_set.add(selectedItem);
});
contextMenu.getItems().add(close);
contextMenu.getItems().add(close_other_tabs);
@ -691,6 +708,7 @@ public class EditorListImplController {
public void handle(Event event) {
// log.info("tabtab.setOnCloseRequest:--->" + tab.getText());
tabPane.getTabs().remove(tab);
remove_set.add(tab);
}
});
AceMode mode = null;

View File

@ -258,29 +258,6 @@ public class AceEditor extends AnchorPane {
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) {
event.consume();
ClipboardUtils.setString(selectedText());
@ -291,7 +268,6 @@ public class AceEditor extends AnchorPane {
if (event.isControlDown() && event.getCode() == KeyCode.S){//保存
event.consume();
if (file != null){
try {
FileWriter writer = new FileWriter(file);
@ -301,15 +277,11 @@ public class AceEditor extends AnchorPane {
} catch (IOException ex) {
ex.printStackTrace();
}
}else {
//
}
AlertUtils.alert_warning("保存成功!");
}
if (event.isControlDown() && event.getCode() == KeyCode.O){//保存
if (event.isControlDown() && event.getCode() == KeyCode.O){
event.consume();
//打开文件
Stage stage = new Stage();

View File

@ -1,23 +0,0 @@
#
# TimiFXExamples 配置文件,不建议手动修改,可能会导致程序异常或崩溃
#
[Main]
# 语言
Lang=zh_CN
# 窗体宽度,静默配置,双精度浮点型,取值范围 [1, 系统最大限制],默认 1300
Width=1300
# 窗体高度,静默配置,双精度浮点型,取值范围 [1, 系统最大限制],默认 850
Height=850
# 编辑器主题
AceJsThem=monokai
[Interpolator]
# 动画插值器持续时间
Duration=1000