♻️ 重构代码
This commit is contained in:
parent
4f59dda32e
commit
f04e1a4899
@ -4,9 +4,9 @@ import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import org.jcnc.jnotepad.app.i18n.UiResourceBundle;
|
||||
import org.jcnc.jnotepad.constants.TextConstants;
|
||||
import org.jcnc.jnotepad.root.center.main.bottom.status.JNotepadStatusBox;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane;
|
||||
import org.jcnc.jnotepad.root.center.main.bottom.status.BottomStatusBox;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.CenterTab;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.CenterTabPane;
|
||||
import org.jcnc.jnotepad.ui.module.LineNumberTextArea;
|
||||
import org.jcnc.jnotepad.view.manager.ViewManager;
|
||||
|
||||
@ -38,15 +38,15 @@ public class NewFile implements EventHandler<ActionEvent> {
|
||||
// TODO: refactor:统一TextArea新建、绑定监听器入口
|
||||
ViewManager viewManager = ViewManager.getInstance();
|
||||
// 创建标签页
|
||||
JNotepadTab JNotepadTab = new JNotepadTab(
|
||||
CenterTab centerTab = new CenterTab(
|
||||
UiResourceBundle.getContent(TextConstants.NEW_FILE)
|
||||
+ viewManager.selfIncreaseAndGetTabIndex(),
|
||||
textArea);
|
||||
// 设置当前标签页与本地文件无关联
|
||||
JNotepadTab.setRelevance(false);
|
||||
centerTab.setRelevance(false);
|
||||
// 将Tab页添加到TabPane中
|
||||
JNotepadTabPane.getInstance().addNewTab(JNotepadTab);
|
||||
CenterTabPane.getInstance().addNewTab(centerTab);
|
||||
// 更新编码信息
|
||||
JNotepadStatusBox.getInstance().updateEncodingLabel();
|
||||
BottomStatusBox.getInstance().updateEncodingLabel();
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,8 +9,8 @@ import javafx.stage.FileChooser;
|
||||
import org.jcnc.jnotepad.app.i18n.UiResourceBundle;
|
||||
import org.jcnc.jnotepad.constants.TextConstants;
|
||||
import org.jcnc.jnotepad.manager.ThreadPoolManager;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.CenterTab;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.CenterTabPane;
|
||||
import org.jcnc.jnotepad.tool.EncodingDetector;
|
||||
import org.jcnc.jnotepad.tool.LogUtil;
|
||||
import org.jcnc.jnotepad.tool.UiUtil;
|
||||
@ -83,7 +83,7 @@ public class OpenFile implements EventHandler<ActionEvent> {
|
||||
*/
|
||||
public void openFile(File file) {
|
||||
// 获取标签页集合
|
||||
JNotepadTabPane jnotepadTabPane = JNotepadTabPane.getInstance();
|
||||
CenterTabPane jnotepadTabPane = CenterTabPane.getInstance();
|
||||
// 遍历标签页,查找匹配的标签页
|
||||
for (Tab tab : jnotepadTabPane.getTabs()) {
|
||||
// 获取绑定的文件
|
||||
@ -119,11 +119,11 @@ public class OpenFile implements EventHandler<ActionEvent> {
|
||||
LogUtil.getLogger(this.getClass()).info("已调用读取文件功能");
|
||||
Platform.runLater(() -> {
|
||||
textArea.getMainTextArea().setText(text);
|
||||
JNotepadTab tab = createNewTab(file.getName(), textArea, encoding);
|
||||
CenterTab tab = createNewTab(file.getName(), textArea, encoding);
|
||||
// 设置当前标签页关联本地文件
|
||||
tab.setRelevance(true);
|
||||
tab.setUserData(file);
|
||||
JNotepadTabPane.getInstance().addNewTab(tab);
|
||||
CenterTabPane.getInstance().addNewTab(tab);
|
||||
});
|
||||
} catch (IOException ignored) {
|
||||
LogUtil.getLogger(this.getClass()).info("已忽视IO异常!");
|
||||
@ -146,7 +146,7 @@ public class OpenFile implements EventHandler<ActionEvent> {
|
||||
* @param textArea 文本区域
|
||||
* @return 新的标签页
|
||||
*/
|
||||
private JNotepadTab createNewTab(String tabName, LineNumberTextArea textArea, Charset charset) {
|
||||
return new JNotepadTab(tabName, textArea, charset);
|
||||
private CenterTab createNewTab(String tabName, LineNumberTextArea textArea, Charset charset) {
|
||||
return new CenterTab(tabName, textArea, charset);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,8 +7,8 @@ import javafx.scene.input.KeyCode;
|
||||
import javafx.stage.FileChooser;
|
||||
import org.jcnc.jnotepad.app.i18n.UiResourceBundle;
|
||||
import org.jcnc.jnotepad.constants.TextConstants;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.CenterTab;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.CenterTabPane;
|
||||
import org.jcnc.jnotepad.tool.LogUtil;
|
||||
import org.jcnc.jnotepad.tool.UiUtil;
|
||||
import org.jcnc.jnotepad.ui.dialog.factory.impl.TextFileChooserFactory;
|
||||
@ -30,54 +30,54 @@ public class RenameFile implements EventHandler<ActionEvent> {
|
||||
@Override
|
||||
public void handle(ActionEvent actionEvent) {
|
||||
// 获取当前标签页
|
||||
JNotepadTab jnotepadtab = JNotepadTabPane.getInstance().getSelected();
|
||||
if (jnotepadtab == null || jnotepadtab.getText().isEmpty()) {
|
||||
CenterTab centerTab = CenterTabPane.getInstance().getSelected();
|
||||
if (centerTab == null || centerTab.getText().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// 判断当前是否为关联文件
|
||||
if (jnotepadtab.isRelevance()) {
|
||||
if (centerTab.isRelevance()) {
|
||||
// 重命名关联文件
|
||||
handleRenameRelevanceFile(jnotepadtab);
|
||||
handleRenameRelevanceFile(centerTab);
|
||||
}
|
||||
// 如果当前不是关联文件则重命名标签页
|
||||
else {
|
||||
handleRenameTab(jnotepadtab);
|
||||
handleRenameTab(centerTab);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重命名标签页。
|
||||
*
|
||||
* @param jnotepadtab 标签页组件
|
||||
* @param centerTab 标签页组件
|
||||
*/
|
||||
private void handleRenameTab(JNotepadTab jnotepadtab) {
|
||||
TextField textField = new TextField(jnotepadtab.getText());
|
||||
private void handleRenameTab(CenterTab centerTab) {
|
||||
TextField textField = new TextField(centerTab.getText());
|
||||
textField.getStyleClass().add("tab-title-editable");
|
||||
// 清空标签页名称
|
||||
jnotepadtab.setText("");
|
||||
centerTab.setText("");
|
||||
// 监听 Enter 键,完成编辑
|
||||
textField.setOnKeyPressed(event -> {
|
||||
if (event.getCode() == KeyCode.ENTER) {
|
||||
jnotepadtab.setText(textField.getText());
|
||||
centerTab.setText(textField.getText());
|
||||
// 可选:移除 TextField 的图形
|
||||
jnotepadtab.setGraphic(null);
|
||||
centerTab.setGraphic(null);
|
||||
// 可选:恢复标签页的关闭按钮
|
||||
jnotepadtab.setClosable(true);
|
||||
centerTab.setClosable(true);
|
||||
}
|
||||
});
|
||||
// 监听失去焦点事件,完成编辑
|
||||
textField.focusedProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (Boolean.FALSE.equals(newValue)) {
|
||||
jnotepadtab.setText(textField.getText());
|
||||
centerTab.setText(textField.getText());
|
||||
// 可选:移除 TextField 的图形
|
||||
jnotepadtab.setGraphic(null);
|
||||
centerTab.setGraphic(null);
|
||||
// 可选:恢复标签页的关闭按钮
|
||||
jnotepadtab.setClosable(true);
|
||||
centerTab.setClosable(true);
|
||||
}
|
||||
});
|
||||
jnotepadtab.setClosable(false);
|
||||
centerTab.setClosable(false);
|
||||
// 设置 TextField 作为标签页的图形
|
||||
jnotepadtab.setGraphic(textField);
|
||||
centerTab.setGraphic(textField);
|
||||
// 默认获取焦点并选中所有文字
|
||||
textField.requestFocus();
|
||||
textField.selectAll();
|
||||
@ -86,25 +86,25 @@ public class RenameFile implements EventHandler<ActionEvent> {
|
||||
/**
|
||||
* 重命名关联文件。
|
||||
*
|
||||
* @param jnotepadtab 标签页组件
|
||||
* @param centerTab 标签页组件
|
||||
*/
|
||||
private void handleRenameRelevanceFile(JNotepadTab jnotepadtab) {
|
||||
private void handleRenameRelevanceFile(CenterTab centerTab) {
|
||||
// 获取原始文件对象
|
||||
File file = (File) jnotepadtab.getUserData();
|
||||
File file = (File) centerTab.getUserData();
|
||||
// 获取应用窗口并绑定
|
||||
File newFile = TextFileChooserFactory.getInstance()
|
||||
.createFileChooser(
|
||||
UiResourceBundle.getContent(TextConstants.RENAME),
|
||||
jnotepadtab.getText(),
|
||||
centerTab.getText(),
|
||||
new File(file.getParent()),
|
||||
new FileChooser.ExtensionFilter("All types", "*.*"))
|
||||
.showSaveDialog(UiUtil.getAppWindow());
|
||||
if (newFile != null) {
|
||||
boolean rename = file.renameTo(newFile);
|
||||
// 设置文件数据
|
||||
jnotepadtab.setUserData(newFile);
|
||||
centerTab.setUserData(newFile);
|
||||
if (rename) {
|
||||
jnotepadtab.setText(newFile.getName());
|
||||
centerTab.setText(newFile.getName());
|
||||
logger.info("文件重命名成功");
|
||||
} else {
|
||||
logger.debug("文件重命名失败");
|
||||
|
||||
@ -6,8 +6,8 @@ import javafx.stage.FileChooser;
|
||||
import org.jcnc.jnotepad.app.i18n.UiResourceBundle;
|
||||
import org.jcnc.jnotepad.constants.TextConstants;
|
||||
import org.jcnc.jnotepad.controller.i18n.LocalizationController;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.CenterTab;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.CenterTabPane;
|
||||
import org.jcnc.jnotepad.root.top.menu.TopMenuBar;
|
||||
import org.jcnc.jnotepad.tool.LogUtil;
|
||||
import org.jcnc.jnotepad.tool.SingletonUtil;
|
||||
@ -40,7 +40,7 @@ public class SaveFile implements EventHandler<ActionEvent> {
|
||||
@Override
|
||||
public void handle(ActionEvent actionEvent) {
|
||||
// 获取当前tab页
|
||||
JNotepadTab selectedTab = JNotepadTabPane.getInstance().getSelected();
|
||||
CenterTab selectedTab = CenterTabPane.getInstance().getSelected();
|
||||
if (selectedTab == null) {
|
||||
return;
|
||||
}
|
||||
@ -72,7 +72,7 @@ public class SaveFile implements EventHandler<ActionEvent> {
|
||||
* @see LogUtil
|
||||
*/
|
||||
protected void saveTab(Class<?> currentClass) {
|
||||
JNotepadTab selectedTab = JNotepadTabPane.getInstance().getSelected();
|
||||
CenterTab selectedTab = CenterTabPane.getInstance().getSelected();
|
||||
if (selectedTab == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package org.jcnc.jnotepad.root.bottom;
|
||||
|
||||
import org.jcnc.jnotepad.root.center.main.bottom.status.JNotepadStatusBox;
|
||||
import org.jcnc.jnotepad.root.center.main.bottom.status.BottomStatusBox;
|
||||
import org.jcnc.jnotepad.ui.module.AbstractVerticalBox;
|
||||
|
||||
/**
|
||||
@ -28,6 +28,6 @@ public class RootBottomSideBarVerticalBox extends AbstractVerticalBox {
|
||||
}
|
||||
|
||||
private void initSidebarVerticalBox() {
|
||||
getChildren().addAll(JNotepadStatusBox.getInstance());
|
||||
getChildren().addAll(BottomStatusBox.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package org.jcnc.jnotepad.root.center.main;
|
||||
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.CenterTabPane;
|
||||
import org.jcnc.jnotepad.ui.module.AbstractBorderPane;
|
||||
|
||||
/**
|
||||
@ -29,7 +29,7 @@ public class MainBorderPane extends AbstractBorderPane {
|
||||
|
||||
private void initRootBorderPane() {
|
||||
// 文本框
|
||||
setCenterComponent(JNotepadTabPane.getInstance());
|
||||
setCenterComponent(CenterTabPane.getInstance());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,8 +6,8 @@ import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextArea;
|
||||
import org.jcnc.jnotepad.app.i18n.UiResourceBundle;
|
||||
import org.jcnc.jnotepad.constants.TextConstants;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.CenterTab;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.CenterTabPane;
|
||||
import org.jcnc.jnotepad.ui.module.AbstractHorizontalBox;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
@ -19,9 +19,9 @@ import java.nio.charset.Charset;
|
||||
*
|
||||
* @author songdragon
|
||||
*/
|
||||
public class JNotepadStatusBox extends AbstractHorizontalBox {
|
||||
public class BottomStatusBox extends AbstractHorizontalBox {
|
||||
|
||||
private static final JNotepadStatusBox STATUS_BOX = new JNotepadStatusBox();
|
||||
private static final BottomStatusBox STATUS_BOX = new BottomStatusBox();
|
||||
private static final String STATUS_LABEL_FORMAT = "%s : %d \t%s: %d \t%s: %d \t";
|
||||
/**
|
||||
* 字数统计及光标
|
||||
@ -33,11 +33,11 @@ public class JNotepadStatusBox extends AbstractHorizontalBox {
|
||||
private Label encodingLabel;
|
||||
|
||||
|
||||
private JNotepadStatusBox() {
|
||||
private BottomStatusBox() {
|
||||
initStatusBox();
|
||||
}
|
||||
|
||||
public static JNotepadStatusBox getInstance() {
|
||||
public static BottomStatusBox getInstance() {
|
||||
return STATUS_BOX;
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ public class JNotepadStatusBox extends AbstractHorizontalBox {
|
||||
* 更新字数统计
|
||||
*/
|
||||
public void updateWordCountStatusLabel() {
|
||||
JNotepadTabPane instance = JNotepadTabPane.getInstance();
|
||||
CenterTabPane instance = CenterTabPane.getInstance();
|
||||
if (instance.getSelected() == null) {
|
||||
return;
|
||||
}
|
||||
@ -107,12 +107,12 @@ public class JNotepadStatusBox extends AbstractHorizontalBox {
|
||||
* <br>2. 状态栏更新当前选中tab的字符编码
|
||||
*/
|
||||
public void updateWhenTabSelected() {
|
||||
JNotepadTabPane instance = JNotepadTabPane.getInstance();
|
||||
CenterTabPane instance = CenterTabPane.getInstance();
|
||||
if (instance.getSelected() != null) {
|
||||
updateWordCountStatusLabel();
|
||||
JNotepadTab JNotepadTab = instance.getSelected();
|
||||
if (JNotepadTab != null) {
|
||||
updateEncodingLabel(JNotepadTab.getCharset().name());
|
||||
CenterTab CenterTab = instance.getSelected();
|
||||
if (CenterTab != null) {
|
||||
updateEncodingLabel(CenterTab.getCharset().name());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -13,7 +13,7 @@ import java.nio.charset.Charset;
|
||||
*
|
||||
* @author songdragon
|
||||
*/
|
||||
public class JNotepadTab extends Tab {
|
||||
public class CenterTab extends Tab {
|
||||
|
||||
private final LineNumberTextArea lineNumberTextArea;
|
||||
/**
|
||||
@ -26,15 +26,15 @@ public class JNotepadTab extends Tab {
|
||||
private boolean isRelevance = false;
|
||||
private Charset charset = Charset.defaultCharset();
|
||||
|
||||
public JNotepadTab(String tabTitle) {
|
||||
public CenterTab(String tabTitle) {
|
||||
this(tabTitle, new LineNumberTextArea());
|
||||
}
|
||||
|
||||
public JNotepadTab(String tabTitle, LineNumberTextArea textArea) {
|
||||
public CenterTab(String tabTitle, LineNumberTextArea textArea) {
|
||||
this(tabTitle, textArea, Charset.defaultCharset());
|
||||
}
|
||||
|
||||
public JNotepadTab(String tabTitle, LineNumberTextArea textArea, Charset charset) {
|
||||
public CenterTab(String tabTitle, LineNumberTextArea textArea, Charset charset) {
|
||||
super(tabTitle);
|
||||
lineNumberTextArea = textArea;
|
||||
this.setContent(lineNumberTextArea);
|
||||
@ -1,7 +1,7 @@
|
||||
package org.jcnc.jnotepad.root.center.main.center.tab;
|
||||
|
||||
import javafx.scene.control.TabPane;
|
||||
import org.jcnc.jnotepad.root.center.main.bottom.status.JNotepadStatusBox;
|
||||
import org.jcnc.jnotepad.root.center.main.bottom.status.BottomStatusBox;
|
||||
import org.jcnc.jnotepad.root.top.menu.TopMenuBar;
|
||||
import org.jcnc.jnotepad.tool.SingletonUtil;
|
||||
|
||||
@ -10,15 +10,15 @@ import org.jcnc.jnotepad.tool.SingletonUtil;
|
||||
*
|
||||
* @author songdragon
|
||||
*/
|
||||
public class JNotepadTabPane extends TabPane {
|
||||
public class CenterTabPane extends TabPane {
|
||||
|
||||
private static final JNotepadTabPane TAB_PANE = new JNotepadTabPane();
|
||||
private static final CenterTabPane TAB_PANE = new CenterTabPane();
|
||||
|
||||
private JNotepadTabPane() {
|
||||
private CenterTabPane() {
|
||||
initListeners();
|
||||
}
|
||||
|
||||
public static JNotepadTabPane getInstance() {
|
||||
public static CenterTabPane getInstance() {
|
||||
return TAB_PANE;
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ public class JNotepadTabPane extends TabPane {
|
||||
TopMenuBar.getInstance().updateMenuStatusBySelectedTab();
|
||||
}
|
||||
// 更新状态标签
|
||||
JNotepadStatusBox.getInstance().updateWhenTabSelected();
|
||||
BottomStatusBox.getInstance().updateWhenTabSelected();
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -44,7 +44,7 @@ public class JNotepadTabPane extends TabPane {
|
||||
*
|
||||
* @param tab 新标签页
|
||||
*/
|
||||
public void addNewTab(JNotepadTab tab) {
|
||||
public void addNewTab(CenterTab tab) {
|
||||
if (tab == null) {
|
||||
return;
|
||||
}
|
||||
@ -61,8 +61,8 @@ public class JNotepadTabPane extends TabPane {
|
||||
*
|
||||
* @return 当前选中的标签页
|
||||
*/
|
||||
public JNotepadTab getSelected() {
|
||||
return (JNotepadTab) this.getSelectionModel().getSelectedItem();
|
||||
public CenterTab getSelected() {
|
||||
return (CenterTab) this.getSelectionModel().getSelectedItem();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,8 +70,8 @@ public class JNotepadTabPane extends TabPane {
|
||||
* 应用当前菜单上选中的自动换行设置。
|
||||
*/
|
||||
public void fireTabSelected() {
|
||||
JNotepadTab selectedTab = getSelected();
|
||||
CenterTab selectedTab = getSelected();
|
||||
selectedTab.setAutoLine(SingletonUtil.getAppConfigController().getAutoLineConfig());
|
||||
JNotepadStatusBox.getInstance().updateWhenTabSelected();
|
||||
BottomStatusBox.getInstance().updateWhenTabSelected();
|
||||
}
|
||||
}
|
||||
@ -10,8 +10,8 @@ import org.jcnc.jnotepad.controller.config.AppConfigController;
|
||||
import org.jcnc.jnotepad.controller.event.handler.menubar.*;
|
||||
import org.jcnc.jnotepad.controller.event.handler.tool.SetBtn;
|
||||
import org.jcnc.jnotepad.controller.i18n.LocalizationController;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.CenterTab;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.CenterTabPane;
|
||||
import org.jcnc.jnotepad.root.left.sidebar.tools.ToolBar;
|
||||
import org.jcnc.jnotepad.tool.LogUtil;
|
||||
import org.slf4j.Logger;
|
||||
@ -35,7 +35,7 @@ public class TopMenuBar extends MenuBar {
|
||||
/**
|
||||
* 标签页布局组件封装。
|
||||
*/
|
||||
JNotepadTabPane JNotepadTabPane = org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane.getInstance();
|
||||
CenterTabPane centerTabPane = CenterTabPane.getInstance();
|
||||
AppConfigController appConfigController = AppConfigController.getInstance();
|
||||
Logger logger = LogUtil.getLogger(this.getClass());
|
||||
/**
|
||||
@ -289,7 +289,7 @@ public class TopMenuBar extends MenuBar {
|
||||
// 1. 更新全局配置
|
||||
AppConfigController.getInstance().setAutoLineConfig(after);
|
||||
// 2. 对当前tab生效配置
|
||||
JNotepadTabPane.fireTabSelected();
|
||||
centerTabPane.fireTabSelected();
|
||||
});
|
||||
topItem.selectedProperty().addListener((observableValue, before, after) -> {
|
||||
// 获取窗口容器
|
||||
@ -322,7 +322,7 @@ public class TopMenuBar extends MenuBar {
|
||||
* 根据当前选中tab,更新菜单选项
|
||||
*/
|
||||
public void updateMenuStatusBySelectedTab() {
|
||||
JNotepadTab selectedTab = JNotepadTabPane.getSelected();
|
||||
CenterTab selectedTab = centerTabPane.getSelected();
|
||||
lineFeedItem.selectedProperty().setValue(selectedTab.isAutoLine());
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ public class UiUtil {
|
||||
* 获取应用窗口。
|
||||
*
|
||||
* @return javafx.stage.Window 应用窗口对象
|
||||
* @apiNote JNotepadTabPane.getInstance().getSelected().getTabPane().getScene().getWindow()
|
||||
* @apiNote LunchApp.getWindow()
|
||||
*/
|
||||
public static Window getAppWindow() {
|
||||
return LunchApp.getWindow();
|
||||
|
||||
@ -3,9 +3,9 @@ package org.jcnc.jnotepad.ui.module;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import org.jcnc.jnotepad.root.center.main.bottom.status.JNotepadStatusBox;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane;
|
||||
import org.jcnc.jnotepad.root.center.main.bottom.status.BottomStatusBox;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.CenterTab;
|
||||
import org.jcnc.jnotepad.root.center.main.center.tab.CenterTabPane;
|
||||
import org.jcnc.jnotepad.tool.LogUtil;
|
||||
import org.jcnc.jnotepad.tool.SingletonUtil;
|
||||
import org.slf4j.Logger;
|
||||
@ -62,12 +62,12 @@ public class LineNumberTextArea extends BorderPane {
|
||||
|
||||
lineNumberArea.textProperty().addListener((observable, oldValue, newValue) -> updateLineNumberWidth());
|
||||
|
||||
this.mainTextArea.caretPositionProperty().addListener((caretObservable, oldPosition, newPosition) -> JNotepadStatusBox.getInstance().updateWordCountStatusLabel());
|
||||
this.mainTextArea.caretPositionProperty().addListener((caretObservable, oldPosition, newPosition) -> BottomStatusBox.getInstance().updateWordCountStatusLabel());
|
||||
this.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
// 更新行号
|
||||
updateLineNumberArea();
|
||||
// 更新状态栏
|
||||
JNotepadStatusBox.getInstance().updateWordCountStatusLabel();
|
||||
BottomStatusBox.getInstance().updateWordCountStatusLabel();
|
||||
// 自动保存
|
||||
save();
|
||||
});
|
||||
@ -77,7 +77,7 @@ public class LineNumberTextArea extends BorderPane {
|
||||
* 以原文件编码格式写回文件
|
||||
*/
|
||||
public void save() {
|
||||
JNotepadTab tab = JNotepadTabPane.getInstance().getSelected();
|
||||
CenterTab tab = CenterTabPane.getInstance().getSelected();
|
||||
if (tab == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user