From 1fc9a0e1ffa41ecaf35fea6660e2669a3a2ba836 Mon Sep 17 00:00:00 2001 From: filipriec Date: Mon, 24 Mar 2025 14:29:28 +0100 Subject: [PATCH] reorganization, preserved functionality --- client/src/modes/general/navigation.rs | 76 ++++++++++++++++++++++++-- client/src/modes/handlers/event.rs | 68 ++--------------------- 2 files changed, 76 insertions(+), 68 deletions(-) diff --git a/client/src/modes/general/navigation.rs b/client/src/modes/general/navigation.rs index ed6017d..1c68747 100644 --- a/client/src/modes/general/navigation.rs +++ b/client/src/modes/general/navigation.rs @@ -1,9 +1,69 @@ // src/modes/general/navigation.rs -// src/modes/general/navigation.rs +use crossterm::event::KeyEvent; +use crate::config::binds::config::Config; use crate::state::state::AppState; use crate::ui::handlers::form::FormState; -use crate::modes::handlers::event; + +pub async fn handle_navigation_event( + key: KeyEvent, + config: &Config, + form_state: &mut FormState, + app_state: &mut AppState, + command_mode: &mut bool, + command_input: &mut String, + command_message: &mut String, +) -> Result<(bool, String), Box> { + if let Some(action) = config.get_general_action(key.code, key.modifiers) { + match action { + "move_up" => { + move_up(app_state); + return Ok((false, String::new())); + } + "move_down" => { + let item_count = if app_state.ui.show_intro { + 2 // Intro options count + } else { + app_state.profile_tree.profiles.len() // Admin panel items + }; + move_down(app_state, item_count); + return Ok((false, String::new())); + } + "next_option" => { + next_option(app_state, 2); // Intro has 2 options + return Ok((false, String::new())); + } + "previous_option" => { + previous_option(app_state); + return Ok((false, String::new())); + } + "select" => { + select(app_state); + return Ok((false, "Selected".to_string())); + } + "toggle_sidebar" => { + toggle_sidebar(app_state); + return Ok((false, format!("Sidebar {}", + if app_state.ui.show_sidebar { "shown" } else { "hidden" } + ))); + } + "next_field" => { + next_field(form_state); + return Ok((false, String::new())); + } + "prev_field" => { + prev_field(form_state); + return Ok((false, String::new())); + } + "enter_command_mode" => { + handle_enter_command_mode(command_mode, command_input, command_message); + return Ok((false, String::new())); + } + _ => {} + } + } + Ok((false, String::new())) +} pub fn move_up(app_state: &mut AppState) { if app_state.ui.show_intro { @@ -104,8 +164,12 @@ pub fn prev_field(form_state: &mut FormState) { } } -pub fn handle_enter_command_mode(handler: &mut event::EventHandler) { - handler.command_mode = true; - handler.command_input.clear(); - handler.command_message.clear(); +pub fn handle_enter_command_mode( + command_mode: &mut bool, + command_input: &mut String, + command_message: &mut String +) { + *command_mode = true; + command_input.clear(); + command_message.clear(); } diff --git a/client/src/modes/handlers/event.rs b/client/src/modes/handlers/event.rs index 1188dc7..9150501 100644 --- a/client/src/modes/handlers/event.rs +++ b/client/src/modes/handlers/event.rs @@ -12,8 +12,8 @@ use crate::ui::handlers::rat_state::UiStateHandler; use crate::modes::{ common::{command_mode}, canvas::{edit, read_only, common}, + general::navigation, }; -use crate::modes::navigation; use crate::config::binds::key_sequences::KeySequenceTracker; use crate::modes::handlers::mode_manager::{ModeManager, AppMode}; @@ -70,12 +70,15 @@ impl EventHandler { // Mode-specific handling match current_mode { AppMode::General => { - return self.handle_general_mode( + return navigation::handle_navigation_event( key, config, form_state, app_state, - ); + &mut self.command_mode, + &mut self.command_input, + &mut self.command_message, + ).await; }, AppMode::ReadOnly => { @@ -240,65 +243,6 @@ impl EventHandler { Ok((false, self.command_message.clone())) } - // Helper method for handling general mode actions - fn handle_general_mode( - &mut self, - key: KeyEvent, - config: &Config, - form_state: &mut FormState, - app_state: &mut crate::state::state::AppState, - ) -> Result<(bool, String), Box> { - if let Some(action) = config.get_general_action(key.code, key.modifiers) { - match action { - "move_up" => { - navigation::move_up(app_state); - return Ok((false, String::new())); - } - "move_down" => { - let item_count = if app_state.ui.show_intro { - 2 // Intro options count - } else { - app_state.profile_tree.profiles.len() // Admin panel items - }; - navigation::move_down(app_state, item_count); - return Ok((false, String::new())); - } - "next_option" => { - navigation::next_option(app_state, 2); // Intro has 2 options - return Ok((false, String::new())); - } - "previous_option" => { - navigation::previous_option(app_state); - return Ok((false, String::new())); - } - "select" => { - navigation::select(app_state); - return Ok((false, "Selected".to_string())); - } - "toggle_sidebar" => { - navigation::toggle_sidebar(app_state); - return Ok((false, format!("Sidebar {}", - if app_state.ui.show_sidebar { "shown" } else { "hidden" } - ))); - } - "next_field" => { - navigation::next_field(form_state); - return Ok((false, String::new())); - } - "prev_field" => { - navigation::prev_field(form_state); - return Ok((false, String::new())); - } - "enter_command_mode" => { - navigation::handle_enter_command_mode(self); - return Ok((false, String::new())); - } - _ => {} - } - } - Ok((false, String::new())) - } - // Helper method for handling core application actions (not navigation) async fn handle_core_action( &mut self,