Add context menu items for sorting

This commit is contained in:
Josh Megnauth 2024-03-15 00:34:16 -04:00 committed by Jeremy Soller
parent e22c74d721
commit 02417a6f2f
3 changed files with 50 additions and 1 deletions

View file

@ -82,6 +82,9 @@ new-folder = New folder
open-in-terminal = Open in terminal open-in-terminal = Open in terminal
move-to-trash = Move to trash move-to-trash = Move to trash
restore-from-trash = Restore from trash restore-from-trash = Restore from trash
sort-by-name = Sort by name
sort-by-modified = Sort by modified
sort-by-size = Sort by size
# Menu # Menu

View file

@ -78,6 +78,7 @@ pub enum Action {
TabViewGrid, TabViewGrid,
TabViewList, TabViewList,
ToggleShowHidden, ToggleShowHidden,
ToggleSort(HeadingOptions),
WindowClose, WindowClose,
WindowNew, WindowNew,
} }
@ -120,6 +121,7 @@ impl Action {
Message::TabMessage(entity_opt, tab::Message::View(tab::View::List)) Message::TabMessage(entity_opt, tab::Message::View(tab::View::List))
} }
Action::ToggleShowHidden => Message::TabMessage(None, tab::Message::ToggleShowHidden), Action::ToggleShowHidden => Message::TabMessage(None, tab::Message::ToggleShowHidden),
Action::ToggleSort(sort) => Message::TabMessage(None, tab::Message::ToggleSort(sort)),
Action::WindowClose => Message::WindowClose, Action::WindowClose => Message::WindowClose,
Action::WindowNew => Message::WindowNew, Action::WindowNew => Message::WindowNew,
} }

View file

@ -16,7 +16,7 @@ use crate::{
app::{Action, Message}, app::{Action, Message},
fl, fl,
key_bind::KeyBind, key_bind::KeyBind,
tab::{self, Location, Tab}, tab::{self, HeadingOptions, Location, Tab},
}; };
macro_rules! menu_button { macro_rules! menu_button {
@ -102,6 +102,28 @@ pub fn context_menu<'a>(
children.push(horizontal_rule(1).into()); children.push(horizontal_rule(1).into());
children.push(menu_item(fl!("select-all"), Action::SelectAll).into()); children.push(menu_item(fl!("select-all"), Action::SelectAll).into());
children.push(menu_item(fl!("paste"), Action::Paste).into()); children.push(menu_item(fl!("paste"), Action::Paste).into());
children.push(horizontal_rule(1).into());
children.push(
menu_item(
fl!("sort-by-name"),
Action::ToggleSort(HeadingOptions::Name),
)
.into(),
);
children.push(
menu_item(
fl!("sort-by-modified"),
Action::ToggleSort(HeadingOptions::Modified),
)
.into(),
);
children.push(
menu_item(
fl!("sort-by-size"),
Action::ToggleSort(HeadingOptions::Size),
)
.into(),
);
} }
} }
Location::Trash => { Location::Trash => {
@ -113,6 +135,28 @@ pub fn context_menu<'a>(
children children
.push(menu_item(fl!("restore-from-trash"), Action::RestoreFromTrash).into()); .push(menu_item(fl!("restore-from-trash"), Action::RestoreFromTrash).into());
} }
children.push(horizontal_rule(1).into());
children.push(
menu_item(
fl!("sort-by-name"),
Action::ToggleSort(HeadingOptions::Name),
)
.into(),
);
children.push(
menu_item(
fl!("sort-by-modified"),
Action::ToggleSort(HeadingOptions::Modified),
)
.into(),
);
children.push(
menu_item(
fl!("sort-by-size"),
Action::ToggleSort(HeadingOptions::Size),
)
.into(),
);
} }
} }