InAppNotification: Extend the widget to allow showing notifications without an undo button.
This commit is contained in:
parent
af7331c6c6
commit
7035fe05c4
@ -5,6 +5,13 @@ use gtk::prelude::*;
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum UndoState {
|
||||||
|
Shown,
|
||||||
|
Hidden,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct InAppNotification {
|
pub struct InAppNotification {
|
||||||
revealer: gtk::Revealer,
|
revealer: gtk::Revealer,
|
||||||
@ -32,7 +39,7 @@ impl Default for InAppNotification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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
|
where
|
||||||
F: FnMut() -> glib::Continue + 'static,
|
F: FnMut() -> glib::Continue + 'static,
|
||||||
U: Fn() + 'static,
|
U: Fn() + 'static,
|
||||||
@ -67,6 +74,11 @@ impl InAppNotification {
|
|||||||
revealer.set_reveal_child(false);
|
revealer.set_reveal_child(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
match show_undo {
|
||||||
|
UndoState::Shown => (),
|
||||||
|
UndoState::Hidden => notif.undo.hide(),
|
||||||
|
}
|
||||||
|
|
||||||
notif
|
notif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@ use hammond_data::utils::delete_show;
|
|||||||
use hammond_data::Podcast;
|
use hammond_data::Podcast;
|
||||||
|
|
||||||
use app::Action;
|
use app::Action;
|
||||||
use appnotif::InAppNotification;
|
use appnotif::{InAppNotification, UndoState};
|
||||||
use utils::{self, lazy_load};
|
use utils::{self, lazy_load};
|
||||||
use widgets::EpisodeWidget;
|
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";
|
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 {
|
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();
|
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:
|
// Ideally if we had a custom widget this would have been as simple as:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user