From dd3f6ee5e5a68cbf5c5bfcff1dcf857fad739c04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Moreno?= Date: Sat, 9 Dec 2017 18:24:38 +0100 Subject: [PATCH] Click on user adds the user alias to the message entry See #18 --- fractal-gtk/src/app.rs | 32 +++++++++++++++++++++---------- fractal-gtk/src/widgets/member.rs | 8 +++++--- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/fractal-gtk/src/app.rs b/fractal-gtk/src/app.rs index b0d5205d..b43496bf 100644 --- a/fractal-gtk/src/app.rs +++ b/fractal-gtk/src/app.rs @@ -612,7 +612,7 @@ impl AppOp { for (_, m) in room.members.iter() { self.add_room_member(m.clone()); } - self.reset_member_search(); + self.show_all_members(); let name_label = self.gtk_builder @@ -1513,13 +1513,6 @@ impl AppOp { self.gtk_app.quit(); } - pub fn reset_member_search(&self) { - let inp: gtk::SearchEntry = self.gtk_builder - .get_object("members_search") - .expect("Couldn't find members_searcn in ui file."); - inp.set_text(""); - } - pub fn show_members(&self, members: Vec) { let mlist: gtk::ListBox = self.gtk_builder .get_object("member_list") @@ -1528,9 +1521,28 @@ impl AppOp { mlist.remove(&ch); } + let msg_entry: gtk::Entry = self.gtk_builder + .get_object("msg_entry") + .expect("Couldn't find msg_entry in ui file."); + for m in members { - let mb = widgets::MemberBox::new(&m, &self); - mlist.add(&mb.widget()); + let w; + + { + let mb = widgets::MemberBox::new(&m, &self); + w = mb.widget(); + } + + let msg = msg_entry.clone(); + w.connect_button_press_event(move |_, _| { + if let Some(ref a) = m.alias { + let mut pos = msg.get_position(); + msg.insert_text(&a.clone(), &mut pos); + } + glib::signal::Inhibit(true) + }); + + mlist.add(&w); } } diff --git a/fractal-gtk/src/widgets/member.rs b/fractal-gtk/src/widgets/member.rs index 73273202..ba8f241f 100644 --- a/fractal-gtk/src/widgets/member.rs +++ b/fractal-gtk/src/widgets/member.rs @@ -27,9 +27,10 @@ impl<'a> MemberBox<'a> { } } - pub fn widget(&self) -> gtk::Box { + pub fn widget(&self) -> gtk::EventBox { let backend = self.op.backend.clone(); let username = gtk::Label::new(""); + let event_box = gtk::EventBox::new(); let w = gtk::Box::new(gtk::Orientation::Horizontal, 5); username.set_text(&self.member.get_alias().unwrap_or_default()); @@ -41,8 +42,9 @@ impl<'a> MemberBox<'a> { w.pack_start(&avatar, false, false, 5); w.pack_start(&username, false, false, 5); - w.show_all(); - w + event_box.add(&w); + event_box.show_all(); + event_box } }