add logic is now using canvas library now
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// src/pages/admin_panel/add_logic/state.rs
|
||||
use crate::config::binds::config::{EditorConfig, EditorKeybindingMode};
|
||||
use crate::components::common::text_editor::{TextEditor, VimState};
|
||||
use canvas::{DataProvider, AppMode};
|
||||
use canvas::{DataProvider, AppMode, FormEditor};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use tui_textarea::TextArea;
|
||||
@@ -315,3 +315,141 @@ impl DataProvider for AddLogicState {
|
||||
field_index == 1
|
||||
}
|
||||
}
|
||||
|
||||
// Wrapper that owns both the raw state and its FormEditor (like LoginFormState)
|
||||
pub struct AddLogicFormState {
|
||||
pub state: AddLogicState,
|
||||
pub editor: FormEditor<AddLogicState>,
|
||||
pub focus_outside_canvas: bool,
|
||||
}
|
||||
|
||||
// manual Debug because FormEditor may not implement Debug
|
||||
impl std::fmt::Debug for AddLogicFormState {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("AddLogicFormState")
|
||||
.field("state", &self.state)
|
||||
.field("focus_outside_canvas", &self.focus_outside_canvas)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl AddLogicFormState {
|
||||
pub fn new(editor_config: &EditorConfig) -> Self {
|
||||
let state = AddLogicState::new(editor_config);
|
||||
let editor = FormEditor::new(state.clone());
|
||||
Self {
|
||||
state,
|
||||
editor,
|
||||
focus_outside_canvas: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_state(state: AddLogicState) -> Self {
|
||||
let editor = FormEditor::new(state.clone());
|
||||
Self {
|
||||
state,
|
||||
editor,
|
||||
focus_outside_canvas: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sync state from editor's data provider snapshot
|
||||
pub fn sync_from_editor(&mut self) {
|
||||
self.state = self.editor.data_provider().clone();
|
||||
}
|
||||
|
||||
// === Delegates to AddLogicState fields ===
|
||||
|
||||
pub fn current_focus(&self) -> AddLogicFocus {
|
||||
self.state.current_focus
|
||||
}
|
||||
|
||||
pub fn set_current_focus(&mut self, focus: AddLogicFocus) {
|
||||
self.state.current_focus = focus;
|
||||
}
|
||||
|
||||
pub fn has_unsaved_changes(&self) -> bool {
|
||||
self.state.has_unsaved_changes
|
||||
}
|
||||
|
||||
pub fn set_has_unsaved_changes(&mut self, changed: bool) {
|
||||
self.state.has_unsaved_changes = changed;
|
||||
}
|
||||
|
||||
pub fn profile_name(&self) -> &str {
|
||||
&self.state.profile_name
|
||||
}
|
||||
|
||||
pub fn selected_table_name(&self) -> Option<&String> {
|
||||
self.state.selected_table_name.as_ref()
|
||||
}
|
||||
|
||||
pub fn selected_table_id(&self) -> Option<i64> {
|
||||
self.state.selected_table_id
|
||||
}
|
||||
|
||||
pub fn script_content_editor(&self) -> &Rc<RefCell<TextArea<'static>>> {
|
||||
&self.state.script_content_editor
|
||||
}
|
||||
|
||||
pub fn script_content_editor_mut(&mut self) -> &mut Rc<RefCell<TextArea<'static>>> {
|
||||
&mut self.state.script_content_editor
|
||||
}
|
||||
|
||||
pub fn vim_state(&self) -> &VimState {
|
||||
&self.state.vim_state
|
||||
}
|
||||
|
||||
pub fn vim_state_mut(&mut self) -> &mut VimState {
|
||||
&mut self.state.vim_state
|
||||
}
|
||||
|
||||
pub fn editor_keybinding_mode(&self) -> &EditorKeybindingMode {
|
||||
&self.state.editor_keybinding_mode
|
||||
}
|
||||
|
||||
pub fn script_editor_autocomplete_active(&self) -> bool {
|
||||
self.state.script_editor_autocomplete_active
|
||||
}
|
||||
|
||||
pub fn script_editor_suggestions(&self) -> &Vec<String> {
|
||||
&self.state.script_editor_suggestions
|
||||
}
|
||||
|
||||
pub fn script_editor_selected_suggestion_index(&self) -> Option<usize> {
|
||||
self.state.script_editor_selected_suggestion_index
|
||||
}
|
||||
|
||||
pub fn target_column_suggestions(&self) -> &Vec<String> {
|
||||
&self.state.target_column_suggestions
|
||||
}
|
||||
|
||||
pub fn selected_target_column_suggestion_index(&self) -> Option<usize> {
|
||||
self.state.selected_target_column_suggestion_index
|
||||
}
|
||||
|
||||
pub fn in_target_column_suggestion_mode(&self) -> bool {
|
||||
self.state.in_target_column_suggestion_mode
|
||||
}
|
||||
|
||||
pub fn show_target_column_suggestions(&self) -> bool {
|
||||
self.state.show_target_column_suggestions
|
||||
}
|
||||
|
||||
// === Delegates to FormEditor ===
|
||||
|
||||
pub fn mode(&self) -> AppMode {
|
||||
self.editor.mode()
|
||||
}
|
||||
|
||||
pub fn cursor_position(&self) -> usize {
|
||||
self.editor.cursor_position()
|
||||
}
|
||||
|
||||
pub fn handle_key_event(
|
||||
&mut self,
|
||||
key_event: crossterm::event::KeyEvent,
|
||||
) -> canvas::keymap::KeyEventOutcome {
|
||||
self.editor.handle_key_event(key_event)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user