1
0
Fork 0
mirror of synced 2024-05-17 19:03:08 +12:00
czkawka/krokiet/src/common.rs
Rafał Mikrut 95c003cfa6 Chang
2024-02-01 07:48:22 +01:00

86 lines
3 KiB
Rust

use std::path::PathBuf;
use slint::{ModelRc, SharedString, StandardListViewItem, VecModel};
use crate::ExcludedDirectoriesModel;
use crate::IncludedDirectoriesModel;
use crate::CurrentTab;
// Remember to match updated this according to ui/main_lists.slint and connect_scan.rs files
pub fn get_path_idx(active_tab: CurrentTab) -> usize {
match active_tab {
CurrentTab::EmptyFolders => 1,
CurrentTab::EmptyFiles => 1,
CurrentTab::SimilarImages => 4,
CurrentTab::Settings => panic!("Button should be disabled"),
}
}
pub fn get_name_idx(active_tab: CurrentTab) -> usize {
match active_tab {
CurrentTab::EmptyFolders => 0,
CurrentTab::EmptyFiles => 0,
CurrentTab::SimilarImages => 3,
CurrentTab::Settings => panic!("Button should be disabled"),
}
}
pub fn get_is_header_mode(active_tab: CurrentTab) -> bool {
match active_tab {
CurrentTab::EmptyFolders | CurrentTab::EmptyFiles => false,
CurrentTab::SimilarImages => true,
CurrentTab::Settings => panic!("Button should be disabled"),
}
}
// pub fn create_string_standard_list_view(items: &[String]) -> ModelRc<StandardListViewItem> {
// let new_folders_standard_list_view = items
// .iter()
// .map(|x| {
// let mut element = StandardListViewItem::default();
// element.text = x.into();
// element
// })
// .collect::<Vec<_>>();
// ModelRc::new(VecModel::from(new_folders_standard_list_view))
// }
pub fn create_string_standard_list_view_from_pathbuf(items: &[PathBuf]) -> ModelRc<StandardListViewItem> {
let new_folders_standard_list_view = items
.iter()
.map(|x| {
let mut element = StandardListViewItem::default();
element.text = x.to_string_lossy().to_string().into();
element
})
.collect::<Vec<_>>();
ModelRc::new(VecModel::from(new_folders_standard_list_view))
}
pub fn create_included_directories_model_from_pathbuf(items: &[PathBuf]) -> ModelRc<IncludedDirectoriesModel> {
let converted = items
.iter()
.map(|x| {
IncludedDirectoriesModel {
path: x.to_string_lossy().to_string().into(),
referenced_folder: false,
selected_row: false,
}
})
.collect::<Vec<_>>();
ModelRc::new(VecModel::from(converted))
}
pub fn create_excluded_directories_model_from_pathbuf(items: &[PathBuf]) -> ModelRc<ExcludedDirectoriesModel> {
let converted = items
.iter()
.map(|x| {
ExcludedDirectoriesModel {
path: x.to_string_lossy().to_string().into(),
selected_row: false,
}
})
.collect::<Vec<_>>();
ModelRc::new(VecModel::from(converted))
}
pub fn create_vec_model_from_vec_string(items: Vec<String>) -> VecModel<SharedString> {
VecModel::from(items.into_iter().map(SharedString::from).collect::<Vec<_>>())
}