working general mode only with canvas, removing highlight, readonly or edit

This commit is contained in:
filipriec
2025-08-23 23:34:14 +02:00
parent 88a4b2d69c
commit 06cc1663b3
6 changed files with 112 additions and 259 deletions

View File

@@ -1,34 +1,27 @@
// src/modes/handlers/mode_manager.rs
use crate::state::app::state::AppState;
use crate::modes::handlers::event::EventHandler;
use crate::state::pages::add_logic::AddLogicFocus;
use crate::pages::routing::{Router, Page};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AppMode {
General, // For intro and admin screens
ReadOnly, // Canvas read-only mode
Edit, // Canvas edit mode
Highlight, // Canvas highlight/visual mode
Command, // Command mode overlay
}
/// General mode = when focus is outside any canvas
/// (Intro, Admin, Login/Register buttons, AddTable/AddLogic menus, dialogs, etc.)
General,
impl From<canvas::AppMode> for AppMode {
fn from(mode: canvas::AppMode) -> Self {
match mode {
canvas::AppMode::General => AppMode::General,
canvas::AppMode::ReadOnly => AppMode::ReadOnly,
canvas::AppMode::Edit => AppMode::Edit,
canvas::AppMode::Highlight => AppMode::Highlight,
canvas::AppMode::Command => AppMode::Command,
}
}
/// Command overlay (":" or "ctrl+;"), available globally
Command,
}
pub struct ModeManager;
impl ModeManager {
/// Determine current mode based on app state + router
/// Determine current mode:
/// - If navigation palette is active → General
/// - If command overlay is active → Command
/// - If focus is inside a canvas (Form, Login, Register, AddTable, AddLogic) → let canvas handle its own mode
/// - Otherwise → General
pub fn derive_mode(
app_state: &AppState,
event_handler: &EventHandler,
@@ -39,76 +32,28 @@ impl ModeManager {
return AppMode::General;
}
// Explicit command mode flag
// Explicit command overlay flag
if event_handler.command_mode {
return AppMode::Command;
}
// If focus is inside a canvas, we don't duplicate canvas modes here.
// Canvas crate owns ReadOnly/Edit/Highlight internally.
match &router.current {
// --- Form view ---
Page::Form(_) if !app_state.ui.focus_outside_canvas => {
if let Some(editor) = &app_state.form_editor {
return AppMode::from(editor.mode());
}
Page::Form(_)
| Page::Login(_)
| Page::Register(_)
| Page::AddTable(_)
| Page::AddLogic(_) if !app_state.ui.focus_outside_canvas => {
// Canvas active → let canvas handle its own AppMode
AppMode::General
}
// --- AddLogic view ---
Page::AddLogic(state) => match state.current_focus {
AddLogicFocus::InputLogicName
| AddLogicFocus::InputTargetColumn
| AddLogicFocus::InputDescription => {
if event_handler.is_edit_mode {
AppMode::Edit
} else {
AppMode::ReadOnly
}
}
_ => AppMode::General,
},
// --- AddTable view ---
Page::AddTable(_) => {
if app_state.ui.focus_outside_canvas {
AppMode::General
} else if event_handler.is_edit_mode {
AppMode::Edit
} else {
AppMode::ReadOnly
}
}
// --- Login/Register views ---
Page::Login(_) | Page::Register(_) => {
if event_handler.is_edit_mode {
AppMode::Edit
} else {
AppMode::ReadOnly
}
}
// --- Everything else (Intro, Admin, etc.) ---
_ => AppMode::General,
}
}
// Mode transition rules
pub fn can_enter_command_mode(current_mode: AppMode) -> bool {
!matches!(current_mode, AppMode::Edit)
}
pub fn can_enter_edit_mode(current_mode: AppMode) -> bool {
matches!(current_mode, AppMode::ReadOnly)
}
pub fn can_enter_read_only_mode(current_mode: AppMode) -> bool {
matches!(
current_mode,
AppMode::Edit | AppMode::Command | AppMode::Highlight
)
}
pub fn can_enter_highlight_mode(current_mode: AppMode) -> bool {
matches!(current_mode, AppMode::ReadOnly)
/// Command overlay can be entered from anywhere (General or Canvas).
pub fn can_enter_command_mode(_current_mode: AppMode) -> bool {
true
}
}