I’ve been trying to create a file tree for quite a while now, and while I’ve gotten close I just can’t seem to fully get it. Here’s my code currently:
pub fn load_folder_view(state: &mut State) {
let path = state.current_folder_path.clone();
let file = File::for_path(&path);
let dir_list = DirectoryList::new(Some("standard::name"), Some(&file));
let model = TreeListModel::new(dir_list, false, false, move |o| {
let dir_str = o.downcast_ref::<FileInfo>().unwrap().name();
let mut dir_path = PathBuf::new();
dir_path.push(&path);
dir_path.push(&dir_str);
if dir_path.is_dir() {
let dir_list_local = DirectoryList::new(None, Some(&File::for_path(dir_path)));
Some(dir_list_local.into())
} else {
None
}
});
let selection = SingleSelection::new(Some(model.model()));
let factory = SignalListItemFactory::new();
factory.connect_setup(move |_, list_item| {
list_item.set_child(Some(
&TreeExpander::builder().child(&Label::new(None)).build(),
));
});
factory.connect_bind(move |_, list_item| {
let item = list_item.item().unwrap();
let file_info = item.downcast_ref::<FileInfo>().unwrap();
let tree = list_item.child().and_downcast::<TreeExpander>().unwrap();
tree.set_list_row(model.row(list_item.position()).as_ref());
tree.set_child(Some(&Label::new(Some(file_info.name().to_str().unwrap()))));
});
state.file_view.set_model(Some(&selection));
state.file_view.set_factory(Some(&factory));
}
It almost works, but not quite- it can load the top-most folder, and the TreeExpander that represent a folder have are expandable, but they have no items within them , even when they should. Below is a example of this:
Does anyone know what I’m doing wrong?
