reorganization, preserved functionality
This commit is contained in:
@@ -1,9 +1,69 @@
|
|||||||
// src/modes/general/navigation.rs
|
// 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::state::state::AppState;
|
||||||
use crate::ui::handlers::form::FormState;
|
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<dyn std::error::Error>> {
|
||||||
|
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) {
|
pub fn move_up(app_state: &mut AppState) {
|
||||||
if app_state.ui.show_intro {
|
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) {
|
pub fn handle_enter_command_mode(
|
||||||
handler.command_mode = true;
|
command_mode: &mut bool,
|
||||||
handler.command_input.clear();
|
command_input: &mut String,
|
||||||
handler.command_message.clear();
|
command_message: &mut String
|
||||||
|
) {
|
||||||
|
*command_mode = true;
|
||||||
|
command_input.clear();
|
||||||
|
command_message.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ use crate::ui::handlers::rat_state::UiStateHandler;
|
|||||||
use crate::modes::{
|
use crate::modes::{
|
||||||
common::{command_mode},
|
common::{command_mode},
|
||||||
canvas::{edit, read_only, common},
|
canvas::{edit, read_only, common},
|
||||||
|
general::navigation,
|
||||||
};
|
};
|
||||||
use crate::modes::navigation;
|
|
||||||
use crate::config::binds::key_sequences::KeySequenceTracker;
|
use crate::config::binds::key_sequences::KeySequenceTracker;
|
||||||
use crate::modes::handlers::mode_manager::{ModeManager, AppMode};
|
use crate::modes::handlers::mode_manager::{ModeManager, AppMode};
|
||||||
|
|
||||||
@@ -70,12 +70,15 @@ impl EventHandler {
|
|||||||
// Mode-specific handling
|
// Mode-specific handling
|
||||||
match current_mode {
|
match current_mode {
|
||||||
AppMode::General => {
|
AppMode::General => {
|
||||||
return self.handle_general_mode(
|
return navigation::handle_navigation_event(
|
||||||
key,
|
key,
|
||||||
config,
|
config,
|
||||||
form_state,
|
form_state,
|
||||||
app_state,
|
app_state,
|
||||||
);
|
&mut self.command_mode,
|
||||||
|
&mut self.command_input,
|
||||||
|
&mut self.command_message,
|
||||||
|
).await;
|
||||||
},
|
},
|
||||||
|
|
||||||
AppMode::ReadOnly => {
|
AppMode::ReadOnly => {
|
||||||
@@ -240,65 +243,6 @@ impl EventHandler {
|
|||||||
Ok((false, self.command_message.clone()))
|
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)
|
// Helper method for handling core application actions (not navigation)
|
||||||
async fn handle_core_action(
|
async fn handle_core_action(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|||||||
Reference in New Issue
Block a user