use gpui::{App, ElementId, Window}; use crate::Root; use crate::dialog::Dialog; use crate::notification::Notification; /// Extension trait for [`Window`] to add dialog, notification .. functionality. pub trait WindowExtension: Sized { /// Opens a Dialog. fn open_dialog(&mut self, cx: &mut App, builder: F) where F: Fn(Dialog, &mut Window, &mut App) -> Dialog + 'static; /// Closes the last active Dialog. fn close_dialog(&mut self, cx: &mut App); /// Closes all active Dialogs. fn close_all_dialogs(&mut self, cx: &mut App); /// Pushes a notification to the notification list. fn push_notification(&mut self, note: T, cx: &mut App) where T: Into; /// Clear the unique notification. fn clear_notification(&mut self, cx: &mut App); /// Clear the unique notification with the given id. fn clear_notification_by_id( &mut self, key: impl Into, cx: &mut App, ); } impl WindowExtension for Window { #[inline] fn open_dialog(&mut self, cx: &mut App, builder: F) where F: Fn(Dialog, &mut Window, &mut App) -> Dialog + 'static, { Root::update(self, cx, move |root, window, cx| { root.open_dialog(builder, window, cx); }) } #[inline] fn close_dialog(&mut self, cx: &mut App) { Root::update(self, cx, move |root, window, cx| { root.close_dialog(window, cx); }) } #[inline] fn close_all_dialogs(&mut self, cx: &mut App) { Root::update(self, cx, |root, window, cx| { root.close_all_dialogs(window, cx); }) } #[inline] fn push_notification(&mut self, note: T, cx: &mut App) where T: Into, { let note = note.into(); Root::update(self, cx, move |root, window, cx| { root.push_notification(note, window, cx); }) } #[inline] fn clear_notification(&mut self, cx: &mut App) { Root::update(self, cx, |root, window, cx| { root.clear_notification::(window, cx); }) } #[inline] fn clear_notification_by_id( &mut self, key: impl Into, cx: &mut App, ) { let key: ElementId = key.into(); Root::update(self, cx, |root, window, cx| { root.clear_notification_by_id::(key, window, cx); }) } }