moving the state from general to each page owning its own state of button or canvas focus
This commit is contained in:
@@ -39,7 +39,7 @@ pub fn handle_add_logic_event(
|
||||
match key_event.code {
|
||||
crossterm::event::KeyCode::Esc => {
|
||||
add_logic_page.state.current_focus = AddLogicFocus::ScriptContentPreview;
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
add_logic_page.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok("Exited script editing.".to_string()));
|
||||
}
|
||||
_ => {
|
||||
@@ -85,7 +85,7 @@ pub fn handle_add_logic_event(
|
||||
if at_last && matches!(ma, MovementAction::Down | MovementAction::Next) {
|
||||
add_logic_page.state.last_canvas_field = last_idx;
|
||||
add_logic_page.state.current_focus = AddLogicFocus::ScriptContentPreview;
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
add_logic_page.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok("Moved to Script Preview".to_string()));
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ pub fn handle_add_logic_event(
|
||||
let mut current = add_logic_page.state.current_focus;
|
||||
if move_focus(&ADD_LOGIC_FOCUS_ORDER, &mut current, ma) {
|
||||
add_logic_page.state.current_focus = current;
|
||||
app_state.ui.focus_outside_canvas = !matches!(
|
||||
add_logic_page.focus_outside_canvas = !matches!(
|
||||
add_logic_page.state.current_focus,
|
||||
AddLogicFocus::InputLogicName
|
||||
| AddLogicFocus::InputTargetColumn
|
||||
@@ -127,7 +127,7 @@ pub fn handle_add_logic_event(
|
||||
MovementAction::Select => match add_logic_page.state.current_focus {
|
||||
AddLogicFocus::ScriptContentPreview => {
|
||||
add_logic_page.state.current_focus = AddLogicFocus::InsideScriptContent;
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
add_logic_page.focus_outside_canvas = false;
|
||||
return Ok(EventOutcome::Ok(
|
||||
"Fullscreen script editing. Esc to exit.".to_string(),
|
||||
));
|
||||
@@ -147,7 +147,7 @@ pub fn handle_add_logic_event(
|
||||
MovementAction::Esc => {
|
||||
if add_logic_page.state.current_focus == AddLogicFocus::ScriptContentPreview {
|
||||
add_logic_page.state.current_focus = AddLogicFocus::InputDescription;
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
add_logic_page.focus_outside_canvas = false;
|
||||
return Ok(EventOutcome::Ok("Back to Description".to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,6 +335,7 @@ pub struct AddLogicFormState {
|
||||
pub state: AddLogicState,
|
||||
pub editor: FormEditor<AddLogicState>,
|
||||
pub focus_outside_canvas: bool,
|
||||
pub focused_button_index: usize,
|
||||
}
|
||||
|
||||
// manual Debug because FormEditor may not implement Debug
|
||||
@@ -343,6 +344,7 @@ impl std::fmt::Debug for AddLogicFormState {
|
||||
f.debug_struct("AddLogicFormState")
|
||||
.field("state", &self.state)
|
||||
.field("focus_outside_canvas", &self.focus_outside_canvas)
|
||||
.field("focused_button_index", &self.focused_button_index)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
@@ -355,6 +357,7 @@ impl AddLogicFormState {
|
||||
state,
|
||||
editor,
|
||||
focus_outside_canvas: false,
|
||||
focused_button_index: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,6 +376,7 @@ impl AddLogicFormState {
|
||||
state,
|
||||
editor,
|
||||
focus_outside_canvas: false,
|
||||
focused_button_index: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,6 +386,7 @@ impl AddLogicFormState {
|
||||
state,
|
||||
editor,
|
||||
focus_outside_canvas: false,
|
||||
focused_button_index: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -252,11 +252,14 @@ pub fn render_add_logic(
|
||||
])
|
||||
.split(buttons_area);
|
||||
|
||||
let save_active = add_logic_state.focus_outside_canvas
|
||||
&& add_logic_state.focused_button_index == 0;
|
||||
let save_button = Paragraph::new(" Save Logic ")
|
||||
.style(get_button_style(
|
||||
AddLogicFocus::SaveButton,
|
||||
add_logic_state.current_focus(),
|
||||
))
|
||||
.style(if save_active {
|
||||
Style::default().fg(theme.highlight).add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
Style::default().fg(theme.secondary)
|
||||
})
|
||||
.alignment(Alignment::Center)
|
||||
.block(
|
||||
Block::default()
|
||||
@@ -269,11 +272,14 @@ pub fn render_add_logic(
|
||||
);
|
||||
f.render_widget(save_button, button_chunks[0]);
|
||||
|
||||
let cancel_active = add_logic_state.focus_outside_canvas
|
||||
&& add_logic_state.focused_button_index == 1;
|
||||
let cancel_button = Paragraph::new(" Cancel ")
|
||||
.style(get_button_style(
|
||||
AddLogicFocus::CancelButton,
|
||||
add_logic_state.current_focus(),
|
||||
))
|
||||
.style(if cancel_active {
|
||||
Style::default().fg(theme.highlight).add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
Style::default().fg(theme.secondary)
|
||||
})
|
||||
.alignment(Alignment::Center)
|
||||
.block(
|
||||
Block::default()
|
||||
|
||||
@@ -51,7 +51,7 @@ pub fn handle_add_table_event(
|
||||
|
||||
if inside_canvas_inputs {
|
||||
// Disable global shortcuts while typing
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
page.focus_outside_canvas = false;
|
||||
|
||||
// Only allow leaving the canvas with Down/Next when in ReadOnly mode
|
||||
let in_edit_mode = page.editor.mode() == CanvasMode::Edit;
|
||||
@@ -62,7 +62,7 @@ pub fn handle_add_table_event(
|
||||
if at_last && matches!(ma, MovementAction::Down | MovementAction::Next) {
|
||||
page.state.last_canvas_field = last_idx;
|
||||
page.set_current_focus(AddTableFocus::AddColumnButton);
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
page.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok("Moved to Add button".to_string()));
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ pub fn handle_add_table_event(
|
||||
} else if !page.state.columns.is_empty() {
|
||||
page.state.column_table_state.select(Some(0));
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
page.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Down => {
|
||||
@@ -111,7 +111,7 @@ pub fn handle_add_table_event(
|
||||
} else if !page.state.columns.is_empty() {
|
||||
page.state.column_table_state.select(Some(0));
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
page.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Select => {
|
||||
@@ -121,13 +121,13 @@ pub fn handle_add_table_event(
|
||||
page.state.has_unsaved_changes = true;
|
||||
}
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
page.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;
|
||||
page.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Next | MovementAction::Previous => {
|
||||
@@ -146,7 +146,7 @@ pub fn handle_add_table_event(
|
||||
} else if !page.state.indexes.is_empty() {
|
||||
page.state.index_table_state.select(Some(0));
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
page.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Down => {
|
||||
@@ -157,7 +157,7 @@ pub fn handle_add_table_event(
|
||||
} else if !page.state.indexes.is_empty() {
|
||||
page.state.index_table_state.select(Some(0));
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
page.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Select => {
|
||||
@@ -167,13 +167,13 @@ pub fn handle_add_table_event(
|
||||
page.state.has_unsaved_changes = true;
|
||||
}
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
page.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;
|
||||
page.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Next | MovementAction::Previous => {
|
||||
@@ -191,7 +191,7 @@ pub fn handle_add_table_event(
|
||||
} else if !page.state.links.is_empty() {
|
||||
page.state.link_table_state.select(Some(0));
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
page.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Down => {
|
||||
@@ -202,7 +202,7 @@ pub fn handle_add_table_event(
|
||||
} else if !page.state.links.is_empty() {
|
||||
page.state.link_table_state.select(Some(0));
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
page.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Select => {
|
||||
@@ -212,13 +212,13 @@ pub fn handle_add_table_event(
|
||||
page.state.has_unsaved_changes = true;
|
||||
}
|
||||
}
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
page.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;
|
||||
page.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
MovementAction::Next | MovementAction::Previous => {
|
||||
@@ -233,7 +233,7 @@ pub fn handle_add_table_event(
|
||||
let mut current = page.current_focus();
|
||||
if move_focus(&ADD_TABLE_FOCUS_ORDER, &mut current, ma) {
|
||||
page.set_current_focus(current);
|
||||
app_state.ui.focus_outside_canvas = !matches!(
|
||||
page.focus_outside_canvas = !matches!(
|
||||
page.current_focus(),
|
||||
AddTableFocus::InputTableName
|
||||
| AddTableFocus::InputColumnName
|
||||
|
||||
@@ -251,6 +251,7 @@ pub struct AddTableFormState {
|
||||
pub state: AddTableState,
|
||||
pub editor: FormEditor<AddTableState>,
|
||||
pub focus_outside_canvas: bool,
|
||||
pub focused_button_index: usize,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for AddTableFormState {
|
||||
@@ -258,6 +259,7 @@ impl std::fmt::Debug for AddTableFormState {
|
||||
f.debug_struct("AddTableFormState")
|
||||
.field("state", &self.state)
|
||||
.field("focus_outside_canvas", &self.focus_outside_canvas)
|
||||
.field("focused_button_index", &self.focused_button_index)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
@@ -271,6 +273,7 @@ impl AddTableFormState {
|
||||
state,
|
||||
editor,
|
||||
focus_outside_canvas: false,
|
||||
focused_button_index: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,6 +283,7 @@ impl AddTableFormState {
|
||||
state,
|
||||
editor,
|
||||
focus_outside_canvas: false,
|
||||
focused_button_index: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,4 +323,10 @@ impl AddTableFormState {
|
||||
pub fn link_table_state(&mut self) -> &mut TableState {
|
||||
&mut self.state.link_table_state
|
||||
}
|
||||
pub fn set_focused_button(&mut self, index: usize) {
|
||||
self.focused_button_index = index;
|
||||
}
|
||||
pub fn focused_button(&self) -> usize {
|
||||
self.focused_button_index
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,11 +489,14 @@ pub fn render_add_table(
|
||||
])
|
||||
.split(bottom_buttons_area);
|
||||
|
||||
let save_active = add_table_state.focus_outside_canvas
|
||||
&& add_table_state.focused_button_index == 0;
|
||||
let save_button = Paragraph::new(" Save table ")
|
||||
.style(get_button_style(
|
||||
AddTableFocus::SaveButton,
|
||||
add_table_state.current_focus(),
|
||||
))
|
||||
.style(if save_active {
|
||||
Style::default().fg(theme.highlight).add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
Style::default().fg(theme.secondary)
|
||||
})
|
||||
.alignment(Alignment::Center)
|
||||
.block(
|
||||
Block::default()
|
||||
@@ -506,37 +509,37 @@ pub fn render_add_table(
|
||||
);
|
||||
f.render_widget(save_button, bottom_button_chunks[0]);
|
||||
|
||||
let delete_active = add_table_state.focus_outside_canvas
|
||||
&& add_table_state.focused_button_index == 1;
|
||||
let delete_button = Paragraph::new(" Delete Selected ")
|
||||
.style(get_button_style(
|
||||
AddTableFocus::DeleteSelectedButton,
|
||||
add_table_state.current_focus(),
|
||||
))
|
||||
.alignment(Alignment::Center)
|
||||
.style(if delete_active {
|
||||
Style::default().fg(theme.highlight).add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
Style::default().fg(theme.secondary)
|
||||
})
|
||||
.alignment(Alignment::Center)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(get_button_border_style(
|
||||
add_table_state.current_focus() == AddTableFocus::DeleteSelectedButton, // Pass bool
|
||||
theme,
|
||||
)),
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(get_button_border_style(delete_active, theme)),
|
||||
);
|
||||
f.render_widget(delete_button, bottom_button_chunks[1]);
|
||||
|
||||
let cancel_active = add_table_state.focus_outside_canvas
|
||||
&& add_table_state.focused_button_index == 2;
|
||||
let cancel_button = Paragraph::new(" Cancel ")
|
||||
.style(get_button_style(
|
||||
AddTableFocus::CancelButton,
|
||||
add_table_state.current_focus(),
|
||||
))
|
||||
.alignment(Alignment::Center)
|
||||
.style(if cancel_active {
|
||||
Style::default().fg(theme.highlight).add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
Style::default().fg(theme.secondary)
|
||||
})
|
||||
.alignment(Alignment::Center)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(get_button_border_style(
|
||||
add_table_state.current_focus() == AddTableFocus::CancelButton, // Pass bool
|
||||
theme,
|
||||
)),
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(get_button_border_style(cancel_active, theme)),
|
||||
);
|
||||
f.render_widget(cancel_button, bottom_button_chunks[2]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user