reorganization, preserved functionality

This commit is contained in:
filipriec
2025-03-24 14:29:28 +01:00
parent cdac78c1bc
commit 1fc9a0e1ff
2 changed files with 76 additions and 68 deletions

View File

@@ -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<dyn std::error::Error>> {
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,