!159 完善文件图标支持

Merge pull request !159 from 格物方能致知/develop
This commit is contained in:
格物方能致知 2023-10-09 14:18:41 +00:00 committed by Gitee
commit b45c22c275
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 33 additions and 2 deletions

View File

@ -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);
};
}
}

View File

@ -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);
});
}
/**

View File

@ -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));