Improve error handling

This commit is contained in:
Reinout Meliesie 2025-02-12 11:34:38 +01:00
commit 2ec2fda116
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
4 changed files with 32 additions and 36 deletions

View file

@ -58,7 +58,12 @@ fn on_media_sort_activated < A : MediaAdapter + 'static > (
on_sort : & impl Fn ( A :: Sorting ) ,
sort_icons : & [ Image ] ,
) {
let ( sorting_property , _ ) = A :: get_property_descriptions () [ row as usize ] . clone () ; // TODO: Bounds checking
let row = row as usize ;
debug_assert ! (
row <= A :: get_property_descriptions () . len () ,
"Sorting menu has more rows than media adapter has property descriptions" ,
) ;
let ( sorting_property , _ ) = A :: get_property_descriptions () [row] . clone () ;
let previous_sorting = * previous_sorting_mut . borrow () ;
if sorting_property == previous_sorting . get_property () {
@ -66,20 +71,20 @@ fn on_media_sort_activated < A : MediaAdapter + 'static > (
Ascending => {
let new_sorting = A :: Sorting :: new ( sorting_property , Descending ) ;
previous_sorting_mut . replace (new_sorting) ;
sort_icons [ row as usize ] . set_icon_name ( Some ("view-sort-descending-symbolic") ) ;
sort_icons [row] . set_icon_name ( Some ("view-sort-descending-symbolic") ) ;
on_sort (new_sorting) ;
} ,
Descending => {
let new_sorting = A :: Sorting :: new ( sorting_property , Ascending ) ;
previous_sorting_mut . replace (new_sorting) ;
sort_icons [ row as usize ] . set_icon_name ( Some ("view-sort-ascending-symbolic") ) ;
sort_icons [row] . set_icon_name ( Some ("view-sort-ascending-symbolic") ) ;
on_sort (new_sorting) ;
} ,
}
} else {
let new_sorting = A :: Sorting :: new ( sorting_property , Ascending ) ;
previous_sorting_mut . replace (new_sorting) ;
sort_icons [ row as usize ] . set_icon_name ( Some ("view-sort-ascending-symbolic") ) ;
sort_icons [row] . set_icon_name ( Some ("view-sort-ascending-symbolic") ) ;
on_sort (new_sorting) ;
}
}