|
| 1 | +use crate::{ |
| 2 | + app::Message, |
| 3 | + context::ContextPage, |
| 4 | + core::models::{List, Task}, |
| 5 | + dialog::{DialogAction, DialogPage}, |
| 6 | +}; |
| 7 | +use cosmic::{ |
| 8 | + iced::keyboard::{Key, Modifiers}, |
| 9 | + widget::{self, menu::Action as MenuAction, segmented_button}, |
| 10 | +}; |
| 11 | + |
| 12 | +#[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 13 | +pub enum Action { |
| 14 | + About, |
| 15 | + Settings, |
| 16 | + WindowClose, |
| 17 | + WindowNew, |
| 18 | + NewList, |
| 19 | + DeleteList, |
| 20 | + RenameList, |
| 21 | + Icon, |
| 22 | +} |
| 23 | + |
| 24 | +#[derive(Debug, Clone)] |
| 25 | +pub enum ApplicationAction { |
| 26 | + WindowClose, |
| 27 | + WindowNew, |
| 28 | + Key(Modifiers, Key), |
| 29 | + Modifiers(Modifiers), |
| 30 | + AppTheme(usize), |
| 31 | + SystemThemeModeChange, |
| 32 | + Focus(widget::Id), |
| 33 | + NavMenuAction(NavMenuAction), |
| 34 | + Dialog(DialogAction), |
| 35 | + ToggleContextDrawer, |
| 36 | + ToggleContextPage(ContextPage), |
| 37 | +} |
| 38 | + |
| 39 | +#[derive(Debug, Clone)] |
| 40 | +pub enum TasksAction { |
| 41 | + PopulateLists(Vec<List>), |
| 42 | + Export(Vec<Task>), |
| 43 | + AddList(List), |
| 44 | + DeleteList(Option<segmented_button::Entity>), |
| 45 | + FetchLists, |
| 46 | +} |
| 47 | + |
| 48 | +impl MenuAction for Action { |
| 49 | + type Message = Message; |
| 50 | + fn message(&self) -> Self::Message { |
| 51 | + match self { |
| 52 | + Action::About => { |
| 53 | + Message::Application(ApplicationAction::ToggleContextPage(ContextPage::About)) |
| 54 | + } |
| 55 | + Action::Settings => { |
| 56 | + Message::Application(ApplicationAction::ToggleContextPage(ContextPage::Settings)) |
| 57 | + } |
| 58 | + Action::WindowClose => Message::Application(ApplicationAction::WindowClose), |
| 59 | + Action::WindowNew => Message::Application(ApplicationAction::WindowNew), |
| 60 | + Action::NewList => Message::Application(ApplicationAction::Dialog(DialogAction::Open( |
| 61 | + DialogPage::New(String::new()), |
| 62 | + ))), |
| 63 | + Action::Icon => Message::Application(ApplicationAction::Dialog(DialogAction::Open( |
| 64 | + DialogPage::Icon(None, String::new()), |
| 65 | + ))), |
| 66 | + Action::RenameList => Message::Application(ApplicationAction::Dialog( |
| 67 | + DialogAction::Open(DialogPage::Rename(None, String::new())), |
| 68 | + )), |
| 69 | + Action::DeleteList => Message::Application(ApplicationAction::Dialog( |
| 70 | + DialogAction::Open(DialogPage::Delete(None)), |
| 71 | + )), |
| 72 | + } |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +#[derive(Debug, Copy, Clone, Eq, PartialEq)] |
| 77 | +pub enum NavMenuAction { |
| 78 | + Rename(segmented_button::Entity), |
| 79 | + SetIcon(segmented_button::Entity), |
| 80 | + Delete(segmented_button::Entity), |
| 81 | +} |
| 82 | + |
| 83 | +impl MenuAction for NavMenuAction { |
| 84 | + type Message = cosmic::app::Message<Message>; |
| 85 | + |
| 86 | + fn message(&self) -> Self::Message { |
| 87 | + cosmic::app::Message::App(Message::Application(ApplicationAction::NavMenuAction( |
| 88 | + *self, |
| 89 | + ))) |
| 90 | + } |
| 91 | +} |
0 commit comments