summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-02-25 18:30:31 +0100
committerAnton Khirnov <anton@khirnov.net>2020-02-25 18:30:31 +0100
commit8422972845bed9253d7a5dad2b901fa4247708cd (patch)
treece3341e823d39f752a1ee31c55e480383b0d9894
parentc3bd46cd204466038401365ef229c747b2c4242c (diff)
thread buffer: make attachments work again
-rw-r--r--alot/buffers/thread.py16
-rw-r--r--alot/commands/thread.py14
-rw-r--r--alot/ui.py12
-rw-r--r--alot/widgets/thread.py11
4 files changed, 27 insertions, 26 deletions
diff --git a/alot/buffers/thread.py b/alot/buffers/thread.py
index 6c92fe64..8615b37d 100644
--- a/alot/buffers/thread.py
+++ b/alot/buffers/thread.py
@@ -86,6 +86,17 @@ class ThreadBuffer(Buffer):
"""Return focussed :class:`~alot.db.message.Message`."""
return self.get_selected_message_widget().get_message()
+ def get_selected_attachment(self):
+ """
+ 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
+ return None
+
def message_widgets(self):
"""
Iterate over all the message widgets in this buffer
@@ -93,11 +104,6 @@ class ThreadBuffer(Buffer):
for w in self._msg_widgets:
yield w
- # needed for ui.get_deep_focus..
- def get_focus(self):
- "Get the focus from the underlying body widget."
- return self.body.focus
-
def set_focus(self, pos):
"Set the focus in the underlying body widget."
logging.debug('setting focus to %s ', pos)
diff --git a/alot/commands/thread.py b/alot/commands/thread.py
index 26045ca8..87e6b4a3 100644
--- a/alot/commands/thread.py
+++ b/alot/commands/thread.py
@@ -832,9 +832,9 @@ class SaveAttachmentCommand(Command):
else:
raise CommandCanceled()
else: # save focussed attachment
- focus = ui.get_deep_focus()
- if hasattr(focus, 'attachment'):
- filename = focus.attachment.get_filename()
+ attachment = ui.current_buffer.get_selected_attachment()
+ if attachment is not None:
+ filename = attachment.get_filename()
if not self.path:
msg = 'save attachment (%s) to ' % filename
initialtext = os.path.join(savedir, filename)
@@ -843,7 +843,7 @@ class SaveAttachmentCommand(Command):
text=initialtext)
if self.path:
try:
- dest = focus.attachment.save(self.path)
+ dest = attachment.save(self.path)
ui.notify('saved attachment as: %s' % dest)
except (IOError, OSError) as e:
ui.notify(str(e), priority='error')
@@ -971,10 +971,10 @@ class ThreadSelectCommand(Command):
- if it is a message summary, toggle visibility of the message;
- if it is an attachment line, open the attachment"""
async def apply(self, ui):
- focus = ui.get_deep_focus()
- if hasattr(focus, 'attachment'):
+ attachment = ui.current_buffer.get_selected_attachment()
+ if attachment is not None:
logging.info('open attachment')
- await ui.apply_command(OpenAttachmentCommand(focus.attachment))
+ await ui.apply_command(OpenAttachmentCommand(attachment))
else:
await ui.apply_command(ChangeDisplaymodeCommand(visible='toggle'))
diff --git a/alot/ui.py b/alot/ui.py
index c62fee27..39999ad8 100644
--- a/alot/ui.py
+++ b/alot/ui.py
@@ -469,18 +469,6 @@ class UI:
if posthook is not None:
posthook(ui=self, dbm=self.dbman, buf=buf, success=success)
- def get_deep_focus(self, startfrom=None):
- """return the bottom most focussed widget of the widget tree"""
- if not startfrom:
- startfrom = self.current_buffer
- if 'get_focus' in dir(startfrom):
- focus = startfrom.get_focus()
- if isinstance(focus, tuple):
- focus = focus[0]
- if isinstance(focus, urwid.Widget):
- return self.get_deep_focus(startfrom=focus)
- return startfrom
-
def get_buffers_of_type(self, t):
"""
returns currently open buffers for a given subclass of
diff --git a/alot/widgets/thread.py b/alot/widgets/thread.py
index 1954d84d..7c423383 100644
--- a/alot/widgets/thread.py
+++ b/alot/widgets/thread.py
@@ -163,8 +163,6 @@ class MessageWidget(urwid.WidgetWrap):
"""
self._message = message
- self.display_attachments = True
-
self._headers_wgt = self._get_headers()
self._summary_wgt = MessageSummaryWidget(message, odd)
self._source_wgt = self._get_source()
@@ -329,6 +327,15 @@ class MessageWidget(urwid.WidgetWrap):
"""
self.display_content = not self._message.matches(querystring)
+ def get_selected_attachment(self):
+ """
+ If an AttachmentWidget is currently focused, return it. Otherwise return
+ None.
+ """
+ if self._w.focus is self._attach_wgt:
+ return self._attach_wgt.focus.attachment
+ return None
+
class ThreadNode(urwid.WidgetWrap):
_ARROW = '➤'
_HBAR = '─'