dialog is a feature
This commit is contained in:
@@ -10,7 +10,8 @@ use ratatui::{
|
|||||||
widgets::{Block, BorderType, Borders, Paragraph},
|
widgets::{Block, BorderType, Borders, Paragraph},
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
use crate::components::common::{dialog, autocomplete}; // Added autocomplete
|
use crate::components::common::autocomplete;
|
||||||
|
use crate::dialog;
|
||||||
use crate::config::binds::config::EditorKeybindingMode;
|
use crate::config::binds::config::EditorKeybindingMode;
|
||||||
|
|
||||||
pub fn render_add_logic(
|
pub fn render_add_logic(
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use ratatui::{
|
|||||||
widgets::{Block, BorderType, Borders, Cell, Paragraph, Row, Table},
|
widgets::{Block, BorderType, Borders, Cell, Paragraph, Row, Table},
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
use crate::components::common::dialog;
|
use crate::dialog;
|
||||||
|
|
||||||
/// Renders the Add New Table page layout, structuring the display of table information,
|
/// Renders the Add New Table page layout, structuring the display of table information,
|
||||||
/// input fields, and action buttons. Adapts layout based on terminal width.
|
/// input fields, and action buttons. Adapts layout based on terminal width.
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
config::colors::themes::Theme,
|
config::colors::themes::Theme,
|
||||||
state::pages::auth::LoginState,
|
state::pages::auth::LoginState,
|
||||||
components::common::dialog,
|
|
||||||
state::app::state::AppState,
|
state::app::state::AppState,
|
||||||
};
|
};
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
@@ -18,6 +17,7 @@ use canvas::{
|
|||||||
render_suggestions_dropdown,
|
render_suggestions_dropdown,
|
||||||
DefaultCanvasTheme,
|
DefaultCanvasTheme,
|
||||||
};
|
};
|
||||||
|
use crate::dialog;
|
||||||
|
|
||||||
pub fn render_login(
|
pub fn render_login(
|
||||||
f: &mut Frame,
|
f: &mut Frame,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
config::colors::themes::Theme,
|
config::colors::themes::Theme,
|
||||||
state::pages::auth::RegisterState,
|
state::pages::auth::RegisterState,
|
||||||
components::common::dialog,
|
|
||||||
state::app::state::AppState,
|
state::app::state::AppState,
|
||||||
modes::handlers::mode_manager::AppMode,
|
modes::handlers::mode_manager::AppMode,
|
||||||
};
|
};
|
||||||
@@ -13,6 +12,7 @@ use ratatui::{
|
|||||||
widgets::{Block, BorderType, Borders, Paragraph},
|
widgets::{Block, BorderType, Borders, Paragraph},
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
|
use crate::dialog;
|
||||||
use canvas::{FormEditor, render_canvas, render_suggestions_dropdown, DefaultCanvasTheme};
|
use canvas::{FormEditor, render_canvas, render_suggestions_dropdown, DefaultCanvasTheme};
|
||||||
|
|
||||||
pub fn render_register(
|
pub fn render_register(
|
||||||
|
|||||||
@@ -2,10 +2,8 @@
|
|||||||
|
|
||||||
pub mod text_editor;
|
pub mod text_editor;
|
||||||
pub mod background;
|
pub mod background;
|
||||||
pub mod dialog;
|
|
||||||
pub mod autocomplete;
|
pub mod autocomplete;
|
||||||
|
|
||||||
pub use text_editor::*;
|
pub use text_editor::*;
|
||||||
pub use background::*;
|
pub use background::*;
|
||||||
pub use dialog::*;
|
|
||||||
pub use autocomplete::*;
|
pub use autocomplete::*;
|
||||||
|
|||||||
85
client/src/dialog/functions.rs
Normal file
85
client/src/dialog/functions.rs
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
// src/dialog/functions.rs
|
||||||
|
|
||||||
|
use crate::dialog::DialogState;
|
||||||
|
use crate::state::app::state::AppState;
|
||||||
|
use crate::ui::handlers::context::DialogPurpose;
|
||||||
|
|
||||||
|
impl AppState {
|
||||||
|
pub fn show_dialog(
|
||||||
|
&mut self,
|
||||||
|
title: &str,
|
||||||
|
message: &str,
|
||||||
|
buttons: Vec<String>,
|
||||||
|
purpose: DialogPurpose,
|
||||||
|
) {
|
||||||
|
self.ui.dialog.dialog_title = title.to_string();
|
||||||
|
self.ui.dialog.dialog_message = message.to_string();
|
||||||
|
self.ui.dialog.dialog_buttons = buttons;
|
||||||
|
self.ui.dialog.dialog_active_button_index = 0;
|
||||||
|
self.ui.dialog.purpose = Some(purpose);
|
||||||
|
self.ui.dialog.is_loading = false;
|
||||||
|
self.ui.dialog.dialog_show = true;
|
||||||
|
self.ui.focus_outside_canvas = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
self.ui.dialog.dialog_active_button_index = 0;
|
||||||
|
self.ui.dialog.purpose = None;
|
||||||
|
self.ui.dialog.is_loading = true;
|
||||||
|
self.ui.dialog.dialog_show = true;
|
||||||
|
self.ui.focus_outside_canvas = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_dialog_content(
|
||||||
|
&mut self,
|
||||||
|
message: &str,
|
||||||
|
buttons: Vec<String>,
|
||||||
|
purpose: DialogPurpose,
|
||||||
|
) {
|
||||||
|
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;
|
||||||
|
self.ui.dialog.purpose = Some(purpose);
|
||||||
|
self.ui.dialog.is_loading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn hide_dialog(&mut self) {
|
||||||
|
self.ui.dialog.dialog_show = false;
|
||||||
|
self.ui.dialog.dialog_title.clear();
|
||||||
|
self.ui.dialog.dialog_message.clear();
|
||||||
|
self.ui.dialog.dialog_buttons.clear();
|
||||||
|
self.ui.dialog.dialog_active_button_index = 0;
|
||||||
|
self.ui.dialog.purpose = None;
|
||||||
|
self.ui.focus_outside_canvas = false;
|
||||||
|
self.ui.dialog.is_loading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_active_dialog_button_label(&self) -> Option<&str> {
|
||||||
|
self.ui.dialog
|
||||||
|
.dialog_buttons
|
||||||
|
.get(self.ui.dialog.dialog_active_button_index)
|
||||||
|
.map(|s| s.as_str())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// src/modes/general/dialog.rs
|
// src/dialog/logic.rs
|
||||||
|
|
||||||
use crossterm::event::{Event, KeyCode};
|
use crossterm::event::{Event, KeyCode};
|
||||||
use crate::config::binds::config::Config;
|
use crate::config::binds::config::Config;
|
||||||
10
client/src/dialog/mod.rs
Normal file
10
client/src/dialog/mod.rs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// src/dialog/mod.rs
|
||||||
|
|
||||||
|
pub mod ui;
|
||||||
|
pub mod logic;
|
||||||
|
pub mod state;
|
||||||
|
pub mod functions;
|
||||||
|
|
||||||
|
pub use ui::render_dialog;
|
||||||
|
pub use logic::handle_dialog_event;
|
||||||
|
pub use state::DialogState;
|
||||||
26
client/src/dialog/state.rs
Normal file
26
client/src/dialog/state.rs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
// src/dialog/state.rs
|
||||||
|
use crate::ui::handlers::context::DialogPurpose;
|
||||||
|
|
||||||
|
pub struct DialogState {
|
||||||
|
pub dialog_show: bool,
|
||||||
|
pub dialog_title: String,
|
||||||
|
pub dialog_message: String,
|
||||||
|
pub dialog_buttons: Vec<String>,
|
||||||
|
pub dialog_active_button_index: usize,
|
||||||
|
pub purpose: Option<DialogPurpose>,
|
||||||
|
pub is_loading: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for DialogState {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
dialog_show: false,
|
||||||
|
dialog_title: String::new(),
|
||||||
|
dialog_message: String::new(),
|
||||||
|
dialog_buttons: Vec::new(),
|
||||||
|
dialog_active_button_index: 0,
|
||||||
|
purpose: None,
|
||||||
|
is_loading: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// src/dialog/ui.rs
|
||||||
|
|
||||||
use crate::config::colors::themes::Theme;
|
use crate::config::colors::themes::Theme;
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::{Constraint, Direction, Layout, Margin, Rect},
|
layout::{Constraint, Direction, Layout, Margin, Rect},
|
||||||
@@ -10,6 +10,7 @@ pub mod services;
|
|||||||
pub mod utils;
|
pub mod utils;
|
||||||
pub mod buffer;
|
pub mod buffer;
|
||||||
pub mod sidebar;
|
pub mod sidebar;
|
||||||
|
pub mod dialog;
|
||||||
pub mod search;
|
pub mod search;
|
||||||
pub mod bottom_panel;
|
pub mod bottom_panel;
|
||||||
pub mod pages;
|
pub mod pages;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// src/client/modes/general.rs
|
// src/client/modes/general.rs
|
||||||
pub mod navigation;
|
pub mod navigation;
|
||||||
pub mod dialog;
|
|
||||||
pub mod command_navigation;
|
pub mod command_navigation;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use crate::modes::general::command_navigation::{
|
|||||||
};
|
};
|
||||||
use crate::modes::{
|
use crate::modes::{
|
||||||
common::{command_mode, commands::CommandHandler},
|
common::{command_mode, commands::CommandHandler},
|
||||||
general::{dialog, navigation},
|
general::navigation,
|
||||||
handlers::mode_manager::{AppMode, ModeManager},
|
handlers::mode_manager::{AppMode, ModeManager},
|
||||||
};
|
};
|
||||||
use crate::services::auth::AuthClient;
|
use crate::services::auth::AuthClient;
|
||||||
@@ -31,6 +31,7 @@ use crate::state::{
|
|||||||
};
|
};
|
||||||
use crate::tui::common::{register, login};
|
use crate::tui::common::{register, login};
|
||||||
use crate::pages::routing::{Router, Page};
|
use crate::pages::routing::{Router, Page};
|
||||||
|
use crate::dialog;
|
||||||
use crate::pages::forms::FormState;
|
use crate::pages::forms::FormState;
|
||||||
use crate::pages::forms::logic::{save, revert, SaveOutcome};
|
use crate::pages::forms::logic::{save, revert, SaveOutcome};
|
||||||
use crate::search::state::SearchState;
|
use crate::search::state::SearchState;
|
||||||
|
|||||||
@@ -10,23 +10,13 @@ use crate::ui::handlers::context::DialogPurpose;
|
|||||||
use crate::config::binds::Config;
|
use crate::config::binds::Config;
|
||||||
use crate::pages::forms::FormState;
|
use crate::pages::forms::FormState;
|
||||||
use canvas::FormEditor;
|
use canvas::FormEditor;
|
||||||
|
use crate::dialog::DialogState;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
#[cfg(feature = "ui-debug")]
|
#[cfg(feature = "ui-debug")]
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
// --- DialogState and UiState are unchanged ---
|
|
||||||
pub struct DialogState {
|
|
||||||
pub dialog_show: bool,
|
|
||||||
pub dialog_title: String,
|
|
||||||
pub dialog_message: String,
|
|
||||||
pub dialog_buttons: Vec<String>,
|
|
||||||
pub dialog_active_button_index: usize,
|
|
||||||
pub purpose: Option<DialogPurpose>,
|
|
||||||
pub is_loading: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct UiState {
|
pub struct UiState {
|
||||||
pub show_sidebar: bool,
|
pub show_sidebar: bool,
|
||||||
pub show_buffer_list: bool,
|
pub show_buffer_list: bool,
|
||||||
@@ -109,84 +99,6 @@ impl AppState {
|
|||||||
self.current_view_table_name = Some(table_name);
|
self.current_view_table_name = Some(table_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show_dialog(
|
|
||||||
&mut self,
|
|
||||||
title: &str,
|
|
||||||
message: &str,
|
|
||||||
buttons: Vec<String>,
|
|
||||||
purpose: DialogPurpose,
|
|
||||||
) {
|
|
||||||
self.ui.dialog.dialog_title = title.to_string();
|
|
||||||
self.ui.dialog.dialog_message = message.to_string();
|
|
||||||
self.ui.dialog.dialog_buttons = buttons;
|
|
||||||
self.ui.dialog.dialog_active_button_index = 0;
|
|
||||||
self.ui.dialog.purpose = Some(purpose);
|
|
||||||
self.ui.dialog.is_loading = false;
|
|
||||||
self.ui.dialog.dialog_show = true;
|
|
||||||
self.ui.focus_outside_canvas = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
self.ui.dialog.dialog_active_button_index = 0;
|
|
||||||
self.ui.dialog.purpose = None;
|
|
||||||
self.ui.dialog.is_loading = true;
|
|
||||||
self.ui.dialog.dialog_show = true;
|
|
||||||
self.ui.focus_outside_canvas = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_dialog_content(
|
|
||||||
&mut self,
|
|
||||||
message: &str,
|
|
||||||
buttons: Vec<String>,
|
|
||||||
purpose: DialogPurpose,
|
|
||||||
) {
|
|
||||||
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;
|
|
||||||
self.ui.dialog.purpose = Some(purpose);
|
|
||||||
self.ui.dialog.is_loading = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn hide_dialog(&mut self) {
|
|
||||||
self.ui.dialog.dialog_show = false;
|
|
||||||
self.ui.dialog.dialog_title.clear();
|
|
||||||
self.ui.dialog.dialog_message.clear();
|
|
||||||
self.ui.dialog.dialog_buttons.clear();
|
|
||||||
self.ui.dialog.dialog_active_button_index = 0;
|
|
||||||
self.ui.dialog.purpose = None;
|
|
||||||
self.ui.focus_outside_canvas = false;
|
|
||||||
self.ui.dialog.is_loading = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_active_dialog_button_label(&self) -> Option<&str> {
|
|
||||||
self.ui.dialog
|
|
||||||
.dialog_buttons
|
|
||||||
.get(self.ui.dialog.dialog_active_button_index)
|
|
||||||
.map(|s| s.as_str())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn init_form_editor(&mut self, form_state: FormState, config: &Config) {
|
pub fn init_form_editor(&mut self, form_state: FormState, config: &Config) {
|
||||||
let mut editor = FormEditor::new(form_state);
|
let mut editor = FormEditor::new(form_state);
|
||||||
editor.set_keymap(config.build_canvas_keymap()); // inject keymap
|
editor.set_keymap(config.build_canvas_keymap()); // inject keymap
|
||||||
@@ -229,17 +141,3 @@ impl Default for UiState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for DialogState {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
dialog_show: false,
|
|
||||||
dialog_title: String::new(),
|
|
||||||
dialog_message: String::new(),
|
|
||||||
dialog_buttons: Vec::new(),
|
|
||||||
dialog_active_button_index: 0,
|
|
||||||
purpose: None,
|
|
||||||
is_loading: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use crate::components::{
|
|||||||
admin::add_logic::render_add_logic,
|
admin::add_logic::render_add_logic,
|
||||||
admin::render_add_table,
|
admin::render_add_table,
|
||||||
auth::{login::render_login, register::render_register},
|
auth::{login::render_login, register::render_register},
|
||||||
common::dialog::render_dialog,
|
|
||||||
intro::intro::render_intro,
|
intro::intro::render_intro,
|
||||||
render_background,
|
render_background,
|
||||||
};
|
};
|
||||||
@@ -27,6 +26,8 @@ use ratatui::{
|
|||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
use crate::pages::routing::{Router, Page};
|
use crate::pages::routing::{Router, Page};
|
||||||
|
use crate::dialog::render_dialog;
|
||||||
|
use crate::pages::forms::render_form_page;
|
||||||
|
|
||||||
pub fn render_ui(
|
pub fn render_ui(
|
||||||
f: &mut Frame,
|
f: &mut Frame,
|
||||||
|
|||||||
Reference in New Issue
Block a user