Fix accumulated stop events (#623)
* Change stop message channel from unbounded to bounded with size 1. * Clear out any stale stop messages before beginning a search operation.
This commit is contained in:
parent
7d32f1c778
commit
2b86e9079e
|
@ -155,6 +155,8 @@ pub fn connect_button_search(
|
|||
|
||||
let glib_stop_sender = glib_stop_sender.clone();
|
||||
let stop_receiver = stop_receiver.clone();
|
||||
// Consume any stale stop messages.
|
||||
stop_receiver.try_iter().for_each(|_| ());
|
||||
|
||||
match to_notebook_main_enum(notebook_main.current_page().unwrap()) {
|
||||
NotebookMainEnum::Duplicate => {
|
||||
|
|
|
@ -1,22 +1,30 @@
|
|||
use crossbeam_channel::{Sender, TrySendError};
|
||||
use gtk::prelude::*;
|
||||
|
||||
use crate::gui_structs::gui_data::GuiData;
|
||||
use crate::help_functions::KEY_ENTER;
|
||||
|
||||
fn send_stop_message(stop_sender: &Sender<()>) {
|
||||
stop_sender
|
||||
.try_send(())
|
||||
.map_or_else(|e| if matches!(e, TrySendError::Full(_)) { Ok(()) } else { Err(e) }, |_| Ok(()))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn connect_button_stop(gui_data: &GuiData) {
|
||||
let evk_button_stop_in_dialog = gui_data.progress_window.evk_button_stop_in_dialog.clone();
|
||||
let stop_sender = gui_data.stop_sender.clone();
|
||||
evk_button_stop_in_dialog.connect_key_released(move |_, _, key_code, _| {
|
||||
if key_code == KEY_ENTER {
|
||||
// Only accept enter key to stop search
|
||||
stop_sender.send(()).unwrap();
|
||||
send_stop_message(&stop_sender);
|
||||
}
|
||||
});
|
||||
|
||||
let button_stop_in_dialog = gui_data.progress_window.button_stop_in_dialog.clone();
|
||||
let stop_sender = gui_data.stop_sender.clone();
|
||||
button_stop_in_dialog.connect_button_release_event(move |_, _e| {
|
||||
stop_sender.send(()).unwrap();
|
||||
send_stop_message(&stop_sender);
|
||||
gtk::Inhibit(false)
|
||||
});
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::cell::RefCell;
|
|||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
use crossbeam_channel::unbounded;
|
||||
use crossbeam_channel::bounded;
|
||||
use gdk::gdk_pixbuf::Pixbuf;
|
||||
use gtk::prelude::*;
|
||||
use gtk::Builder;
|
||||
|
@ -156,7 +156,7 @@ impl GuiData {
|
|||
scrolled_window_errors.show_all(); // Not sure why needed, but without it text view errors sometimes hide itself
|
||||
|
||||
// Used for sending stop signal to thread
|
||||
let (stop_sender, stop_receiver): (crossbeam_channel::Sender<()>, crossbeam_channel::Receiver<()>) = unbounded();
|
||||
let (stop_sender, stop_receiver): (crossbeam_channel::Sender<()>, crossbeam_channel::Receiver<()>) = bounded(1);
|
||||
|
||||
Self {
|
||||
glade_src,
|
||||
|
|
Loading…
Reference in New Issue