From 279b8316341841dd32bdda5a21bb61fed8b9d1ef Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 8 Feb 2020 20:54:38 +0100 Subject: thread: implement tree decorations They were temporarily removed in the previous commit. Still not working: - theming for the decorations - drawing the connector line properly for expanded messages - configurable indentation --- alot/buffers/thread.py | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'alot/buffers') diff --git a/alot/buffers/thread.py b/alot/buffers/thread.py index bc467ded..6c92fe64 100644 --- a/alot/buffers/thread.py +++ b/alot/buffers/thread.py @@ -8,7 +8,7 @@ import logging from .buffer import Buffer from ..settings.const import settings -from ..widgets.thread import MessageWidget +from ..widgets.thread import MessageWidget, ThreadNode from .. import commands from ..db.errors import NonexistantObjectError @@ -18,6 +18,8 @@ class ThreadBuffer(Buffer): modename = 'thread' + _msg_widgets = None + def __init__(self, ui, thread): """ :param ui: main UI @@ -59,11 +61,17 @@ class ThreadBuffer(Buffer): self.body = urwid.SolidFill() return - self._msg_walker = urwid.SimpleFocusListWalker( - [MessageWidget(msg, idx & 1) for (idx, msg) in - enumerate(self.thread.message_list)]) + self._msg_widgets = [] + + body_walker = urwid.SimpleFocusListWalker([]) + for pos, msg in enumerate(self.thread.message_list): + msg_wgt = MessageWidget(msg, pos & 1) + wgt = ThreadNode(msg_wgt, self.thread, pos, self._indent_width) + + self._msg_widgets.append(msg_wgt) + body_walker.append(wgt) - self.body = urwid.ListBox(self._msg_walker) + self.body = urwid.ListBox(body_walker) def get_selected_message_position(self): """Return position of focussed message in the thread tree.""" @@ -71,7 +79,8 @@ class ThreadBuffer(Buffer): def get_selected_message_widget(self): """Return currently focused :class:`MessageWidget`.""" - return self.body.focus + pos = self.get_selected_message_position() + return self._msg_widgets[pos] def get_selected_message(self): """Return focussed :class:`~alot.db.message.Message`.""" @@ -81,7 +90,7 @@ class ThreadBuffer(Buffer): """ Iterate over all the message widgets in this buffer """ - for w in self._msg_walker: + for w in self._msg_widgets: yield w # needed for ui.get_deep_focus.. @@ -99,7 +108,7 @@ class ThreadBuffer(Buffer): self.set_focus(0) def focus_last(self): - self.set_focus(max(self.thread.total_messages - 1), 0) + self.set_focus(max(self.thread.total_messages - 1, 0)) def focus_selected_message(self): """focus the summary line of currently focused message""" @@ -107,14 +116,9 @@ class ThreadBuffer(Buffer): def focus_parent(self): """move focus to parent of currently focused message""" - pos = self.get_selected_message_position() - cur_depth = self.get_selected_message().depth - - for idx in reversed(range(0, pos)): - msg = self.thread.message_list[idx] - if msg.depth < cur_depth: - self.set_focus(idx) - break + msg = self.get_selected_message() + if msg.parent: + self.set_focus(self.thread.message_list.index(msg.parent)) def focus_first_reply(self): """move focus to first reply to currently focused message""" @@ -171,7 +175,7 @@ class ThreadBuffer(Buffer): walk = reversed(range(0, cur_pos)) for pos in walk: - if prop(self._msg_walker[pos]): + if prop(self._msg_widgets[pos]): self.set_focus(pos) break -- cgit v1.2.3