Commit 3cb6e8ee authored by Eisha Chen-yen-su's avatar Eisha Chen-yen-su

Invite: Use the new GtkTextView for searching users

See #78
parent 2d8cbef0
......@@ -57,6 +57,62 @@ impl App {
.get_object::<gtk::Dialog>("invite_user_dialog")
.expect("Can't find invite_user_dialog in ui file.");
// this is used to cancel the timeout and not search for every key input. We'll wait 500ms
// without key release event to launch the search
let source_id: Arc<Mutex<Option<glib::source::SourceId>>> = Arc::new(Mutex::new(None));
to_chat_textview.connect_key_release_event(clone!(op => move |entry, _| {
{
let mut id = source_id.lock().unwrap();
if let Some(sid) = id.take() {
glib::source::source_remove(sid);
}
}
let sid = gtk::timeout_add(500, clone!(op, entry, source_id => move || {
if let Some(buffer) = entry.get_buffer() {
let start = buffer.get_start_iter();
let end = buffer.get_end_iter();
let text = buffer.get_text(&start, &end, false);
op.lock().unwrap().search_invite_user(text);
}
*(source_id.lock().unwrap()) = None;
gtk::Continue(false)
}));
*(source_id.lock().unwrap()) = Some(sid);
glib::signal::Inhibit(false)
}));
// this is used to cancel the timeout and not search for every key input. We'll wait 500ms
// without key release event to launch the search
let source_id: Arc<Mutex<Option<glib::source::SourceId>>> = Arc::new(Mutex::new(None));
invite_textview.connect_key_release_event(clone!(op => move |entry, _| {
{
let mut id = source_id.lock().unwrap();
if let Some(sid) = id.take() {
glib::source::source_remove(sid);
}
}
let sid = gtk::timeout_add(500, clone!(op, entry, source_id => move || {
if let Some(buffer) = entry.get_buffer() {
let start = buffer.get_start_iter();
let end = buffer.get_end_iter();
let text = buffer.get_text(&start, &end, false);
op.lock().unwrap().search_invite_user(text);
}
*(source_id.lock().unwrap()) = None;
gtk::Continue(false)
}));
*(source_id.lock().unwrap()) = Some(sid);
glib::signal::Inhibit(false)
}));
// this is used to cancel the timeout and not search for every key input. We'll wait 500ms
// without key release event to launch the search
let source_id: Arc<Mutex<Option<glib::source::SourceId>>> = Arc::new(Mutex::new(None));
......
......@@ -51,9 +51,19 @@ impl AppOp {
.map(|btn| btn.set_sensitive(true));
if let Some(buffer) = to_invite_textview.get_buffer() {
let mut iter = buffer.get_end_iter();
let mut start_word = buffer.get_iter_at_offset(buffer.get_property_cursor_position());
let mut end_word = buffer.get_iter_at_offset(buffer.get_property_cursor_position());
if let Some(anchor) = buffer.create_child_anchor(&mut iter) {
// Remove the search input in the entry before inserting the member's pill
if !start_word.starts_word() {
start_word.backward_word_start();
}
if !end_word.ends_word() {
end_word.forward_word_end();
}
buffer.delete(&mut start_word, &mut end_word);
if let Some(anchor) = buffer.create_child_anchor(&mut end_word) {
let w;
{
let mb = widgets::MemberBox::new(&u, &self);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment