| 1 | use gpui_kit::*; |
| 2 | |
| 3 | #[derive(Clone, Copy)] |
| 4 | pub struct RenderHooks { |
| 5 | pub open_profile_link: fn(&str, Point<Pixels>, &mut App) -> bool, |
| 6 | pub jump_to_quoted: fn(String, &mut App), |
| 7 | pub inline_image: fn(&str, &App) -> Option<std::path::PathBuf>, |
| 8 | } |
| 9 | |
| 10 | impl Global for RenderHooks {} |
| 11 | |
| 12 | pub fn open_profile_link(url: &str, position: Point<Pixels>, cx: &mut App) -> bool { |
| 13 | match cx.try_global::<RenderHooks>().copied() { |
| 14 | Some(hooks) => (hooks.open_profile_link)(url, position, cx), |
| 15 | None => false, |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | pub fn jump_to_quoted(message_id: String, cx: &mut App) { |
| 20 | if let Some(hooks) = cx.try_global::<RenderHooks>().copied() { |
| 21 | (hooks.jump_to_quoted)(message_id, cx); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | pub fn inline_image(url: &str, cx: &App) -> Option<std::path::PathBuf> { |
| 26 | let hooks = cx.try_global::<RenderHooks>().copied()?; |
| 27 | (hooks.inline_image)(url, cx) |
| 28 | } |