I've been struggling with this for a while, and I've almost got it- but not quite. This is what I have so far:
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 manages to load the folder into the ListView (referred to here as state.file_view. I've used a ListView as TreeView seems to be deprecated), and it can recognise folders as item that can be expanded, however expanding them doesn't seem to do anything. For example:
A ListView with an item expanded, however it has no child items.
I'm using GTK-RS with Relm4. How can I fix this?