summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--alot/buffers.py74
-rw-r--r--alot/commands/thread.py53
m---------alot/foreign/urwidtrees0
3 files changed, 81 insertions, 46 deletions
diff --git a/alot/buffers.py b/alot/buffers.py
index 6071f624..b3b6f200 100644
--- a/alot/buffers.py
+++ b/alot/buffers.py
@@ -4,6 +4,7 @@
import urwid
import os
from notmuch import NotmuchError
+import logging
from settings import settings
import commands
@@ -17,7 +18,7 @@ from alot.widgets.globals import AttachmentWidget
from alot.widgets.bufferlist import BufferlineWidget
from alot.widgets.search import ThreadlineWidget
from alot.widgets.thread import ThreadTree
-from alot.foreign.urwidtrees import ArrowTree, TreeBox, NestedTree
+from alot.foreign.urwidtrees import ArrowTree, TreeBox, NestedTree, CollapsibleArrowTree
class Buffer(object):
@@ -322,7 +323,9 @@ class ThreadBuffer(Buffer):
return
self._tree = ThreadTree(self.thread)
- self.body = TreeBox(NestedTree(ArrowTree(self._tree)))
+ A = ArrowTree(self._tree)
+ self._nested_tree =NestedTree(A, interpret_covered=True)
+ self.body = TreeBox(self._nested_tree)
self.message_count = self.thread.get_total_messages()
def get_selection(self):
@@ -339,17 +342,48 @@ class ThreadBuffer(Buffer):
messagewidget = self.get_selection()
return messagewidget.get_message()
- def get_message_widgets(self):
+ def get_messagetree_positions(self):
"""
- returns all :class:`MessageWidgets <alot.widgets.MessageWidget>`
- displayed in this thread-tree.
"""
- # TODO, do it properly
- return self._tree._message.values()
+ return [(pos,) for pos in self._tree.positions()]
+
+ def refresh(self):
+ self.body.refresh()
+
+ def messagetrees(self):
+ for pos in self._tree.positions():
+ yield self._tree[pos]
def get_focus(self):
return self.body.get_focus()
+ def expand(self, msgpos):
+ MT = self._tree[msgpos]
+ MT.expand(MT.root)
+
+ def messagetree_at_position(self, pos):
+ return self._tree[pos[0]]
+
+ def expand_and_remove_unread(self, pos):
+ messagetree = self.messagetree_at_position(pos)
+ msg = messagetree._message
+ messagetree.expand(messagetree.root)
+ if 'unread' in msg.get_tags():
+ msg.remove_tags(['unread'])
+ self.ui.apply_command(commands.globals.FlushCommand())
+
+ def expand_all(self):
+ for MT in self.messagetrees():
+ MT.expand(MT.root)
+
+ def collapse(self, msgpos):
+ MT = self._tree[msgpos]
+ MT.collapse(MT.root)
+
+ def collapse_all(self):
+ for MT in self.messagetrees():
+ MT.collapse(MT.root)
+
def unfold_matching(self, querystring, focus_first=True):
"""
unfolds messages that match a given querystring.
@@ -360,27 +394,19 @@ class ThreadBuffer(Buffer):
:type focus_first: bool
"""
return
- # TODO
- i = 0
- for mw in self.get_message_widgets():
- msg = mw.get_message()
+ first = None
+ for MT in self.messagetrees():
+ msg = MT._message
if msg.matches(querystring):
- if focus_first:
- # let urwid.ListBox focus this widget:
- # The first parameter is a "size" tuple: that needs only to
- # be iterable an is *never* used. i is the integer index
- # to focus. offset_inset is may be used to shift the
- # visible area so that the focus lies at given offset
- self.body.change_focus((0, 0), i,
- offset_inset=0,
- coming_from='above')
- focus_first = False
- mw.folded = False
+ MT.expand(MT.root)
+ if first is None:
+ logging.debug('BODY %s' % self.body)
+ self.body.set_focus((pos, MT.root))
if 'unread' in msg.get_tags():
msg.remove_tags(['unread'])
self.ui.apply_command(commands.globals.FlushCommand())
- mw.rebuild()
- i = i + 1
+ else:
+ MT.collapse(MT.root)
class TagListBuffer(Buffer):
diff --git a/alot/commands/thread.py b/alot/commands/thread.py
index c31a63c7..847659fb 100644
--- a/alot/commands/thread.py
+++ b/alot/commands/thread.py
@@ -419,36 +419,45 @@ class ChangeDisplaymodeCommand(Command):
Command.__init__(self, **kwargs)
def apply(self, ui):
+ messagetrees = []
lines = []
+ tbuffer = ui.current_buffer
if not self.all:
lines.append(ui.current_buffer.get_selection())
+ focuspos = tbuffer.get_focus()[1]
+ messagetrees = [tbuffer.messagetree_at_position(focuspos)]
else:
- lines = ui.current_buffer.get_message_widgets()
+ messagetrees = tbuffer.messagetrees()
- for widget in lines:
- msg = widget.get_message()
-
- # in case the thread is yet unread, remove this tag
- if self.visible or (self.visible == 'toggle' and widget.folded):
+ for mt in messagetrees:
+ # update collapsed-status
+ if self.visible == 'toggle':
+ self.visible = mt.is_collapsed(mt.root)
+ if self.visible is False:
+ mt.collapse(mt.root)
+ elif self.visible is True:
+ mt.expand(mt.root)
+ # in case the thread is yet unread, remove this tag
+ msg = mt._message
if 'unread' in msg.get_tags():
msg.remove_tags(['unread'])
ui.apply_command(FlushCommand())
-
- if self.visible == 'toggle':
- self.visible = widget.folded
- if self.raw == 'toggle':
- self.raw = not widget.show_raw
- if self.all_headers == 'toggle':
- self.all_headers = not widget.show_all_headers
-
- logging.debug((self.visible, self.raw, self.all_headers))
- if self.visible is not None:
- widget.folded = not self.visible
- if self.raw is not None:
- widget.show_raw = self.raw
- if self.all_headers is not None:
- widget.show_all_headers = self.all_headers
- widget.rebuild()
+ # if visible == None, we don't touch the messagetree
+
+ tbuffer.refresh()
+ #if self.raw == 'toggle':
+ # self.raw = not widget.show_raw
+ #if self.all_headers == 'toggle':
+ # self.all_headers = not widget.show_all_headers
+
+ #logging.debug((self.visible, self.raw, self.all_headers))
+ #if self.visible is not None:
+ # widget.folded = not self.visible
+ #if self.raw is not None:
+ # widget.show_raw = self.raw
+ #if self.all_headers is not None:
+ # widget.show_all_headers = self.all_headers
+ #widget.rebuild()
@registerCommand(MODE, 'pipeto', arguments=[
diff --git a/alot/foreign/urwidtrees b/alot/foreign/urwidtrees
-Subproject 167d34e096df86602f50331584141720555ab59
+Subproject ab8d90113f0c70455c90ea45db4bcc0ac02678a