Commit 65414515 authored by Eisha Chen-yen-su's avatar Eisha Chen-yen-su

Invite: Cleanup the code to remove the old `GtkEntry`

See #78
parent 5d8ce756
......@@ -76,19 +76,6 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="to_chat_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="placeholder_text" translatable="yes">Matrix username, email or phone number</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="direct_chat_search_scroll">
<property name="height_request">150</property>
......@@ -115,7 +102,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">1</property>
</packing>
</child>
</object>
......
......@@ -76,19 +76,6 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="invite_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="placeholder_text" translatable="yes">Matrix username, email or phone number</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="user_search_scroll">
<property name="height_request">150</property>
......@@ -115,7 +102,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">1</property>
</packing>
</child>
</object>
......
......@@ -17,9 +17,6 @@ impl App {
let invite = self.ui.builder
.get_object::<gtk::Button>("direct_chat_button")
.expect("Can't find direct_chat_button in ui file.");
let entry = self.ui.builder
.get_object::<gtk::Entry>("to_chat_entry")
.expect("Can't find to_chat_entry in ui file.");
let to_chat_textview_box = self.ui.builder
.get_object::<gtk::Box>("to_chat_textview_box")
.expect("Can't find to_chat_textview_box in ui file.");
......@@ -48,7 +45,7 @@ impl App {
// 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));
entry.connect_key_release_event(clone!(op => move |entry, _| {
to_chat_textview.connect_key_release_event(clone!(op => move |entry, _| {
{
let mut id = source_id.lock().unwrap();
if let Some(sid) = id.take() {
......@@ -57,7 +54,15 @@ impl App {
}
let sid = gtk::timeout_add(500, clone!(op, entry, source_id => move || {
op.lock().unwrap().search_invite_user(entry.get_text());
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)
}));
......
......@@ -51,9 +51,6 @@ impl App {
let invite_textview = self.ui.builder
.get_object::<gtk::TextView>("invite_textview")
.expect("Can't find invite_textview in ui file.");
let entry = self.ui.builder
.get_object::<gtk::Entry>("invite_entry")
.expect("Can't find invite_entry in ui file.");
let dialog = self.ui.builder
.get_object::<gtk::Dialog>("invite_user_dialog")
.expect("Can't find invite_user_dialog in ui file.");
......@@ -101,30 +98,14 @@ impl App {
*(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));
entry.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);
}
invite_textview.connect_focus_in_event(clone!(op, invite_textview_box => move |_, _| {
if let Some(style) = invite_textview_box.get_style_context() {
style.add_class("message-input-focused");
}
let sid = gtk::timeout_add(500, clone!(op, entry, source_id => move || {
op.lock().unwrap().search_invite_user(entry.get_text());
*(source_id.lock().unwrap()) = None;
gtk::Continue(false)
}));
op.lock().unwrap().remove_invite_user_dialog_placeholder();
*(source_id.lock().unwrap()) = Some(sid);
glib::signal::Inhibit(false)
Inhibit(false)
}));
......
......@@ -169,9 +169,6 @@ impl AppOp {
let invite_textview = self.ui.builder
.get_object::<gtk::TextView>("invite_textview")
.expect("Can't find invite_textview in ui file.");
let entry = self.ui.builder
.get_object::<gtk::Entry>("invite_entry")
.expect("Can't find invite_entry in ui file.");
let dialog = self.ui.builder
.get_object::<gtk::Dialog>("invite_user_dialog")
.expect("Can't find invite_user_dialog in ui file.");
......@@ -187,7 +184,6 @@ impl AppOp {
listbox.remove(ch);
}
scroll.hide();
entry.set_text("");
dialog.hide();
dialog.resize(300, 200);
}
......
......@@ -77,27 +77,39 @@ impl AppOp {
match self.search_type {
SearchType::Invite => {
let entry = self.ui.builder
.get_object::<gtk::Entry>("invite_entry")
.expect("Can't find invite_entry in ui file.");
.get_object::<gtk::TextView>("invite_textview")
.expect("Can't find invite_textview in ui file.");
let listbox = self.ui.builder
.get_object::<gtk::ListBox>("user_search_box")
.expect("Can't find user_search_box in ui file.");
let scroll = self.ui.builder
.get_object::<gtk::Widget>("user_search_scroll")
.expect("Can't find user_search_scroll in ui file.");
self.search_finished(users, listbox, scroll, entry.get_text());
if let Some(buffer) = entry.get_buffer() {
let start = buffer.get_start_iter();
let end = buffer.get_end_iter();
self.search_finished(users, listbox, scroll, buffer.get_text(&start, &end, false));
}
},
SearchType::DirectChat => {
let entry = self.ui.builder
.get_object::<gtk::Entry>("to_chat_entry")
.expect("Can't find to_chat_entry in ui file.");
.get_object::<gtk::TextView>("to_chat_textview")
.expect("Can't find to_chat_textview in ui file.");
let listbox = self.ui.builder
.get_object::<gtk::ListBox>("direct_chat_search_box")
.expect("Can't find direct_chat_search_box in ui file.");
let scroll = self.ui.builder
.get_object::<gtk::Widget>("direct_chat_search_scroll")
.expect("Can't find direct_chat_search_scroll in ui file.");
self.search_finished(users, listbox, scroll, entry.get_text());
if let Some(buffer) = entry.get_buffer() {
let start = buffer.get_start_iter();
let end = buffer.get_end_iter();
self.search_finished(users, listbox, scroll, buffer.get_text(&start, &end, false));
}
}
}
}
......
......@@ -60,8 +60,8 @@ impl AppOp {
.get_object::<gtk::TextView>("to_chat_textview")
.expect("Can't find to_chat_textview in ui file.");
let entry = self.ui.builder
.get_object::<gtk::Entry>("to_chat_entry")
.expect("Can't find to_chat_entry in ui file.");
.get_object::<gtk::TextView>("to_chat_textview")
.expect("Can't find to_chat_textview in ui file.");
let dialog = self.ui.builder
.get_object::<gtk::Dialog>("direct_chat_dialog")
.expect("Can't find direct_chat_dialog in ui file.");
......@@ -77,7 +77,9 @@ impl AppOp {
listbox.remove(ch);
}
scroll.hide();
entry.set_text("");
if let Some(buffer) = entry.get_buffer() {
buffer.set_text("");
}
dialog.hide();
dialog.resize(300, 200);
}
......
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