use super::{
super::{backend::*, model::*},
actions::*,
};
use {cursive::*, event::*};
pub struct TreeView<BackendT>
where
BackendT: TreeBackend,
{
pub model: TreeModel<BackendT>,
pub(crate) selected_row: Option<usize>,
pub(crate) page: usize,
pub(crate) debug: bool,
pub(crate) actions: Actions,
}
impl<BackendT> TreeView<BackendT>
where
BackendT: TreeBackend,
{
pub fn page(&self) -> usize {
self.page
}
pub fn set_page(&mut self, page: usize) {
self.page = page;
}
pub fn with_page(self, page: usize) -> Self {
self.with(|self_| self_.set_page(page))
}
pub fn debug(&self) -> bool {
self.debug
}
pub fn set_debug(&mut self, debug: bool) {
self.debug = debug;
}
pub fn with_debug(self, debug: bool) -> Self {
self.with(|self_| self_.set_debug(debug))
}
pub fn actions(&self) -> &Actions {
&self.actions
}
pub fn actions_mut(&mut self) -> &mut Actions {
&mut self.actions
}
pub fn set_actions(&mut self, actions: Actions) {
self.actions = actions;
}
pub fn with_actions(self, actions: Actions) -> Self {
self.with(|self_| self_.set_actions(actions))
}
pub fn set_action<EventT>(&mut self, action: Action, event: EventT)
where
EventT: Into<Event>,
{
self.actions.insert(event.into(), action);
}
pub fn with_action<EventT>(self, action: Action, event: EventT) -> Self
where
EventT: Into<Event>,
{
self.with(|self_| self_.set_action(action, event))
}
pub fn remove_action(&mut self, action: Action) -> bool {
action.remove(&mut self.actions)
}
pub fn without_action(self, action: Action) -> Self {
self.with(|self_| _ = self_.remove_action(action))
}
}
impl<BackendT> From<TreeModel<BackendT>> for TreeView<BackendT>
where
BackendT: TreeBackend,
{
fn from(model: TreeModel<BackendT>) -> Self {
Self { model, selected_row: None, page: 10, debug: false, actions: Action::defaults() }
}
}