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

Merge pull request !162 from 格物方能致知/develop
This commit is contained in:
格物方能致知 2023-10-10 12:46:59 +00:00 committed by Gitee
commit 4fdefea1bd
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 29 additions and 3 deletions

View File

@ -13,13 +13,26 @@ import java.util.List;
* @author cccqyu * @author cccqyu
*/ */
public class DirFileModel { public class DirFileModel {
/**
* 路径
*/
private String path; private String path;
/**
* 文件名
*/
private String name; private String name;
/**
* 未选中时的图标
*/
private Node iconIsNotSelected; private Node iconIsNotSelected;
/**
* 选中时的图标
*/
private Node iconIsSelected; private Node iconIsSelected;
/**
* 子文件
*/
private List<DirFileModel> childFile; private List<DirFileModel> childFile;
public DirFileModel(String path, String name, List<DirFileModel> childFile, Node iconIsNotSelected, Node iconIsSelected) { 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); 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 * 递归展开 dirFileModel
* *
@ -123,7 +133,10 @@ public class DirectorySidebarManager {
if (childFileList != null) { if (childFileList != null) {
for (DirFileModel childFile : childFileList) { for (DirFileModel childFile : childFileList) {
TreeItem<DirFileModel> childItem = new TreeItem<>(childFile, childFile.getIconIsNotSelected()); TreeItem<DirFileModel> childItem = new TreeItem<>(childFile, childFile.getIconIsNotSelected());
// 只有文件夹树才添加监听事件
if (isDirectoryByDirFileModel(childFile)) {
childItem.expandedProperty().addListener(getTreeItemListener(childItem)); childItem.expandedProperty().addListener(getTreeItemListener(childItem));
}
item.getChildren().add(childItem); item.getChildren().add(childItem);
expandFolder(childFile, childItem); expandFolder(childFile, childItem);
} }