- * public boolean hasLeftTabs(CenterTab centerTab) {
- * ObservableList tabs = centerTabPane.getTabs();
- * int edge = tabs.indexOf(centerTab);
- * if (edge == 0) {
- * return false;
- * }
- * for (int i = 0; i < edge; i++) {
- * CenterTab tab = (CenterTab) tabs.get(i);
- * if (!tab.isFixed()) {
- * return true;
- * }
- * }
- * return false;
- * }
- *
- * @return 是否有左侧标签页
+ * @param tab the center tab to update
*/
- public boolean hasLeftTabs(CenterTab centerTab) {
- int index = centerTabPane.getTabs().indexOf(centerTab);
- return index > 0;
+ public void updateTabPinnedState(CenterTab tab) {
+ tab.setFixedProperty(tab.getNotFixedProperty());
+ tab.setClosable(tab.getNotFixedProperty());
}
/**
- * 判断是否有右侧标签页
+ * Updates the read-only property of a given tab and its associated check menu item.
*
- * @param centerTab 标签页
- * @return 是否有右侧标签页
- * @apiNote 由于不知道怎么监听固定状态,因此,还是使用简单的判断,如果能够监听固定状态时可以把代码修改为
- *
- * public boolean hasRightTabs(CenterTab centerTab) {
- * ObservableList tabs = centerTabPane.getTabs();
- * for (int i = tabs.indexOf(centerTab)+1; i < tabs.size(); i++) {
- * CenterTab tab = (CenterTab) tabs.get(i);
- * if (!tab.isFixed()) {
- * return true;
- * }
- * }
- * return false;
- * }
- *
+ * @param tab the center tab to update
*/
- public boolean hasRightTabs(CenterTab centerTab) {
- ObservableList tabs = centerTabPane.getTabs();
- int index = tabs.indexOf(centerTab);
- return index != tabs.size() - 1;
+ public void updateReadOnlyProperty(CenterTab tab) {
+ TextCodeArea textCodeArea = tab.getTextCodeArea();
+ textCodeArea.setEditable(!textCodeArea.isEditable());
+ BottomStatusBoxManager.getInstance().updateReadOnlyProperty(tab, centerTabPane.getTabs());
}
/**
- * Sets a listener for the tabs in the center tab pane.
- *
- * @param tab the tab to set the listener for
+ * Adds a listener to the tabs in the center tab pane.
*/
- public void setTabsListener(CenterTab tab) {
- ObservableList tabs = centerTabPane.getTabs();
- tabs.addListener((ListChangeListener) c -> {
- tab.contextMenuMonitor();
- BottomStatusBoxManager.getInstance().updateReadOnlyProperty(tab, tabs);
+ private void addTabsListener() {
+ centerTabPane.getTabs().addListener((ListChangeListener) change -> {
+ ObservableList extends Tab> list = change.getList();
+ list.forEach(tab -> {
+ CenterTab centerTab = (CenterTab) tab;
+ // 判断标签页
+ checkTabs(list, centerTab);
+ });
});
}
/**
- * Updates the pinned state of the given center tab.
+ * Checks the tabs in the given list and updates the properties of the centerTab accordingly.
*
- * @param tab the center tab to update
+ * @param list the list of tabs to check
+ * @param centerTab the centerTab to update
*/
- public void updateTabPinnedState(CenterTab tab) {
- tab.setFixed(!tab.isFixed());
- tab.setClosable(!tab.isFixed());
- }
+ public void checkTabs(ObservableList extends Tab> list, CenterTab centerTab) {
+ int index = list.indexOf(centerTab);
+ boolean hasOther = false;
+ boolean hasLeft = false;
+ boolean hasRight = false;
+ int tabCount = list.size();
- /**
- * Updates the read-only property of a given tab and its associated check menu item.
- *
- * @param tab the center tab to update
- */
- public void updateReadOnlyProperty(CenterTab tab) {
- TextCodeArea textCodeArea = tab.getTextCodeArea();
- textCodeArea.setEditable(!textCodeArea.isEditable());
- tab.contextMenuMonitor();
- BottomStatusBoxManager.getInstance().updateReadOnlyProperty(tab, centerTabPane.getTabs());
+ for (int i = 0; i < tabCount; i++) {
+ CenterTab temp = (CenterTab) list.get(i);
+
+ // 判断是否有其他标签页
+ if (!centerTab.equals(temp) && temp.getNotFixedProperty()) {
+ hasOther = true;
+ }
+
+ // 判断是否有左侧标签页
+ if (!centerTab.equals(temp) && i < index && temp.getNotFixedProperty()) {
+ hasLeft = true;
+ }
+
+ // 判断是否有右侧标签页
+ if (!centerTab.equals(temp) && i > index && temp.getNotFixedProperty()) {
+ hasRight = true;
+ }
+ }
+
+ centerTab.setHasOtherTabsProperty(hasOther);
+ centerTab.setHasLeftTabsProperty(hasLeft);
+ centerTab.setHasRightTabsProperty(hasRight);
}
}
diff --git a/src/main/java/org/jcnc/jnotepad/ui/views/manager/DirectorySidebarManager.java b/src/main/java/org/jcnc/jnotepad/ui/views/manager/DirectorySidebarManager.java
index f774190..4e0f941 100644
--- a/src/main/java/org/jcnc/jnotepad/ui/views/manager/DirectorySidebarManager.java
+++ b/src/main/java/org/jcnc/jnotepad/ui/views/manager/DirectorySidebarManager.java
@@ -23,29 +23,49 @@ import java.util.List;
*/
public class DirectorySidebarManager {
- private DirectorySidebarManager() {
- }
-
private static final ApplicationCacheManager CACHE_MANAGER = ApplicationCacheManager.getInstance();
-
/**
* 单例模式,保证只有一个 DirectorySidebar 实例
*/
private static final DirectorySidebarManager INSTANCE = new DirectorySidebarManager();
+ private static final MainBorderPane MAIN_BORDER_PANE = MainBorderPane.getInstance();
+ private static final DirectorySidebarPane DIRECTORY_SIDEBAR_PANE = DirectorySidebarPane.getInstance();
+ private static final double LAST_DIVIDER_POSITION = 0.3;
+ private static boolean isShow = false;
+ private DirectorySidebarManager() {
+ }
+
public static DirectorySidebarManager getInstance() {
return INSTANCE;
}
- private static final MainBorderPane MAIN_BORDER_PANE = MainBorderPane.getInstance();
-
- private static final DirectorySidebarPane DIRECTORY_SIDEBAR_PANE = DirectorySidebarPane.getInstance();
-
-
- private static final double LAST_DIVIDER_POSITION = 0.3;
+ /**
+ * 设置文件树项监听事件
+ *
+ * @param item 文件树项
+ * @return 监听事件
+ */
+ private static ChangeListener getTreeItemListener(TreeItem item) {
+ return (observable, oldValue, newValue) -> {
+ if (Boolean.TRUE.equals(newValue)) {
+ item.setGraphic(item.getValue().getIconIsSelected());
+ } else {
+ item.setGraphic(item.getValue().getIconIsNotSelected());
+ }
+ };
+ }
- private static boolean isShow = false;
+ /**
+ * Check if the given `DirFileModel` represents a directory.
+ *
+ * @param childFile the `DirFileModel` to check
+ * @return `true` if the `childFile` represents a directory, `false` otherwise
+ */
+ private static boolean isDirectoryByDirFileModel(DirFileModel childFile) {
+ return new File(childFile.getPath()).isDirectory();
+ }
/**
* 控制文件树显示
@@ -83,22 +103,6 @@ public class DirectorySidebarManager {
}
}
- /**
- * 设置文件树项监听事件
- *
- * @param item 文件树项
- * @return 监听事件
- */
- private static ChangeListener getTreeItemListener(TreeItem item) {
- return (observable, oldValue, newValue) -> {
- if (Boolean.TRUE.equals(newValue)) {
- item.setGraphic(item.getValue().getIconIsSelected());
- } else {
- item.setGraphic(item.getValue().getIconIsNotSelected());
- }
- };
- }
-
/**
* 设置文件树内容
*
@@ -112,16 +116,6 @@ public class DirectorySidebarManager {
expandFolder(dirFileModel, rootItem);
}
- /**
- * Check if the given `DirFileModel` represents a directory.
- *
- * @param childFile the `DirFileModel` to check
- * @return `true` if the `childFile` represents a directory, `false` otherwise
- */
- private static boolean isDirectoryByDirFileModel(DirFileModel childFile) {
- return new File(childFile.getPath()).isDirectory();
- }
-
/**
* 递归展开 dirFileModel
*
diff --git a/src/main/java/org/jcnc/jnotepad/ui/views/manager/RootManager.java b/src/main/java/org/jcnc/jnotepad/ui/views/manager/RootManager.java
index 5e0fb37..99e00ed 100644
--- a/src/main/java/org/jcnc/jnotepad/ui/views/manager/RootManager.java
+++ b/src/main/java/org/jcnc/jnotepad/ui/views/manager/RootManager.java
@@ -24,11 +24,11 @@ import org.jcnc.jnotepad.ui.views.root.RootBorderPane;
public class RootManager {
private static RootManager instance = null;
- StackPane rootStackPane;
/**
* 主布局
*/
private final BorderPane root;
+ StackPane rootStackPane;
/**
* 私有构造函数。设置场景和根布局。
@@ -67,23 +67,6 @@ public class RootManager {
}
}
-
- /**
- * 初始化屏幕组件。
- *
- * @param scene 与视图相关联的 JavaFX 场景。
- */
- public void initScreen(Scene scene) {
- rootStackPane = new StackPane();
-
- // 创建主界面布局
- root.setCenter(RootBorderPane.getInstance());
-
- rootStackPane.getChildren().addAll(root);
- scene.setRoot(rootStackPane);
-
- }
-
/**
* 将提示框添加到 StackPane 中。
*
@@ -155,6 +138,22 @@ public class RootManager {
timeline.play();
}
+ /**
+ * 初始化屏幕组件。
+ *
+ * @param scene 与视图相关联的 JavaFX 场景。
+ */
+ public void initScreen(Scene scene) {
+ rootStackPane = new StackPane();
+
+ // 创建主界面布局
+ root.setCenter(RootBorderPane.getInstance());
+
+ rootStackPane.getChildren().addAll(root);
+ scene.setRoot(rootStackPane);
+
+ }
+
public StackPane getRootStackPane() {
return rootStackPane;
}
diff --git a/src/main/java/org/jcnc/jnotepad/ui/views/manager/SidebarToolBarManager.java b/src/main/java/org/jcnc/jnotepad/ui/views/manager/SidebarToolBarManager.java
index ba25342..b8f57bd 100644
--- a/src/main/java/org/jcnc/jnotepad/ui/views/manager/SidebarToolBarManager.java
+++ b/src/main/java/org/jcnc/jnotepad/ui/views/manager/SidebarToolBarManager.java
@@ -19,11 +19,11 @@ import java.util.List;
*/
public class SidebarToolBarManager extends AbstractManager {
private static final SidebarToolBarManager INSTANCE = new SidebarToolBarManager();
+ private final List nodeList = new ArrayList<>();
/**
* 工具栏
*/
SidebarToolBar sidebarToolBar = SidebarToolBar.getInstance();
- private final List nodeList = new ArrayList<>();
public static SidebarToolBarManager getInstance() {
return INSTANCE;
diff --git a/src/main/java/org/jcnc/jnotepad/ui/views/manager/TopMenuBarManager.java b/src/main/java/org/jcnc/jnotepad/ui/views/manager/TopMenuBarManager.java
index 707924c..c2db679 100644
--- a/src/main/java/org/jcnc/jnotepad/ui/views/manager/TopMenuBarManager.java
+++ b/src/main/java/org/jcnc/jnotepad/ui/views/manager/TopMenuBarManager.java
@@ -31,7 +31,7 @@ public class TopMenuBarManager extends AbstractManager