summaryrefslogtreecommitdiff
path: root/alot/buffers
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-04-25 16:39:31 +0200
committerAnton Khirnov <anton@khirnov.net>2020-04-25 16:39:31 +0200
commitd549a4dc743f3e8044473bd7856108a1827b3884 (patch)
treee35da162ab1d31ec7db3ef2ec82ab5661d7ae794 /alot/buffers
parentcb069bdeab97bbe4be47e2a0041e5a4a404796fd (diff)
buffers/thread: only return selected attachments when the message is in focus
Diffstat (limited to 'alot/buffers')
-rw-r--r--alot/buffers/thread.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/alot/buffers/thread.py b/alot/buffers/thread.py
index eafd84b4..8d1aa374 100644
--- a/alot/buffers/thread.py
+++ b/alot/buffers/thread.py
@@ -2,9 +2,11 @@
# Copyright © 2018 Dylan Baker
# This file is released under the GNU GPL, version 3 or a later revision.
# For further details see the COPYING file
+
import asyncio
-import urwid
+import enum
import logging
+import urwid
from .buffer import Buffer
from ..settings.const import settings
@@ -12,6 +14,9 @@ from ..widgets.thread import MessageWidget, ThreadNode
from .. import commands
from ..db.errors import NonexistantObjectError
+class _ThreadBufFocus(enum.Enum):
+ TREE = enum.auto()
+ MESSAGE = enum.auto()
class ThreadBuffer(Buffer):
"""displays a thread as a tree of messages."""
@@ -70,6 +75,15 @@ class ThreadBuffer(Buffer):
self.thread.total_messages,
's' * (self.thread.total_messages > 1))
+ @property
+ def _focus(self):
+ if self.body.focus_position == 0:
+ return _ThreadBufFocus.TREE
+ elif self.body.focus_position == 2:
+ return _ThreadBufFocus.MESSAGE
+ else:
+ raise ValueError('Invalid focus position: %s' % str(self.body.focus_position))
+
def _update_cur_msg(self):
pos = self._msgtree_widget.body.focus
if pos is not None and pos < len(self._msg_widgets):
@@ -137,10 +151,10 @@ class ThreadBuffer(Buffer):
If an attachment widget is currently in focus, return the associated
Attachment. Otherwise return None.
"""
- msg_wgt = self.get_selected_message_widget()
- att = msg_wgt.get_selected_attachment()
- if att is not None:
- return att
+ if self._focus == _ThreadBufFocus.MESSAGE:
+ msg_wgt = self.get_selected_message_widget()
+ return msg_wgt.get_selected_attachment()
+
return None
def message_widgets(self):
@@ -266,9 +280,7 @@ class ThreadBuffer(Buffer):
self.body.focus_position = 2
self._divider_holder.original_widget = self._divider_down
def focus_toggle(self):
- if self.body.focus_position == 0:
+ if self._focus == _ThreadBufFocus.TREE:
self.focus_msg_widget()
- elif self.body.focus_position == 2:
- self.focus_thread_widget()
else:
- raise ValueError('Invalid focus position: %s' % str(self.body.focus_position))
+ self.focus_thread_widget()