2020-11-01 02:23:31 +13:00
|
|
|
use crate::gui_data::GuiData;
|
2021-11-25 20:36:49 +13:00
|
|
|
use crate::help_functions::{get_list_store, ColumnsDirectory};
|
2020-11-01 02:23:31 +13:00
|
|
|
use gtk::prelude::*;
|
2021-11-25 20:36:49 +13:00
|
|
|
use gtk::{TreeView, Window};
|
2020-11-01 02:23:31 +13:00
|
|
|
|
2020-12-31 01:41:18 +13:00
|
|
|
#[cfg(target_family = "windows")]
|
|
|
|
use czkawka_core::common::Common;
|
|
|
|
|
2020-12-08 03:25:44 +13:00
|
|
|
pub fn connect_selection_of_directories(gui_data: &GuiData) {
|
2020-12-31 01:41:18 +13:00
|
|
|
// Add manually directory
|
|
|
|
{
|
2021-01-11 08:12:08 +13:00
|
|
|
let tree_view_included_directories = gui_data.upper_notebook.tree_view_included_directories.clone();
|
2020-12-31 01:41:18 +13:00
|
|
|
let window_main = gui_data.window_main.clone();
|
2021-01-11 08:12:08 +13:00
|
|
|
let buttons_manual_add_directory = gui_data.upper_notebook.buttons_manual_add_directory.clone();
|
2020-12-31 01:41:18 +13:00
|
|
|
buttons_manual_add_directory.connect_clicked(move |_| {
|
2021-11-25 20:36:49 +13:00
|
|
|
add_manually_directories(&window_main, &tree_view_included_directories);
|
2020-12-31 22:26:07 +13:00
|
|
|
});
|
|
|
|
}
|
|
|
|
// Add manually excluded directory
|
|
|
|
{
|
2021-01-11 08:12:08 +13:00
|
|
|
let tree_view_excluded_directories = gui_data.upper_notebook.tree_view_excluded_directories.clone();
|
2020-12-31 22:26:07 +13:00
|
|
|
let window_main = gui_data.window_main.clone();
|
2021-01-11 08:12:08 +13:00
|
|
|
let buttons_manual_add_excluded_directory = gui_data.upper_notebook.buttons_manual_add_excluded_directory.clone();
|
2020-12-31 22:26:07 +13:00
|
|
|
buttons_manual_add_excluded_directory.connect_clicked(move |_| {
|
2021-11-25 20:36:49 +13:00
|
|
|
add_manually_directories(&window_main, &tree_view_excluded_directories);
|
2020-12-31 01:41:18 +13:00
|
|
|
});
|
|
|
|
}
|
2020-11-01 02:23:31 +13:00
|
|
|
// Add included directory
|
|
|
|
{
|
2021-01-11 08:12:08 +13:00
|
|
|
let tree_view_included_directories = gui_data.upper_notebook.tree_view_included_directories.clone();
|
2020-11-01 02:23:31 +13:00
|
|
|
let window_main = gui_data.window_main.clone();
|
2021-01-11 08:12:08 +13:00
|
|
|
let buttons_add_included_directory = gui_data.upper_notebook.buttons_add_included_directory.clone();
|
2020-11-01 02:23:31 +13:00
|
|
|
buttons_add_included_directory.connect_clicked(move |_| {
|
2021-11-25 20:36:49 +13:00
|
|
|
add_chosen_directories(&window_main, &tree_view_included_directories, false);
|
2020-11-01 02:23:31 +13:00
|
|
|
});
|
|
|
|
}
|
|
|
|
// Add excluded directory
|
|
|
|
{
|
2021-01-11 08:12:08 +13:00
|
|
|
let tree_view_excluded_directories = gui_data.upper_notebook.tree_view_excluded_directories.clone();
|
2020-11-01 02:23:31 +13:00
|
|
|
let window_main = gui_data.window_main.clone();
|
2021-01-11 08:12:08 +13:00
|
|
|
let buttons_add_excluded_directory = gui_data.upper_notebook.buttons_add_excluded_directory.clone();
|
2020-11-01 02:23:31 +13:00
|
|
|
buttons_add_excluded_directory.connect_clicked(move |_| {
|
2021-11-25 20:36:49 +13:00
|
|
|
add_chosen_directories(&window_main, &tree_view_excluded_directories, true);
|
2020-11-01 02:23:31 +13:00
|
|
|
});
|
|
|
|
}
|
|
|
|
// Remove Excluded Folder
|
|
|
|
{
|
2021-01-11 08:12:08 +13:00
|
|
|
let buttons_remove_excluded_directory = gui_data.upper_notebook.buttons_remove_excluded_directory.clone();
|
|
|
|
let tree_view_excluded_directories = gui_data.upper_notebook.tree_view_excluded_directories.clone();
|
2020-11-01 02:23:31 +13:00
|
|
|
buttons_remove_excluded_directory.connect_clicked(move |_| {
|
2021-01-11 01:45:05 +13:00
|
|
|
let list_store = get_list_store(&tree_view_excluded_directories);
|
2021-06-26 04:07:13 +12:00
|
|
|
let selection = tree_view_excluded_directories.selection();
|
2020-11-01 02:23:31 +13:00
|
|
|
|
2021-06-26 04:07:13 +12:00
|
|
|
let (vec_tree_path, _tree_model) = selection.selected_rows();
|
2020-12-30 07:31:09 +13:00
|
|
|
|
|
|
|
for tree_path in vec_tree_path.iter().rev() {
|
2021-06-26 04:07:13 +12:00
|
|
|
list_store.remove(&list_store.iter(tree_path).unwrap());
|
2020-12-30 07:31:09 +13:00
|
|
|
}
|
2020-11-01 02:23:31 +13:00
|
|
|
});
|
|
|
|
}
|
|
|
|
// Remove Included Folder
|
|
|
|
{
|
2021-01-11 08:12:08 +13:00
|
|
|
let buttons_remove_included_directory = gui_data.upper_notebook.buttons_remove_included_directory.clone();
|
|
|
|
let tree_view_included_directories = gui_data.upper_notebook.tree_view_included_directories.clone();
|
2020-11-01 02:23:31 +13:00
|
|
|
buttons_remove_included_directory.connect_clicked(move |_| {
|
2021-01-11 01:45:05 +13:00
|
|
|
let list_store = get_list_store(&tree_view_included_directories);
|
2021-06-26 04:07:13 +12:00
|
|
|
let selection = tree_view_included_directories.selection();
|
2020-11-01 02:23:31 +13:00
|
|
|
|
2021-06-26 04:07:13 +12:00
|
|
|
let (vec_tree_path, _tree_model) = selection.selected_rows();
|
2020-12-30 07:31:09 +13:00
|
|
|
|
|
|
|
for tree_path in vec_tree_path.iter().rev() {
|
2021-06-26 04:07:13 +12:00
|
|
|
list_store.remove(&list_store.iter(tree_path).unwrap());
|
2020-12-30 07:31:09 +13:00
|
|
|
}
|
2020-11-01 02:23:31 +13:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-11-25 20:36:49 +13:00
|
|
|
|
|
|
|
fn add_chosen_directories(window_main: &Window, tree_view: &TreeView, excluded_items: bool) {
|
|
|
|
let folders_to = if excluded_items { "Folders to exclude" } else { "Folders to include" };
|
|
|
|
let chooser = gtk::FileChooserDialog::with_buttons(Some(folders_to), Some(window_main), gtk::FileChooserAction::SelectFolder, &[("Ok", gtk::ResponseType::Ok), ("Close", gtk::ResponseType::Cancel)]);
|
|
|
|
chooser.set_select_multiple(true);
|
|
|
|
chooser.show_all();
|
|
|
|
let response_type = chooser.run();
|
|
|
|
if response_type == gtk::ResponseType::Ok {
|
|
|
|
let folder = chooser.filenames();
|
|
|
|
|
|
|
|
let list_store = get_list_store(tree_view);
|
|
|
|
|
|
|
|
for file_entry in &folder {
|
|
|
|
let values: [(u32, &dyn ToValue); 1] = [(ColumnsDirectory::Path as u32, &file_entry.to_string_lossy().to_string())];
|
|
|
|
list_store.set(&list_store.append(), &values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
chooser.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn add_manually_directories(window_main: &Window, tree_view: &TreeView) {
|
|
|
|
let dialog_manual_add_directory = gtk::Dialog::with_buttons(Some("Add directory manually"), Some(window_main), gtk::DialogFlags::MODAL, &[("Ok", gtk::ResponseType::Ok), ("Close", gtk::ResponseType::Cancel)]);
|
|
|
|
let entry: gtk::Entry = gtk::Entry::new();
|
|
|
|
|
|
|
|
for widgets in dialog_manual_add_directory.children() {
|
|
|
|
// By default GtkBox is child of dialog, so we can easily add other things to it
|
|
|
|
widgets.clone().downcast::<gtk::Box>().unwrap().add(&entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog_manual_add_directory.show_all();
|
|
|
|
|
|
|
|
let response_type = dialog_manual_add_directory.run();
|
|
|
|
if response_type == gtk::ResponseType::Ok {
|
|
|
|
let text = entry.text().to_string().trim().to_string();
|
|
|
|
|
|
|
|
#[cfg(target_family = "windows")]
|
|
|
|
let text = Common::normalize_windows_path(text).to_string_lossy().to_string();
|
|
|
|
|
|
|
|
if !text.is_empty() {
|
|
|
|
let list_store = get_list_store(tree_view);
|
|
|
|
|
|
|
|
let values: [(u32, &dyn ToValue); 1] = [(ColumnsDirectory::Path as u32, &text)];
|
|
|
|
list_store.set(&list_store.append(), &values);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dialog_manual_add_directory.close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dialog_manual_add_directory.close();
|
|
|
|
}
|