add logic, not working tho
This commit is contained in:
@@ -2,3 +2,4 @@
|
||||
|
||||
pub mod admin_nav;
|
||||
pub mod add_table_nav;
|
||||
pub mod add_logic_nav;
|
||||
|
||||
215
client/src/functions/modes/navigation/add_logic_nav.rs
Normal file
215
client/src/functions/modes/navigation/add_logic_nav.rs
Normal file
@@ -0,0 +1,215 @@
|
||||
// client/src/functions/modes/navigation/add_logic_nav.rs
|
||||
use crate::config::binds::config::Config;
|
||||
use crate::state::{
|
||||
app::state::AppState,
|
||||
pages::add_logic::{AddLogicFocus, AddLogicState},
|
||||
app::buffer::AppView,
|
||||
app::buffer::BufferState,
|
||||
};
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
use crossterm::event::{KeyEvent};
|
||||
use crate::services::GrpcClient;
|
||||
use tokio::sync::mpsc;
|
||||
use anyhow::Result;
|
||||
use common::proto::multieko2::table_script::{PostTableScriptRequest};
|
||||
|
||||
pub type SaveLogicResultSender = mpsc::Sender<Result<String>>;
|
||||
|
||||
pub fn handle_add_logic_navigation(
|
||||
key: KeyEvent,
|
||||
config: &Config,
|
||||
app_state: &mut AppState,
|
||||
add_logic_state: &mut AddLogicState,
|
||||
is_edit_mode: &mut bool,
|
||||
buffer_state: &mut BufferState,
|
||||
grpc_client: GrpcClient,
|
||||
save_logic_sender: SaveLogicResultSender,
|
||||
command_message: &mut String,
|
||||
) -> bool {
|
||||
let action = config.get_general_action(key.code, key.modifiers).map(String::from);
|
||||
let mut handled = false;
|
||||
|
||||
// Check if focus is on canvas input fields
|
||||
let focus_on_canvas_inputs = matches!(
|
||||
add_logic_state.current_focus,
|
||||
AddLogicFocus::InputLogicName | AddLogicFocus::InputTargetColumn | AddLogicFocus::InputDescription
|
||||
);
|
||||
|
||||
// Handle script content editing separately (multiline)
|
||||
if *is_edit_mode && add_logic_state.current_focus == AddLogicFocus::InputScriptContent {
|
||||
match key.code {
|
||||
crossterm::event::KeyCode::Char(c) => {
|
||||
add_logic_state.script_content_input.push(c);
|
||||
add_logic_state.has_unsaved_changes = true;
|
||||
handled = true;
|
||||
}
|
||||
crossterm::event::KeyCode::Enter => {
|
||||
add_logic_state.script_content_input.push('\n');
|
||||
add_logic_state.has_unsaved_changes = true;
|
||||
add_logic_state.script_content_scroll.0 = add_logic_state.script_content_scroll.0.saturating_add(1);
|
||||
handled = true;
|
||||
}
|
||||
crossterm::event::KeyCode::Backspace => {
|
||||
if !add_logic_state.script_content_input.is_empty() {
|
||||
add_logic_state.script_content_input.pop();
|
||||
add_logic_state.has_unsaved_changes = true;
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
if !handled {
|
||||
match action.as_deref() {
|
||||
Some("exit_view") | Some("cancel_action") => {
|
||||
buffer_state.update_history(AppView::Admin); // Fixed: was AdminPanel
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
*command_message = "Exited Add Logic".to_string();
|
||||
handled = true;
|
||||
}
|
||||
Some("next_field") => {
|
||||
let previous_focus = add_logic_state.current_focus;
|
||||
add_logic_state.current_focus = match add_logic_state.current_focus {
|
||||
AddLogicFocus::InputLogicName => AddLogicFocus::InputTargetColumn,
|
||||
AddLogicFocus::InputTargetColumn => AddLogicFocus::InputDescription,
|
||||
AddLogicFocus::InputDescription => AddLogicFocus::InputScriptContent,
|
||||
AddLogicFocus::InputScriptContent => AddLogicFocus::SaveButton,
|
||||
AddLogicFocus::SaveButton => AddLogicFocus::CancelButton,
|
||||
AddLogicFocus::CancelButton => AddLogicFocus::InputLogicName,
|
||||
};
|
||||
|
||||
// Update canvas field index only when moving between canvas inputs
|
||||
if matches!(previous_focus, AddLogicFocus::InputLogicName | AddLogicFocus::InputTargetColumn) {
|
||||
if matches!(add_logic_state.current_focus, AddLogicFocus::InputTargetColumn | AddLogicFocus::InputDescription) {
|
||||
let new_field = match add_logic_state.current_focus {
|
||||
AddLogicFocus::InputTargetColumn => 1,
|
||||
AddLogicFocus::InputDescription => 2,
|
||||
_ => 0,
|
||||
};
|
||||
add_logic_state.set_current_field(new_field);
|
||||
}
|
||||
}
|
||||
|
||||
// Update focus outside canvas flag
|
||||
app_state.ui.focus_outside_canvas = !matches!(
|
||||
add_logic_state.current_focus,
|
||||
AddLogicFocus::InputLogicName | AddLogicFocus::InputTargetColumn | AddLogicFocus::InputDescription
|
||||
);
|
||||
|
||||
*command_message = format!("Focus: {:?}", add_logic_state.current_focus);
|
||||
*is_edit_mode = matches!(add_logic_state.current_focus,
|
||||
AddLogicFocus::InputLogicName | AddLogicFocus::InputTargetColumn |
|
||||
AddLogicFocus::InputDescription | AddLogicFocus::InputScriptContent);
|
||||
handled = true;
|
||||
}
|
||||
Some("prev_field") => {
|
||||
let previous_focus = add_logic_state.current_focus;
|
||||
add_logic_state.current_focus = match add_logic_state.current_focus {
|
||||
AddLogicFocus::InputLogicName => AddLogicFocus::CancelButton,
|
||||
AddLogicFocus::InputTargetColumn => AddLogicFocus::InputLogicName,
|
||||
AddLogicFocus::InputDescription => AddLogicFocus::InputTargetColumn,
|
||||
AddLogicFocus::InputScriptContent => AddLogicFocus::InputDescription,
|
||||
AddLogicFocus::SaveButton => AddLogicFocus::InputScriptContent,
|
||||
AddLogicFocus::CancelButton => AddLogicFocus::SaveButton,
|
||||
};
|
||||
|
||||
// Update canvas field index only when moving between canvas inputs
|
||||
if matches!(previous_focus, AddLogicFocus::InputTargetColumn | AddLogicFocus::InputDescription) {
|
||||
if matches!(add_logic_state.current_focus, AddLogicFocus::InputLogicName | AddLogicFocus::InputTargetColumn) {
|
||||
let new_field = match add_logic_state.current_focus {
|
||||
AddLogicFocus::InputLogicName => 0,
|
||||
AddLogicFocus::InputTargetColumn => 1,
|
||||
_ => 0,
|
||||
};
|
||||
add_logic_state.set_current_field(new_field);
|
||||
}
|
||||
}
|
||||
|
||||
// Update focus outside canvas flag
|
||||
app_state.ui.focus_outside_canvas = !matches!(
|
||||
add_logic_state.current_focus,
|
||||
AddLogicFocus::InputLogicName | AddLogicFocus::InputTargetColumn | AddLogicFocus::InputDescription
|
||||
);
|
||||
|
||||
*command_message = format!("Focus: {:?}", add_logic_state.current_focus);
|
||||
*is_edit_mode = matches!(add_logic_state.current_focus,
|
||||
AddLogicFocus::InputLogicName | AddLogicFocus::InputTargetColumn |
|
||||
AddLogicFocus::InputDescription | AddLogicFocus::InputScriptContent);
|
||||
handled = true;
|
||||
}
|
||||
Some("select") => {
|
||||
match add_logic_state.current_focus {
|
||||
AddLogicFocus::SaveButton => {
|
||||
if let Some(table_def_id) = add_logic_state.selected_table_id {
|
||||
if add_logic_state.target_column_input.trim().is_empty() {
|
||||
*command_message = "Cannot save: Target Column cannot be empty.".to_string();
|
||||
} else if add_logic_state.script_content_input.trim().is_empty() {
|
||||
*command_message = "Cannot save: Script Content cannot be empty.".to_string();
|
||||
} else {
|
||||
*command_message = "Saving logic script...".to_string();
|
||||
app_state.show_loading_dialog("Saving Script", "Please wait...");
|
||||
|
||||
let request = PostTableScriptRequest {
|
||||
table_definition_id: table_def_id,
|
||||
target_column: add_logic_state.target_column_input.trim().to_string(),
|
||||
script: add_logic_state.script_content_input.trim().to_string(),
|
||||
description: add_logic_state.description_input.trim().to_string(),
|
||||
};
|
||||
|
||||
let mut client_clone = grpc_client.clone();
|
||||
let sender_clone = save_logic_sender.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
let result = client_clone.post_table_script(request).await
|
||||
.map(|res| format!("Script saved with ID: {}", res.id))
|
||||
.map_err(|e| anyhow::anyhow!("gRPC call failed: {}", e));
|
||||
let _ = sender_clone.send(result).await;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
*command_message = "Cannot save: Table Definition ID is missing.".to_string();
|
||||
}
|
||||
handled = true;
|
||||
}
|
||||
AddLogicFocus::CancelButton => {
|
||||
buffer_state.update_history(AppView::Admin); // Fixed: was AdminPanel
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
*command_message = "Cancelled Add Logic".to_string();
|
||||
handled = true;
|
||||
}
|
||||
AddLogicFocus::InputLogicName | AddLogicFocus::InputTargetColumn |
|
||||
AddLogicFocus::InputDescription | AddLogicFocus::InputScriptContent => {
|
||||
if !*is_edit_mode {
|
||||
*is_edit_mode = true;
|
||||
*command_message = "Edit mode: ON".to_string();
|
||||
}
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some("toggle_edit_mode") => {
|
||||
*is_edit_mode = !*is_edit_mode;
|
||||
*command_message = format!("Edit mode: {}", if *is_edit_mode { "ON" } else { "OFF" });
|
||||
handled = true;
|
||||
}
|
||||
// Handle script content scrolling when not in edit mode
|
||||
_ if !*is_edit_mode && add_logic_state.current_focus == AddLogicFocus::InputScriptContent => {
|
||||
match action.as_deref() {
|
||||
Some("move_up") => {
|
||||
add_logic_state.script_content_scroll.0 = add_logic_state.script_content_scroll.0.saturating_sub(1);
|
||||
handled = true;
|
||||
}
|
||||
Some("move_down") => {
|
||||
add_logic_state.script_content_scroll.0 = add_logic_state.script_content_scroll.0.saturating_add(1);
|
||||
handled = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
handled
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use crossterm::event::KeyEvent;
|
||||
use crate::state::app::buffer::AppView;
|
||||
use crate::state::app::buffer::BufferState;
|
||||
use crate::state::pages::add_table::{AddTableState, LinkDefinition};
|
||||
use crate::state::pages::add_logic::AddLogicState;
|
||||
use ratatui::widgets::ListState;
|
||||
|
||||
// --- Helper functions for ListState navigation (similar to TableState) ---
|
||||
@@ -68,11 +69,10 @@ pub fn handle_admin_navigation(
|
||||
}
|
||||
}
|
||||
AdminFocus::Tables => {
|
||||
// Do nothing when focus is on the Tables pane itself
|
||||
*command_message = "Press Enter to select and scroll tables".to_string();
|
||||
}
|
||||
AdminFocus::InsideTablesList => { // Scroll inside
|
||||
if let Some(p_idx) = admin_state.profile_list_state.selected().or(admin_state.selected_profile_index) { // Use nav or persistent selection
|
||||
AdminFocus::InsideTablesList => {
|
||||
if let Some(p_idx) = admin_state.profile_list_state.selected().or(admin_state.selected_profile_index) {
|
||||
if let Some(profile) = app_state.profile_tree.profiles.get(p_idx) {
|
||||
list_select_previous(&mut admin_state.table_list_state, profile.tables.len());
|
||||
}
|
||||
@@ -85,17 +85,15 @@ pub fn handle_admin_navigation(
|
||||
match current_focus {
|
||||
AdminFocus::Profiles => {
|
||||
if profile_count > 0 {
|
||||
// Updates navigation state, resets table state
|
||||
admin_state.next_profile(profile_count);
|
||||
*command_message = "Navigated profiles list".to_string();
|
||||
}
|
||||
}
|
||||
AdminFocus::Tables => {
|
||||
// Do nothing when focus is on the Tables pane itself
|
||||
*command_message = "Press Enter to select and scroll tables".to_string();
|
||||
}
|
||||
AdminFocus::InsideTablesList => { // Scroll inside
|
||||
if let Some(p_idx) = admin_state.profile_list_state.selected().or(admin_state.selected_profile_index) { // Use nav or persistent selection
|
||||
AdminFocus::InsideTablesList => {
|
||||
if let Some(p_idx) = admin_state.profile_list_state.selected().or(admin_state.selected_profile_index) {
|
||||
if let Some(profile) = app_state.profile_tree.profiles.get(p_idx) {
|
||||
list_select_next(&mut admin_state.table_list_state, profile.tables.len());
|
||||
}
|
||||
@@ -110,18 +108,16 @@ pub fn handle_admin_navigation(
|
||||
let is_next = action.as_deref() == Some("next_option");
|
||||
|
||||
admin_state.current_focus = match old_focus {
|
||||
AdminFocus::Profiles => if is_next { AdminFocus::Tables } else { AdminFocus::Button3 }, // P -> T (l) or P -> B3 (h)
|
||||
AdminFocus::Tables => if is_next { AdminFocus::Button1 } else { AdminFocus::Profiles }, // T -> B1 (l) or T -> P (h)
|
||||
AdminFocus::Button1 => if is_next { AdminFocus::Button2 } else { AdminFocus::Tables }, // B1 -> B2 (l) or B1 -> T (h)
|
||||
AdminFocus::Button2 => if is_next { AdminFocus::Button3 } else { AdminFocus::Button1 }, // B2 -> B3 (l) or B2 -> B1 (h)
|
||||
AdminFocus::Button3 => if is_next { AdminFocus::Profiles } else { AdminFocus::Button2 }, // B3 -> P (l) or B3 -> B2 (h)
|
||||
// Prevent horizontal nav when inside lists
|
||||
AdminFocus::Profiles => if is_next { AdminFocus::Tables } else { AdminFocus::Button3 },
|
||||
AdminFocus::Tables => if is_next { AdminFocus::Button1 } else { AdminFocus::Profiles },
|
||||
AdminFocus::Button1 => if is_next { AdminFocus::Button2 } else { AdminFocus::Tables },
|
||||
AdminFocus::Button2 => if is_next { AdminFocus::Button3 } else { AdminFocus::Button1 },
|
||||
AdminFocus::Button3 => if is_next { AdminFocus::Profiles } else { AdminFocus::Button2 },
|
||||
AdminFocus::InsideTablesList => old_focus,
|
||||
};
|
||||
|
||||
let new_focus = admin_state.current_focus;
|
||||
new_focus = admin_state.current_focus; // Update new_focus after changing admin_state.current_focus
|
||||
*command_message = format!("Focus set to {:?}", new_focus);
|
||||
// Auto-select first item only when moving from Profiles to Tables via 'l'
|
||||
if old_focus == AdminFocus::Profiles && new_focus == AdminFocus::Tables && is_next {
|
||||
if let Some(profile_idx) = admin_state.profile_list_state.selected() {
|
||||
if let Some(profile) = app_state.profile_tree.profiles.get(profile_idx) {
|
||||
@@ -137,37 +133,24 @@ pub fn handle_admin_navigation(
|
||||
admin_state.table_list_state.select(None);
|
||||
}
|
||||
}
|
||||
// Clear table nav selection if moving away from Tables
|
||||
if old_focus == AdminFocus::Tables && new_focus != AdminFocus::Tables {
|
||||
if old_focus == AdminFocus::Tables && new_focus != AdminFocus::Tables && old_focus != AdminFocus::InsideTablesList {
|
||||
admin_state.table_list_state.select(None);
|
||||
}
|
||||
// Clear profile nav selection if moving away from Profiles
|
||||
if old_focus == AdminFocus::Profiles && new_focus != AdminFocus::Profiles {
|
||||
// Maybe keep profile nav highlight? Let's try clearing it.
|
||||
// admin_state.profile_list_state.select(None); // Optional: clear profile nav highlight
|
||||
}
|
||||
|
||||
// No change needed for profile_list_state clearing here based on current logic
|
||||
}
|
||||
// --- Selection ---
|
||||
Some("select") => {
|
||||
match current_focus {
|
||||
AdminFocus::Profiles => {
|
||||
// --- Perform persistent selection ---
|
||||
// Set the persistent selection to the currently navigated item
|
||||
if let Some(nav_idx) = admin_state.profile_list_state.selected() {
|
||||
admin_state.selected_profile_index = Some(nav_idx);
|
||||
|
||||
// Move focus to Tables (like pressing 'l')
|
||||
new_focus = AdminFocus::Tables;
|
||||
|
||||
// Select the first table for navigation highlight
|
||||
admin_state.table_list_state.select(None); // Clear table nav first
|
||||
admin_state.selected_table_index = None; // Clear persistent table selection
|
||||
admin_state.table_list_state.select(None);
|
||||
admin_state.selected_table_index = None;
|
||||
if let Some(profile) = app_state.profile_tree.profiles.get(nav_idx) {
|
||||
if !profile.tables.is_empty() {
|
||||
admin_state.table_list_state.select(Some(0));
|
||||
}
|
||||
|
||||
*command_message = format!("Selected profile: {}", app_state.profile_tree.profiles[nav_idx].name);
|
||||
}
|
||||
} else {
|
||||
@@ -175,9 +158,7 @@ pub fn handle_admin_navigation(
|
||||
}
|
||||
}
|
||||
AdminFocus::Tables => {
|
||||
// --- Enter InsideTablesList focus ---
|
||||
new_focus = AdminFocus::InsideTablesList;
|
||||
// Select first item if none selected when entering
|
||||
if let Some(p_idx) = admin_state.profile_list_state.selected().or(admin_state.selected_profile_index) {
|
||||
if let Some(profile) = app_state.profile_tree.profiles.get(p_idx) {
|
||||
if admin_state.table_list_state.selected().is_none() && !profile.tables.is_empty() {
|
||||
@@ -188,11 +169,8 @@ pub fn handle_admin_navigation(
|
||||
*command_message = "Entered Tables List (Select item with Enter, Exit with Esc)".to_string();
|
||||
}
|
||||
AdminFocus::InsideTablesList => {
|
||||
// --- Perform persistent selection ---
|
||||
// Set the persistent selection to the currently navigated item
|
||||
if let Some(nav_idx) = admin_state.table_list_state.selected() {
|
||||
admin_state.selected_table_index = Some(nav_idx); // Set persistent selection
|
||||
// Get table name for message
|
||||
admin_state.selected_table_index = Some(nav_idx);
|
||||
let table_name = admin_state.profile_list_state.selected().or(admin_state.selected_profile_index)
|
||||
.and_then(|p_idx| app_state.profile_tree.profiles.get(p_idx))
|
||||
.and_then(|p| p.tables.get(nav_idx).map(|t| t.name.clone()))
|
||||
@@ -201,91 +179,116 @@ pub fn handle_admin_navigation(
|
||||
} else {
|
||||
*command_message = "No table highlighted".to_string();
|
||||
}
|
||||
// Stay inside
|
||||
}
|
||||
|
||||
AdminFocus::Button1 => {
|
||||
*command_message = "Action: Add Logic (Not Implemented)".to_string();
|
||||
// TODO: Trigger action for Button 1
|
||||
AdminFocus::Button1 => { // Add Logic
|
||||
let mut logic_state_profile_name = "None (Global)".to_string();
|
||||
let mut selected_table_id: Option<i64> = None;
|
||||
let mut selected_table_name_for_logic: Option<String> = None;
|
||||
if let Some(p_idx) = admin_state.selected_profile_index {
|
||||
if let Some(profile) = app_state.profile_tree.profiles.get(p_idx) {
|
||||
logic_state_profile_name = profile.name.clone();
|
||||
// Check for persistently selected table within this profile
|
||||
if let Some(t_idx) = admin_state.selected_table_index {
|
||||
if let Some(table) = profile.tables.get(t_idx) {
|
||||
selected_table_id = None;
|
||||
selected_table_name_for_logic = Some(table.name.clone());
|
||||
*command_message = format!("Adding logic for table: {}. CRITICAL: Table ID not found in profile tree response!", table.name);
|
||||
} else {
|
||||
*command_message = format!("Selected table index {} out of bounds for profile '{}'. Logic will not be table-specific.", t_idx, profile.name);
|
||||
}} else {
|
||||
*command_message = format!("No table selected in profile '{}'. Logic will not be table-specific.", profile.name);
|
||||
}
|
||||
} else {
|
||||
*command_message = "Error: Selected profile index out of bounds, associating with 'None'.".to_string();
|
||||
}
|
||||
} else {
|
||||
*command_message = "No profile selected ([*]), associating Logic with 'None (Global)'.".to_string();
|
||||
// Keep logic_state_profile_name as "None (Global)"
|
||||
}
|
||||
|
||||
admin_state.add_logic_state = AddLogicState {
|
||||
profile_name: logic_state_profile_name.clone(),
|
||||
..AddLogicState::default()
|
||||
};
|
||||
buffer_state.update_history(AppView::AddLogic);
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
// Command message might be overwritten if profile selection had an issue,
|
||||
// so set the navigation message last if no error.
|
||||
if !command_message.starts_with("Error:") && !command_message.contains("associating Logic with 'None (Global)'") {
|
||||
*command_message = format!(
|
||||
"Navigating to Add Logic for profile '{}'...",
|
||||
logic_state_profile_name
|
||||
);
|
||||
} else if command_message.contains("associating Logic with 'None (Global)'") {
|
||||
// Append to existing message
|
||||
let existing_msg = command_message.clone();
|
||||
*command_message = format!(
|
||||
"{} Navigating to Add Logic...",
|
||||
existing_msg
|
||||
);
|
||||
}
|
||||
}
|
||||
AdminFocus::Button2 => {
|
||||
// --- Prepare AddTableState based on persistent selections ---
|
||||
if let Some(p_idx) = admin_state.selected_profile_index {
|
||||
if let Some(profile) = app_state.profile_tree.profiles.get(p_idx) {
|
||||
let selected_profile_name = profile.name.clone();
|
||||
// Populate links from the selected profile's tables
|
||||
let available_links: Vec<LinkDefinition> = profile
|
||||
.tables
|
||||
.iter()
|
||||
.map(|table| LinkDefinition {
|
||||
linked_table_name: table.name.clone(),
|
||||
is_required: false, // Default
|
||||
selected: false, // Default
|
||||
is_required: false,
|
||||
selected: false,
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Create and populate the new AddTableState
|
||||
let new_add_table_state = AddTableState {
|
||||
profile_name: selected_profile_name,
|
||||
links: available_links, // Assign populated links
|
||||
links: available_links,
|
||||
..AddTableState::default()
|
||||
};
|
||||
|
||||
// Assign the prepared state
|
||||
admin_state.add_table_state = new_add_table_state;
|
||||
|
||||
// Switch view
|
||||
buffer_state.update_history(AppView::AddTable);
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
*command_message = format!(
|
||||
"Navigating to Add Table for profile '{}'...",
|
||||
admin_state.add_table_state.profile_name
|
||||
);
|
||||
|
||||
} else {
|
||||
*command_message = "Error: Selected profile index out of bounds.".to_string();
|
||||
}
|
||||
} else {
|
||||
*command_message = "Please select a profile ([*]) first.".to_string();
|
||||
}
|
||||
// --- End preparation ---
|
||||
}
|
||||
AdminFocus::Button3 => {
|
||||
*command_message = "Action: Change Table (Not Implemented)".to_string();
|
||||
// TODO: Trigger action for Button 3
|
||||
}
|
||||
}
|
||||
}
|
||||
// --- Handle Exiting Inside Mode ---
|
||||
Some("exit_table_scroll") => { // Assuming you have this action bound (e.g., to Esc)
|
||||
Some("exit_table_scroll") => {
|
||||
match current_focus {
|
||||
AdminFocus::InsideTablesList => {
|
||||
new_focus = AdminFocus::Tables;
|
||||
admin_state.table_list_state.select(None); // Clear nav highlight on exit
|
||||
admin_state.table_list_state.select(None);
|
||||
*command_message = "Exited Tables List".to_string();
|
||||
}
|
||||
_ => handled = false, // Not applicable
|
||||
_ => handled = false,
|
||||
}
|
||||
}
|
||||
// --- Other General Keys (Ignore for admin nav) ---
|
||||
Some("toggle_sidebar") | Some("toggle_buffer_list") | Some("next_field") | Some("prev_field") => {
|
||||
// These are handled globally or not applicable here.
|
||||
handled = false;
|
||||
}
|
||||
// --- No matching action ---
|
||||
_ => handled = false, // Event not handled by admin navigation
|
||||
_ => handled = false,
|
||||
}
|
||||
|
||||
// Update focus state if it changed and was handled
|
||||
if handled && current_focus != new_focus {
|
||||
if handled && admin_state.current_focus != new_focus { // Check admin_state.current_focus
|
||||
admin_state.current_focus = new_focus;
|
||||
// Avoid overwriting specific messages set during 'select' or 'exit' handling
|
||||
if command_message.is_empty() || command_message.starts_with("Focus set to") {
|
||||
*command_message = format!("Focus set to {:?}", admin_state.current_focus);
|
||||
}
|
||||
} else if !handled {
|
||||
// command_message.clear(); // Optional: Clear message if not handled here
|
||||
}
|
||||
|
||||
handled // Return whether the event was handled by this function
|
||||
handled
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user