-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1256 from pazz/namedqueries
New buffer type for notmuch's named query strings
- Loading branch information
Showing
32 changed files
with
544 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Copyright (C) 2011-2018 Patrick Totzke <patricktotzke@gmail.com> | ||
# This file is released under the GNU GPL, version 3 or a later revision. | ||
# For further details see the COPYING file | ||
import urwid | ||
|
||
from .buffer import Buffer | ||
from ..settings.const import settings | ||
from ..widgets.namedqueries import QuerylineWidget | ||
|
||
|
||
class NamedQueriesBuffer(Buffer): | ||
"""lists named queries present in the notmuch database""" | ||
|
||
modename = 'namedqueries' | ||
|
||
def __init__(self, ui, filtfun): | ||
self.ui = ui | ||
self.filtfun = filtfun | ||
self.isinitialized = False | ||
self.querylist = None | ||
self.rebuild() | ||
Buffer.__init__(self, ui, self.body) | ||
|
||
def rebuild(self): | ||
self.queries = self.ui.dbman.get_named_queries() | ||
|
||
if self.isinitialized: | ||
focusposition = self.querylist.get_focus()[1] | ||
else: | ||
focusposition = 0 | ||
|
||
lines = [] | ||
for (num, key) in enumerate(self.queries): | ||
value = self.queries[key] | ||
count = self.ui.dbman.count_messages('query:"%s"' % key) | ||
count_unread = self.ui.dbman.count_messages('query:"%s" and ' | ||
'tag:unread' % key) | ||
line = QuerylineWidget(key, value, count, count_unread) | ||
|
||
if (num % 2) == 0: | ||
attr = settings.get_theming_attribute('namedqueries', | ||
'line_even') | ||
else: | ||
attr = settings.get_theming_attribute('namedqueries', | ||
'line_odd') | ||
focus_att = settings.get_theming_attribute('namedqueries', | ||
'line_focus') | ||
|
||
line = urwid.AttrMap(line, attr, focus_att) | ||
lines.append(line) | ||
|
||
self.querylist = urwid.ListBox(urwid.SimpleListWalker(lines)) | ||
self.body = self.querylist | ||
|
||
self.querylist.set_focus(focusposition % len(self.queries)) | ||
|
||
self.isinitialized = True | ||
|
||
def focus_first(self): | ||
"""Focus the first line in the query list.""" | ||
self.body.set_focus(0) | ||
|
||
def focus_last(self): | ||
allpos = self.querylist.body.positions(reverse=True) | ||
if allpos: | ||
lastpos = allpos[0] | ||
self.body.set_focus(lastpos) | ||
|
||
def get_selected_query(self): | ||
"""returns selected query""" | ||
return self.querylist.get_focus()[0].original_widget.query | ||
|
||
def get_info(self): | ||
info = {} | ||
|
||
info['query_count'] = len(self.queries) | ||
|
||
return info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright (C) 2011-2018 Patrick Totzke <patricktotzke@gmail.com> | ||
# This file is released under the GNU GPL, version 3 or a later revision. | ||
# For further details see the COPYING file | ||
import argparse | ||
|
||
from . import Command, registerCommand | ||
from .globals import SearchCommand | ||
|
||
MODE = 'namedqueries' | ||
|
||
|
||
@registerCommand(MODE, 'select', arguments=[ | ||
(['filt'], {'nargs': argparse.REMAINDER, | ||
'help': 'additional filter to apply to query'}), | ||
]) | ||
class NamedqueriesSelectCommand(Command): | ||
|
||
"""search for messages with selected query""" | ||
def __init__(self, filt=None, **kwargs): | ||
self._filt = filt | ||
Command.__init__(self, **kwargs) | ||
|
||
def apply(self, ui): | ||
query_name = ui.current_buffer.get_selected_query() | ||
query = ['query:"%s"' % query_name] | ||
if self._filt: | ||
query.extend(['and'] + self._filt) | ||
|
||
cmd = SearchCommand(query=query) | ||
ui.apply_command(cmd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.