commit
b45c22c275
@ -1,5 +1,6 @@
|
|||||||
package org.jcnc.jnotepad.util;
|
package org.jcnc.jnotepad.util;
|
||||||
|
|
||||||
|
import javafx.scene.Node;
|
||||||
import org.jcnc.jnotepad.controller.event.handler.menuitem.OpenFile;
|
import org.jcnc.jnotepad.controller.event.handler.menuitem.OpenFile;
|
||||||
import org.jcnc.jnotepad.controller.exception.AppException;
|
import org.jcnc.jnotepad.controller.exception.AppException;
|
||||||
import org.jcnc.jnotepad.model.entity.DirFileModel;
|
import org.jcnc.jnotepad.model.entity.DirFileModel;
|
||||||
@ -287,5 +288,26 @@ public class FileUtil {
|
|||||||
throw new AppException(e);
|
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
|
* @param currTab the current tab
|
||||||
*/
|
*/
|
||||||
public void removeOtherTabs(CenterTab currTab) {
|
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.
|
* 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) {
|
public void updateReadOnlyProperty(CenterTab tab) {
|
||||||
TextCodeArea textCodeArea = tab.getTextCodeArea();
|
TextCodeArea textCodeArea = tab.getTextCodeArea();
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import javafx.scene.control.Tab;
|
|||||||
import org.fxmisc.flowless.VirtualizedScrollPane;
|
import org.fxmisc.flowless.VirtualizedScrollPane;
|
||||||
import org.jcnc.jnotepad.component.module.TextCodeArea;
|
import org.jcnc.jnotepad.component.module.TextCodeArea;
|
||||||
import org.jcnc.jnotepad.controller.config.UserConfigController;
|
import org.jcnc.jnotepad.controller.config.UserConfigController;
|
||||||
|
import org.jcnc.jnotepad.util.FileUtil;
|
||||||
import org.jcnc.jnotepad.util.LogUtil;
|
import org.jcnc.jnotepad.util.LogUtil;
|
||||||
import org.jcnc.jnotepad.util.TabUtil;
|
import org.jcnc.jnotepad.util.TabUtil;
|
||||||
import org.jcnc.jnotepad.views.manager.BottomStatusBoxManager;
|
import org.jcnc.jnotepad.views.manager.BottomStatusBoxManager;
|
||||||
@ -56,6 +57,8 @@ public class CenterTab extends Tab {
|
|||||||
|
|
||||||
public CenterTab(String tabTitle, TextCodeArea textArea, Charset charset) {
|
public CenterTab(String tabTitle, TextCodeArea textArea, Charset charset) {
|
||||||
super(tabTitle);
|
super(tabTitle);
|
||||||
|
// 在此根据标签页名称设置文件图标
|
||||||
|
this.setGraphic(FileUtil.getIconCorrespondingToFileName(tabTitle));
|
||||||
textCodeArea = textArea;
|
textCodeArea = textArea;
|
||||||
initTextAreaListeners();
|
initTextAreaListeners();
|
||||||
this.setContent(new VirtualizedScrollPane<>(textCodeArea));
|
this.setContent(new VirtualizedScrollPane<>(textCodeArea));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user