Commit 8547d2b4 authored by Philipp Hörist's avatar Philipp Hörist

Simplify scrolling in conversation textview

parent 1e06db9f
......@@ -323,7 +323,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
id_ = widget.connect('changed',
self.on_conversation_vadjustment_changed)
self.handlers[id_] = widget
self.scroll_to_end_id = None
self.was_at_the_end = True
self.correcting = False
self.last_sent_msg = None
......@@ -984,27 +983,8 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
# There were events to remove
self.redraw_after_event_removed(jid)
def bring_scroll_to_end(self, textview, diff_y=0):
"""
Scroll to the end of textview if end is not visible
"""
if self.scroll_to_end_id:
# a scroll is already planned
return
buffer_ = textview.get_buffer()
end_iter = buffer_.get_end_iter()
end_rect = textview.get_iter_location(end_iter)
visible_rect = textview.get_visible_rect()
# scroll only if expected end is not visible
if end_rect.y >= (visible_rect.y + visible_rect.height + diff_y):
self.scroll_to_end_id = GLib.idle_add(self.scroll_to_end_iter,
textview)
def scroll_to_end_iter(self, textview):
buffer_ = textview.get_buffer()
end_iter = buffer_.get_end_iter()
textview.scroll_to_iter(end_iter, 0, False, 1, 1)
self.scroll_to_end_id = None
def scroll_to_end_iter(self):
self.conv_textview.scroll_to_end_iter()
return False
def on_configure_event(self, msg_textview, event):
......@@ -1065,9 +1045,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
# used to stay at the end of the textview when we shrink conversation
# textview.
if self.was_at_the_end:
if self.conv_textview.at_the_end():
# we are at the end
self.conv_textview.bring_scroll_to_end(-18)
self.scroll_to_end_iter()
self.was_at_the_end = (adjustment.get_upper() - adjustment.get_value()\
- adjustment.get_page_size()) < 18
......
......@@ -394,34 +394,7 @@ class ConversationTextview(GObject.GObject):
self.tv.tagSthAtSth.set_property('foreground', color)
def at_the_end(self):
buffer_ = self.tv.get_buffer()
end_iter = buffer_.get_end_iter()
end_rect = self.tv.get_iter_location(end_iter)
visible_rect = self.tv.get_visible_rect()
if end_rect.y <= (visible_rect.y + visible_rect.height):
return True
return False
def scroll_to_end(self):
parent = self.tv.get_parent()
buffer_ = self.tv.get_buffer()
end_mark = buffer_.get_mark('end')
if not end_mark:
return False
self.tv.scroll_to_mark(end_mark, 0, True, 0, 1)
adjustment = parent.get_hadjustment()
adjustment.set_value(0)
return False # when called in an idle_add, just do it once
def bring_scroll_to_end(self, diff_y=0):
''' scrolls to the end of textview if end is not visible '''
buffer_ = self.tv.get_buffer()
end_iter = buffer_.get_end_iter()
end_rect = self.tv.get_iter_location(end_iter)
visible_rect = self.tv.get_visible_rect()
# scroll only if expected end is not visible
if end_rect.y >= (visible_rect.y + visible_rect.height + diff_y):
GLib.idle_add(self.scroll_to_end_iter)
return gtkgui_helpers.at_the_end(self.tv.get_parent())
def scroll_to_end_iter(self):
buffer_ = self.tv.get_buffer()
......@@ -586,7 +559,7 @@ class ConversationTextview(GObject.GObject):
if scroll:
# scroll to the end (via idle in case the scrollbar has
# appeared)
GLib.idle_add(self.scroll_to_end)
GLib.idle_add(self.scroll_to_end_iter)
def on_textview_draw(self, widget, ctx):
return
......@@ -1220,8 +1193,6 @@ class ConversationTextview(GObject.GObject):
# even if we insert directly at the mark iter
temp_mark = buffer_.create_mark('temp', iter_, left_gravity=True)
at_the_end = self.at_the_end()
if text.startswith('/me '):
direction_mark = i18n.paragraph_direction_mark(str(text[3:]))
else:
......@@ -1306,10 +1277,9 @@ class ConversationTextview(GObject.GObject):
self.last_sent_message_id = (msg_stanza_id, new_mark)
if not insert_mark:
if at_the_end or kind == 'outgoing':
if self.at_the_end() or kind == 'outgoing':
# we are at the end or we are sending something
# scroll to the end (via idle in case the scrollbar has appeared)
GLib.idle_add(self.scroll_to_end)
GLib.idle_add(self.scroll_to_end_iter)
self.just_cleared = False
buffer_.end_user_action()
......
......@@ -1831,7 +1831,7 @@ class Interface:
# Using isinstance here because we want to catch all derived types
if isinstance(ctrl, ChatControlBase):
tv = ctrl.conv_textview
tv.scroll_to_end()
tv.scroll_to_end_iter()
################################################################################
### Methods dealing with emoticons
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment