diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2013-08-09 15:10:50 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2013-08-09 15:10:50 +0100 |
commit | 66d24cf0f00a58133c159940d8f65a4f622a09eb (patch) | |
tree | 3ca94494a13241a2132800f0066f69054c9fda1a /alot | |
parent | 5628dc0fbfff945f55229c6bc5845e4e456eda8e (diff) |
smug focus_last in SearchBuffers
In case a search buffer displays more than 200 threads
and one calls `move last`, this will now result in a
new search with reversed search order displayed using a
reversed PipeWalker.
This makes it unnecessary to read all thread id's
when focussing the last element and thus speeds up the UI
considerably.
Diffstat (limited to 'alot')
-rw-r--r-- | alot/buffers.py | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/alot/buffers.py b/alot/buffers.py index c40c24e5..3c1bf4c1 100644 --- a/alot/buffers.py +++ b/alot/buffers.py @@ -207,6 +207,8 @@ class SearchBuffer(Buffer): modename = 'search' threads = [] + _REVERSE = {'oldest_first': 'newest_first', + 'newest_first': 'oldest_first'} def __init__(self, ui, initialquery='', sort_order=None): self.dbman = ui.dbman @@ -244,14 +246,20 @@ class SearchBuffer(Buffer): if self.proc.is_alive(): self.proc.terminate() - def rebuild(self): + def rebuild(self, reverse=False): self.isinitialized = True + self.reversed = reverse self.kill_filler_process() self.result_count = self.dbman.count_messages(self.querystring) + if reverse: + order = self._REVERSE[self.sort_order] + else: + order = self.sort_order + try: self.pipe, self.proc = self.dbman.get_threads(self.querystring, - self.sort_order) + order) except NotmuchError: self.ui.notify('malformed query string: %s' % self.querystring, 'error') @@ -260,7 +268,8 @@ class SearchBuffer(Buffer): return self.threadlist = PipeWalker(self.pipe, ThreadlineWidget, - dbman=self.dbman) + dbman=self.dbman, + reverse=reverse) self.listbox = urwid.ListBox(self.threadlist) self.body = self.listbox @@ -286,12 +295,22 @@ class SearchBuffer(Buffer): self.threadlist._get_next_item() def focus_first(self): - self.body.set_focus(0) + if not self.reversed: + self.body.set_focus(0) + else: + self.rebuild(reverse=False) def focus_last(self): - self.consume_pipe() - num_lines = len(self.threadlist.get_lines()) - self.body.set_focus(num_lines - 1) + if self.reversed: + self.body.set_focus(0) + elif (self.result_count < 200) or \ + (self.sort_order not in self._REVERSE.keys()): + self.consume_pipe() + num_lines = len(self.threadlist.get_lines()) + self.body.set_focus(num_lines - 1) + else: + self.rebuild(reverse=True) + class ThreadBuffer(Buffer): |