forbid jump from the last to the first and vice versa

This commit is contained in:
filipriec
2025-05-25 11:39:25 +02:00
parent 2e1d7fdf2b
commit d28c310704

View File

@@ -58,33 +58,30 @@ pub fn handle_admin_navigation(
*command_message = "Navigating profiles. Use Up/Down. Esc to exit.".to_string(); *command_message = "Navigating profiles. Use Up/Down. Esc to exit.".to_string();
handled = true; handled = true;
} }
Some("next_option") | Some("move_down") => { // move_down acts as next_option Some("next_option") | Some("move_down") => {
admin_state.current_focus = AdminFocus::Tables; admin_state.current_focus = AdminFocus::Tables;
*command_message = "Focus: Tables Pane".to_string(); *command_message = "Focus: Tables Pane".to_string();
handled = true; handled = true;
} }
Some("previous_option") | Some("move_up") => { // move_up acts as previous_option Some("previous_option") | Some("move_up") => {
admin_state.current_focus = AdminFocus::Button3; // Cycle to last button // No wrap-around: Stay on ProfilesPane if trying to go "before" it
*command_message = "Focus: Button 3".to_string(); *command_message = "At first focusable pane.".to_string();
handled = true; handled = true;
} }
// If move_up/move_down were not explicitly for pane nav,
// they would be caught here if not handled above.
// But since we want them for pane nav, this is fine.
_ => handled = false, _ => handled = false,
} }
} }
AdminFocus::InsideProfilesList => { AdminFocus::InsideProfilesList => {
match action.as_deref() { match action.as_deref() {
Some("move_up") => { // Only item navigation here Some("move_up") => {
if profile_count > 0 { if profile_count > 0 {
list_select_previous(&mut admin_state.profile_list_state, profile_count); list_select_previous(&mut admin_state.profile_list_state, profile_count);
*command_message = "".to_string(); *command_message = "".to_string();
handled = true; handled = true;
} }
} }
Some("move_down") => { // Only item navigation here Some("move_down") => {
if profile_count > 0 { if profile_count > 0 {
list_select_next(&mut admin_state.profile_list_state, profile_count); list_select_next(&mut admin_state.profile_list_state, profile_count);
*command_message = "".to_string(); *command_message = "".to_string();
@@ -111,12 +108,11 @@ pub fn handle_admin_navigation(
); );
handled = true; handled = true;
} }
Some("exit_table_scroll") => { // 'esc' Some("exit_table_scroll") => {
admin_state.current_focus = AdminFocus::ProfilesPane; admin_state.current_focus = AdminFocus::ProfilesPane;
*command_message = "Focus: Profiles Pane".to_string(); *command_message = "Focus: Profiles Pane".to_string();
handled = true; handled = true;
} }
// next_option & previous_option are NOT handled here to enforce 'esc' first
_ => handled = false, _ => handled = false,
} }
} }
@@ -146,22 +142,21 @@ pub fn handle_admin_navigation(
if admin_state.current_focus == AdminFocus::InsideTablesList && !admin_state.table_list_state.selected().is_none() { if admin_state.current_focus == AdminFocus::InsideTablesList && !admin_state.table_list_state.selected().is_none() {
*command_message = "Navigating tables. Use Up/Down. Esc to exit.".to_string(); *command_message = "Navigating tables. Use Up/Down. Esc to exit.".to_string();
} else if admin_state.table_list_state.selected().is_none() { } else if admin_state.table_list_state.selected().is_none() {
// If no tables, or no profile, don't enter InsideTablesList or revert
if current_profile_idx.is_none() { if current_profile_idx.is_none() {
*command_message = "No profile selected to view tables.".to_string(); *command_message = "No profile selected to view tables.".to_string();
} else { } else {
*command_message = "No tables in selected profile.".to_string(); *command_message = "No tables in selected profile.".to_string();
} }
admin_state.current_focus = AdminFocus::Tables; // Stay on Tables pane admin_state.current_focus = AdminFocus::Tables;
} }
handled = true; handled = true;
} }
Some("previous_option") | Some("move_up") => { // move_up acts as previous_option Some("previous_option") | Some("move_up") => {
admin_state.current_focus = AdminFocus::ProfilesPane; admin_state.current_focus = AdminFocus::ProfilesPane;
*command_message = "Focus: Profiles Pane".to_string(); *command_message = "Focus: Profiles Pane".to_string();
handled = true; handled = true;
} }
Some("next_option") | Some("move_down") => { // move_down acts as next_option Some("next_option") | Some("move_down") => {
admin_state.current_focus = AdminFocus::Button1; admin_state.current_focus = AdminFocus::Button1;
*command_message = "Focus: Add Logic Button".to_string(); *command_message = "Focus: Add Logic Button".to_string();
handled = true; handled = true;
@@ -172,7 +167,7 @@ pub fn handle_admin_navigation(
AdminFocus::InsideTablesList => { AdminFocus::InsideTablesList => {
match action.as_deref() { match action.as_deref() {
Some("move_up") => { // Only item navigation Some("move_up") => {
let current_profile_idx = admin_state.selected_profile_index let current_profile_idx = admin_state.selected_profile_index
.or_else(|| admin_state.profile_list_state.selected()); .or_else(|| admin_state.profile_list_state.selected());
if let Some(p_idx) = current_profile_idx { if let Some(p_idx) = current_profile_idx {
@@ -191,7 +186,7 @@ pub fn handle_admin_navigation(
handled = true; handled = true;
} }
} }
Some("move_down") => { // Only item navigation Some("move_down") => {
let current_profile_idx = admin_state.selected_profile_index let current_profile_idx = admin_state.selected_profile_index
.or_else(|| admin_state.profile_list_state.selected()); .or_else(|| admin_state.profile_list_state.selected());
if let Some(p_idx) = current_profile_idx { if let Some(p_idx) = current_profile_idx {
@@ -220,21 +215,18 @@ pub fn handle_admin_navigation(
*command_message = format!("Table '{}' set as active.", table_name); *command_message = format!("Table '{}' set as active.", table_name);
handled = true; handled = true;
} }
Some("exit_table_scroll") => { // 'esc' Some("exit_table_scroll") => {
admin_state.current_focus = AdminFocus::Tables; admin_state.current_focus = AdminFocus::Tables;
*command_message = "Focus: Tables Pane".to_string(); *command_message = "Focus: Tables Pane".to_string();
handled = true; handled = true;
} }
// next_option & previous_option are NOT handled here
_ => handled = false, _ => handled = false,
} }
} }
// --- Button Navigation ---
// move_up/move_down on buttons will cycle through them or to adjacent panes (Tables/Profiles)
AdminFocus::Button1 => { AdminFocus::Button1 => {
match action.as_deref() { match action.as_deref() {
Some("select") => { /* ... existing select logic ... */ Some("select") => {
let mut logic_state_profile_name = "None (Global)".to_string(); let mut logic_state_profile_name = "None (Global)".to_string();
let mut selected_table_name_for_logic: Option<String> = None; let mut selected_table_name_for_logic: Option<String> = None;
if let Some(p_idx) = admin_state.selected_profile_index { if let Some(p_idx) = admin_state.selected_profile_index {
@@ -258,12 +250,12 @@ pub fn handle_admin_navigation(
*command_message = "Opening Add Logic...".to_string(); *command_message = "Opening Add Logic...".to_string();
handled = true; handled = true;
} }
Some("previous_option") | Some("move_up") => { // move_up from Button1 goes to Tables Pane Some("previous_option") | Some("move_up") => {
admin_state.current_focus = AdminFocus::Tables; admin_state.current_focus = AdminFocus::Tables;
*command_message = "Focus: Tables Pane".to_string(); *command_message = "Focus: Tables Pane".to_string();
handled = true; handled = true;
} }
Some("next_option") | Some("move_down") => { // move_down from Button1 goes to Button2 Some("next_option") | Some("move_down") => {
admin_state.current_focus = AdminFocus::Button2; admin_state.current_focus = AdminFocus::Button2;
*command_message = "Focus: Add Table Button".to_string(); *command_message = "Focus: Add Table Button".to_string();
handled = true; handled = true;
@@ -274,7 +266,7 @@ pub fn handle_admin_navigation(
AdminFocus::Button2 => { AdminFocus::Button2 => {
match action.as_deref() { match action.as_deref() {
Some("select") => { /* ... existing select logic ... */ Some("select") => {
if let Some(p_idx) = admin_state.selected_profile_index { if let Some(p_idx) = admin_state.selected_profile_index {
if let Some(profile) = app_state.profile_tree.profiles.get(p_idx) { if let Some(profile) = app_state.profile_tree.profiles.get(p_idx) {
let selected_profile_name = profile.name.clone(); let selected_profile_name = profile.name.clone();
@@ -300,12 +292,12 @@ pub fn handle_admin_navigation(
handled = true; handled = true;
} }
} }
Some("previous_option") | Some("move_up") => { // move_up from Button2 goes to Button1 Some("previous_option") | Some("move_up") => {
admin_state.current_focus = AdminFocus::Button1; admin_state.current_focus = AdminFocus::Button1;
*command_message = "Focus: Add Logic Button".to_string(); *command_message = "Focus: Add Logic Button".to_string();
handled = true; handled = true;
} }
Some("next_option") | Some("move_down") => { // move_down from Button2 goes to Button3 Some("next_option") | Some("move_down") => {
admin_state.current_focus = AdminFocus::Button3; admin_state.current_focus = AdminFocus::Button3;
*command_message = "Focus: Change Table Button".to_string(); *command_message = "Focus: Change Table Button".to_string();
handled = true; handled = true;
@@ -320,14 +312,14 @@ pub fn handle_admin_navigation(
*command_message = "Action: Change Table (Not Implemented)".to_string(); *command_message = "Action: Change Table (Not Implemented)".to_string();
handled = true; handled = true;
} }
Some("previous_option") | Some("move_up") => { // move_up from Button3 goes to Button2 Some("previous_option") | Some("move_up") => {
admin_state.current_focus = AdminFocus::Button2; admin_state.current_focus = AdminFocus::Button2;
*command_message = "Focus: Add Table Button".to_string(); *command_message = "Focus: Add Table Button".to_string();
handled = true; handled = true;
} }
Some("next_option") | Some("move_down") => { // move_down from Button3 goes to Profiles Pane Some("next_option") | Some("move_down") => {
admin_state.current_focus = AdminFocus::ProfilesPane; // No wrap-around: Stay on Button3 if trying to go "after" it
*command_message = "Focus: Profiles Pane".to_string(); *command_message = "At last focusable button.".to_string();
handled = true; handled = true;
} }
_ => handled = false, _ => handled = false,