Periodically check for and handle pending GTK events while performing long operations. (#625)
This commit is contained in:
parent
c64ab05648
commit
c48b355bf0
|
@ -292,7 +292,8 @@ pub fn empty_folder_remover(
|
||||||
let mut messages: String = "".to_string();
|
let mut messages: String = "".to_string();
|
||||||
|
|
||||||
// Must be deleted from end to start, because when deleting entries, TreePath(and also TreeIter) will points to invalid data
|
// Must be deleted from end to start, because when deleting entries, TreePath(and also TreeIter) will points to invalid data
|
||||||
for tree_path in selected_rows.iter().rev() {
|
for (counter, tree_path) in selected_rows.iter().rev().enumerate() {
|
||||||
|
handle_gtk_pending_event_counter(counter);
|
||||||
let iter = model.iter(tree_path).unwrap();
|
let iter = model.iter(tree_path).unwrap();
|
||||||
|
|
||||||
let name = model.value(&iter, column_file_name).get::<String>().unwrap();
|
let name = model.value(&iter, column_file_name).get::<String>().unwrap();
|
||||||
|
@ -408,7 +409,8 @@ pub fn basic_remove(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Must be deleted from end to start, because when deleting entries, TreePath(and also TreeIter) will points to invalid data
|
// Must be deleted from end to start, because when deleting entries, TreePath(and also TreeIter) will points to invalid data
|
||||||
for tree_path in selected_rows.iter().rev() {
|
for (counter, tree_path) in selected_rows.iter().rev().enumerate() {
|
||||||
|
handle_gtk_pending_event_counter(counter);
|
||||||
let iter = model.iter(tree_path).unwrap();
|
let iter = model.iter(tree_path).unwrap();
|
||||||
|
|
||||||
let name = model.value(&iter, column_file_name).get::<String>().unwrap();
|
let name = model.value(&iter, column_file_name).get::<String>().unwrap();
|
||||||
|
@ -504,10 +506,13 @@ pub fn tree_remove(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete duplicated entries, and remove real files
|
// Delete duplicated entries, and remove real files
|
||||||
|
let mut counter = 0_usize;
|
||||||
for (path, mut vec_file_name) in map_with_path_to_delete {
|
for (path, mut vec_file_name) in map_with_path_to_delete {
|
||||||
vec_file_name.sort();
|
vec_file_name.sort();
|
||||||
vec_file_name.dedup();
|
vec_file_name.dedup();
|
||||||
for file_name in vec_file_name {
|
for file_name in vec_file_name {
|
||||||
|
handle_gtk_pending_event_counter(counter);
|
||||||
|
counter += 1;
|
||||||
if !use_trash {
|
if !use_trash {
|
||||||
if let Err(e) = fs::remove_file(get_full_name_from_path_name(&path, &file_name)) {
|
if let Err(e) = fs::remove_file(get_full_name_from_path_name(&path, &file_name)) {
|
||||||
messages += flg!(
|
messages += flg!(
|
||||||
|
|
|
@ -200,7 +200,8 @@ fn hardlink_symlink(
|
||||||
}
|
}
|
||||||
if hardlinking == TypeOfTool::Hardlinking {
|
if hardlinking == TypeOfTool::Hardlinking {
|
||||||
for symhardlink_data in vec_symhardlink_data {
|
for symhardlink_data in vec_symhardlink_data {
|
||||||
for file_to_hardlink in symhardlink_data.files_to_symhardlink {
|
for (counter, file_to_hardlink) in symhardlink_data.files_to_symhardlink.into_iter().enumerate() {
|
||||||
|
handle_gtk_pending_event_counter(counter);
|
||||||
if let Err(e) = make_hard_link(&PathBuf::from(&symhardlink_data.original_data), &PathBuf::from(&file_to_hardlink)) {
|
if let Err(e) = make_hard_link(&PathBuf::from(&symhardlink_data.original_data), &PathBuf::from(&file_to_hardlink)) {
|
||||||
add_text_to_text_view(text_view_errors, format!("{} {}, reason {}", flg!("hardlink_failed"), file_to_hardlink, e).as_str());
|
add_text_to_text_view(text_view_errors, format!("{} {}, reason {}", flg!("hardlink_failed"), file_to_hardlink, e).as_str());
|
||||||
continue;
|
continue;
|
||||||
|
@ -209,7 +210,8 @@ fn hardlink_symlink(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for symhardlink_data in vec_symhardlink_data {
|
for symhardlink_data in vec_symhardlink_data {
|
||||||
for file_to_symlink in symhardlink_data.files_to_symhardlink {
|
for (counter, file_to_symlink) in symhardlink_data.files_to_symhardlink.into_iter().enumerate() {
|
||||||
|
handle_gtk_pending_event_counter(counter);
|
||||||
if let Err(e) = fs::remove_file(&file_to_symlink) {
|
if let Err(e) = fs::remove_file(&file_to_symlink) {
|
||||||
add_text_to_text_view(
|
add_text_to_text_view(
|
||||||
text_view_errors,
|
text_view_errors,
|
||||||
|
|
|
@ -224,7 +224,8 @@ fn move_files_common(
|
||||||
let mut moved_files: u32 = 0;
|
let mut moved_files: u32 = 0;
|
||||||
|
|
||||||
// Save to variable paths of files, and remove it when not removing all occurrences.
|
// Save to variable paths of files, and remove it when not removing all occurrences.
|
||||||
'next_result: for tree_path in selected_rows.iter().rev() {
|
'next_result: for (counter, tree_path) in selected_rows.iter().rev().enumerate() {
|
||||||
|
handle_gtk_pending_event_counter(counter);
|
||||||
let iter = model.iter(tree_path).unwrap();
|
let iter = model.iter(tree_path).unwrap();
|
||||||
|
|
||||||
let file_name = model.value(&iter, column_file_name).get::<String>().unwrap();
|
let file_name = model.value(&iter, column_file_name).get::<String>().unwrap();
|
||||||
|
|
|
@ -39,6 +39,8 @@ pub const KEY_SPACE: u32 = 65;
|
||||||
// pub const KEY_HOME: u32 = 115;
|
// pub const KEY_HOME: u32 = 115;
|
||||||
// pub const KEY_END: u32 = 110;
|
// pub const KEY_END: u32 = 110;
|
||||||
|
|
||||||
|
pub const CHECK_GTK_EVENTS_INTERVAL: usize = 100;
|
||||||
|
|
||||||
#[derive(Eq, PartialEq)]
|
#[derive(Eq, PartialEq)]
|
||||||
pub enum PopoverTypes {
|
pub enum PopoverTypes {
|
||||||
All,
|
All,
|
||||||
|
@ -805,6 +807,21 @@ pub fn get_custom_image_from_button_with_image(button: >k::Bin) -> gtk::Image
|
||||||
panic!("Button doesn't have proper custom label child");
|
panic!("Button doesn't have proper custom label child");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn handle_gtk_pending_event() -> bool {
|
||||||
|
let have_pending = gtk::events_pending();
|
||||||
|
if have_pending {
|
||||||
|
gtk::main_iteration();
|
||||||
|
}
|
||||||
|
have_pending
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handle_gtk_pending_event_counter(counter: usize) -> bool {
|
||||||
|
if counter > 0 && (counter % CHECK_GTK_EVENTS_INTERVAL) == 0 {
|
||||||
|
return handle_gtk_pending_event();
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
// GTK 4
|
// GTK 4
|
||||||
// pub fn get_custom_label_from_button_with_image<P: IsA<gtk4::Widget>>(button: &P) -> gtk4::Label {
|
// pub fn get_custom_label_from_button_with_image<P: IsA<gtk4::Widget>>(button: &P) -> gtk4::Label {
|
||||||
// let internal_box = button.first_child().unwrap().downcast::<gtk4::Box>().unwrap();
|
// let internal_box = button.first_child().unwrap().downcast::<gtk4::Box>().unwrap();
|
||||||
|
|
Loading…
Reference in a new issue