search added, but unable to trigger it yet
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
// src/state/state.rs
|
||||
// src/state/app/state.rs
|
||||
|
||||
use std::env;
|
||||
use common::proto::multieko2::table_definition::ProfileTreeResponse;
|
||||
use crate::modes::handlers::mode_manager::AppMode;
|
||||
use crate::ui::handlers::context::DialogPurpose;
|
||||
use crate::state::app::search::SearchState; // ADDED
|
||||
use anyhow::Result;
|
||||
|
||||
// --- YOUR EXISTING DIALOGSTATE IS UNTOUCHED ---
|
||||
pub struct DialogState {
|
||||
pub dialog_show: bool,
|
||||
pub dialog_title: String,
|
||||
@@ -26,6 +28,7 @@ pub struct UiState {
|
||||
pub show_form: bool,
|
||||
pub show_login: bool,
|
||||
pub show_register: bool,
|
||||
pub show_search_palette: bool, // ADDED
|
||||
pub focus_outside_canvas: bool,
|
||||
pub dialog: DialogState,
|
||||
}
|
||||
@@ -42,6 +45,9 @@ pub struct AppState {
|
||||
pub focused_button_index: usize,
|
||||
pub pending_table_structure_fetch: Option<(String, String)>,
|
||||
|
||||
// ADDED: State for the search palette
|
||||
pub search_state: Option<SearchState>,
|
||||
|
||||
// UI preferences
|
||||
pub ui: UiState,
|
||||
|
||||
@@ -63,6 +69,7 @@ impl AppState {
|
||||
current_mode: AppMode::General,
|
||||
focused_button_index: 0,
|
||||
pending_table_structure_fetch: None,
|
||||
search_state: None, // ADDED
|
||||
ui: UiState::default(),
|
||||
|
||||
#[cfg(feature = "ui-debug")]
|
||||
@@ -70,18 +77,17 @@ impl AppState {
|
||||
})
|
||||
}
|
||||
|
||||
// --- ALL YOUR EXISTING METHODS ARE UNTOUCHED ---
|
||||
|
||||
pub fn update_mode(&mut self, mode: AppMode) {
|
||||
self.current_mode = mode;
|
||||
}
|
||||
|
||||
|
||||
pub fn set_current_view_table(&mut self, profile_name: String, table_name: String) {
|
||||
self.current_view_profile_name = Some(profile_name);
|
||||
self.current_view_table_name = Some(table_name);
|
||||
}
|
||||
|
||||
// Add dialog helper methods
|
||||
/// Shows a dialog with the given title, message, and buttons.
|
||||
/// The first button (index 0) is active by default.
|
||||
pub fn show_dialog(
|
||||
&mut self,
|
||||
title: &str,
|
||||
@@ -99,19 +105,17 @@ impl AppState {
|
||||
self.ui.focus_outside_canvas = true;
|
||||
}
|
||||
|
||||
/// Shows a dialog specifically for loading states.
|
||||
pub fn show_loading_dialog(&mut self, title: &str, message: &str) {
|
||||
self.ui.dialog.dialog_title = title.to_string();
|
||||
self.ui.dialog.dialog_message = message.to_string();
|
||||
self.ui.dialog.dialog_buttons.clear(); // No buttons during loading
|
||||
self.ui.dialog.dialog_buttons.clear();
|
||||
self.ui.dialog.dialog_active_button_index = 0;
|
||||
self.ui.dialog.purpose = None; // Purpose is set when loading finishes
|
||||
self.ui.dialog.purpose = None;
|
||||
self.ui.dialog.is_loading = true;
|
||||
self.ui.dialog.dialog_show = true;
|
||||
self.ui.focus_outside_canvas = true; // Keep focus management consistent
|
||||
self.ui.focus_outside_canvas = true;
|
||||
}
|
||||
|
||||
/// Updates the content of an existing dialog, typically after loading.
|
||||
pub fn update_dialog_content(
|
||||
&mut self,
|
||||
message: &str,
|
||||
@@ -121,16 +125,12 @@ impl AppState {
|
||||
if self.ui.dialog.dialog_show {
|
||||
self.ui.dialog.dialog_message = message.to_string();
|
||||
self.ui.dialog.dialog_buttons = buttons;
|
||||
self.ui.dialog.dialog_active_button_index = 0; // Reset focus
|
||||
self.ui.dialog.dialog_active_button_index = 0;
|
||||
self.ui.dialog.purpose = Some(purpose);
|
||||
self.ui.dialog.is_loading = false; // Loading finished
|
||||
// Keep dialog_show = true
|
||||
// Keep focus_outside_canvas = true
|
||||
self.ui.dialog.is_loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Hides the dialog and clears its content.
|
||||
pub fn hide_dialog(&mut self) {
|
||||
self.ui.dialog.dialog_show = false;
|
||||
self.ui.dialog.dialog_title.clear();
|
||||
@@ -142,30 +142,27 @@ impl AppState {
|
||||
self.ui.dialog.is_loading = false;
|
||||
}
|
||||
|
||||
/// Sets the active button index, wrapping around if necessary.
|
||||
pub fn next_dialog_button(&mut self) {
|
||||
if !self.ui.dialog.dialog_buttons.is_empty() {
|
||||
let next_index = (self.ui.dialog.dialog_active_button_index + 1)
|
||||
% self.ui.dialog.dialog_buttons.len();
|
||||
self.ui.dialog.dialog_active_button_index = next_index; // Use new name
|
||||
self.ui.dialog.dialog_active_button_index = next_index;
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the active button index, wrapping around if necessary.
|
||||
pub fn previous_dialog_button(&mut self) {
|
||||
if !self.ui.dialog.dialog_buttons.is_empty() {
|
||||
let len = self.ui.dialog.dialog_buttons.len();
|
||||
let prev_index =
|
||||
(self.ui.dialog.dialog_active_button_index + len - 1) % len;
|
||||
self.ui.dialog.dialog_active_button_index = prev_index; // Use new name
|
||||
self.ui.dialog.dialog_active_button_index = prev_index;
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the label of the currently active button, if any.
|
||||
pub fn get_active_dialog_button_label(&self) -> Option<&str> {
|
||||
self.ui.dialog
|
||||
.dialog_buttons // Use new name
|
||||
.get(self.ui.dialog.dialog_active_button_index) // Use new name
|
||||
.dialog_buttons
|
||||
.get(self.ui.dialog.dialog_active_button_index)
|
||||
.map(|s| s.as_str())
|
||||
}
|
||||
}
|
||||
@@ -182,13 +179,13 @@ impl Default for UiState {
|
||||
show_login: false,
|
||||
show_register: false,
|
||||
show_buffer_list: true,
|
||||
show_search_palette: false, // ADDED
|
||||
focus_outside_canvas: false,
|
||||
dialog: DialogState::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the Default implementation for DialogState itself
|
||||
impl Default for DialogState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
||||
Reference in New Issue
Block a user