Philipp Hörist pushed to branch master at gajim / gajim
Commits: e2cf6aa4 by lovetox at 2021-12-15T21:49:14+01:00 MessageWidget: Move process code into widget
- - - - -
5 changed files:
- gajim/gtk/conversation/message_widget.py - gajim/gtk/conversation/rows/message.py - gajim/gtk/conversation/rows/muc_subject.py - gajim/gtk/conversation/rows/muc_user_status.py - gajim/gtk/search_view.py
Changes:
===================================== gajim/gtk/conversation/message_widget.py ===================================== @@ -12,28 +12,45 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see http://www.gnu.org/licenses/.
+from __future__ import annotations + +from typing import Any +from typing import Union +from typing import cast + from gi.repository import Gtk
+from gajim.common.styling import process +from gajim.common.styling import ParsingResult +from gajim.common.styling import QuoteBlock + from .code_widget import CodeWidget from .quote_widget import QuoteWidget from .plain_widget import PlainWidget
+ContentT = Union[ParsingResult, QuoteBlock] + + class MessageWidget(Gtk.Box): def __init__(self, account: str, selectable: bool = True) -> None: Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL) self._account = account self._selectable = selectable
- self._content = None + self._content = cast(ContentT, None)
- def get_content(self): + def get_content(self) -> ContentT: return self._content
- def get_text(self): + def get_text(self) -> str: return self._content.text
- def add_content(self, content): + def add_with_styling(self, text: str) -> None: + result = process(text) + self.add_content(result) + + def add_content(self, content: ContentT) -> None: self.clear() self._content = content for block in content.blocks: @@ -62,7 +79,7 @@ def add_content(self, content): def clear(self) -> None: self.foreach(self.remove)
- def update_text_tags(self, *args): + def update_text_tags(self, *args: Any) -> None: for widget in self.get_children(): if not isinstance(widget, CodeWidget): widget.update_text_tags()
===================================== gajim/gtk/conversation/rows/message.py ===================================== @@ -39,7 +39,6 @@ from gajim.common.helpers import message_needs_highlight from gajim.common.helpers import reduce_chars_newlines from gajim.common.helpers import to_user_string -from gajim.common.styling import process from gajim.common.styling import ParsingResult from gajim.common.i18n import _ from gajim.common.i18n import Q_ @@ -110,14 +109,13 @@ def __init__(self, app.interface.preview_manager.create_preview( text, self._message_widget, context) else: - result = process(text) self._message_widget = MessageWidget(account) - self._message_widget.add_content(result) + self._message_widget.add_with_styling(text) if self._is_groupchat: our_nick = get_group_chat_nick( self._account, self._contact.jid) if name != our_nick: - self._check_for_highlight(result) + self._check_for_highlight(self._message_widget.content)
if self._is_groupchat: our_nick = get_group_chat_nick(self._account, self._contact.jid) @@ -353,12 +351,11 @@ def set_displayed(self): self._has_displayed = True
def set_retracted(self, text: str) -> None: - self._message_widget.add_content(process(text)) + self._message_widget.add_with_styling(text) self.get_style_context().add_class('retracted-message')
def set_correction(self, text: str) -> None: - result = process(text) - self._message_widget.add_content(result) + self._message_widget.add_with_styling(text)
self._has_receipt = False self._message_icons.set_receipt_icon_visible(False)
===================================== gajim/gtk/conversation/rows/muc_subject.py ===================================== @@ -19,7 +19,6 @@
from gajim.common.const import AvatarSize from gajim.common.i18n import _ -from gajim.common.styling import process
from .base import BaseRow from ..message_widget import MessageWidget @@ -57,9 +56,8 @@ def __init__(self, account: str, text: str, nick: str, date: str) -> None: meta.get_style_context().add_class('small-label') subject_box.add(meta)
- result = process(text) message_widget = MessageWidget(account) - message_widget.add_content(result) + message_widget.add_with_styling(text) subject_box.add(message_widget) self.grid.attach(subject_box, 1, 0, 1, 1)
===================================== gajim/gtk/conversation/rows/muc_user_status.py ===================================== @@ -21,7 +21,6 @@ from gajim.common.i18n import _ from gajim.common.const import AvatarSize from gajim.common.helpers import get_uf_show -from gajim.common.styling import process
from .widgets import SimpleLabel from .base import BaseRow @@ -60,10 +59,9 @@ def __init__(self, account: str, user_contact: GroupchatParticipant, self.grid.attach(self._label, 2, 0, 1, 1)
if user_contact.status is not None: - result = process(user_contact.status) message_widget = MessageWidget(account) message_widget.get_style_context().add_class('gajim-status-message') - message_widget.add_content(result) + message_widget.add_with_styling(user_contact.status) self.grid.attach(message_widget, 2, 1, 1, 1)
timestamp_widget = self.create_timestamp_widget(self.timestamp)
===================================== gajim/gtk/search_view.py ===================================== @@ -35,7 +35,6 @@ from gajim.common.const import KindConstant from gajim.common.const import FILE_CATEGORIES from gajim.common.i18n import _ -from gajim.common.styling import process
from .conversation.message_widget import MessageWidget from .util import get_builder @@ -361,9 +360,8 @@ 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) self._ui.result_row_grid.attach(message_widget, 1, 1, 2, 1) - result = process(msg.message) - message_widget.add_content(result)
self.show_all()
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/e2cf6aa4a8b587225b54e93f9d941cefe...