🐛 尝试修复文件图标渲染问题

This commit is contained in:
gewuyou 2023-10-10 20:45:23 +08:00
parent 0a94a9f7d1
commit 0d191ef104
2 changed files with 29 additions and 3 deletions

View File

@ -13,13 +13,26 @@ import java.util.List;
* @author cccqyu
*/
public class DirFileModel {
/**
* 路径
*/
private String path;
/**
* 文件名
*/
private String name;
/**
* 未选中时的图标
*/
private Node iconIsNotSelected;
/**
* 选中时的图标
*/
private Node iconIsSelected;
/**
* 子文件
*/
private List<DirFileModel> childFile;
public DirFileModel(String path, String name, List<DirFileModel> childFile, Node iconIsNotSelected, Node iconIsSelected) {

View File

@ -112,6 +112,16 @@ 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
*
@ -123,7 +133,10 @@ public class DirectorySidebarManager {
if (childFileList != null) {
for (DirFileModel childFile : childFileList) {
TreeItem<DirFileModel> childItem = new TreeItem<>(childFile, childFile.getIconIsNotSelected());
childItem.expandedProperty().addListener(getTreeItemListener(childItem));
// 只有文件夹树才添加监听事件
if (isDirectoryByDirFileModel(childFile)) {
childItem.expandedProperty().addListener(getTreeItemListener(childItem));
}
item.getChildren().add(childItem);
expandFolder(childFile, childItem);
}