BlueGit

ict rusty-teams

feat(chat): right-click message menu at the cursor like Telegram

- With "message actions on right click" on, a right click opens a menu at the cursor: quick reactions in a pill on top, the actions in a flat list below
- Closes on a click outside, Escape, an action or a reaction, and on a chat switch
- Replaces the hover toolbar that opened above the message
- Deviation from Teams (Teams opens the toolbar above the message), on Daniel's request 2026-11-11

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-11 · 2 weeks ago

Hash
dbf62e211a558edf553df8f6b1e88bf15b38e656
Parent
47241abe
6 files changed +272 −22
crates/app/src/views/conversation.rs +27 −13
@@ -239,7 +239,7 @@ pub struct ConversationView {
239 239 downloads: Downloads,
240 240 hovered_message: Option<String>,
241 241 toolbar_hovered: Option<String>,
242 toolbar_opened: Option<String>,
242 context_menu: Option<(String, Point<Pixels>)>,
243 243 timeline_bounds: TimelineBounds,
244 244 header_width: Rc<Cell<f32>>,
245 245 toolbar_pinned: Option<String>,
@@ -552,6 +552,7 @@ impl ConversationView {
552 552 cx.observe_keystrokes(|this, event, _, cx| {
553 553 if event.keystroke.key == "escape" {
554 554 this.close_reaction_details(cx);
555 this.close_context_menu(false, cx);
555 556 }
556 557 }),
557 558 ];
@@ -590,7 +591,7 @@ impl ConversationView {
590 591 downloads: Downloads::default(),
591 592 hovered_message: None,
592 593 toolbar_hovered: None,
593 toolbar_opened: None,
594 context_menu: None,
594 595 timeline_bounds: TimelineBounds::default(),
595 596 header_width: Rc::default(),
596 597 toolbar_pinned: None,
@@ -932,6 +933,7 @@ impl ConversationView {
932 933 crate::inline_video::stop(cx);
933 934 self.toolbar_pinned = None;
934 935 self.toolbar_suppressed = None;
936 self.context_menu = None;
935 937 self.agent_layouts.clear();
936 938 self.agent_runs.borrow_mut().clear();
937 939 self.reaction_proposals.borrow_mut().clear();
@@ -2812,9 +2814,6 @@ impl ConversationView {
2812 2814 } else if target.as_deref() == Some(key) {
2813 2815 *target = None;
2814 2816 }
2815 if !hovered && matches!(slot, HoverSlot::Row) && self.toolbar_opened.as_deref() == Some(key) {
2816 self.toolbar_opened = None;
2817 }
2818 2817 if hovered
2819 2818 && matches!(slot, HoverSlot::Row)
2820 2819 && self.toolbar_hovered.as_deref().is_some_and(|toolbar| toolbar != key)
@@ -2848,11 +2847,9 @@ impl ConversationView {
2848 2847 }
2849 2848
2850 2849 fn toolbar_visible(&self, key: &str, cx: &App) -> bool {
2851 let row_trigger = if self.app.read(cx).actions_on_right_click {
2852 self.toolbar_opened.as_deref()
2853 } else {
2854 self.hovered_message.as_deref()
2855 };
2850 let row_trigger = (!self.app.read(cx).actions_on_right_click)
2851 .then_some(self.hovered_message.as_deref())
2852 .flatten();
2856 2853 self.toolbar_suppressed.as_deref() != Some(key)
2857 2854 && self
2858 2855 .toolbar_pinned
@@ -2862,9 +2859,26 @@ impl ConversationView {
2862 2859 == Some(key)
2863 2860 }
2864 2861
2865 fn open_toolbar(&mut self, key: &str, cx: &mut Context<Self>) {
2866 self.toolbar_opened = Some(key.to_owned());
2867 self.toolbar_suppressed = None;
2862 pub(crate) fn context_menu_at(&self, key: &str) -> Option<Point<Pixels>> {
2863 self.context_menu
2864 .as_ref()
2865 .filter(|(open, _)| open == key)
2866 .map(|(_, position)| *position)
2867 }
2868
2869 fn open_context_menu(&mut self, key: &str, position: Point<Pixels>, cx: &mut Context<Self>) {
2870 self.context_menu = Some((key.to_owned(), position));
2871 cx.notify();
2872 }
2873
2874 fn close_context_menu(&mut self, from_outside: bool, cx: &mut Context<Self>) {
2875 let Some((key, _)) = &self.context_menu else {
2876 return;
2877 };
2878 if from_outside && self.toolbar_pinned.as_deref() == Some(key.as_str()) {
2879 return;
2880 }
2881 self.context_menu = None;
2868 2882 cx.notify();
2869 2883 }
2870 2884
@@ -239,7 +239,7 @@ pub struct ConversationView {
239 downloads: Downloads,
239 downloads: Downloads,
240 hovered_message: Option<String>,
240 hovered_message: Option<String>,
241 toolbar_hovered: Option<String>,
241 toolbar_hovered: Option<String>,
242 toolbar_opened: Option<String>,
242 context_menu: Option<(String, Point<Pixels>)>,
243 timeline_bounds: TimelineBounds,
243 timeline_bounds: TimelineBounds,
244 header_width: Rc<Cell<f32>>,
244 header_width: Rc<Cell<f32>>,
245 toolbar_pinned: Option<String>,
245 toolbar_pinned: Option<String>,
@@ -552,6 +552,7 @@ impl ConversationView {
552 cx.observe_keystrokes(|this, event, _, cx| {
552 cx.observe_keystrokes(|this, event, _, cx| {
553 if event.keystroke.key == "escape" {
553 if event.keystroke.key == "escape" {
554 this.close_reaction_details(cx);
554 this.close_reaction_details(cx);
555 this.close_context_menu(false, cx);
555 }
556 }
556 }),
557 }),
557 ];
558 ];
@@ -590,7 +591,7 @@ impl ConversationView {
590 downloads: Downloads::default(),
591 downloads: Downloads::default(),
591 hovered_message: None,
592 hovered_message: None,
592 toolbar_hovered: None,
593 toolbar_hovered: None,
593 toolbar_opened: None,
594 context_menu: None,
594 timeline_bounds: TimelineBounds::default(),
595 timeline_bounds: TimelineBounds::default(),
595 header_width: Rc::default(),
596 header_width: Rc::default(),
596 toolbar_pinned: None,
597 toolbar_pinned: None,
@@ -932,6 +933,7 @@ impl ConversationView {
932 crate::inline_video::stop(cx);
933 crate::inline_video::stop(cx);
933 self.toolbar_pinned = None;
934 self.toolbar_pinned = None;
934 self.toolbar_suppressed = None;
935 self.toolbar_suppressed = None;
936 self.context_menu = None;
935 self.agent_layouts.clear();
937 self.agent_layouts.clear();
936 self.agent_runs.borrow_mut().clear();
938 self.agent_runs.borrow_mut().clear();
937 self.reaction_proposals.borrow_mut().clear();
939 self.reaction_proposals.borrow_mut().clear();
@@ -2812,9 +2814,6 @@ impl ConversationView {
2812 } else if target.as_deref() == Some(key) {
2814 } else if target.as_deref() == Some(key) {
2813 *target = None;
2815 *target = None;
2814 }
2816 }
2815 if !hovered && matches!(slot, HoverSlot::Row) && self.toolbar_opened.as_deref() == Some(key) {
2816 self.toolbar_opened = None;
2817 }
2818 if hovered
2817 if hovered
2819 && matches!(slot, HoverSlot::Row)
2818 && matches!(slot, HoverSlot::Row)
2820 && self.toolbar_hovered.as_deref().is_some_and(|toolbar| toolbar != key)
2819 && self.toolbar_hovered.as_deref().is_some_and(|toolbar| toolbar != key)
@@ -2848,11 +2847,9 @@ impl ConversationView {
2848 }
2847 }
2849
2848
2850 fn toolbar_visible(&self, key: &str, cx: &App) -> bool {
2849 fn toolbar_visible(&self, key: &str, cx: &App) -> bool {
2851 let row_trigger = if self.app.read(cx).actions_on_right_click {
2850 let row_trigger = (!self.app.read(cx).actions_on_right_click)
2852 self.toolbar_opened.as_deref()
2851 .then_some(self.hovered_message.as_deref())
2853 } else {
2852 .flatten();
2854 self.hovered_message.as_deref()
2855 };
2856 self.toolbar_suppressed.as_deref() != Some(key)
2853 self.toolbar_suppressed.as_deref() != Some(key)
2857 && self
2854 && self
2858 .toolbar_pinned
2855 .toolbar_pinned
@@ -2862,9 +2859,26 @@ impl ConversationView {
2862 == Some(key)
2859 == Some(key)
2863 }
2860 }
2864
2861
2865 fn open_toolbar(&mut self, key: &str, cx: &mut Context<Self>) {
2862 pub(crate) fn context_menu_at(&self, key: &str) -> Option<Point<Pixels>> {
2866 self.toolbar_opened = Some(key.to_owned());
2863 self.context_menu
2867 self.toolbar_suppressed = None;
2864 .as_ref()
2865 .filter(|(open, _)| open == key)
2866 .map(|(_, position)| *position)
2867 }
2868
2869 fn open_context_menu(&mut self, key: &str, position: Point<Pixels>, cx: &mut Context<Self>) {
2870 self.context_menu = Some((key.to_owned(), position));
2871 cx.notify();
2872 }
2873
2874 fn close_context_menu(&mut self, from_outside: bool, cx: &mut Context<Self>) {
2875 let Some((key, _)) = &self.context_menu else {
2876 return;
2877 };
2878 if from_outside && self.toolbar_pinned.as_deref() == Some(key.as_str()) {
2879 return;
2880 }
2881 self.context_menu = None;
2868 cx.notify();
2882 cx.notify();
2869 }
2883 }
2870
2884
crates/app/src/views/conversation/render_env.rs +37 −5
@@ -20,6 +20,7 @@ use crate::views::attachments::ImageActions;
20 20 use crate::views::call_card::CallActions;
21 21 use crate::views::call_notice::RecapActions;
22 22 use crate::views::composer::Composer;
23 use crate::views::message_context_menu::message_context_menu;
23 24 use crate::views::message_row::{DeliveryActions, RowActions, RowSelect, SharedRowAction};
24 25 use crate::views::post_card::{PostAction, PostActions};
25 26 use crate::views::reaction_proposal_pill::ReactionPill;
@@ -241,14 +242,43 @@ impl RenderEnv {
241 242 })
242 243 .unwrap_or((None, None, None, None));
243 244 let right_click_opens_actions = self.app.read(cx).actions_on_right_click;
244 let reply = (is_real && !message.deleted).then(|| {
245 let open_context = (right_click_opens_actions && actionable).then(|| {
246 let (view, key) = (view.clone(), message.key.clone());
247 Rc::new(move |position: Point<Pixels>, cx: &mut App| {
248 view.update(cx, |this, cx| this.open_context_menu(&key, position, cx))
249 .ok();
250 }) as Rc<dyn Fn(Point<Pixels>, &mut App)>
251 });
252 let context_menu = view
253 .upgrade()
254 .filter(|_| actionable)
255 .and_then(|entity| {
256 let this = entity.read(cx);
257 let position = this.context_menu_at(&message.key)?;
258 let mine = message
259 .reactions
260 .iter()
261 .filter(|chip| chip.mine)
262 .map(|chip| chip.glyph())
263 .collect();
264 let menu = this.message_menu(message, mine, None, view.clone(), cx);
265 let (closing, outside) = (view.clone(), view.clone());
266 Some(message_context_menu(
267 menu,
268 position,
269 Rc::new(move |_, cx| {
270 closing.update(cx, |this, cx| this.close_context_menu(false, cx)).ok();
271 }),
272 Rc::new(move |_, cx| {
273 outside.update(cx, |this, cx| this.close_context_menu(true, cx)).ok();
274 }),
275 cx,
276 ))
277 });
278 let reply = (is_real && !message.deleted && !right_click_opens_actions).then(|| {
245 279 let (view, key, handle) = (view.clone(), message.key.clone(), window.window_handle());
246 280 boxed(move |cx| {
247 281 let (view, key) = (view.clone(), key.clone());
248 if right_click_opens_actions {
249 view.update(cx, |this, cx| this.open_toolbar(&key, cx)).ok();
250 return;
251 }
252 282 handle
253 283 .update(cx, move |_, window, cx| {
254 284 view.update(cx, |this, cx| this.begin_reply(&key, window, cx))
@@ -316,6 +346,8 @@ impl RenderEnv {
316 346 bot,
317 347 delivery,
318 348 reply: reply.filter(|_| !selecting),
349 open_context: open_context.filter(|_| !selecting),
350 context_menu: context_menu.filter(|_| !selecting),
319 351 hovered: hovered.filter(|_| !selecting),
320 352 menu: menu.filter(|_| !selecting),
321 353 scheduled_menu,
@@ -20,6 +20,7 @@ use crate::views::attachments::ImageActions;
20use crate::views::call_card::CallActions;
20use crate::views::call_card::CallActions;
21use crate::views::call_notice::RecapActions;
21use crate::views::call_notice::RecapActions;
22use crate::views::composer::Composer;
22use crate::views::composer::Composer;
23use crate::views::message_context_menu::message_context_menu;
23use crate::views::message_row::{DeliveryActions, RowActions, RowSelect, SharedRowAction};
24use crate::views::message_row::{DeliveryActions, RowActions, RowSelect, SharedRowAction};
24use crate::views::post_card::{PostAction, PostActions};
25use crate::views::post_card::{PostAction, PostActions};
25use crate::views::reaction_proposal_pill::ReactionPill;
26use crate::views::reaction_proposal_pill::ReactionPill;
@@ -241,14 +242,43 @@ impl RenderEnv {
241 })
242 })
242 .unwrap_or((None, None, None, None));
243 .unwrap_or((None, None, None, None));
243 let right_click_opens_actions = self.app.read(cx).actions_on_right_click;
244 let right_click_opens_actions = self.app.read(cx).actions_on_right_click;
244 let reply = (is_real && !message.deleted).then(|| {
245 let open_context = (right_click_opens_actions && actionable).then(|| {
246 let (view, key) = (view.clone(), message.key.clone());
247 Rc::new(move |position: Point<Pixels>, cx: &mut App| {
248 view.update(cx, |this, cx| this.open_context_menu(&key, position, cx))
249 .ok();
250 }) as Rc<dyn Fn(Point<Pixels>, &mut App)>
251 });
252 let context_menu = view
253 .upgrade()
254 .filter(|_| actionable)
255 .and_then(|entity| {
256 let this = entity.read(cx);
257 let position = this.context_menu_at(&message.key)?;
258 let mine = message
259 .reactions
260 .iter()
261 .filter(|chip| chip.mine)
262 .map(|chip| chip.glyph())
263 .collect();
264 let menu = this.message_menu(message, mine, None, view.clone(), cx);
265 let (closing, outside) = (view.clone(), view.clone());
266 Some(message_context_menu(
267 menu,
268 position,
269 Rc::new(move |_, cx| {
270 closing.update(cx, |this, cx| this.close_context_menu(false, cx)).ok();
271 }),
272 Rc::new(move |_, cx| {
273 outside.update(cx, |this, cx| this.close_context_menu(true, cx)).ok();
274 }),
275 cx,
276 ))
277 });
278 let reply = (is_real && !message.deleted && !right_click_opens_actions).then(|| {
245 let (view, key, handle) = (view.clone(), message.key.clone(), window.window_handle());
279 let (view, key, handle) = (view.clone(), message.key.clone(), window.window_handle());
246 boxed(move |cx| {
280 boxed(move |cx| {
247 let (view, key) = (view.clone(), key.clone());
281 let (view, key) = (view.clone(), key.clone());
248 if right_click_opens_actions {
249 view.update(cx, |this, cx| this.open_toolbar(&key, cx)).ok();
250 return;
251 }
252 handle
282 handle
253 .update(cx, move |_, window, cx| {
283 .update(cx, move |_, window, cx| {
254 view.update(cx, |this, cx| this.begin_reply(&key, window, cx))
284 view.update(cx, |this, cx| this.begin_reply(&key, window, cx))
@@ -316,6 +346,8 @@ impl RenderEnv {
316 bot,
346 bot,
317 delivery,
347 delivery,
318 reply: reply.filter(|_| !selecting),
348 reply: reply.filter(|_| !selecting),
349 open_context: open_context.filter(|_| !selecting),
350 context_menu: context_menu.filter(|_| !selecting),
319 hovered: hovered.filter(|_| !selecting),
351 hovered: hovered.filter(|_| !selecting),
320 menu: menu.filter(|_| !selecting),
352 menu: menu.filter(|_| !selecting),
321 scheduled_menu,
353 scheduled_menu,
crates/app/src/views/message_actions.rs +2 −2
@@ -94,7 +94,7 @@ pub(super) fn bar_button(id: ElementId) -> Stateful<Div> {
94 94 .hover(|button| button.bg(theme::popup_hover()))
95 95 }
96 96
97 fn reaction_button(menu: &MessageMenu, glyph: &str, index: usize) -> AnyElement {
97 pub(super) fn reaction_button(menu: &MessageMenu, glyph: &str, index: usize) -> AnyElement {
98 98 let (react, done, picked) = (menu.react.clone(), menu.done.clone(), glyph.to_owned());
99 99 let selected = menu.mine.contains(&reaction_glyph(glyph));
100 100 bar_button(element_id(&format!("quick-reaction-{index}"), &menu.key))
@@ -161,7 +161,7 @@ fn picker_popover(adder: ReactionAdder, prefix: &str, trigger: Button, anchor: A
161 161 .into_any_element()
162 162 }
163 163
164 fn picker_button(menu: &MessageMenu, cx: &App) -> AnyElement {
164 pub(super) fn picker_button(menu: &MessageMenu, cx: &App) -> AnyElement {
165 165 let trigger = Button::new(element_id("add-reaction", &menu.key))
166 166 .child(icon(IconName::Plus, BAR_ICON, theme::text_soft()))
167 167 .custom(bar_variant(cx))
@@ -94,7 +94,7 @@ pub(super) fn bar_button(id: ElementId) -> Stateful<Div> {
94 .hover(|button| button.bg(theme::popup_hover()))
94 .hover(|button| button.bg(theme::popup_hover()))
95}
95}
96
96
97fn reaction_button(menu: &MessageMenu, glyph: &str, index: usize) -> AnyElement {
97pub(super) fn reaction_button(menu: &MessageMenu, glyph: &str, index: usize) -> AnyElement {
98 let (react, done, picked) = (menu.react.clone(), menu.done.clone(), glyph.to_owned());
98 let (react, done, picked) = (menu.react.clone(), menu.done.clone(), glyph.to_owned());
99 let selected = menu.mine.contains(&reaction_glyph(glyph));
99 let selected = menu.mine.contains(&reaction_glyph(glyph));
100 bar_button(element_id(&format!("quick-reaction-{index}"), &menu.key))
100 bar_button(element_id(&format!("quick-reaction-{index}"), &menu.key))
@@ -161,7 +161,7 @@ fn picker_popover(adder: ReactionAdder, prefix: &str, trigger: Button, anchor: A
161 .into_any_element()
161 .into_any_element()
162}
162}
163
163
164fn picker_button(menu: &MessageMenu, cx: &App) -> AnyElement {
164pub(super) fn picker_button(menu: &MessageMenu, cx: &App) -> AnyElement {
165 let trigger = Button::new(element_id("add-reaction", &menu.key))
165 let trigger = Button::new(element_id("add-reaction", &menu.key))
166 .child(icon(IconName::Plus, BAR_ICON, theme::text_soft()))
166 .child(icon(IconName::Plus, BAR_ICON, theme::text_soft()))
167 .custom(bar_variant(cx))
167 .custom(bar_variant(cx))
crates/app/src/views/message_context_menu.rs added +192 −0
@@ -0,0 +1,192 @@
1 use std::rc::Rc;
2
3 use gpui_kit::assets::IconName;
4 use gpui_kit::base::POPUP_PRIORITY;
5 use gpui_kit::component::{h_flex, v_flex};
6 use gpui_kit::*;
7
8 use super::message_actions::{Action, MessageMenu, picker_button, reaction_button};
9 use super::widgets::icon;
10 use crate::forward_selection::FORWARD_LABEL;
11 use crate::post_follow::follow_label;
12 use crate::share_outlook::SHARE_TO_OUTLOOK_LABEL;
13 use crate::theme::{self, ElevatedSurface as _};
14
15 pub const CONTEXT_MENU_TAG: &str = "message-context-menu";
16 const MENU_WIDTH: f32 = 220.;
17 const PANEL_GAP: f32 = 6.;
18 const PILL_PADDING: f32 = 4.;
19 const LIST_PADDING: f32 = 4.;
20 const ITEM_HEIGHT: f32 = 32.;
21 const ITEM_ICON: f32 = 16.;
22 const WINDOW_MARGIN: f32 = 8.;
23 const SELECT_LABEL: &str = "Select";
24
25 pub type Close = Rc<dyn Fn(&mut Window, &mut App)>;
26
27 struct Entry {
28 label: SharedString,
29 glyph: IconName,
30 action: Action,
31 danger: bool,
32 }
33
34 fn entry(label: impl Into<SharedString>, glyph: IconName, action: Action) -> Entry {
35 Entry {
36 label: label.into(),
37 glyph,
38 action,
39 danger: false,
40 }
41 }
42
43 fn entries(menu: &MessageMenu) -> Vec<Entry> {
44 let mut list = Vec::new();
45 if let Some(reply) = menu.reply.clone() {
46 list.push(entry("Reply", IconName::Reply, reply));
47 }
48 if let Some(edit) = menu.edit.clone() {
49 list.push(entry("Edit", IconName::Pencil, edit));
50 }
51 if let Some(toggle_pinned) = menu.toggle_pinned.clone() {
52 list.push(if menu.pinned {
53 entry("Unpin", IconName::PinOff, toggle_pinned)
54 } else {
55 entry("Pin", IconName::Pin, toggle_pinned)
56 });
57 }
58 list.push(entry("Copy text", IconName::Copy, menu.copy.clone()));
59 if let Some(copy_link) = menu.copy_link.clone() {
60 list.push(entry("Copy link", IconName::Link, copy_link));
61 }
62 if let Some(forward) = menu.forward.clone() {
63 list.push(entry(FORWARD_LABEL, IconName::Forward, forward));
64 }
65 if let Some(save) = menu.save.clone() {
66 list.push(if menu.saved {
67 entry("Unsave", IconName::BookmarkOff, save)
68 } else {
69 entry("Save", IconName::Bookmark, save)
70 });
71 }
72 if let Some(toggle_follow) = menu.toggle_follow.clone() {
73 let glyph = if menu.followed { IconName::BellOff } else { IconName::Bell };
74 list.push(entry(follow_label(menu.followed), glyph, toggle_follow));
75 }
76 if let Some(mark_unread) = menu.mark_unread.clone() {
77 list.push(entry("Mark as unread", IconName::EyeOff, mark_unread));
78 }
79 if let Some(translate) = menu.translate.clone() {
80 list.push(entry(menu.translate_label, IconName::Languages, translate));
81 }
82 if let Some(share_to_outlook) = menu.share_to_outlook.clone() {
83 list.push(entry(SHARE_TO_OUTLOOK_LABEL, IconName::Mail, share_to_outlook));
84 }
85 if let Some(refresh_card) = menu.refresh_card.clone() {
86 list.push(entry("Refresh card", IconName::RefreshCw, refresh_card));
87 }
88 for delegate in &menu.delegate {
89 list.push(entry(delegate.label.clone(), IconName::Bot, delegate.action.clone()));
90 }
91 if let Some(delete) = menu.delete.clone() {
92 list.push(Entry {
93 danger: true,
94 ..entry("Delete", IconName::Trash, delete)
95 });
96 }
97 if let Some(select) = menu.forward_multiple.clone() {
98 list.push(entry(SELECT_LABEL, IconName::CircleCheck, select));
99 }
100 list
101 }
102
103 fn item(key: &str, index: usize, entry: Entry, close: Close) -> AnyElement {
104 let color = if entry.danger { theme::red() } else { theme::text() };
105 let action = entry.action;
106 h_flex()
107 .id(ElementId::Name(format!("context-item-{index}-{key}").into()))
108 .debug_selector(|| format!("{CONTEXT_MENU_TAG}/item").into())
109 .h(px(ITEM_HEIGHT))
110 .px(px(10.))
111 .gap(px(12.))
112 .items_center()
113 .rounded(px(6.))
114 .cursor_pointer()
115 .text_size(px(13.))
116 .text_color(color)
117 .hover(|row| row.bg(theme::popup_hover()))
118 .child(icon(entry.glyph, ITEM_ICON, if entry.danger { theme::red() } else { theme::text_soft() }))
119 .child(div().flex_1().min_w_0().truncate().child(entry.label))
120 .on_click(move |_, window, cx| {
121 cx.stop_propagation();
122 close(window, cx);
123 action(window, cx);
124 })
125 .into_any_element()
126 }
127
128 /// Telegram-style message menu: opens at the cursor, quick reactions on top, the actions below.
129 pub fn message_context_menu(
130 mut menu: MessageMenu,
131 position: Point<Pixels>,
132 close: Close,
133 close_from_outside: Close,
134 cx: &App,
135 ) -> AnyElement {
136 let picked = menu.done.clone();
137 let after_pick = close.clone();
138 menu.done = Rc::new(move |window, cx| {
139 picked(window, cx);
140 after_pick(window, cx);
141 });
142 let key = menu.key.clone();
143 let mut reactions: Vec<AnyElement> = menu
144 .quick
145 .iter()
146 .enumerate()
147 .map(|(index, glyph)| reaction_button(&menu, glyph, index))
148 .collect();
149 reactions.push(picker_button(&menu, cx));
150 let items: Vec<AnyElement> = entries(&menu)
151 .into_iter()
152 .enumerate()
153 .map(|(index, entry)| item(&key, index, entry, close.clone()))
154 .collect();
155 deferred(
156 anchored()
157 .position(position)
158 .snap_to_window_with_margin(px(WINDOW_MARGIN))
159 .child(
160 v_flex()
161 .id(ElementId::Name(format!("{CONTEXT_MENU_TAG}-{key}").into()))
162 .debug_selector(|| CONTEXT_MENU_TAG.into())
163 .w(px(MENU_WIDTH))
164 .gap(px(PANEL_GAP))
165 .occlude()
166 .on_mouse_down_out(move |_, window, cx| close_from_outside(window, cx))
167 .on_scroll_wheel(|_, _, cx| cx.stop_propagation())
168 .child(
169 h_flex()
170 .debug_selector(|| format!("{CONTEXT_MENU_TAG}/reactions").into())
171 .self_start()
172 .p(px(PILL_PADDING))
173 .gap(px(1.))
174 .items_center()
175 .rounded_full()
176 .flyout_surface()
177 .children(reactions),
178 )
179 .child(
180 v_flex()
181 .debug_selector(|| format!("{CONTEXT_MENU_TAG}/list").into())
182 .w_full()
183 .p(px(LIST_PADDING))
184 .rounded(px(10.))
185 .flyout_surface()
186 .children(items),
187 ),
188 ),
189 )
190 .with_priority(POPUP_PRIORITY)
191 .into_any_element()
192 }
@@ -0,0 +1,192 @@
1use std::rc::Rc;
2
3use gpui_kit::assets::IconName;
4use gpui_kit::base::POPUP_PRIORITY;
5use gpui_kit::component::{h_flex, v_flex};
6use gpui_kit::*;
7
8use super::message_actions::{Action, MessageMenu, picker_button, reaction_button};
9use super::widgets::icon;
10use crate::forward_selection::FORWARD_LABEL;
11use crate::post_follow::follow_label;
12use crate::share_outlook::SHARE_TO_OUTLOOK_LABEL;
13use crate::theme::{self, ElevatedSurface as _};
14
15pub const CONTEXT_MENU_TAG: &str = "message-context-menu";
16const MENU_WIDTH: f32 = 220.;
17const PANEL_GAP: f32 = 6.;
18const PILL_PADDING: f32 = 4.;
19const LIST_PADDING: f32 = 4.;
20const ITEM_HEIGHT: f32 = 32.;
21const ITEM_ICON: f32 = 16.;
22const WINDOW_MARGIN: f32 = 8.;
23const SELECT_LABEL: &str = "Select";
24
25pub type Close = Rc<dyn Fn(&mut Window, &mut App)>;
26
27struct Entry {
28 label: SharedString,
29 glyph: IconName,
30 action: Action,
31 danger: bool,
32}
33
34fn entry(label: impl Into<SharedString>, glyph: IconName, action: Action) -> Entry {
35 Entry {
36 label: label.into(),
37 glyph,
38 action,
39 danger: false,
40 }
41}
42
43fn entries(menu: &MessageMenu) -> Vec<Entry> {
44 let mut list = Vec::new();
45 if let Some(reply) = menu.reply.clone() {
46 list.push(entry("Reply", IconName::Reply, reply));
47 }
48 if let Some(edit) = menu.edit.clone() {
49 list.push(entry("Edit", IconName::Pencil, edit));
50 }
51 if let Some(toggle_pinned) = menu.toggle_pinned.clone() {
52 list.push(if menu.pinned {
53 entry("Unpin", IconName::PinOff, toggle_pinned)
54 } else {
55 entry("Pin", IconName::Pin, toggle_pinned)
56 });
57 }
58 list.push(entry("Copy text", IconName::Copy, menu.copy.clone()));
59 if let Some(copy_link) = menu.copy_link.clone() {
60 list.push(entry("Copy link", IconName::Link, copy_link));
61 }
62 if let Some(forward) = menu.forward.clone() {
63 list.push(entry(FORWARD_LABEL, IconName::Forward, forward));
64 }
65 if let Some(save) = menu.save.clone() {
66 list.push(if menu.saved {
67 entry("Unsave", IconName::BookmarkOff, save)
68 } else {
69 entry("Save", IconName::Bookmark, save)
70 });
71 }
72 if let Some(toggle_follow) = menu.toggle_follow.clone() {
73 let glyph = if menu.followed { IconName::BellOff } else { IconName::Bell };
74 list.push(entry(follow_label(menu.followed), glyph, toggle_follow));
75 }
76 if let Some(mark_unread) = menu.mark_unread.clone() {
77 list.push(entry("Mark as unread", IconName::EyeOff, mark_unread));
78 }
79 if let Some(translate) = menu.translate.clone() {
80 list.push(entry(menu.translate_label, IconName::Languages, translate));
81 }
82 if let Some(share_to_outlook) = menu.share_to_outlook.clone() {
83 list.push(entry(SHARE_TO_OUTLOOK_LABEL, IconName::Mail, share_to_outlook));
84 }
85 if let Some(refresh_card) = menu.refresh_card.clone() {
86 list.push(entry("Refresh card", IconName::RefreshCw, refresh_card));
87 }
88 for delegate in &menu.delegate {
89 list.push(entry(delegate.label.clone(), IconName::Bot, delegate.action.clone()));
90 }
91 if let Some(delete) = menu.delete.clone() {
92 list.push(Entry {
93 danger: true,
94 ..entry("Delete", IconName::Trash, delete)
95 });
96 }
97 if let Some(select) = menu.forward_multiple.clone() {
98 list.push(entry(SELECT_LABEL, IconName::CircleCheck, select));
99 }
100 list
101}
102
103fn item(key: &str, index: usize, entry: Entry, close: Close) -> AnyElement {
104 let color = if entry.danger { theme::red() } else { theme::text() };
105 let action = entry.action;
106 h_flex()
107 .id(ElementId::Name(format!("context-item-{index}-{key}").into()))
108 .debug_selector(|| format!("{CONTEXT_MENU_TAG}/item").into())
109 .h(px(ITEM_HEIGHT))
110 .px(px(10.))
111 .gap(px(12.))
112 .items_center()
113 .rounded(px(6.))
114 .cursor_pointer()
115 .text_size(px(13.))
116 .text_color(color)
117 .hover(|row| row.bg(theme::popup_hover()))
118 .child(icon(entry.glyph, ITEM_ICON, if entry.danger { theme::red() } else { theme::text_soft() }))
119 .child(div().flex_1().min_w_0().truncate().child(entry.label))
120 .on_click(move |_, window, cx| {
121 cx.stop_propagation();
122 close(window, cx);
123 action(window, cx);
124 })
125 .into_any_element()
126}
127
128/// Telegram-style message menu: opens at the cursor, quick reactions on top, the actions below.
129pub fn message_context_menu(
130 mut menu: MessageMenu,
131 position: Point<Pixels>,
132 close: Close,
133 close_from_outside: Close,
134 cx: &App,
135) -> AnyElement {
136 let picked = menu.done.clone();
137 let after_pick = close.clone();
138 menu.done = Rc::new(move |window, cx| {
139 picked(window, cx);
140 after_pick(window, cx);
141 });
142 let key = menu.key.clone();
143 let mut reactions: Vec<AnyElement> = menu
144 .quick
145 .iter()
146 .enumerate()
147 .map(|(index, glyph)| reaction_button(&menu, glyph, index))
148 .collect();
149 reactions.push(picker_button(&menu, cx));
150 let items: Vec<AnyElement> = entries(&menu)
151 .into_iter()
152 .enumerate()
153 .map(|(index, entry)| item(&key, index, entry, close.clone()))
154 .collect();
155 deferred(
156 anchored()
157 .position(position)
158 .snap_to_window_with_margin(px(WINDOW_MARGIN))
159 .child(
160 v_flex()
161 .id(ElementId::Name(format!("{CONTEXT_MENU_TAG}-{key}").into()))
162 .debug_selector(|| CONTEXT_MENU_TAG.into())
163 .w(px(MENU_WIDTH))
164 .gap(px(PANEL_GAP))
165 .occlude()
166 .on_mouse_down_out(move |_, window, cx| close_from_outside(window, cx))
167 .on_scroll_wheel(|_, _, cx| cx.stop_propagation())
168 .child(
169 h_flex()
170 .debug_selector(|| format!("{CONTEXT_MENU_TAG}/reactions").into())
171 .self_start()
172 .p(px(PILL_PADDING))
173 .gap(px(1.))
174 .items_center()
175 .rounded_full()
176 .flyout_surface()
177 .children(reactions),
178 )
179 .child(
180 v_flex()
181 .debug_selector(|| format!("{CONTEXT_MENU_TAG}/list").into())
182 .w_full()
183 .p(px(LIST_PADDING))
184 .rounded(px(10.))
185 .flyout_surface()
186 .children(items),
187 ),
188 ),
189 )
190 .with_priority(POPUP_PRIORITY)
191 .into_any_element()
192}
crates/app/src/views/message_row.rs +13 −2
@@ -3,6 +3,7 @@ use gpui_kit::component::{h_flex, v_flex};
3 3 use gpui_kit::prelude::FluentBuilder as _;
4 4 use gpui_kit::*;
5 5 use std::time::Duration;
6 use std::rc::Rc;
6 7
7 8 use super::adaptive_card::cards_view;
8 9 use super::attachments::{FileActions, ImageActions, attachments_view, message_body};
@@ -105,6 +106,8 @@ pub struct RowActions {
105 106 pub bot: Option<BotIdentity>,
106 107 pub delivery: DeliveryActions,
107 108 pub reply: RowAction,
109 pub open_context: Option<Rc<dyn Fn(Point<Pixels>, &mut App)>>,
110 pub context_menu: Option<AnyElement>,
108 111 pub hovered: Option<HoverChange>,
109 112 pub menu: Option<MessageMenu>,
110 113 pub scheduled_menu: Option<ScheduledMenu>,
@@ -788,6 +791,8 @@ pub fn render_message_row(
788 791 bot,
789 792 delivery,
790 793 reply,
794 open_context,
795 context_menu,
791 796 hovered,
792 797 menu,
793 798 scheduled_menu,
@@ -849,9 +854,15 @@ pub fn render_message_row(
849 854 .id(ElementId::Name(format!("row-{index}").into()))
850 855 .w_full()
851 856 .pt(spacing)
852 .when_some(reply, |element, reply| {
853 element.on_mouse_down(MouseButton::Right, move |_, _, cx| reply(cx))
857 .map(|element| match (open_context, reply) {
858 (Some(open_context), _) => element.on_mouse_down(MouseButton::Right, move |event, _, cx| {
859 cx.stop_propagation();
860 open_context(event.position, cx)
861 }),
862 (None, Some(reply)) => element.on_mouse_down(MouseButton::Right, move |_, _, cx| reply(cx)),
863 (None, None) => element,
854 864 })
865 .children(context_menu)
855 866 .child(
856 867 div()
857 868 .w_full()
@@ -3,6 +3,7 @@ use gpui_kit::component::{h_flex, v_flex};
3use gpui_kit::prelude::FluentBuilder as _;
3use gpui_kit::prelude::FluentBuilder as _;
4use gpui_kit::*;
4use gpui_kit::*;
5use std::time::Duration;
5use std::time::Duration;
6use std::rc::Rc;
6
7
7use super::adaptive_card::cards_view;
8use super::adaptive_card::cards_view;
8use super::attachments::{FileActions, ImageActions, attachments_view, message_body};
9use super::attachments::{FileActions, ImageActions, attachments_view, message_body};
@@ -105,6 +106,8 @@ pub struct RowActions {
105 pub bot: Option<BotIdentity>,
106 pub bot: Option<BotIdentity>,
106 pub delivery: DeliveryActions,
107 pub delivery: DeliveryActions,
107 pub reply: RowAction,
108 pub reply: RowAction,
109 pub open_context: Option<Rc<dyn Fn(Point<Pixels>, &mut App)>>,
110 pub context_menu: Option<AnyElement>,
108 pub hovered: Option<HoverChange>,
111 pub hovered: Option<HoverChange>,
109 pub menu: Option<MessageMenu>,
112 pub menu: Option<MessageMenu>,
110 pub scheduled_menu: Option<ScheduledMenu>,
113 pub scheduled_menu: Option<ScheduledMenu>,
@@ -788,6 +791,8 @@ pub fn render_message_row(
788 bot,
791 bot,
789 delivery,
792 delivery,
790 reply,
793 reply,
794 open_context,
795 context_menu,
791 hovered,
796 hovered,
792 menu,
797 menu,
793 scheduled_menu,
798 scheduled_menu,
@@ -849,9 +854,15 @@ pub fn render_message_row(
849 .id(ElementId::Name(format!("row-{index}").into()))
854 .id(ElementId::Name(format!("row-{index}").into()))
850 .w_full()
855 .w_full()
851 .pt(spacing)
856 .pt(spacing)
852 .when_some(reply, |element, reply| {
857 .map(|element| match (open_context, reply) {
853 element.on_mouse_down(MouseButton::Right, move |_, _, cx| reply(cx))
858 (Some(open_context), _) => element.on_mouse_down(MouseButton::Right, move |event, _, cx| {
859 cx.stop_propagation();
860 open_context(event.position, cx)
861 }),
862 (None, Some(reply)) => element.on_mouse_down(MouseButton::Right, move |_, _, cx| reply(cx)),
863 (None, None) => element,
854 })
864 })
865 .children(context_menu)
855 .child(
866 .child(
856 div()
867 div()
857 .w_full()
868 .w_full()
crates/app/src/views/mod.rs +1 −0
@@ -61,6 +61,7 @@ pub mod join_dialog;
61 61 pub mod jumbo_emoji;
62 62 pub mod link_preview;
63 63 pub mod message_actions;
64 pub mod message_context_menu;
64 65 pub mod message_row;
65 66 pub mod new_chat;
66 67 pub mod notice_toast;
@@ -61,6 +61,7 @@ pub mod join_dialog;
61pub mod jumbo_emoji;
61pub mod jumbo_emoji;
62pub mod link_preview;
62pub mod link_preview;
63pub mod message_actions;
63pub mod message_actions;
64pub mod message_context_menu;
64pub mod message_row;
65pub mod message_row;
65pub mod new_chat;
66pub mod new_chat;
66pub mod notice_toast;
67pub mod notice_toast;