From 6f3eee1430b1e3bdb22b8c532f8b609015d01bfb Mon Sep 17 00:00:00 2001 From: fiaxh Date: Thu, 16 Mar 2017 16:28:32 +0100 Subject: Improve when to send chat state notifications --- main/src/ui/chat_input.vala | 19 ++++++++----------- main/src/ui/unified_window.vala | 4 ++-- 2 files changed, 10 insertions(+), 13 deletions(-) (limited to 'main/src/ui') diff --git a/main/src/ui/chat_input.vala b/main/src/ui/chat_input.vala index 209869a8..2079d747 100644 --- a/main/src/ui/chat_input.vala +++ b/main/src/ui/chat_input.vala @@ -38,23 +38,21 @@ public class ChatInput : Box { this.stream_interactor = stream_interactor; scrolled.get_vscrollbar().get_preferred_height(out vscrollbar_min_height, null); scrolled.vadjustment.notify["upper"].connect_after(on_upper_notify); + text_input.key_press_event.connect(on_text_input_key_press); + text_input.buffer.changed.connect(on_text_input_changed); } public void initialize_for_conversation(Conversation conversation) { - if (this.conversation != null) { - if (text_input.buffer.text != "") { - entry_cache[this.conversation] = text_input.buffer.text; - } else { - entry_cache.unset(this.conversation); - } - } + if (this.conversation != null) entry_cache[this.conversation] = text_input.buffer.text; this.conversation = conversation; + + text_input.buffer.changed.disconnect(on_text_input_changed); text_input.buffer.text = ""; if (entry_cache.has_key(conversation)) { text_input.buffer.text = entry_cache[conversation]; } - text_input.key_press_event.connect(on_text_input_key_press); - text_input.key_release_event.connect(on_text_input_key_release); + text_input.buffer.changed.connect(on_text_input_changed); + text_input.grab_focus(); } @@ -117,13 +115,12 @@ public class ChatInput : Box { } } - private bool on_text_input_key_release(EventKey event) { + private void on_text_input_changed() { if (text_input.buffer.text != "") { ChatInteraction.get_instance(stream_interactor).on_message_entered(conversation); } else { ChatInteraction.get_instance(stream_interactor).on_message_cleared(conversation); } - return false; } } diff --git a/main/src/ui/unified_window.vala b/main/src/ui/unified_window.vala index 269799c2..0f33450d 100644 --- a/main/src/ui/unified_window.vala +++ b/main/src/ui/unified_window.vala @@ -68,12 +68,12 @@ public class UnifiedWindow : Window { } private bool on_focus_in_event() { - ChatInteraction.get_instance(stream_interactor).window_focus_in(conversation); + ChatInteraction.get_instance(stream_interactor).on_window_focus_in(conversation); return false; } private bool on_focus_out_event() { - ChatInteraction.get_instance(stream_interactor).window_focus_out(conversation); + ChatInteraction.get_instance(stream_interactor).on_window_focus_out(conversation); return false; } } -- cgit v1.2.3-54-g00ecf