Add manual adding of directories (#165)
This commit is contained in:
parent
a2f44d58c2
commit
083db7aa51
|
@ -109,6 +109,12 @@ impl Common {
|
||||||
|
|
||||||
pub fn normalize_windows_path(path_to_change: impl AsRef<Path>) -> PathBuf {
|
pub fn normalize_windows_path(path_to_change: impl AsRef<Path>) -> PathBuf {
|
||||||
let path = path_to_change.as_ref();
|
let path = path_to_change.as_ref();
|
||||||
|
|
||||||
|
// Don't do anything, because network path may be case intensive
|
||||||
|
if path.to_string_lossy().starts_with('\\') {
|
||||||
|
return path.to_path_buf();
|
||||||
|
}
|
||||||
|
|
||||||
match path.to_str() {
|
match path.to_str() {
|
||||||
Some(path) if path.is_char_boundary(1) => {
|
Some(path) if path.is_char_boundary(1) => {
|
||||||
let replaced = path.replace("/", "\\");
|
let replaced = path.replace("/", "\\");
|
||||||
|
@ -157,5 +163,8 @@ mod test {
|
||||||
assert_eq!(PathBuf::from("C:\\path.txt"), Common::normalize_windows_path("c:/PATH.tXt"));
|
assert_eq!(PathBuf::from("C:\\path.txt"), Common::normalize_windows_path("c:/PATH.tXt"));
|
||||||
assert_eq!(PathBuf::from("H:\\reka\\weza\\roman.txt"), Common::normalize_windows_path("h:/RekA/Weza\\roMan.Txt"));
|
assert_eq!(PathBuf::from("H:\\reka\\weza\\roman.txt"), Common::normalize_windows_path("h:/RekA/Weza\\roMan.Txt"));
|
||||||
assert_eq!(PathBuf::from("T:\\a"), Common::normalize_windows_path("T:\\A"));
|
assert_eq!(PathBuf::from("T:\\a"), Common::normalize_windows_path("T:\\A"));
|
||||||
|
assert_eq!(PathBuf::from("\\\\aBBa"), Common::normalize_windows_path("\\\\aBBa"));
|
||||||
|
assert_eq!(PathBuf::from("a"), Common::normalize_windows_path("a"));
|
||||||
|
assert_eq!(PathBuf::from(""), Common::normalize_windows_path(""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,18 @@ impl Directories {
|
||||||
text_messages.warnings.push(format!("Included Directory Warning: Wildcards in path are not supported, ignoring {}", directory.display()));
|
text_messages.warnings.push(format!("Included Directory Warning: Wildcards in path are not supported, ignoring {}", directory.display()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "windows"))]
|
||||||
if directory.is_relative() {
|
if directory.is_relative() {
|
||||||
text_messages.warnings.push(format!("Included Directory Warning: Relative path are not supported, ignoring {}", directory.display()));
|
text_messages.warnings.push(format!("Included Directory Warning: Relative path are not supported, ignoring {}", directory.display()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
#[cfg(target_family = "windows")]
|
||||||
|
if directory.is_relative() && !directory.starts_with("\\") {
|
||||||
|
text_messages.warnings.push(format!("Included Directory Warning: Relative path are not supported, ignoring {}", directory.display()));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if !directory.exists() {
|
if !directory.exists() {
|
||||||
text_messages.warnings.push(format!("Included Directory Warning: Provided folder path must exits, ignoring {}", directory.display()));
|
text_messages.warnings.push(format!("Included Directory Warning: Provided folder path must exits, ignoring {}", directory.display()));
|
||||||
continue;
|
continue;
|
||||||
|
@ -79,10 +87,17 @@ impl Directories {
|
||||||
text_messages.warnings.push(format!("Excluded Directory Warning: Wildcards in path are not supported, ignoring {}", directory.display()));
|
text_messages.warnings.push(format!("Excluded Directory Warning: Wildcards in path are not supported, ignoring {}", directory.display()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
#[cfg(not(target_family = "windows"))]
|
||||||
if directory.is_relative() {
|
if directory.is_relative() {
|
||||||
text_messages.warnings.push(format!("Excluded Directory Warning: Relative path are not supported, ignoring {}", directory.display()));
|
text_messages.warnings.push(format!("Excluded Directory Warning: Relative path are not supported, ignoring {}", directory.display()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
#[cfg(target_family = "windows")]
|
||||||
|
if directory.is_relative() && !directory.starts_with("\\") {
|
||||||
|
text_messages.warnings.push(format!("Excluded Directory Warning: Relative path are not supported, ignoring {}", directory.display()));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if !directory.exists() {
|
if !directory.exists() {
|
||||||
// text_messages.warnings.push(format!("Excluded Directory Warning: Provided folder path must exits, ignoring {}", directory.display()));
|
// text_messages.warnings.push(format!("Excluded Directory Warning: Provided folder path must exits, ignoring {}", directory.display()));
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -548,6 +548,57 @@ Author: Rafał Mikrut
|
||||||
<property name="position">1</property>
|
<property name="position">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="buttons_manual_add_directory">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkAlignment">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="xscale">0</property>
|
||||||
|
<property name="yscale">0</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="spacing">4</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkImage">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="icon_name">insert-link</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">Manual Add</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">False</property>
|
||||||
|
<property name="position">2</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
|
|
|
@ -3,7 +3,49 @@ use crate::gui_data::GuiData;
|
||||||
use crate::help_functions::{get_list_store, get_tree_view};
|
use crate::help_functions::{get_list_store, get_tree_view};
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
#[cfg(target_family = "windows")]
|
||||||
|
use czkawka_core::common::Common;
|
||||||
|
|
||||||
pub fn connect_selection_of_directories(gui_data: &GuiData) {
|
pub fn connect_selection_of_directories(gui_data: &GuiData) {
|
||||||
|
// Add manually directory
|
||||||
|
{
|
||||||
|
let scrolled_window_included_directories = gui_data.scrolled_window_included_directories.clone();
|
||||||
|
let window_main = gui_data.window_main.clone();
|
||||||
|
let buttons_manual_add_directory = gui_data.buttons_manual_add_directory.clone();
|
||||||
|
buttons_manual_add_directory.connect_clicked(move |_| {
|
||||||
|
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.get_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.get_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 tree_view = scrolled_window_included_directories.get_children().get(0).unwrap().clone().downcast::<gtk::TreeView>().unwrap();
|
||||||
|
let list_store = tree_view.get_model().unwrap().downcast::<gtk::ListStore>().unwrap();
|
||||||
|
|
||||||
|
let col_indices = [0];
|
||||||
|
|
||||||
|
let values: [&dyn ToValue; 1] = [&text];
|
||||||
|
list_store.set(&list_store.append(), &col_indices, &values);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dialog_manual_add_directory.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dialog_manual_add_directory.close();
|
||||||
|
});
|
||||||
|
}
|
||||||
// Add included directory
|
// Add included directory
|
||||||
{
|
{
|
||||||
let scrolled_window_included_directories = gui_data.scrolled_window_included_directories.clone();
|
let scrolled_window_included_directories = gui_data.scrolled_window_included_directories.clone();
|
||||||
|
|
|
@ -63,6 +63,8 @@ pub struct GuiData {
|
||||||
pub buttons_show_errors: gtk::Button,
|
pub buttons_show_errors: gtk::Button,
|
||||||
pub buttons_names: [String; 5],
|
pub buttons_names: [String; 5],
|
||||||
pub buttons_array: [Button; 5],
|
pub buttons_array: [Button; 5],
|
||||||
|
|
||||||
|
pub buttons_manual_add_directory: gtk::Button,
|
||||||
pub buttons_add_included_directory: gtk::Button,
|
pub buttons_add_included_directory: gtk::Button,
|
||||||
pub buttons_remove_included_directory: gtk::Button,
|
pub buttons_remove_included_directory: gtk::Button,
|
||||||
pub buttons_add_excluded_directory: gtk::Button,
|
pub buttons_add_excluded_directory: gtk::Button,
|
||||||
|
@ -276,6 +278,7 @@ impl GuiData {
|
||||||
let buttons_names = ["search".to_string(), "select".to_string(), "delete".to_string(), "save".to_string(), "symlink".to_string()];
|
let buttons_names = ["search".to_string(), "select".to_string(), "delete".to_string(), "save".to_string(), "symlink".to_string()];
|
||||||
let buttons_array = [buttons_search.clone(), buttons_select.clone(), buttons_delete.clone(), buttons_save.clone(), buttons_symlink.clone()];
|
let buttons_array = [buttons_search.clone(), buttons_select.clone(), buttons_delete.clone(), buttons_save.clone(), buttons_symlink.clone()];
|
||||||
|
|
||||||
|
let buttons_manual_add_directory: gtk::Button = builder.get_object("buttons_manual_add_directory").unwrap();
|
||||||
let buttons_add_included_directory: gtk::Button = builder.get_object("buttons_add_included_directory").unwrap();
|
let buttons_add_included_directory: gtk::Button = builder.get_object("buttons_add_included_directory").unwrap();
|
||||||
let buttons_remove_included_directory: gtk::Button = builder.get_object("buttons_remove_included_directory").unwrap();
|
let buttons_remove_included_directory: gtk::Button = builder.get_object("buttons_remove_included_directory").unwrap();
|
||||||
let buttons_add_excluded_directory: gtk::Button = builder.get_object("buttons_add_excluded_directory").unwrap();
|
let buttons_add_excluded_directory: gtk::Button = builder.get_object("buttons_add_excluded_directory").unwrap();
|
||||||
|
@ -428,6 +431,7 @@ impl GuiData {
|
||||||
buttons_show_errors,
|
buttons_show_errors,
|
||||||
buttons_names,
|
buttons_names,
|
||||||
buttons_array,
|
buttons_array,
|
||||||
|
buttons_manual_add_directory,
|
||||||
buttons_add_included_directory,
|
buttons_add_included_directory,
|
||||||
buttons_remove_included_directory,
|
buttons_remove_included_directory,
|
||||||
buttons_add_excluded_directory,
|
buttons_add_excluded_directory,
|
||||||
|
|
Loading…
Reference in a new issue