dialog: implement view and sort menu as designed
This commit is contained in:
parent
36d61d574d
commit
b851f3dd66
2 changed files with 90 additions and 4 deletions
|
|
@ -43,6 +43,7 @@ use crate::{
|
||||||
config::{Config, Favorite, TabConfig},
|
config::{Config, Favorite, TabConfig},
|
||||||
fl, home_dir,
|
fl, home_dir,
|
||||||
localize::LANGUAGE_SORTER,
|
localize::LANGUAGE_SORTER,
|
||||||
|
menu,
|
||||||
mounter::{mounters, MounterItem, MounterItems, MounterKey, Mounters},
|
mounter::{mounters, MounterItem, MounterItems, MounterKey, Mounters},
|
||||||
tab::{self, ItemMetadata, Location, Tab},
|
tab::{self, ItemMetadata, Location, Tab},
|
||||||
};
|
};
|
||||||
|
|
@ -293,6 +294,7 @@ struct Flags {
|
||||||
/// Messages that are used specifically by our [`App`].
|
/// Messages that are used specifically by our [`App`].
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
enum Message {
|
enum Message {
|
||||||
|
None,
|
||||||
Cancel,
|
Cancel,
|
||||||
Choice(usize, usize),
|
Choice(usize, usize),
|
||||||
Config(Config),
|
Config(Config),
|
||||||
|
|
@ -682,9 +684,16 @@ impl Application for App {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
elements.push(
|
elements.push(
|
||||||
widget::segmented_control::horizontal(&self.view_model)
|
menu::dialog_menu(&self.tab, &self.key_binds)
|
||||||
.on_activate(Message::ViewSelect)
|
.map(|message| match message {
|
||||||
.width(Length::Shrink)
|
AppMessage::TabMessage(_entity_opt, tab_message) => {
|
||||||
|
Message::TabMessage(tab_message)
|
||||||
|
}
|
||||||
|
unsupported => {
|
||||||
|
log::warn!("{unsupported:?} not supported in dialog mode");
|
||||||
|
Message::None
|
||||||
|
}
|
||||||
|
})
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -773,6 +782,7 @@ impl Application for App {
|
||||||
/// Handle application events here.
|
/// Handle application events here.
|
||||||
fn update(&mut self, message: Message) -> Command<Message> {
|
fn update(&mut self, message: Message) -> Command<Message> {
|
||||||
match message {
|
match message {
|
||||||
|
Message::None => {}
|
||||||
Message::Cancel => {
|
Message::Cancel => {
|
||||||
if self.replace_dialog {
|
if self.replace_dialog {
|
||||||
self.replace_dialog = false;
|
self.replace_dialog = false;
|
||||||
|
|
|
||||||
78
src/menu.rs
78
src/menu.rs
|
|
@ -4,7 +4,7 @@ use cosmic::{
|
||||||
iced::{Alignment, Background, Border, Length},
|
iced::{Alignment, Background, Border, Length},
|
||||||
theme,
|
theme,
|
||||||
widget::{
|
widget::{
|
||||||
button, column, container, divider, horizontal_space,
|
self, button, column, container, divider, horizontal_space,
|
||||||
menu::{self, key_bind::KeyBind, ItemHeight, ItemWidth, MenuBar},
|
menu::{self, key_bind::KeyBind, ItemHeight, ItemWidth, MenuBar},
|
||||||
text, Row,
|
text, Row,
|
||||||
},
|
},
|
||||||
|
|
@ -240,6 +240,82 @@ pub fn context_menu<'a>(
|
||||||
.into()
|
.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>(
|
pub fn menu_bar<'a>(
|
||||||
tab_opt: Option<&Tab>,
|
tab_opt: Option<&Tab>,
|
||||||
key_binds: &HashMap<KeyBind, Action>,
|
key_binds: &HashMap<KeyBind, Action>,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue