Skip to content

Commit

Permalink
dialog: implement view and sort menu as designed
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Sep 11, 2024
1 parent 36d61d5 commit b851f3d
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use crate::{
config::{Config, Favorite, TabConfig},
fl, home_dir,
localize::LANGUAGE_SORTER,
menu,
mounter::{mounters, MounterItem, MounterItems, MounterKey, Mounters},
tab::{self, ItemMetadata, Location, Tab},
};
Expand Down Expand Up @@ -293,6 +294,7 @@ struct Flags {
/// Messages that are used specifically by our [`App`].
#[derive(Clone, Debug)]
enum Message {
None,
Cancel,
Choice(usize, usize),
Config(Config),
Expand Down Expand Up @@ -682,9 +684,16 @@ impl Application for App {
*/

elements.push(
widget::segmented_control::horizontal(&self.view_model)
.on_activate(Message::ViewSelect)
.width(Length::Shrink)
menu::dialog_menu(&self.tab, &self.key_binds)
.map(|message| match message {
AppMessage::TabMessage(_entity_opt, tab_message) => {
Message::TabMessage(tab_message)
}
unsupported => {
log::warn!("{unsupported:?} not supported in dialog mode");
Message::None
}
})
.into(),
);

Expand Down Expand Up @@ -773,6 +782,7 @@ impl Application for App {
/// Handle application events here.
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::None => {}
Message::Cancel => {
if self.replace_dialog {
self.replace_dialog = false;
Expand Down
78 changes: 77 additions & 1 deletion src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cosmic::{
iced::{Alignment, Background, Border, Length},
theme,
widget::{
button, column, container, divider, horizontal_space,
self, button, column, container, divider, horizontal_space,
menu::{self, key_bind::KeyBind, ItemHeight, ItemWidth, MenuBar},
text, Row,
},
Expand Down Expand Up @@ -240,6 +240,82 @@ pub fn context_menu<'a>(
.into()
}

pub fn dialog_menu<'a>(
tab: &Tab,
key_binds: &HashMap<KeyBind, Action>,
) -> Element<'static, Message> {
let sort_item = |label, sort, dir| {
menu::Item::CheckBox(
label,
tab.config.sort_name == sort && tab.config.sort_direction == dir,
Action::SetSort(sort, dir),
)
};

MenuBar::new(vec![
menu::Tree::with_children(
widget::button::icon(widget::icon::from_name(match tab.config.view {
tab::View::Grid => "view-grid-symbolic",
tab::View::List => "view-list-symbolic",
})),
menu::items(
key_binds,
vec![
menu::Item::CheckBox(
fl!("grid-view"),
matches!(tab.config.view, tab::View::Grid),
Action::TabViewGrid,
),
menu::Item::CheckBox(
fl!("list-view"),
matches!(tab.config.view, tab::View::List),
Action::TabViewList,
),
],
),
),
menu::Tree::with_children(
widget::button::icon(widget::icon::from_name(if tab.config.sort_direction {
"view-sort-ascending-symbolic"
} else {
"view-sort-descending-symbolic"
})),
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))
.spacing(theme::active().cosmic().spacing.space_xxxs.into())
.into()
}

pub fn menu_bar<'a>(
tab_opt: Option<&Tab>,
key_binds: &HashMap<KeyBind, Action>,
Expand Down

0 comments on commit b851f3d

Please sign in to comment.