diff options
| -rw-r--r-- | schist_desktop_gui/src/config/keys.rs | 3 | ||||
| -rw-r--r-- | schist_desktop_gui/src/gui.rs | 38 | ||||
| -rw-r--r-- | schist_desktop_gui/src/gui/screens/files_screen.rs | 1 | ||||
| -rw-r--r-- | schist_desktop_gui/src/gui/screens/files_screen/update_files_screen.rs | 6 | ||||
| -rw-r--r-- | schist_desktop_gui/src/shortcut.rs | 2 |
5 files changed, 36 insertions, 14 deletions
diff --git a/schist_desktop_gui/src/config/keys.rs b/schist_desktop_gui/src/config/keys.rs index fef2dc3..d72fb12 100644 --- a/schist_desktop_gui/src/config/keys.rs +++ b/schist_desktop_gui/src/config/keys.rs @@ -7,6 +7,7 @@ use crate::{ #[derive(Debug, Clone)] pub struct Keyboard { + pub activate: KeyBind, pub goto_next_item: KeyBind, pub goto_prev_item: KeyBind, pub goto_next_view: KeyBind, @@ -21,6 +22,7 @@ pub struct Keyboard { impl Default for Keyboard { fn default() -> Self { Self { + activate: KeyBind::activate(), goto_next_item: KeyBind::goto_next_item(), goto_prev_item: KeyBind::goto_prev_item(), goto_next_view: KeyBind::goto_next_view(), @@ -37,6 +39,7 @@ impl Default for Keyboard { impl Keyboard { pub fn shortcuts(&self) -> Vec<Shortcut> { vec![ + shortcut(self.activate.clone(), Command::Activate), shortcut(self.goto_next_item.clone(), Command::GotoNextItem), shortcut(self.goto_prev_item.clone(), Command::GotoPrevItem), shortcut(self.goto_next_view.clone(), Command::GotoNextView), diff --git a/schist_desktop_gui/src/gui.rs b/schist_desktop_gui/src/gui.rs index ae8e034..eb2fce9 100644 --- a/schist_desktop_gui/src/gui.rs +++ b/schist_desktop_gui/src/gui.rs @@ -84,6 +84,12 @@ impl Gui { .find_map(|shortcut| shortcut.execute(&key_bind)) { match command { + crate::shortcut::Command::Activate => match self.active_screen { + Screen::FilesScreen => self + .update_files_screen(files_screen::Message::ActivateSelectedOption), + Screen::MainScreen => iced::Task::none(), + }, + crate::shortcut::Command::GotoNextView => { self.main_screen.update(main_screen::Message::SelectView( self.main_screen.active_view.next(), @@ -160,20 +166,24 @@ impl Gui { } iced::Task::none() } - Message::FilesScreenMessage(message) => match self.files_screen.update(message) { - files_screen::Action::None => iced::Task::none(), - files_screen::Action::OpenedFile(sqlite_connection) => { - let mut connection = sqlite_connection.connection; - let buckets = get_all_buckets(&mut connection).map_err(FetchError::new); - let accounts = get_all_accounts(&mut connection).map_err(FetchError::new); - self.connection = Some(connection); - self.active_screen = Screen::MainScreen; - iced::Task::batch(vec![ - self.update(Message::RefetchedBuckets(buckets)), - self.update(Message::RefetchedAccounts(accounts)), - ]) - } - }, + Message::FilesScreenMessage(message) => self.update_files_screen(message), + } + } + + fn update_files_screen(&mut self, message: files_screen::Message) -> iced::Task<Message> { + match self.files_screen.update(message) { + files_screen::Action::None => iced::Task::none(), + files_screen::Action::OpenedFile(sqlite_connection) => { + let mut connection = sqlite_connection.connection; + let buckets = get_all_buckets(&mut connection).map_err(FetchError::new); + let accounts = get_all_accounts(&mut connection).map_err(FetchError::new); + self.connection = Some(connection); + self.active_screen = Screen::MainScreen; + iced::Task::batch(vec![ + self.update(Message::RefetchedBuckets(buckets)), + self.update(Message::RefetchedAccounts(accounts)), + ]) + } } } } diff --git a/schist_desktop_gui/src/gui/screens/files_screen.rs b/schist_desktop_gui/src/gui/screens/files_screen.rs index 373b54f..9757355 100644 --- a/schist_desktop_gui/src/gui/screens/files_screen.rs +++ b/schist_desktop_gui/src/gui/screens/files_screen.rs @@ -23,6 +23,7 @@ pub enum OptionId { #[derive(Clone, Debug, PartialEq)] pub enum Message { NavigationMessage(navigation::Message<Panel<OptionId>>), + ActivateSelectedOption, NextOption, PrevOption, } diff --git a/schist_desktop_gui/src/gui/screens/files_screen/update_files_screen.rs b/schist_desktop_gui/src/gui/screens/files_screen/update_files_screen.rs index 82ca7b6..aa47f56 100644 --- a/schist_desktop_gui/src/gui/screens/files_screen/update_files_screen.rs +++ b/schist_desktop_gui/src/gui/screens/files_screen/update_files_screen.rs @@ -18,6 +18,12 @@ impl<'a> Component<'a, Message, Action> for FilesScreen { Message::NavigationMessage(message) => self.update_options(message), Message::NextOption => self.update_options(navigation::Message::SelectNext), Message::PrevOption => self.update_options(navigation::Message::SelectPrev), + Message::ActivateSelectedOption => match &self.options.active_option { + Some(option) => { + self.update_options(navigation::Message::ActivateOption(option.clone())) + } + None => Action::None, + }, } } } diff --git a/schist_desktop_gui/src/shortcut.rs b/schist_desktop_gui/src/shortcut.rs index 0b8cb7a..1de2bad 100644 --- a/schist_desktop_gui/src/shortcut.rs +++ b/schist_desktop_gui/src/shortcut.rs @@ -25,6 +25,7 @@ impl Shortcut { #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Command { + Activate, GotoNextItem, GotoPrevItem, GotoNextView, @@ -115,6 +116,7 @@ impl KeyBind { default!(goto_view_1, "1", Modifiers::CTRL); default!(goto_view_2, "2", Modifiers::CTRL); default!(goto_view_3, "3", Modifiers::CTRL); + default!(activate, Enter, Modifiers::EMPTY); } impl From<(keyboard::Key, keyboard::Modifiers)> for KeyBind { |
