| ... |
... |
@@ -18,14 +18,17 @@ |
|
18
|
18
|
from typing import Optional
|
|
19
|
19
|
from typing import Union
|
|
20
|
20
|
|
|
|
21
|
+from gi.repository import Gdk
|
|
21
|
22
|
from gi.repository import Gtk
|
|
22
|
23
|
|
|
|
24
|
+from gajim.common.i18n import _
|
|
23
|
25
|
from gajim.common.styling import ParsingResult
|
|
24
|
26
|
from gajim.common.styling import PlainBlock
|
|
25
|
27
|
from gajim.common.styling import PreBlock
|
|
26
|
28
|
from gajim.common.styling import process
|
|
27
|
29
|
from gajim.common.styling import QuoteBlock
|
|
28
|
30
|
|
|
|
31
|
+from gajim.gtk.const import MAX_MESSAGE_LENGTH
|
|
29
|
32
|
from gajim.gtk.conversation.code_widget import CodeWidget
|
|
30
|
33
|
from gajim.gtk.conversation.plain_widget import PlainWidget
|
|
31
|
34
|
from gajim.gtk.conversation.quote_widget import QuoteWidget
|
| ... |
... |
@@ -59,12 +62,20 @@ def add_with_styling(self, |
|
59
|
62
|
text: str,
|
|
60
|
63
|
nickname: Optional[str] = None) -> None:
|
|
61
|
64
|
|
|
|
65
|
+ original_text = text
|
|
|
66
|
+ if len(text) > MAX_MESSAGE_LENGTH:
|
|
|
67
|
+ text = text[:MAX_MESSAGE_LENGTH]
|
|
|
68
|
+
|
|
62
|
69
|
if text.startswith('/me') and nickname is not None:
|
|
63
|
70
|
self._add_action_phrase(text, nickname)
|
|
|
71
|
+ if len(original_text) > MAX_MESSAGE_LENGTH:
|
|
|
72
|
+ self._add_read_more_button(original_text)
|
|
64
|
73
|
return
|
|
65
|
74
|
|
|
66
|
75
|
result = process(text)
|
|
67
|
76
|
self.add_content(result)
|
|
|
77
|
+ if len(original_text) > MAX_MESSAGE_LENGTH:
|
|
|
78
|
+ self._add_read_more_button(original_text)
|
|
68
|
79
|
|
|
69
|
80
|
def _add_action_phrase(self, text: str, nickname: str):
|
|
70
|
81
|
self.clear()
|
| ... |
... |
@@ -101,5 +112,49 @@ def add_content(self, content: ContentT) -> None: |
|
101
|
112
|
|
|
102
|
113
|
self.show_all()
|
|
103
|
114
|
|
|
|
115
|
+ def _add_read_more_button(self, text: str) -> None:
|
|
|
116
|
+ link_button = Gtk.LinkButton(label=_('[read more]'))
|
|
|
117
|
+ link_button.set_halign(Gtk.Align.START)
|
|
|
118
|
+ link_button.connect('activate-link', self._on_read_more, text)
|
|
|
119
|
+ self.add(link_button)
|
|
|
120
|
+
|
|
|
121
|
+ def _on_read_more(self, _button: Gtk.LinkButton, text: str) -> bool:
|
|
|
122
|
+ FullMessageWindow(text)
|
|
|
123
|
+ return True
|
|
|
124
|
+
|
|
104
|
125
|
def clear(self) -> None:
|
|
105
|
126
|
self.foreach(self.remove)
|
|
|
127
|
+
|
|
|
128
|
+
|
|
|
129
|
+class FullMessageWindow(Gtk.ApplicationWindow):
|
|
|
130
|
+ def __init__(self, text: str) -> None:
|
|
|
131
|
+ Gtk.ApplicationWindow.__init__(self)
|
|
|
132
|
+ self.set_size_request(800, 800)
|
|
|
133
|
+ self.set_title(_('Full Message View'))
|
|
|
134
|
+ self.get_style_context().add_class('dialog-margin')
|
|
|
135
|
+
|
|
|
136
|
+ textview = Gtk.TextView()
|
|
|
137
|
+ textview.set_editable(False)
|
|
|
138
|
+ textview.set_left_margin(3)
|
|
|
139
|
+ textview.set_top_margin(3)
|
|
|
140
|
+ textview.get_buffer().set_text(text)
|
|
|
141
|
+
|
|
|
142
|
+ scrolled = Gtk.ScrolledWindow()
|
|
|
143
|
+ scrolled.set_hexpand(True)
|
|
|
144
|
+ scrolled.set_shadow_type(Gtk.ShadowType.IN)
|
|
|
145
|
+ scrolled.add(textview)
|
|
|
146
|
+
|
|
|
147
|
+ box = Gtk.Box()
|
|
|
148
|
+ box.add(scrolled)
|
|
|
149
|
+
|
|
|
150
|
+ self.add(box)
|
|
|
151
|
+ self.show_all()
|
|
|
152
|
+
|
|
|
153
|
+ self.connect('key-press-event', self._on_key_press_event)
|
|
|
154
|
+
|
|
|
155
|
+ def _on_key_press_event(self,
|
|
|
156
|
+ _widget: Gtk.Widget,
|
|
|
157
|
+ event: Gdk.EventKey
|
|
|
158
|
+ ) -> None:
|
|
|
159
|
+ if event.keyval == Gdk.KEY_Escape:
|
|
|
160
|
+ self.destroy() |