Nicer context menu sort buttons
Adds an up or down arrow code point to context menu sort buttons.
This commit is contained in:
parent
1a7a4e19aa
commit
7c8bcbe998
2 changed files with 32 additions and 44 deletions
72
src/menu.rs
72
src/menu.rs
|
|
@ -14,6 +14,7 @@ use std::collections::HashMap;
|
|||
|
||||
use crate::{
|
||||
app::{Action, Message},
|
||||
config::TabConfig,
|
||||
fl,
|
||||
key_bind::KeyBind,
|
||||
tab::{self, HeadingOptions, Location, Tab},
|
||||
|
|
@ -57,6 +58,27 @@ pub fn context_menu<'a>(
|
|||
.on_press(tab::Message::ContextAction(action))
|
||||
};
|
||||
|
||||
let TabConfig {
|
||||
sort_name,
|
||||
sort_direction,
|
||||
..
|
||||
} = tab.config;
|
||||
let sort_item = |label, variant| {
|
||||
menu_item(
|
||||
format!(
|
||||
"{} {}",
|
||||
label,
|
||||
match (sort_name == variant, sort_direction) {
|
||||
(true, true) => "\u{2B07}",
|
||||
(true, false) => "\u{2B06}",
|
||||
_ => "",
|
||||
}
|
||||
),
|
||||
Action::ToggleSort(variant),
|
||||
)
|
||||
.into()
|
||||
};
|
||||
|
||||
let mut selected_dir = 0;
|
||||
let mut selected = 0;
|
||||
tab.items_opt().map(|items| {
|
||||
|
|
@ -103,27 +125,10 @@ pub fn context_menu<'a>(
|
|||
children.push(menu_item(fl!("select-all"), Action::SelectAll).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(),
|
||||
);
|
||||
// TODO: Nested menu
|
||||
children.push(sort_item(fl!("sort-by-name"), HeadingOptions::Name));
|
||||
children.push(sort_item(fl!("sort-by-modified"), HeadingOptions::Modified));
|
||||
children.push(sort_item(fl!("sort-by-size"), HeadingOptions::Size));
|
||||
}
|
||||
}
|
||||
Location::Trash => {
|
||||
|
|
@ -136,27 +141,10 @@ pub fn context_menu<'a>(
|
|||
.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(),
|
||||
);
|
||||
// TODO: Nested menu
|
||||
children.push(sort_item(fl!("sort-by-name"), HeadingOptions::Name));
|
||||
children.push(sort_item(fl!("sort-by-modified"), HeadingOptions::Modified));
|
||||
children.push(sort_item(fl!("sort-by-size"), HeadingOptions::Size));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1605,8 +1605,8 @@ impl Tab {
|
|||
//TODO: HACK If we don't reach the bottom of the view, go ahead and add a spacer to do that
|
||||
{
|
||||
let mut max_bottom = 0;
|
||||
for item in items.iter() {
|
||||
if let Some(rect) = item.1.rect_opt.get() {
|
||||
for (_, item) in items {
|
||||
if let Some(rect) = item.rect_opt.get() {
|
||||
let bottom = (rect.y + rect.height).ceil() as usize;
|
||||
if bottom > max_bottom {
|
||||
max_bottom = bottom;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue