BlueGit

ict rusty-teams

Files

rusty-teams / crates / app-ui-kit / src / render / hooks.rs

hooks.rs

hooks.rs 1.1 KiB Download Raw
1use gpui_kit::*;
2
3#[derive(Clone, Copy)]
4pub 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 pub open_link: fn(&str, &mut App),
9}
10
11impl Global for RenderHooks {}
12
13pub fn open_profile_link(url: &str, position: Point<Pixels>, cx: &mut App) -> bool {
14 match cx.try_global::<RenderHooks>().copied() {
15 Some(hooks) => (hooks.open_profile_link)(url, position, cx),
16 None => false,
17 }
18}
19
20pub fn open_link(url: &str, cx: &mut App) {
21 match cx.try_global::<RenderHooks>().copied() {
22 Some(hooks) => (hooks.open_link)(url, cx),
23 None => cx.open_url(url),
24 }
25}
26
27pub fn jump_to_quoted(message_id: String, cx: &mut App) {
28 if let Some(hooks) = cx.try_global::<RenderHooks>().copied() {
29 (hooks.jump_to_quoted)(message_id, cx);
30 }
31}
32
33pub fn inline_image(url: &str, cx: &App) -> Option<std::path::PathBuf> {
34 let hooks = cx.try_global::<RenderHooks>().copied()?;
35 (hooks.inline_image)(url, cx)
36}