commit
b45c22c275
@ -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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user