InAppNotification: Extend the widget to allow showing notifications without an undo button.

This commit is contained in:
Jordan Petridis 2018-05-16 16:58:03 +03:00
parent af7331c6c6
commit 7035fe05c4
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
2 changed files with 16 additions and 4 deletions

View File

@ -5,6 +5,13 @@ use gtk::prelude::*;
use std::cell::RefCell;
use std::rc::Rc;
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub enum UndoState {
Shown,
Hidden,
}
#[derive(Debug, Clone)]
pub struct InAppNotification {
revealer: gtk::Revealer,
@ -32,7 +39,7 @@ impl Default for InAppNotification {
}
impl InAppNotification {
pub fn new<F, U>(text: &str, mut callback: F, undo_callback: U) -> Self
pub fn new<F, U>(text: &str, mut callback: F, undo_callback: U, show_undo: UndoState) -> Self
where
F: FnMut() -> glib::Continue + 'static,
U: Fn() + 'static,
@ -67,6 +74,11 @@ impl InAppNotification {
revealer.set_reveal_child(false);
});
match show_undo {
UndoState::Shown => (),
UndoState::Hidden => notif.undo.hide(),
}
notif
}

View File

@ -13,7 +13,7 @@ use hammond_data::utils::delete_show;
use hammond_data::Podcast;
use app::Action;
use appnotif::InAppNotification;
use appnotif::{InAppNotification, UndoState};
use utils::{self, lazy_load};
use widgets::EpisodeWidget;
@ -279,7 +279,7 @@ pub fn mark_all_notif(pd: Arc<Podcast>, sender: &Sender<Action>) -> InAppNotific
});
let text = "Marked all episodes as listened";
InAppNotification::new(text, callback, undo_callback)
InAppNotification::new(text, callback, undo_callback, UndoState::Shown)
}
pub fn remove_show_notif(pd: Arc<Podcast>, sender: Sender<Action>) -> InAppNotification {
@ -319,7 +319,7 @@ pub fn remove_show_notif(pd: Arc<Podcast>, sender: Sender<Action>) -> InAppNotif
undo_wrap().map_err(|err| error!("{}", err)).ok();
};
InAppNotification::new(&text, callback, undo_callback)
InAppNotification::new(&text, callback, undo_callback, UndoState::Shown)
}
// Ideally if we had a custom widget this would have been as simple as: