From d25d788bdcf91f4066ae8e80ef7aebe85213d4d3 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 8 Feb 2020 13:56:56 +0100 Subject: thread: drop the use of urwidtrees Their API is misdesigned - forces the use of trees for nontree objects and mixes data relationships with display properties. The result is a mess that is hard to understand/maintain/extend. Replace the use of urwidtrees with urwid Pile and ListBox. This temporarily removes tree-style indentation and decorations for thread buffers. That will be reimplemented in following commits. --- alot/commands/thread.py | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) (limited to 'alot/commands') diff --git a/alot/commands/thread.py b/alot/commands/thread.py index f720e297..6ceaddd2 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -555,45 +555,40 @@ class ChangeDisplaymodeCommand(Command): logging.debug('matching lines %s...', self.query) if self.query is None: - messagetrees = [tbuffer.get_selected_messagetree()] + msg_wgts = [tbuffer.get_selected_message_widget()] else: - messagetrees = tbuffer.messagetrees() + msg_wgts = list(tbuffer.message_widgets()) if self.query != '*': def matches(msgt): msg = msgt.get_message() return msg.matches(self.query) - messagetrees = [m for m in messagetrees if matches(m)] + msg_wgts = [m for m in msg_wgts if matches(m)] - for mt in messagetrees: + for m in msg_wgts: # determine new display values for this message if self.visible == 'toggle': - visible = mt.is_collapsed(mt.root) + visible = not m.display_content else: visible = self.visible if self.raw == 'toggle': tbuffer.focus_selected_message() - raw = not mt.display_source if self.raw == 'toggle' else self.raw - all_headers = not mt.display_all_headers \ + raw = not m.display_source if self.raw == 'toggle' else self.raw + all_headers = not m.display_all_headers \ if self.all_headers == 'toggle' else self.all_headers # collapse/expand depending on new 'visible' value if visible is False: - mt.collapse(mt.root) + m.collapse() elif visible is True: # could be None - mt.expand(mt.root) + m.expand() tbuffer.focus_selected_message() # set new values in messagetree obj if raw is not None: - mt.display_source = raw + m.display_source = raw if all_headers is not None: - mt.display_all_headers = all_headers - mt.debug() - # let the messagetree reassemble itself - mt.reassemble() - # refresh the buffer (clears Tree caches etc) - tbuffer.refresh() + m.display_all_headers = all_headers @registerCommand(MODE, 'pipeto', arguments=[ @@ -1057,26 +1052,20 @@ class TagCommand(Command): async def apply(self, ui): tbuffer = ui.current_buffer if self.all: - messagetrees = tbuffer.messagetrees() + msg_wgts = list(tbuffer.message_widgets()) else: - messagetrees = [tbuffer.get_selected_messagetree()] - - def refresh_widgets(): - for mt in messagetrees: - mt.refresh() - tbuffer.refresh() + msg_wgts = [tbuffer.get_selected_message_widget()] tags = [t for t in self.tagsstring.split(',') if t] try: - for mt in messagetrees: + for mt in msg_wgts: m = mt.get_message() if self.action == 'add': - m.add_tags(tags, afterwards=refresh_widgets) + m.add_tags(tags) if self.action == 'set': - m.add_tags(tags, afterwards=refresh_widgets, - remove_rest=True) + m.add_tags(tags, remove_rest=True) elif self.action == 'remove': - m.remove_tags(tags, afterwards=refresh_widgets) + m.remove_tags(tags) elif self.action == 'toggle': to_remove = [] to_add = [] @@ -1086,7 +1075,7 @@ class TagCommand(Command): else: to_add.append(t) m.remove_tags(to_remove) - m.add_tags(to_add, afterwards=refresh_widgets) + m.add_tags(to_add) except DatabaseROError: ui.notify('index in read-only mode', priority='error') -- cgit v1.2.3