Philipp Hörist pushed to branch master at gajim / gajim


Commits:
e3fd830a by lovetox at 2021-12-15T22:59:29+01:00
Add back styling of /me command

- - - - -


4 changed files:

- gajim/gtk/conversation/message_widget.py
- gajim/gtk/conversation/plain_widget.py
- gajim/gtk/conversation/rows/message.py
- gajim/gtk/search_view.py


Changes:

=====================================
gajim/gtk/conversation/message_widget.py
=====================================
@@ -15,6 +15,7 @@
 from __future__ import annotations
 
 from typing import Any
+from typing import Optional
 from typing import Union
 from typing import cast
 
@@ -46,10 +47,23 @@ def get_content(self) -> ContentT:
     def get_text(self) -> str:
         return self._content.text
 
-    def add_with_styling(self, text: str) -> None:
+    def add_with_styling(self,
+                         text: str,
+                         nickname: Optional[str] = None) -> None:
+
+        if text.startswith('/me') and nickname is not None:
+            self._add_action_phrase(text, nickname)
+            return
+
         result = process(text)
         self.add_content(result)
 
+    def _add_action_phrase(self, text: str, nickname: str):
+        widget = PlainWidget(self._account, self._selectable)
+        widget.add_action_phrase(text, nickname)
+        self.add(widget)
+        return
+
     def add_content(self, content: ContentT) -> None:
         self.clear()
         self._content = content


=====================================
gajim/gtk/conversation/plain_widget.py
=====================================
@@ -62,6 +62,11 @@ def __init__(self, account: str, selectable: bool) -> None:
     def add_content(self, block: PlainBlock) -> None:
         self._text_widget.print_text_with_styling(block)
 
+    def add_action_phrase(self, text: str, nickname: str) -> None:
+        text = text.replace('/me', '* %s' % nickname, 1)
+        text = GLib.markup_escape_text(text)
+        self._text_widget.add_action_phrase(text)
+
     def update_text_tags(self) -> None:
         self._text_widget.update_text_tags()
 
@@ -107,6 +112,9 @@ def print_text_with_styling(self, block: PlainBlock) -> 
None:
         self.set_markup(text)
         self.set_attributes(make_pango_attributes(block))
 
+    def add_action_phrase(self, text: str) -> None:
+        self.set_markup(f'<i>{text}</i>')
+
     def update_text_tags(self) -> None:
         pass
 
@@ -197,6 +205,14 @@ def print_text_with_styling(self, block: PlainBlock) -> 
None:
             end_iter = buffer_.get_iter_at_offset(uri.end)
             buffer_.apply_tag_by_name(uri.name, start_iter, end_iter)
 
+    def add_action_phrase(self, text: str) -> None:
+        buffer_ = self.get_buffer()
+        buffer_.insert(buffer_.get_start_iter(), text.strip())
+
+        start_iter = buffer_.get_start_iter()
+        end_iter = buffer_.get_end_iter()
+        buffer_.apply_tag_by_name('emphasis', start_iter, end_iter)
+
     def _query_tooltip(self, widget: Any, x_pos: int, y_pos: int,
                        _keyboard_mode: bool, tooltip: Gtk.Tooltip) -> bool:
         window = widget.get_window(Gtk.TextWindowType.TEXT)


=====================================
gajim/gtk/conversation/rows/message.py
=====================================
@@ -110,12 +110,12 @@ def __init__(self,
                 text, self._message_widget, context)
         else:
             self._message_widget = MessageWidget(account)
-            self._message_widget.add_with_styling(text)
+            self._message_widget.add_with_styling(text, nickname=name)
             if self._is_groupchat:
                 our_nick = get_group_chat_nick(
                     self._account, self._contact.jid)
                 if name != our_nick:
-                    self._check_for_highlight(self._message_widget.content)
+                    self._check_for_highlight(text)
 
         if self._is_groupchat:
             our_nick = get_group_chat_nick(self._account, self._contact.jid)
@@ -211,9 +211,9 @@ def update_text_tags(self) -> None:
         if isinstance(self._message_widget, MessageWidget):
             self._message_widget.update_text_tags()
 
-    def _check_for_highlight(self, content: ParsingResult) -> None:
+    def _check_for_highlight(self, text: str) -> None:
         needs_highlight = message_needs_highlight(
-            content.text,
+            text,
             self._contact.nickname,
             self._client.get_own_jid().bare)
         if needs_highlight:


=====================================
gajim/gtk/search_view.py
=====================================
@@ -360,7 +360,7 @@ def __init__(self, msg: namedtuple, account: str, jid: JID) 
-> None:
         self._ui.row_time_label.set_label(date)
 
         message_widget = MessageWidget(account, selectable=False)
-        message_widget.add_with_styling(msg.message_widget)
+        message_widget.add_with_styling(msg.message, nickname=contact_name)
         self._ui.result_row_grid.attach(message_widget, 1, 1, 2, 1)
 
         self.show_all()



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/e3fd830ab8f2aee912e3894361d303fe6a4dd0ef

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/e3fd830ab8f2aee912e3894361d303fe6a4dd0ef
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to