fn init_view(&mut self) -> io::Result<()> {
        // Create the first tree entry for the given file or directory name
        let mut path = self.init_path.clone();
        let root = self.root_path.clone();
        let prefpath = path.clone();
        let rel = prefpath.strip_prefix(&root)
            .map_err(|_e| io::Error::new(
                io::ErrorKind::InvalidInput,
                "Target not under base",
        ))?;
        let mut row = self.view
            .insert_item(FileEntry::new(path.clone()), Placement::LastChild, 0).expect("Bad add");
        for comp in rel.iter() {
            path.push(comp);
            row = self.view
                .insert_item(FileEntry::new(path.clone()), Placement::LastChild, row).expect("Bad add");
        }

        // Select the init path - currently the last row
        let selrow = self.view.len() - 1;
        self.view.set_selected_row(selrow);

        // If the entry is a directory, expand it.
        let idx = self.view.len() - 1;
        let path = self.init_path.clone();
        self.expand_tree(idx, &path);
        Ok(())
    }
/// Initialize the FileView to get a working view
///
/// # Example
///
/// ```rust
/// # extern crate cursive;
/// # extern crate cursive_tree_view;
/// # use cursive::Cursive;
/// # use cursive_tree_view::FileView;
/// # use std::path::PathBuf;
/// # fn main() {
/// let mut fileview = FileView::new().on_submit(|siv: &mut Cursive, path: PathBuf| {
///		println!("Path: {:?}", path)
/// }).init_view();
/// let mut siv = Cursive::default();
/// siv.add_layer(cursive::views::Dialog::around(fileview));
/// siv.run();
/// # }
/// ```
Initialize the FileView to get a working view
Initialize the FileView to get a working view
fn init_view(&mut self) -> io::Result<()> {
        // Create the first tree entry for the given file or directory name
        let mut path = self.init_path.clone();
        let root = self.root_path.clone();
        let prefpath = path.clone();
        let rel = prefpath.strip_prefix(&root)
            .map_err(|_e| io::Error::new(
                io::ErrorKind::InvalidInput,
                "Target not under base",
        ))?;
        let mut row = self.view
            .insert_item(FileEntry::new(path.clone()), Placement::LastChild, 0).expect("Bad add");
        for comp in rel.iter() {
            path.push(comp);
            row = self.view
                .insert_item(FileEntry::new(path.clone()), Placement::LastChild, row).expect("Bad add");
        }
        // Select the init path - currently the last row
        let selrow = self.view.len() - 1;
        self.view.set_selected_row(selrow);
        // If the entry is a directory, expand it.
        let idx = self.view.len() - 1;
        let path = self.init_path.clone();
        self.expand_tree(idx, &path);
        Ok(())
    }
fn init_view ( & mut self ) -> io :: Result < ( ) > { // Create the first tree entry for the given file or directory name let mut path = self . init_path . clone ( ) ; let root = self . root_path . clone ( ) ; let prefpath = path . clone ( ) ; let rel = prefpath . strip_prefix ( & root ) . map_err ( | _e | io :: Error :: new ( io :: ErrorKind :: InvalidInput , " " , ) ) ? ; let mut row = self . view . insert_item ( FileEntry :: new ( path . clone ( ) ) , Placement :: LastChild , 0 ) . expect ( " " ) ; for comp in rel . iter ( ) { path . push ( comp ) ; row = self . view . insert_item ( FileEntry :: new ( path . clone ( ) ) , Placement :: LastChild , row ) . expect ( " " ) ; } // Select the init path - currently the last row let selrow = self . view . len ( ) - 1 ; self . view . set_selected_row ( selrow ) ; // If the entry is a directory, expand it. let idx = self . view . len ( ) - 1 ; let path = self . init_path . clone ( ) ; self . expand_tree ( idx , & path ) ; Ok ( ( ) ) }
Initialize the FileView to get a working view
Initialize the FileView to get a working view
&mut self
&mut self
example
None
extern crate cursive;
None
extern crate cursive_tree_view;
None
use cursive::cursive;
None
use cursive_tree_view::fileview;
None
use std::path::pathbuf;
None
fn main() {
let mut fileview = FileView::new().on_submit(|siv: &mut Cursive, path: PathBuf| {
println!("Path: {:?}", path)
}).init_view();
let mut siv = Cursive::default();
siv.add_layer(cursive::views::Dialog::around(fileview));
siv.run().
let mut fileview = FileView :: new () . on_submit ( |siv : &mut Cursive path : PathBuf| { println! ( " Path : { : ? } " path ) } ) . init_view () ; let mut siv = Cursive :: default () ; siv . add_layer ( cursive :: views :: Dialog :: around ( fileview )) ; siv . run () .
}
None