diff --git a/podcasts-gtk/resources/gtk/inapp_notif.ui b/podcasts-gtk/resources/gtk/inapp_notif.ui index 0b76e4f..60cdd4e 100644 --- a/podcasts-gtk/resources/gtk/inapp_notif.ui +++ b/podcasts-gtk/resources/gtk/inapp_notif.ui @@ -100,7 +100,6 @@ Tobias Bernard Undo - True True True center diff --git a/podcasts-gtk/src/app.rs b/podcasts-gtk/src/app.rs index 7892043..1d35ea6 100644 --- a/podcasts-gtk/src/app.rs +++ b/podcasts-gtk/src/app.rs @@ -17,7 +17,7 @@ use settings::{self, WindowGeometry}; use stacks::{Content, PopulatedState}; use utils; use widgets::about_dialog; -use widgets::appnotif::{InAppNotification, UndoState}; +use widgets::appnotif::InAppNotification; use widgets::player; use widgets::show_menu::{mark_all_notif, remove_show_notif, ShowMenu}; @@ -306,7 +306,8 @@ impl App { Action::ErrorNotification(err) => { error!("An error notification was triggered: {}", err); let callback = || glib::Continue(false); - let notif = InAppNotification::new(&err, callback, || {}, UndoState::Hidden); + let undo_cb: Option = None; + let notif = InAppNotification::new(&err, callback, undo_cb); notif.show(&self.overlay); } Action::InitEpisode(rowid) => { diff --git a/podcasts-gtk/src/widgets/appnotif.rs b/podcasts-gtk/src/widgets/appnotif.rs index 8936726..cf439ff 100644 --- a/podcasts-gtk/src/widgets/appnotif.rs +++ b/podcasts-gtk/src/widgets/appnotif.rs @@ -6,6 +6,7 @@ use std::cell::RefCell; use std::rc::Rc; #[derive(Debug, Clone, Copy)] +#[allow(dead_code)] pub(crate) enum UndoState { Shown, Hidden, @@ -38,12 +39,7 @@ impl Default for InAppNotification { } impl InAppNotification { - pub(crate) fn new( - text: &str, - mut callback: F, - undo_callback: U, - show_undo: UndoState, - ) -> Self + pub(crate) fn new(text: &str, mut callback: F, undo_callback: Option) -> Self where F: FnMut() -> glib::Continue + 'static, U: Fn() + 'static, @@ -58,6 +54,10 @@ impl InAppNotification { }); let id = Rc::new(RefCell::new(Some(id))); + if undo_callback.is_some() { + notif.set_undo_state(UndoState::Shown) + }; + // Cancel the callback let revealer = notif.revealer.clone(); notif.undo.connect_clicked(move |_| { @@ -66,7 +66,9 @@ impl InAppNotification { glib::source::source_remove(id); } - undo_callback(); + if let Some(ref f) = undo_callback { + f(); + } // Hide the notification revealer.set_reveal_child(false); @@ -78,11 +80,6 @@ impl InAppNotification { revealer.set_reveal_child(false); }); - match show_undo { - UndoState::Shown => (), - UndoState::Hidden => notif.undo.hide(), - } - notif } @@ -96,4 +93,11 @@ impl InAppNotification { // so there will be a nice animation. self.revealer.set_reveal_child(true); } + + pub(crate) fn set_undo_state(&self, state: UndoState) { + match state { + UndoState::Shown => self.undo.show(), + UndoState::Hidden => self.undo.hide(), + } + } } diff --git a/podcasts-gtk/src/widgets/show_menu.rs b/podcasts-gtk/src/widgets/show_menu.rs index b67df6e..45a5e07 100644 --- a/podcasts-gtk/src/widgets/show_menu.rs +++ b/podcasts-gtk/src/widgets/show_menu.rs @@ -13,7 +13,7 @@ use podcasts_data::Show; use app::Action; use utils; -use widgets::appnotif::{InAppNotification, UndoState}; +use widgets::appnotif::InAppNotification; use std::sync::Arc; @@ -145,7 +145,7 @@ pub(crate) fn mark_all_notif(pd: Arc, sender: &Sender) -> InAppNot let undo_callback = clone!(sender => move || sender.send(Action::RefreshWidgetIfSame(id))); let text = i18n("Marked all episodes as listened"); - InAppNotification::new(&text, callback, undo_callback, UndoState::Shown) + InAppNotification::new(&text, callback, Some(undo_callback)) } pub(crate) fn remove_show_notif(pd: Arc, sender: Sender) -> InAppNotification { @@ -177,5 +177,5 @@ pub(crate) fn remove_show_notif(pd: Arc, sender: Sender) -> InAppN sender.send(Action::RefreshEpisodesView); }; - InAppNotification::new(&text, callback, undo_callback, UndoState::Shown) + InAppNotification::new(&text, callback, Some(undo_callback)) }