moving add_table to add_logic modern architecture
This commit is contained in:
@@ -15,11 +15,14 @@ use canvas::{AppMode as CanvasMode, DataProvider};
|
||||
use crossterm::event::KeyEvent;
|
||||
|
||||
/// Focus traversal order for AddTable (outside canvas)
|
||||
const ADD_TABLE_FOCUS_ORDER: [AddTableFocus; 7] = [
|
||||
const ADD_TABLE_FOCUS_ORDER: [AddTableFocus; 10] = [
|
||||
AddTableFocus::InputTableName,
|
||||
AddTableFocus::InputColumnName,
|
||||
AddTableFocus::InputColumnType,
|
||||
AddTableFocus::AddColumnButton,
|
||||
AddTableFocus::ColumnsTable,
|
||||
AddTableFocus::IndexesTable,
|
||||
AddTableFocus::LinksTable,
|
||||
AddTableFocus::SaveButton,
|
||||
AddTableFocus::DeleteSelectedButton,
|
||||
AddTableFocus::CancelButton,
|
||||
@@ -49,17 +52,6 @@ pub fn handle_add_table_event(
|
||||
// Disable global shortcuts while typing
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
|
||||
// Special case: allow ":" to enter command mode even inside canvas
|
||||
if let Some(action) = config.get_general_action(key_event.code, key_event.modifiers) {
|
||||
if action == "enter_command_mode"
|
||||
&& !app_state.ui.show_search_palette
|
||||
&& !app_state.ui.dialog.dialog_show
|
||||
{
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
}
|
||||
|
||||
// Only allow leaving the canvas with Down/Next when in ReadOnly mode
|
||||
let in_edit_mode = page.editor.mode() == CanvasMode::Edit;
|
||||
if !in_edit_mode {
|
||||
@@ -96,16 +88,146 @@ pub fn handle_add_table_event(
|
||||
|
||||
// 2) Outside canvas
|
||||
if let Some(ma) = movement {
|
||||
// First let the AddTable state's own movement handler process
|
||||
if page.state.handle_movement(ma) {
|
||||
app_state.ui.focus_outside_canvas = !matches!(
|
||||
page.current_focus(),
|
||||
AddTableFocus::InputTableName
|
||||
| AddTableFocus::InputColumnName
|
||||
| AddTableFocus::InputColumnType
|
||||
);
|
||||
// Block outer moves when "inside" any table and handle locally
|
||||
match page.current_focus() {
|
||||
AddTableFocus::InsideColumnsTable => {
|
||||
match ma {
|
||||
MovementAction::Up => {
|
||||
if let Some(i) = page.state.column_table_state.selected() {
|
||||
let next = i.saturating_sub(1);
|
||||
page.state.column_table_state.select(Some(next));
|
||||
} else if !page.state.columns.is_empty() {
|
||||
page.state.column_table_state.select(Some(0));
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Down => {
|
||||
if let Some(i) = page.state.column_table_state.selected() {
|
||||
let last = page.state.columns.len().saturating_sub(1);
|
||||
let next = if i < last { i + 1 } else { i };
|
||||
page.state.column_table_state.select(Some(next));
|
||||
} else if !page.state.columns.is_empty() {
|
||||
page.state.column_table_state.select(Some(0));
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Select => {
|
||||
if let Some(i) = page.state.column_table_state.selected() {
|
||||
if let Some(col) = page.state.columns.get_mut(i) {
|
||||
col.selected = !col.selected;
|
||||
page.state.has_unsaved_changes = true;
|
||||
}
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Esc => {
|
||||
page.state.column_table_state.select(None);
|
||||
page.set_current_focus(AddTableFocus::ColumnsTable);
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Next | MovementAction::Previous => {
|
||||
// Block outer movement while inside
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
AddTableFocus::InsideIndexesTable => {
|
||||
match ma {
|
||||
MovementAction::Up => {
|
||||
if let Some(i) = page.state.index_table_state.selected() {
|
||||
let next = i.saturating_sub(1);
|
||||
page.state.index_table_state.select(Some(next));
|
||||
} else if !page.state.indexes.is_empty() {
|
||||
page.state.index_table_state.select(Some(0));
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Down => {
|
||||
if let Some(i) = page.state.index_table_state.selected() {
|
||||
let last = page.state.indexes.len().saturating_sub(1);
|
||||
let next = if i < last { i + 1 } else { i };
|
||||
page.state.index_table_state.select(Some(next));
|
||||
} else if !page.state.indexes.is_empty() {
|
||||
page.state.index_table_state.select(Some(0));
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Select => {
|
||||
if let Some(i) = page.state.index_table_state.selected() {
|
||||
if let Some(ix) = page.state.indexes.get_mut(i) {
|
||||
ix.selected = !ix.selected;
|
||||
page.state.has_unsaved_changes = true;
|
||||
}
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Esc => {
|
||||
page.state.index_table_state.select(None);
|
||||
page.set_current_focus(AddTableFocus::IndexesTable);
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Next | MovementAction::Previous => {
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
AddTableFocus::InsideLinksTable => {
|
||||
match ma {
|
||||
MovementAction::Up => {
|
||||
if let Some(i) = page.state.link_table_state.selected() {
|
||||
let next = i.saturating_sub(1);
|
||||
page.state.link_table_state.select(Some(next));
|
||||
} else if !page.state.links.is_empty() {
|
||||
page.state.link_table_state.select(Some(0));
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Down => {
|
||||
if let Some(i) = page.state.link_table_state.selected() {
|
||||
let last = page.state.links.len().saturating_sub(1);
|
||||
let next = if i < last { i + 1 } else { i };
|
||||
page.state.link_table_state.select(Some(next));
|
||||
} else if !page.state.links.is_empty() {
|
||||
page.state.link_table_state.select(Some(0));
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Select => {
|
||||
if let Some(i) = page.state.link_table_state.selected() {
|
||||
if let Some(link) = page.state.links.get_mut(i) {
|
||||
link.selected = !link.selected;
|
||||
page.state.has_unsaved_changes = true;
|
||||
}
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Esc => {
|
||||
page.state.link_table_state.select(None);
|
||||
page.set_current_focus(AddTableFocus::LinksTable);
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Next | MovementAction::Previous => {
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let mut current = page.current_focus();
|
||||
if move_focus(&ADD_TABLE_FOCUS_ORDER, &mut current, ma) {
|
||||
|
||||
Reference in New Issue
Block a user