fn toggle_tag(siv: &mut Cursive, state: &mut AppState) {
    let tp = siv
        .call_on_id("tagsview", |v: &mut SelectView<PathBuf>| {
            v.selection().unwrap()
        })
        .unwrap();
    let tp = tp.as_path();
    let tag = state.tags.get_mut(tp).unwrap();

    // check for mixed state and abort if needed
    {
        let mut iter = state.sel.iter();
        let first = if let Some(x) = iter.next() {
            tag.items.contains_key(x)
        } else {
            false /* actually irrelevant */
        };
        for i in iter {
            let contains = tag.items.contains_key(i);
            if (first && !contains) || (!first && contains) {
                return;
            }
        }
    }

    for ip in state.sel.iter() {
        let item = state.items_all.get_mut(ip).unwrap();
        if let Some(p) = tag.items.get(ip) {
            fs::remove_file(p).expect("could not delete symlink");
            tag.items.remove(ip);
            item.tags.remove(tp);
        } else {
            let target = tag_target_path(&tp, &ip);
            let mut link = tp.to_path_buf();
            link.push(&item.filename);

            std::os::unix::fs::symlink(&target, &link).expect("could not create symlink");
            tag.items.insert(ip.to_owned(), link);
            item.tags.insert(tp.to_owned());
        }
    }
}
/// UI callback to tag/untag selected items
UI callback to tag/untag selected items
UI callback to tag / untag selected items
fn toggle_tag(siv: &mut Cursive, state: &mut AppState) {
    let tp = siv
        .call_on_id("tagsview", |v: &mut SelectView<PathBuf>| {
            v.selection().unwrap()
        })
        .unwrap();
    let tp = tp.as_path();
    let tag = state.tags.get_mut(tp).unwrap();
    // check for mixed state and abort if needed
    {
        let mut iter = state.sel.iter();
        let first = if let Some(x) = iter.next() {
            tag.items.contains_key(x)
        } else {
            false /* actually irrelevant */
        };
        for i in iter {
            let contains = tag.items.contains_key(i);
            if (first && !contains) || (!first && contains) {
                return;
            }
        }
    }
    for ip in state.sel.iter() {
        let item = state.items_all.get_mut(ip).unwrap();
        if let Some(p) = tag.items.get(ip) {
            fs::remove_file(p).expect("could not delete symlink");
            tag.items.remove(ip);
            item.tags.remove(tp);
        } else {
            let target = tag_target_path(&tp, &ip);
            let mut link = tp.to_path_buf();
            link.push(&item.filename);
            std::os::unix::fs::symlink(&target, &link).expect("could not create symlink");
            tag.items.insert(ip.to_owned(), link);
            item.tags.insert(tp.to_owned());
        }
    }
}
fn toggle_tag ( siv : & mut Cursive , state : & mut AppState ) { let tp = siv . call_on_id ( " " , | v : & mut SelectView < PathBuf > | { v . selection ( ) . unwrap ( ) } ) . unwrap ( ) ; let tp = tp . as_path ( ) ; let tag = state . tags . get_mut ( tp ) . unwrap ( ) ; // check for mixed state and abort if needed { let mut iter = state . sel . iter ( ) ; let first = if let Some ( x ) = iter . next ( ) { tag . items . contains_key ( x ) } else { false /* actually irrelevant */ } ; for i in iter { let contains = tag . items . contains_key ( i ) ; if ( first && ! contains ) || ( ! first && contains ) { return ; } } } for ip in state . sel . iter ( ) { let item = state . items_all . get_mut ( ip ) . unwrap ( ) ; if let Some ( p ) = tag . items . get ( ip ) { fs :: remove_file ( p ) . expect ( " " ) ; tag . items . remove ( ip ) ; item . tags . remove ( tp ) ; } else { let target = tag_target_path ( & tp , & ip ) ; let mut link = tp . to_path_buf ( ) ; link . push ( & item . filename ) ; std :: os :: unix :: fs :: symlink ( & target , & link ) . expect ( " " ) ; tag . items . insert ( ip . to_owned ( ) , link ) ; item . tags . insert ( tp . to_owned ( ) ) ; } } }
UI callback to tag/untag selected items
UI callback to tag / untag selected items
siv
&mut Cursive
state
&mut AppState