From 69f0381167bf80e1c17005b2645ffbfcff98423a Mon Sep 17 00:00:00 2001 From: gewuyou <1063891901@qq.com> Date: Mon, 9 Oct 2023 22:15:31 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A9=20=E5=AE=8C=E5=96=84=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=9B=BE=E6=A0=87=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/jcnc/jnotepad/util/FileUtil.java | 22 +++++++++++++++++++ .../views/manager/CenterTabPaneManager.java | 10 +++++++-- .../center/main/center/tab/CenterTab.java | 3 +++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jcnc/jnotepad/util/FileUtil.java b/src/main/java/org/jcnc/jnotepad/util/FileUtil.java index 33b7d74..ba0709a 100644 --- a/src/main/java/org/jcnc/jnotepad/util/FileUtil.java +++ b/src/main/java/org/jcnc/jnotepad/util/FileUtil.java @@ -1,5 +1,6 @@ package org.jcnc.jnotepad.util; +import javafx.scene.Node; import org.jcnc.jnotepad.controller.event.handler.menuitem.OpenFile; import org.jcnc.jnotepad.controller.exception.AppException; import org.jcnc.jnotepad.model.entity.DirFileModel; @@ -287,5 +288,26 @@ public class FileUtil { throw new AppException(e); } } + + + /** + * Retrieves the icon corresponding to the given file name. + * + * @param tabTitle the title of the tab + * @return the icon node corresponding to the file name + */ + public static Node getIconCorrespondingToFileName(String tabTitle) { + // todo 在此根据文件缀名获取对应的图标 + String fileExtension = tabTitle.substring(tabTitle.lastIndexOf(".") + 1); + return switch (fileExtension.toLowerCase()) { + case "txt" -> FontIcon.of(FILE_TEXT); + case "doc" -> FontIcon.of(FILE_WORD); + case "pdf" -> FontIcon.of(FILE_PDF); + case "ppt" -> FontIcon.of(FILE_PPT); + case "xls" -> FontIcon.of(FILE_EXCEL); + case "md" -> FontIcon.of(FILE_MARKDOWN); + default -> FontIcon.of(FILE_UNKNOWN); + }; + } } diff --git a/src/main/java/org/jcnc/jnotepad/views/manager/CenterTabPaneManager.java b/src/main/java/org/jcnc/jnotepad/views/manager/CenterTabPaneManager.java index e2e6035..d7e6584 100644 --- a/src/main/java/org/jcnc/jnotepad/views/manager/CenterTabPaneManager.java +++ b/src/main/java/org/jcnc/jnotepad/views/manager/CenterTabPaneManager.java @@ -182,7 +182,13 @@ public class CenterTabPaneManager { * @param currTab the current tab */ public void removeOtherTabs(CenterTab currTab) { - centerTabPane.getTabs().removeIf(tab -> (!currTab.equals(tab) || !((CenterTab) tab).isFixed())); + centerTabPane.getTabs().removeIf(tab -> { + CenterTab centerTab = (CenterTab) tab; + if (centerTab.equals(currTab)) { + return false; + } + return !centerTab.isFixed() && !centerTab.equals(currTab); + }); } /** @@ -314,7 +320,7 @@ public class CenterTabPaneManager { /** * Updates the read-only property of a given tab and its associated check menu item. * - * @param tab the center tab to update + * @param tab the center tab to update */ public void updateReadOnlyProperty(CenterTab tab) { TextCodeArea textCodeArea = tab.getTextCodeArea(); diff --git a/src/main/java/org/jcnc/jnotepad/views/root/center/main/center/tab/CenterTab.java b/src/main/java/org/jcnc/jnotepad/views/root/center/main/center/tab/CenterTab.java index 72c0dcc..f365523 100644 --- a/src/main/java/org/jcnc/jnotepad/views/root/center/main/center/tab/CenterTab.java +++ b/src/main/java/org/jcnc/jnotepad/views/root/center/main/center/tab/CenterTab.java @@ -6,6 +6,7 @@ import javafx.scene.control.Tab; import org.fxmisc.flowless.VirtualizedScrollPane; import org.jcnc.jnotepad.component.module.TextCodeArea; import org.jcnc.jnotepad.controller.config.UserConfigController; +import org.jcnc.jnotepad.util.FileUtil; import org.jcnc.jnotepad.util.LogUtil; import org.jcnc.jnotepad.util.TabUtil; import org.jcnc.jnotepad.views.manager.BottomStatusBoxManager; @@ -56,6 +57,8 @@ public class CenterTab extends Tab { public CenterTab(String tabTitle, TextCodeArea textArea, Charset charset) { super(tabTitle); + // 在此根据标签页名称设置文件图标 + this.setGraphic(FileUtil.getIconCorrespondingToFileName(tabTitle)); textCodeArea = textArea; initTextAreaListeners(); this.setContent(new VirtualizedScrollPane<>(textCodeArea));