Click on user adds the user alias to the message entry

See #18
This commit is contained in:
Daniel García Moreno 2017-12-09 18:24:38 +01:00
parent 4af74a30b6
commit dd3f6ee5e5
2 changed files with 27 additions and 13 deletions

View file

@ -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<Member>) {
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);
}
}

View file

@ -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
}
}