use crate::buffer::{AppMode, FilterState, FuzzyFilterState, SearchState};
use crate::ui::state::shadow_state::SearchType;
#[derive(Debug, Clone)]
pub enum StateEvent {
ModeChanged { from: AppMode, to: AppMode },
SearchStarted { search_type: SearchType },
SearchEnded { search_type: SearchType },
SearchPatternUpdated {
search_type: SearchType,
pattern: String,
},
FilterToggled {
filter_type: FilterType,
active: bool,
},
DataViewUpdated,
ColumnOperation { op: ColumnOp },
ViewportChanged { row: usize, col: usize },
}
#[derive(Debug, Clone)]
pub enum FilterType {
Regex,
Fuzzy,
Column,
}
#[derive(Debug, Clone)]
pub enum ColumnOp {
Hide(usize),
Pin(usize),
Sort(usize),
Reset,
}
#[derive(Debug, Default, Clone)]
pub struct StateChange {
pub mode: Option<AppMode>,
pub search_state: Option<SearchState>,
pub filter_state: Option<FilterState>,
pub fuzzy_filter_state: Option<FuzzyFilterState>,
pub clear_all_searches: bool,
}
impl StateChange {
#[must_use]
pub fn clear_searches() -> Self {
Self {
search_state: Some(SearchState::default()),
filter_state: Some(FilterState::default()),
fuzzy_filter_state: Some(FuzzyFilterState::default()),
clear_all_searches: true,
..Default::default()
}
}
#[must_use]
pub fn mode(mode: AppMode) -> Self {
Self {
mode: Some(mode),
..Default::default()
}
}
pub fn and(mut self, other: StateChange) -> Self {
if other.mode.is_some() {
self.mode = other.mode;
}
if other.search_state.is_some() {
self.search_state = other.search_state;
}
if other.filter_state.is_some() {
self.filter_state = other.filter_state;
}
if other.fuzzy_filter_state.is_some() {
self.fuzzy_filter_state = other.fuzzy_filter_state;
}
if other.clear_all_searches {
self.clear_all_searches = true;
}
self
}
}