Remove Toast and DismissToast internal actions

This commit is contained in:
Antonio Scandurra 2023-04-27 14:43:10 +02:00
parent 2950344c25
commit b6437d6d9e
4 changed files with 75 additions and 73 deletions

View file

@ -1,9 +1,7 @@
use std::{any::TypeId, ops::DerefMut};
use crate::{Toast, Workspace};
use collections::HashSet;
use gpui::{AnyViewHandle, AppContext, Entity, View, ViewContext, ViewHandle};
use crate::Workspace;
use std::{any::TypeId, ops::DerefMut};
pub fn init(cx: &mut AppContext) {
cx.set_global(NotificationTracker::new());
@ -113,6 +111,28 @@ impl Workspace {
self.dismiss_notification_internal(type_id, id, cx)
}
pub fn show_toast(&mut self, toast: Toast, cx: &mut ViewContext<Self>) {
self.dismiss_notification::<simple_message_notification::MessageNotification>(toast.id, cx);
self.show_notification(toast.id, cx, |cx| {
cx.add_view(|_cx| match &toast.click {
Some((click_msg, action)) => {
simple_message_notification::MessageNotification::new_boxed_action(
toast.msg.clone(),
action.boxed_clone(),
click_msg.clone(),
)
}
None => {
simple_message_notification::MessageNotification::new_message(toast.msg.clone())
}
})
})
}
pub fn dismiss_toast(&mut self, id: usize, cx: &mut ViewContext<Self>) {
self.dismiss_notification::<simple_message_notification::MessageNotification>(id, cx);
}
fn dismiss_notification_internal(
&mut self,
type_id: TypeId,