Add setting for deletion confirmation dialog (#114)
This commit is contained in:
parent
62e5e8e03e
commit
30bd1f2f38
|
@ -955,10 +955,19 @@ Author: Rafał Mikrut
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
<object class="GtkCheckButton" id="check_button_settings_confirm_deletion">
|
||||
<property name="label" translatable="yes">Show confirm dialog when deleting</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="width">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
|
|
|
@ -9,7 +9,6 @@ use std::fs::Metadata;
|
|||
pub fn connect_button_delete(gui_data: &GuiData) {
|
||||
let gui_data = gui_data.clone();
|
||||
let buttons_delete = gui_data.buttons_delete.clone();
|
||||
let shared_confirmation_dialog_delete_dialog_showing_state = gui_data.shared_confirmation_dialog_delete_dialog_showing_state.clone();
|
||||
let scrolled_window_duplicate_finder = gui_data.scrolled_window_duplicate_finder.clone();
|
||||
let notebook_main_children_names = gui_data.notebook_main_children_names.clone();
|
||||
let notebook_main = gui_data.notebook_main.clone();
|
||||
|
@ -21,9 +20,10 @@ pub fn connect_button_delete(gui_data: &GuiData) {
|
|||
let scrolled_window_similar_images_finder = gui_data.scrolled_window_similar_images_finder.clone();
|
||||
let scrolled_window_zeroed_files_finder = gui_data.scrolled_window_zeroed_files_finder.clone();
|
||||
let scrolled_window_same_music_finder = gui_data.scrolled_window_same_music_finder.clone();
|
||||
let check_button_settings_confirm_deletion = gui_data.check_button_settings_confirm_deletion.clone();
|
||||
|
||||
buttons_delete.connect_clicked(move |_| {
|
||||
if *shared_confirmation_dialog_delete_dialog_showing_state.borrow_mut() {
|
||||
if check_button_settings_confirm_deletion.get_active() {
|
||||
let confirmation_dialog_delete = gtk::Dialog::with_buttons(Some("Delete confirmation"), Some(&window_main), gtk::DialogFlags::MODAL, &[("Ok", gtk::ResponseType::Ok), ("Close", gtk::ResponseType::Cancel)]);
|
||||
let label: gtk::Label = gtk::Label::new(Some("Are you sure that you want to delete files?"));
|
||||
let check_button: gtk::CheckButton = gtk::CheckButton::with_label("Ask in future");
|
||||
|
@ -40,7 +40,7 @@ pub fn connect_button_delete(gui_data: &GuiData) {
|
|||
let response_type = confirmation_dialog_delete.run();
|
||||
if response_type == gtk::ResponseType::Ok {
|
||||
if !check_button.get_active() {
|
||||
*shared_confirmation_dialog_delete_dialog_showing_state.borrow_mut() = false;
|
||||
check_button_settings_confirm_deletion.set_active(false);
|
||||
}
|
||||
} else {
|
||||
confirmation_dialog_delete.close();
|
||||
|
|
|
@ -44,9 +44,6 @@ pub struct GuiData {
|
|||
pub shared_zeroed_files_state: Rc<RefCell<ZeroedFiles>>,
|
||||
pub shared_same_music_state: Rc<RefCell<SameMusic>>,
|
||||
|
||||
// State of confirmation dialogs
|
||||
pub shared_confirmation_dialog_delete_dialog_showing_state: Rc<RefCell<bool>>,
|
||||
|
||||
//// GUI Entry
|
||||
pub entry_similar_images_minimal_size: gtk::Entry,
|
||||
pub entry_duplicate_minimal_size: gtk::Entry,
|
||||
|
@ -149,6 +146,7 @@ pub struct GuiData {
|
|||
//// Settings
|
||||
pub check_button_settings_save_at_exit: gtk::CheckButton,
|
||||
pub check_button_settings_load_at_start: gtk::CheckButton,
|
||||
pub check_button_settings_confirm_deletion: gtk::CheckButton,
|
||||
|
||||
pub button_settings_save_configuration: gtk::Button,
|
||||
pub button_settings_load_configuration: gtk::Button,
|
||||
|
@ -235,9 +233,6 @@ impl GuiData {
|
|||
let shared_zeroed_files_state: Rc<RefCell<_>> = Rc::new(RefCell::new(ZeroedFiles::new()));
|
||||
let shared_same_music_state: Rc<RefCell<_>> = Rc::new(RefCell::new(SameMusic::new()));
|
||||
|
||||
// State of confirmation dialogs
|
||||
let shared_confirmation_dialog_delete_dialog_showing_state: Rc<RefCell<_>> = Rc::new(RefCell::new(true));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//// GUI Entry
|
||||
|
@ -349,6 +344,7 @@ impl GuiData {
|
|||
//// Settings
|
||||
let check_button_settings_save_at_exit: gtk::CheckButton = builder.get_object("check_button_settings_save_at_exit").unwrap();
|
||||
let check_button_settings_load_at_start: gtk::CheckButton = builder.get_object("check_button_settings_load_at_start").unwrap();
|
||||
let check_button_settings_confirm_deletion: gtk::CheckButton = builder.get_object("check_button_settings_confirm_deletion").unwrap();
|
||||
|
||||
let button_settings_save_configuration: gtk::Button = builder.get_object("button_settings_save_configuration").unwrap();
|
||||
let button_settings_load_configuration: gtk::Button = builder.get_object("button_settings_load_configuration").unwrap();
|
||||
|
@ -377,7 +373,6 @@ impl GuiData {
|
|||
shared_similar_images_state,
|
||||
shared_zeroed_files_state,
|
||||
shared_same_music_state,
|
||||
shared_confirmation_dialog_delete_dialog_showing_state,
|
||||
entry_similar_images_minimal_size,
|
||||
entry_duplicate_minimal_size,
|
||||
entry_allowed_extensions,
|
||||
|
@ -445,6 +440,7 @@ impl GuiData {
|
|||
button_stop_in_dialog,
|
||||
check_button_settings_save_at_exit,
|
||||
check_button_settings_load_at_start,
|
||||
check_button_settings_confirm_deletion,
|
||||
button_settings_save_configuration,
|
||||
button_settings_load_configuration,
|
||||
button_settings_reset_configuration,
|
||||
|
|
|
@ -95,6 +95,11 @@ pub fn save_configuration(gui_data: &GuiData, manual_execution: bool) {
|
|||
let check_button_settings_load_at_start = gui_data.check_button_settings_load_at_start.clone();
|
||||
data_to_save.push(check_button_settings_load_at_start.get_active().to_string());
|
||||
|
||||
//// Load at start
|
||||
data_to_save.push("--confirm_deletion:".to_string());
|
||||
let check_button_settings_confirm_deletion = gui_data.check_button_settings_confirm_deletion.clone();
|
||||
data_to_save.push(check_button_settings_confirm_deletion.get_active().to_string());
|
||||
|
||||
// Creating/Opening config file
|
||||
|
||||
let config_file = config_dir.join(Path::new(SAVE_FILE_NAME));
|
||||
|
@ -131,6 +136,7 @@ enum TypeOfLoadedData {
|
|||
AllowedExtensions,
|
||||
LoadingAtStart,
|
||||
SavingAtExit,
|
||||
ConfirmDeletion,
|
||||
}
|
||||
|
||||
pub fn load_configuration(gui_data: &GuiData, manual_execution: bool) {
|
||||
|
@ -167,6 +173,7 @@ pub fn load_configuration(gui_data: &GuiData, manual_execution: bool) {
|
|||
let mut allowed_extensions: Vec<String> = Vec::new();
|
||||
let mut loading_at_start: bool = true;
|
||||
let mut saving_at_exit: bool = true;
|
||||
let mut confirm_deletion: bool = true;
|
||||
|
||||
let mut current_type = TypeOfLoadedData::None;
|
||||
for (line_number, line) in loaded_data.replace("\r\n", "\n").split('\n').enumerate() {
|
||||
|
@ -186,6 +193,13 @@ pub fn load_configuration(gui_data: &GuiData, manual_execution: bool) {
|
|||
current_type = TypeOfLoadedData::LoadingAtStart;
|
||||
} else if line.starts_with("--save_at_exit") {
|
||||
current_type = TypeOfLoadedData::SavingAtExit;
|
||||
} else if line.starts_with("--confirm_deletion") {
|
||||
current_type = TypeOfLoadedData::ConfirmDeletion;
|
||||
} else if line.starts_with("--") {
|
||||
text_view_errors
|
||||
.get_buffer()
|
||||
.unwrap()
|
||||
.set_text(format!("Found invalid header in line {} \"\"\"{}\"\"\" when loading file {:?}", line_number, line, config_file).as_str());
|
||||
} else {
|
||||
match current_type {
|
||||
TypeOfLoadedData::None => {
|
||||
|
@ -233,6 +247,19 @@ pub fn load_configuration(gui_data: &GuiData, manual_execution: bool) {
|
|||
.set_text(format!("Found invalid data in line {} \"\"\"{}\"\"\" isn't proper value(0/1/true/false) when loading file {:?}", line_number, line, config_file).as_str());
|
||||
}
|
||||
}
|
||||
TypeOfLoadedData::ConfirmDeletion => {
|
||||
let line = line.to_lowercase();
|
||||
if line == "1" || line == "true" {
|
||||
confirm_deletion = true;
|
||||
} else if line == "0" || line == "false" {
|
||||
confirm_deletion = false;
|
||||
} else {
|
||||
text_view_errors
|
||||
.get_buffer()
|
||||
.unwrap()
|
||||
.set_text(format!("Found invalid data in line {} \"\"\"{}\"\"\" isn't proper value(0/1/true/false) when loading file {:?}", line_number, line, config_file).as_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -274,6 +301,7 @@ pub fn load_configuration(gui_data: &GuiData, manual_execution: bool) {
|
|||
//// Buttons
|
||||
gui_data.check_button_settings_load_at_start.set_active(loading_at_start);
|
||||
gui_data.check_button_settings_save_at_exit.set_active(saving_at_exit);
|
||||
gui_data.check_button_settings_confirm_deletion.set_active(confirm_deletion);
|
||||
} else {
|
||||
gui_data.check_button_settings_load_at_start.set_active(false);
|
||||
}
|
||||
|
@ -347,6 +375,7 @@ pub fn reset_configuration(gui_data: &GuiData, manual_clearing: bool) {
|
|||
{
|
||||
gui_data.check_button_settings_save_at_exit.set_active(true);
|
||||
gui_data.check_button_settings_load_at_start.set_active(true);
|
||||
gui_data.check_button_settings_confirm_deletion.set_active(true);
|
||||
}
|
||||
if manual_clearing {
|
||||
text_view_errors.get_buffer().unwrap().set_text("Current configuration was cleared.");
|
||||
|
|
Loading…
Reference in a new issue