Add sort menu, fixes #192

This commit is contained in:
Jeremy Soller 2024-09-11 13:29:00 -06:00
parent 24a44c3b52
commit 76cf9865f0
No known key found for this signature in database
GPG key ID: D02FD439211AF56F
4 changed files with 59 additions and 0 deletions

View file

@ -244,6 +244,16 @@ pub fn menu_bar<'a>(
tab_opt: Option<&Tab>,
key_binds: &HashMap<KeyBind, Action>,
) -> Element<'a, Message> {
let sort_item = |label, sort, dir| {
menu::Item::CheckBox(
label,
tab_opt.map_or(false, |tab| {
tab.config.sort_name == sort && tab.config.sort_direction == dir
}),
Action::SetSort(sort, dir),
)
};
MenuBar::new(vec![
menu::Tree::with_children(
menu::root(fl!("file")),
@ -321,6 +331,37 @@ pub fn menu_bar<'a>(
],
),
),
menu::Tree::with_children(
menu::root(fl!("sort")),
menu::items(
key_binds,
vec![
sort_item(fl!("sort-a-z"), tab::HeadingOptions::Name, true),
sort_item(fl!("sort-z-a"), tab::HeadingOptions::Name, false),
sort_item(
fl!("sort-newest-first"),
tab::HeadingOptions::Modified,
false,
),
sort_item(
fl!("sort-oldest-first"),
tab::HeadingOptions::Modified,
true,
),
sort_item(
fl!("sort-smallest-to-largest"),
tab::HeadingOptions::Size,
true,
),
sort_item(
fl!("sort-largest-to-smallest"),
tab::HeadingOptions::Size,
false,
),
//TODO: sort by type
],
),
),
])
.item_height(ItemHeight::Dynamic(40))
.item_width(ItemWidth::Uniform(240))