Skip to main content

cursive_tree/view/
state.rs

1use super::{
2    super::{backend::*, model::*},
3    tree::*,
4};
5
6use cursive::event::*;
7
8impl<BackendT> TreeView<BackendT>
9where
10    BackendT: TreeBackend,
11    BackendT::Context: Clone,
12    BackendT::Error: 'static + Send + Sync,
13{
14    /// Toggle branch state.
15    pub fn toggle_branch_state(node: &mut Node<BackendT>, context: BackendT::Context) -> EventResult {
16        EventResult::Consumed(match node.toggle_branch_state(context) {
17            Ok(_) => None,
18            Err(error) => Some(Callback::from_fn_once(|cursive| {
19                BackendT::handle_error(cursive, error);
20            })),
21        })
22    }
23
24    /// Expand branch.
25    pub fn expand_branch(node: &mut Node<BackendT>, context: BackendT::Context) -> EventResult {
26        EventResult::Consumed(match node.expand_branch(context) {
27            Ok(_) => None,
28            Err(error) => Some(Callback::from_fn_once(|cursive| {
29                BackendT::handle_error(cursive, error);
30            })),
31        })
32    }
33}