context.rs (5985B)
1 use egui::{Rect, Vec2}; 2 use enostr::NoteId; 3 use nostrdb::NoteKey; 4 use notedeck::{tr, BroadcastContext, Localization, NoteContextSelection}; 5 6 use crate::context_menu::{context_button, stationary_arbitrary_menu_button}; 7 8 pub struct NoteContextButton { 9 put_at: Option<Rect>, 10 note_key: NoteKey, 11 } 12 13 impl egui::Widget for NoteContextButton { 14 fn ui(self, ui: &mut egui::Ui) -> egui::Response { 15 let r = if let Some(r) = self.put_at { 16 r 17 } else { 18 let mut place = ui.available_rect_before_wrap(); 19 let size = Self::max_width(); 20 place.set_width(size); 21 place.set_height(size); 22 place 23 }; 24 25 Self::show(ui, self.note_key, r) 26 } 27 } 28 29 impl NoteContextButton { 30 pub fn new(note_key: NoteKey) -> Self { 31 let put_at: Option<Rect> = None; 32 NoteContextButton { note_key, put_at } 33 } 34 35 pub fn place_at(mut self, rect: Rect) -> Self { 36 self.put_at = Some(rect); 37 self 38 } 39 40 pub fn max_width() -> f32 { 41 Self::max_radius() * 3.0 + Self::max_distance_between_circles() * 2.0 42 } 43 44 pub fn size() -> Vec2 { 45 let width = Self::max_width(); 46 egui::vec2(width, width) 47 } 48 49 fn max_radius() -> f32 { 50 4.0 51 } 52 53 fn max_distance_between_circles() -> f32 { 54 2.0 55 } 56 57 #[profiling::function] 58 pub fn show(ui: &mut egui::Ui, note_key: NoteKey, put_at: Rect) -> egui::Response { 59 let id = ui.id().with(("more_options_anim", note_key)); 60 61 context_button(ui, id, put_at) 62 } 63 64 #[profiling::function] 65 pub fn menu( 66 ui: &mut egui::Ui, 67 i18n: &mut Localization, 68 button_response: egui::Response, 69 note_id: NoteId, 70 can_sign: bool, 71 is_muted: bool, 72 ) -> Option<NoteContextSelection> { 73 let mut context_selection: Option<NoteContextSelection> = None; 74 75 stationary_arbitrary_menu_button(ui, button_response, |ui| { 76 ui.set_max_width(200.0); 77 78 if ui 79 .button(tr!( 80 i18n, 81 "Summarize Thread", 82 "Ask Dave to summarize this note's thread" 83 )) 84 .clicked() 85 { 86 context_selection = Some(NoteContextSelection::SummarizeThread(note_id)); 87 ui.close_menu(); 88 } 89 90 if ui 91 .button(tr!( 92 i18n, 93 "Copy Note Link", 94 "Copy the damus.io note link for this note to clipboard" 95 )) 96 .clicked() 97 { 98 context_selection = Some(NoteContextSelection::CopyNeventLink); 99 ui.close_menu(); 100 } 101 102 // Debug: Check what the tr! macro returns 103 let copy_text = tr!( 104 i18n, 105 "Copy Text", 106 "Copy the text content of the note to clipboard" 107 ); 108 109 if ui.button(copy_text).clicked() { 110 context_selection = Some(NoteContextSelection::CopyText); 111 ui.close_menu(); 112 } 113 if ui 114 .button(tr!( 115 i18n, 116 "Copy Pubkey", 117 "Copy the author's public key to clipboard" 118 )) 119 .clicked() 120 { 121 context_selection = Some(NoteContextSelection::CopyPubkey); 122 ui.close_menu(); 123 } 124 if ui 125 .button(tr!( 126 i18n, 127 "Copy Note ID", 128 "Copy the note identifier to clipboard" 129 )) 130 .clicked() 131 { 132 context_selection = Some(NoteContextSelection::CopyNevent); 133 ui.close_menu(); 134 } 135 if ui 136 .button(tr!( 137 i18n, 138 "Copy Note JSON", 139 "Copy the raw note data in JSON format to clipboard" 140 )) 141 .clicked() 142 { 143 context_selection = Some(NoteContextSelection::CopyNoteJSON); 144 ui.close_menu(); 145 } 146 if ui 147 .button(tr!( 148 i18n, 149 "Broadcast", 150 "Broadcast the note to all connected relays" 151 )) 152 .clicked() 153 { 154 context_selection = Some(NoteContextSelection::Broadcast( 155 BroadcastContext::Everywhere, 156 )); 157 ui.close_menu(); 158 } 159 if ui 160 .button(tr!( 161 i18n, 162 "Broadcast Local", 163 "Broadcast the note only to local network relays" 164 )) 165 .clicked() 166 { 167 context_selection = Some(NoteContextSelection::Broadcast( 168 BroadcastContext::LocalNetwork, 169 )); 170 ui.close_menu(); 171 } 172 173 if can_sign { 174 let label = if is_muted { 175 tr!(i18n, "Unmute User", "Unmute the author of this note") 176 } else { 177 tr!(i18n, "Mute User", "Mute the author of this note") 178 }; 179 if ui.button(label).clicked() { 180 context_selection = Some(NoteContextSelection::MuteUser); 181 ui.close_menu(); 182 } 183 184 if ui 185 .button(tr!( 186 i18n, 187 "Report Note", 188 "Report this note for objectionable content" 189 )) 190 .clicked() 191 { 192 context_selection = Some(NoteContextSelection::ReportUser); 193 ui.close_menu(); 194 } 195 } 196 }); 197 198 context_selection 199 } 200 }