Improve selection logic

This commit is contained in:
Jeremy Soller 2024-01-10 09:47:47 -07:00
parent 69531644ff
commit 07c91042db
No known key found for this signature in database
GPG key ID: DCFCA852D3906975
4 changed files with 113 additions and 64 deletions

View file

@ -11,7 +11,7 @@ use cosmic::{
Element,
};
use crate::{fl, Action, Message};
use crate::{fl, Action, Location, Message};
macro_rules! menu_button {
($($x:expr),+ $(,)?) => (
@ -28,38 +28,56 @@ macro_rules! menu_button {
);
}
pub fn context_menu<'a>(entity: segmented_button::Entity) -> Element<'a, Message> {
pub fn context_menu<'a>(
entity: segmented_button::Entity,
location: &Location,
) -> Element<'a, Message> {
let menu_action = |label, action| {
menu_button!(widget::text(label)).on_press(Message::TabContextAction(entity, action))
};
//TODO: change items based on selection
widget::container(column!(
menu_action(fl!("new-file"), Action::NewFile),
menu_action(fl!("new-folder"), Action::NewFolder),
horizontal_rule(1),
menu_action(fl!("copy"), Action::Copy),
menu_action(fl!("paste"), Action::Paste),
menu_action(fl!("select-all"), Action::SelectAll),
horizontal_rule(1),
menu_action(fl!("move-to-trash"), Action::MoveToTrash),
horizontal_rule(1),
menu_action(fl!("properties"), Action::Properties),
))
.padding(1)
//TODO: move style to libcosmic
.style(theme::Container::custom(|theme| {
let cosmic = theme.cosmic();
let component = &cosmic.background.component;
widget::container::Appearance {
icon_color: Some(component.on.into()),
text_color: Some(component.on.into()),
background: Some(Background::Color(component.base.into())),
border_radius: 8.0.into(),
border_width: 1.0,
border_color: component.divider.into(),
let column = match location {
Location::Path(_) => {
column!(
menu_action(fl!("new-file"), Action::NewFile),
menu_action(fl!("new-folder"), Action::NewFolder),
horizontal_rule(1),
menu_action(fl!("copy"), Action::Copy),
menu_action(fl!("paste"), Action::Paste),
menu_action(fl!("select-all"), Action::SelectAll),
horizontal_rule(1),
menu_action(fl!("move-to-trash"), Action::MoveToTrash),
horizontal_rule(1),
menu_action(fl!("properties"), Action::Properties),
)
}
}))
.width(Length::Fixed(240.0))
.into()
Location::Trash => {
column!(
menu_action(fl!("select-all"), Action::SelectAll),
horizontal_rule(1),
menu_action(fl!("restore-from-trash"), Action::RestoreFromTrash),
horizontal_rule(1),
menu_action(fl!("properties"), Action::Properties),
)
}
};
widget::container(column)
.padding(1)
//TODO: move style to libcosmic
.style(theme::Container::custom(|theme| {
let cosmic = theme.cosmic();
let component = &cosmic.background.component;
widget::container::Appearance {
icon_color: Some(component.on.into()),
text_color: Some(component.on.into()),
background: Some(Background::Color(component.base.into())),
border_radius: 8.0.into(),
border_width: 1.0,
border_color: component.divider.into(),
}
}))
.width(Length::Fixed(240.0))
.into()
}