Now About Social Code
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/chat.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/chat.py b/src/chat.py
index ab33ebe..d7f1ce8 100644
--- a/src/chat.py
+++ b/src/chat.py
@@ -68,7 +68,13 @@ class WeegtkChat(Adw.Bin):
adj.connect("value-changed", self.scroll_changes)
adj.connect("notify::upper", self.upper_notify)
- self.text_entry.get_buffer().connect("insert-text", self.text_inserted)
+ sc_controller = Gtk.ShortcutController(propagation_phase=Gtk.PropagationPhase.CAPTURE)
+ action = Gtk.CallbackAction.new(self.entry_callback, self)
+ trigger = Gtk.ShortcutTrigger.parse_string("Return")
+ shortcut = Gtk.Shortcut(action=action, trigger=trigger)
+ sc_controller.add_shortcut(shortcut)
+
+ self.add_controller(sc_controller)
# Enable spell checking
self.checker = Spelling.Checker.get_default()
@@ -202,14 +208,9 @@ class WeegtkChat(Adw.Bin):
entry_buffer.set_text("", 0)
self.emit("buffer_input", self.data['full_name'], text)
- def text_inserted(self, buffer, location, text, length):
- if text == "\n":
- print("Got newline!")
- entry_buffer = self.text_entry.get_buffer()
- text = entry_buffer.get_text(entry_buffer.get_start_iter(), entry_buffer.get_end_iter(), False)
- print("Buffer is {}".format(text))
- print("Last char is {}".format(text[-1]))
- self.entry_activate()
+ def entry_callback(self, *args):
+ self.entry_activate()
+ return True
def open_file_dialog(self, dialog, result, caller):
try:
@@ -221,7 +222,7 @@ class WeegtkChat(Adw.Bin):
conf = config.read()
file_url = netfile.upload(file.get_path(), conf["upload"]["url"])
entry_buffer = self.text_entry.get_buffer()
- entry_buffer.insert_text(self.text_entry.get_position(), file_url, -1)
+ entry_buffer.insert_at_cursor(file_url, -1)
@Gtk.Template.Callback()
def attach_file(self, *args):