Remove Toast
and DismissToast
internal actions
This commit is contained in:
parent
2950344c25
commit
b6437d6d9e
4 changed files with 75 additions and 73 deletions
|
@ -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,
|
||||
|
|
|
@ -220,17 +220,6 @@ impl Clone for Toast {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct DismissToast {
|
||||
id: usize,
|
||||
}
|
||||
|
||||
impl DismissToast {
|
||||
pub fn new(id: usize) -> Self {
|
||||
DismissToast { id }
|
||||
}
|
||||
}
|
||||
|
||||
pub type WorkspaceId = i64;
|
||||
|
||||
impl_internal_actions!(
|
||||
|
@ -244,8 +233,6 @@ impl_internal_actions!(
|
|||
SplitWithItem,
|
||||
SplitWithProjectEntry,
|
||||
OpenProjectEntryInPane,
|
||||
Toast,
|
||||
DismissToast
|
||||
]
|
||||
);
|
||||
impl_actions!(workspace, [ActivatePane]);
|
||||
|
@ -431,24 +418,6 @@ pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
|
|||
.detach();
|
||||
});
|
||||
|
||||
cx.add_action(|workspace: &mut Workspace, alert: &Toast, cx| {
|
||||
workspace.dismiss_notification::<MessageNotification>(alert.id, cx);
|
||||
workspace.show_notification(alert.id, cx, |cx| {
|
||||
cx.add_view(|_cx| match &alert.click {
|
||||
Some((click_msg, action)) => MessageNotification::new_boxed_action(
|
||||
alert.msg.clone(),
|
||||
action.boxed_clone(),
|
||||
click_msg.clone(),
|
||||
),
|
||||
None => MessageNotification::new_message(alert.msg.clone()),
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
cx.add_action(|workspace: &mut Workspace, alert: &DismissToast, cx| {
|
||||
workspace.dismiss_notification::<MessageNotification>(alert.id, cx);
|
||||
});
|
||||
|
||||
let client = &app_state.client;
|
||||
client.add_view_request_handler(Workspace::handle_follow);
|
||||
client.add_view_message_handler(Workspace::handle_unfollow);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue