Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
e3fd830a
by lovetox at 2021-12-15T22:59:29+01:00
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:
| ... | ... | @@ -15,6 +15,7 @@ |
| 15 | 15 |
from __future__ import annotations
|
| 16 | 16 |
|
| 17 | 17 |
from typing import Any
|
| 18 |
+from typing import Optional
|
|
| 18 | 19 |
from typing import Union
|
| 19 | 20 |
from typing import cast
|
| 20 | 21 |
|
| ... | ... | @@ -46,10 +47,23 @@ def get_content(self) -> ContentT: |
| 46 | 47 |
def get_text(self) -> str:
|
| 47 | 48 |
return self._content.text
|
| 48 | 49 |
|
| 49 |
- def add_with_styling(self, text: str) -> None:
|
|
| 50 |
+ def add_with_styling(self,
|
|
| 51 |
+ text: str,
|
|
| 52 |
+ nickname: Optional[str] = None) -> None:
|
|
| 53 |
+ |
|
| 54 |
+ if text.startswith('/me') and nickname is not None:
|
|
| 55 |
+ self._add_action_phrase(text, nickname)
|
|
| 56 |
+ return
|
|
| 57 |
+ |
|
| 50 | 58 |
result = process(text)
|
| 51 | 59 |
self.add_content(result)
|
| 52 | 60 |
|
| 61 |
+ def _add_action_phrase(self, text: str, nickname: str):
|
|
| 62 |
+ widget = PlainWidget(self._account, self._selectable)
|
|
| 63 |
+ widget.add_action_phrase(text, nickname)
|
|
| 64 |
+ self.add(widget)
|
|
| 65 |
+ return
|
|
| 66 |
+ |
|
| 53 | 67 |
def add_content(self, content: ContentT) -> None:
|
| 54 | 68 |
self.clear()
|
| 55 | 69 |
self._content = content
|
| ... | ... | @@ -62,6 +62,11 @@ def __init__(self, account: str, selectable: bool) -> None: |
| 62 | 62 |
def add_content(self, block: PlainBlock) -> None:
|
| 63 | 63 |
self._text_widget.print_text_with_styling(block)
|
| 64 | 64 |
|
| 65 |
+ def add_action_phrase(self, text: str, nickname: str) -> None:
|
|
| 66 |
+ text = text.replace('/me', '* %s' % nickname, 1)
|
|
| 67 |
+ text = GLib.markup_escape_text(text)
|
|
| 68 |
+ self._text_widget.add_action_phrase(text)
|
|
| 69 |
+ |
|
| 65 | 70 |
def update_text_tags(self) -> None:
|
| 66 | 71 |
self._text_widget.update_text_tags()
|
| 67 | 72 |
|
| ... | ... | @@ -107,6 +112,9 @@ def print_text_with_styling(self, block: PlainBlock) -> None: |
| 107 | 112 |
self.set_markup(text)
|
| 108 | 113 |
self.set_attributes(make_pango_attributes(block))
|
| 109 | 114 |
|
| 115 |
+ def add_action_phrase(self, text: str) -> None:
|
|
| 116 |
+ self.set_markup(f'<i>{text}</i>')
|
|
| 117 |
+ |
|
| 110 | 118 |
def update_text_tags(self) -> None:
|
| 111 | 119 |
pass
|
| 112 | 120 |
|
| ... | ... | @@ -197,6 +205,14 @@ def print_text_with_styling(self, block: PlainBlock) -> None: |
| 197 | 205 |
end_iter = buffer_.get_iter_at_offset(uri.end)
|
| 198 | 206 |
buffer_.apply_tag_by_name(uri.name, start_iter, end_iter)
|
| 199 | 207 |
|
| 208 |
+ def add_action_phrase(self, text: str) -> None:
|
|
| 209 |
+ buffer_ = self.get_buffer()
|
|
| 210 |
+ buffer_.insert(buffer_.get_start_iter(), text.strip())
|
|
| 211 |
+ |
|
| 212 |
+ start_iter = buffer_.get_start_iter()
|
|
| 213 |
+ end_iter = buffer_.get_end_iter()
|
|
| 214 |
+ buffer_.apply_tag_by_name('emphasis', start_iter, end_iter)
|
|
| 215 |
+ |
|
| 200 | 216 |
def _query_tooltip(self, widget: Any, x_pos: int, y_pos: int,
|
| 201 | 217 |
_keyboard_mode: bool, tooltip: Gtk.Tooltip) -> bool:
|
| 202 | 218 |
window = widget.get_window(Gtk.TextWindowType.TEXT)
|
| ... | ... | @@ -110,12 +110,12 @@ def __init__(self, |
| 110 | 110 |
text, self._message_widget, context)
|
| 111 | 111 |
else:
|
| 112 | 112 |
self._message_widget = MessageWidget(account)
|
| 113 |
- self._message_widget.add_with_styling(text)
|
|
| 113 |
+ self._message_widget.add_with_styling(text, nickname=name)
|
|
| 114 | 114 |
if self._is_groupchat:
|
| 115 | 115 |
our_nick = get_group_chat_nick(
|
| 116 | 116 |
self._account, self._contact.jid)
|
| 117 | 117 |
if name != our_nick:
|
| 118 |
- self._check_for_highlight(self._message_widget.content)
|
|
| 118 |
+ self._check_for_highlight(text)
|
|
| 119 | 119 |
|
| 120 | 120 |
if self._is_groupchat:
|
| 121 | 121 |
our_nick = get_group_chat_nick(self._account, self._contact.jid)
|
| ... | ... | @@ -211,9 +211,9 @@ def update_text_tags(self) -> None: |
| 211 | 211 |
if isinstance(self._message_widget, MessageWidget):
|
| 212 | 212 |
self._message_widget.update_text_tags()
|
| 213 | 213 |
|
| 214 |
- def _check_for_highlight(self, content: ParsingResult) -> None:
|
|
| 214 |
+ def _check_for_highlight(self, text: str) -> None:
|
|
| 215 | 215 |
needs_highlight = message_needs_highlight(
|
| 216 |
- content.text,
|
|
| 216 |
+ text,
|
|
| 217 | 217 |
self._contact.nickname,
|
| 218 | 218 |
self._client.get_own_jid().bare)
|
| 219 | 219 |
if needs_highlight:
|
| ... | ... | @@ -360,7 +360,7 @@ def __init__(self, msg: namedtuple, account: str, jid: JID) -> None: |
| 360 | 360 |
self._ui.row_time_label.set_label(date)
|
| 361 | 361 |
|
| 362 | 362 |
message_widget = MessageWidget(account, selectable=False)
|
| 363 |
- message_widget.add_with_styling(msg.message_widget)
|
|
| 363 |
+ message_widget.add_with_styling(msg.message, nickname=contact_name)
|
|
| 364 | 364 |
self._ui.result_row_grid.attach(message_widget, 1, 1, 2, 1)
|
| 365 | 365 |
|
| 366 | 366 |
self.show_all()
|