summaryrefslogtreecommitdiff
path: root/alot/buffers
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-02-08 20:54:38 +0100
committerAnton Khirnov <anton@khirnov.net>2020-02-19 16:00:44 +0100
commit279b8316341841dd32bdda5a21bb61fed8b9d1ef (patch)
treed35fd36b6a887351c4c9dd198e337b8148c34423 /alot/buffers
parentd25d788bdcf91f4066ae8e80ef7aebe85213d4d3 (diff)
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
Diffstat (limited to 'alot/buffers')
-rw-r--r--alot/buffers/thread.py38
1 files changed, 21 insertions, 17 deletions
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