1
0
Fork 0
mirror of synced 2024-06-01 18:19:46 +12:00
czkawka/krokiet/src/common.rs

86 lines
3.2 KiB
Rust
Raw Normal View History

use std::path::PathBuf;
2024-02-04 06:47:00 +13:00
use crate::CurrentTab;
2024-02-01 19:48:22 +13:00
use crate::ExcludedDirectoriesModel;
use crate::IncludedDirectoriesModel;
2024-02-04 06:47:00 +13:00
use slint::{ModelRc, SharedString, VecModel};
2024-01-15 08:00:56 +13:00
// 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))
// }
2024-02-04 06:47:00 +13:00
// 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))
// }
2024-02-04 06:47:00 +13:00
pub fn create_included_directories_model_from_pathbuf(items: &[PathBuf], referenced: &[PathBuf]) -> ModelRc<IncludedDirectoriesModel> {
let referenced_as_string = referenced.iter().map(|x| x.to_string_lossy().to_string()).collect::<Vec<_>>();
2024-02-01 19:48:22 +13:00
let converted = items
.iter()
.map(|x| {
2024-02-04 06:47:00 +13:00
let path_as_string = x.to_string_lossy().to_string();
2024-02-01 19:48:22 +13:00
IncludedDirectoriesModel {
path: x.to_string_lossy().to_string().into(),
2024-02-04 06:47:00 +13:00
referenced_folder: referenced_as_string.contains(&path_as_string),
2024-02-01 19:48:22 +13:00
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()
2024-02-04 06:47:00 +13:00
.map(|x| ExcludedDirectoriesModel {
path: x.to_string_lossy().to_string().into(),
selected_row: false,
2024-02-01 19:48:22 +13:00
})
.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<_>>())
}