pub fn tree_remove(tree_view: &gtk::TreeView, column_file_name: i32, column_path: i32, column_color: i32, column_selection: i32, check_button_settings_use_trash: &CheckButton, text_view_errors: &TextView) {
    let use_trash = check_button_settings_use_trash.is_active();

    let model = get_list_store(tree_view);

    let mut messages: String = "".to_string();

    let mut vec_path_to_delete: Vec<(String, String)> = Vec::new();
    let mut map_with_path_to_delete: BTreeMap<String, Vec<String>> = Default::default(); // BTreeMap<Path,Vec<FileName>>

    let mut selected_rows = Vec::new();

    if let Some(iter) = model.iter_first() {
        loop {
            if model.value(&iter, column_selection).get::<bool>().unwrap() {
                if model.value(&iter, column_color).get::<String>().unwrap() == MAIN_ROW_COLOR {
                    selected_rows.push(model.path(&iter).unwrap());
                } else {
                    panic!("Header row shouldn't be selected, please report bug.");
                }
            }

            if !model.iter_next(&iter) {
                break;
            }
        }
    }

    if selected_rows.is_empty() {
        return; // No selected rows
    }

    // Save to variable paths of files, and remove it when not removing all occurrences.
    for tree_path in selected_rows.iter().rev() {
        let iter = model.iter(tree_path).unwrap();

        let file_name = model.value(&iter, column_file_name).get::<String>().unwrap();
        let path = model.value(&iter, column_path).get::<String>().unwrap();

        model.remove(&iter);

        map_with_path_to_delete.entry(path.clone()).or_insert_with(Vec::new);
        map_with_path_to_delete.get_mut(path.as_str()).unwrap().push(file_name);
    }

    // Delete duplicated entries, and remove real files
    for (path, mut vec_file_name) in map_with_path_to_delete {
        vec_file_name.sort();
        vec_file_name.dedup();
        for file_name in vec_file_name {
            if !use_trash {
                if let Err(e) = fs::remove_file(format!("{}/{}", path.clone(), file_name.clone())) {
                    messages += format!("Failed to remove file {}/{}, reason {}\n", path, file_name, e).as_str()
                }
            } else if let Err(e) = trash::delete(format!("{}/{}", path.clone(), file_name.clone())) {
                messages += format!("Failed to remove file {}/{}, reason {}\n", path, file_name, e).as_str()
            }

            vec_path_to_delete.push((path.clone(), file_name.clone()));
        }
    }

    clean_invalid_headers(&model, column_color);

    text_view_errors.buffer().unwrap().set_text(messages.as_str());
}
// Remove all occurrences - remove every element which have same path and name as even non selected ones
Remove all occurrences - remove every element which have same path and name as even non selected ones
Remove all occurrences - remove every element which have same path and name as even non selected ones
pub fn tree_remove(tree_view: &gtk::TreeView, column_file_name: i32, column_path: i32, column_color: i32, column_selection: i32, check_button_settings_use_trash: &CheckButton, text_view_errors: &TextView) {
    let use_trash = check_button_settings_use_trash.is_active();
    let model = get_list_store(tree_view);
    let mut messages: String = "".to_string();
    let mut vec_path_to_delete: Vec<(String, String)> = Vec::new();
    let mut map_with_path_to_delete: BTreeMap<String, Vec<String>> = Default::default(); // BTreeMap<Path,Vec<FileName>>
    let mut selected_rows = Vec::new();
    if let Some(iter) = model.iter_first() {
        loop {
            if model.value(&iter, column_selection).get::<bool>().unwrap() {
                if model.value(&iter, column_color).get::<String>().unwrap() == MAIN_ROW_COLOR {
                    selected_rows.push(model.path(&iter).unwrap());
                } else {
                    panic!("Header row shouldn't be selected, please report bug.");
                }
            }
            if !model.iter_next(&iter) {
                break;
            }
        }
    }
    if selected_rows.is_empty() {
        return; // No selected rows
    }
    // Save to variable paths of files, and remove it when not removing all occurrences.
    for tree_path in selected_rows.iter().rev() {
        let iter = model.iter(tree_path).unwrap();
        let file_name = model.value(&iter, column_file_name).get::<String>().unwrap();
        let path = model.value(&iter, column_path).get::<String>().unwrap();
        model.remove(&iter);
        map_with_path_to_delete.entry(path.clone()).or_insert_with(Vec::new);
        map_with_path_to_delete.get_mut(path.as_str()).unwrap().push(file_name);
    }
    // Delete duplicated entries, and remove real files
    for (path, mut vec_file_name) in map_with_path_to_delete {
        vec_file_name.sort();
        vec_file_name.dedup();
        for file_name in vec_file_name {
            if !use_trash {
                if let Err(e) = fs::remove_file(format!("{}/{}", path.clone(), file_name.clone())) {
                    messages += format!("Failed to remove file {}/{}, reason {}\n", path, file_name, e).as_str()
                }
            } else if let Err(e) = trash::delete(format!("{}/{}", path.clone(), file_name.clone())) {
                messages += format!("Failed to remove file {}/{}, reason {}\n", path, file_name, e).as_str()
            }
            vec_path_to_delete.push((path.clone(), file_name.clone()));
        }
    }
    clean_invalid_headers(&model, column_color);
    text_view_errors.buffer().unwrap().set_text(messages.as_str());
}
pub fn tree_remove ( tree_view : & gtk :: TreeView , column_file_name : i32 , column_path : i32 , column_color : i32 , column_selection : i32 , check_button_settings_use_trash : & CheckButton , text_view_errors : & TextView ) { let use_trash = check_button_settings_use_trash . is_active ( ) ; let model = get_list_store ( tree_view ) ; let mut messages : String = " " . to_string ( ) ; let mut vec_path_to_delete : Vec < ( String , String ) > = Vec :: new ( ) ; let mut map_with_path_to_delete : BTreeMap < String , Vec < String > > = Default :: default ( ) ; // BTreeMap<Path,Vec<FileName>> let mut selected_rows = Vec :: new ( ) ; if let Some ( iter ) = model . iter_first ( ) { loop { if model . value ( & iter , column_selection ) . get :: < bool > ( ) . unwrap ( ) { if model . value ( & iter , column_color ) . get :: < String > ( ) . unwrap ( ) == MAIN_ROW_COLOR { selected_rows . push ( model . path ( & iter ) . unwrap ( ) ) ; } else { panic ! ( " " ) ; } } if ! model . iter_next ( & iter ) { break ; } } } if selected_rows . is_empty ( ) { return ; // No selected rows } // Save to variable paths of files, and remove it when not removing all occurrences. for tree_path in selected_rows . iter ( ) . rev ( ) { let iter = model . iter ( tree_path ) . unwrap ( ) ; let file_name = model . value ( & iter , column_file_name ) . get :: < String > ( ) . unwrap ( ) ; let path = model . value ( & iter , column_path ) . get :: < String > ( ) . unwrap ( ) ; model . remove ( & iter ) ; map_with_path_to_delete . entry ( path . clone ( ) ) . or_insert_with ( Vec :: new ) ; map_with_path_to_delete . get_mut ( path . as_str ( ) ) . unwrap ( ) . push ( file_name ) ; } // Delete duplicated entries, and remove real files for ( path , mut vec_file_name ) in map_with_path_to_delete { vec_file_name . sort ( ) ; vec_file_name . dedup ( ) ; for file_name in vec_file_name { if ! use_trash { if let Err ( e ) = fs :: remove_file ( format ! ( " " path clone ( ) file_name clone ( ) ) ) { messages += format ! ( " \n " path file_name e ) . as_str ( ) } } else if let Err ( e ) = trash :: delete ( format ! ( " " path clone ( ) file_name clone ( ) ) ) { messages += format ! ( " \n " path file_name e ) . as_str ( ) } vec_path_to_delete . push ( ( path . clone ( ) , file_name . clone ( ) ) ) ; } } clean_invalid_headers ( & model , column_color ) ; text_view_errors . buffer ( ) . unwrap ( ) . set_text ( messages . as_str ( ) ) ; }
Remove all occurrences - remove every element which have same path and name as even non selected ones
Remove all occurrences - remove every element which have same path and name as even non selected ones
tree_view
&gtk::TreeView
column_file_name
i32
column_path
i32
column_color
i32
column_selection
i32
check_button_settings_use_trash
&CheckButton
text_view_errors
&TextView
tree_view
&gtk::TreeView
column_file_name
i32
column_path
i32
column_color
i32
column_selection
i32
check_button_settings_use_trash
&CheckButton
text_view_errors
&TextView