diff options
author | pazz <patricktotzke@gmail.com> | 2011-05-28 19:14:30 +0100 |
---|---|---|
committer | pazz <patricktotzke@gmail.com> | 2011-05-28 19:14:30 +0100 |
commit | 2067a7508241b3eb8271b58e9eda808df3038cc2 (patch) | |
tree | 9b0e55cd3bfc0fed1c19cac49b0b03a70cd9fda0 | |
parent | c14a0a0ddfcb167cd086e64b02b5b4ca0a09f165 (diff) |
added manual labeling of threads from search (l)
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | alot/buffer.py | 1 | ||||
-rw-r--r-- | alot/command.py | 38 | ||||
-rw-r--r-- | alot/db.py | 46 | ||||
-rw-r--r-- | alot/ui.py | 9 | ||||
-rw-r--r-- | alot/widgets.py | 32 |
6 files changed, 82 insertions, 45 deletions
@@ -33,6 +33,7 @@ Here the buffer-specific bindings: Searchbuffer: enter, opens single thread view for select thread, a, toggles "inbox" tag +l, manually change labels Single thread: h, toggles show header (all fields from settings displayed_headers) diff --git a/alot/buffer.py b/alot/buffer.py index 718c285e..c6094475 100644 --- a/alot/buffer.py +++ b/alot/buffer.py @@ -108,6 +108,7 @@ class SearchBuffer(Buffer): Buffer.__init__(self, ui, self.body, 'search') self.bindings = { 'enter': ('open_thread', {'thread': self.get_selected_thread}), + 'l': ('thread_tag_prompt', {'thread': self.get_selected_thread}), 'a': ('toggle_thread_tag', {'thread': self.get_selected_thread, 'tag': 'inbox'}), } diff --git a/alot/command.py b/alot/command.py index d5e09803..8ec38d02 100644 --- a/alot/command.py +++ b/alot/command.py @@ -226,7 +226,6 @@ class ToggleThreadTagCommand(Command): # refresh selected threadline sbuffer = ui.current_buffer threadwidget = sbuffer.get_selected_threadline() - #threadwidget.reload_tag(ui.dbman) # threads seem to cache their tags threadwidget.rebuild() # rebuild and redraw the line #remove line from searchlist if thread doesn't match the query qs = "(%s) AND thread:%s" % (sbuffer.querystring, @@ -238,25 +237,44 @@ class ToggleThreadTagCommand(Command): sbuffer.result_count -= self.thread.get_total_messages() ui.update_footer() +class ThreadTagPromptCommand(Command): + """prompt the user for labels, then tag thread""" + + def __init__(self, thread, **kwargs): + assert thread + self.thread = thread + Command.__init__(self, **kwargs) + + def apply(self, ui): + initial_tagstring = ','.join(self.thread.get_tags()) + tagsstring = ui.prompt('label thread:',text=initial_tagstring) + if tagsstring != None: # esc -> None, enter could return '' + tags = filter(lambda x: x,tagsstring.split(',')) + ui.logger.info("got %s:%s" % (tagsstring,tags)) + self.thread.set_tags(tags) + + # refresh selected threadline + sbuffer = ui.current_buffer + threadwidget = sbuffer.get_selected_threadline() + threadwidget.rebuild() # rebuild and redraw the line commands = { 'buffer_close': (BufferCloseCommand, {}), - 'buffer_list': (BufferListCommand, {}), 'buffer_focus': (BufferFocusCommand, {}), + 'buffer_list': (BufferListCommand, {}), 'buffer_next': (BufferFocusCommand, {'offset': 1}), 'buffer_prev': (BufferFocusCommand, {'offset': -1}), - 'open_inbox': (SearchCommand, {'query': 'tag:inbox'}), - 'open_unread': (SearchCommand, {'query': 'tag:unread'}), - 'open_search': (SearchPromptCommand, {}), - 'open_thread': (OpenThreadCommand, {}), - 'search': (SearchCommand, {}), - 'shutdown': (ShutdownCommand, {}), - 'shell': (OpenPythonShellCommand, {}), - 'view_log': (PagerCommand, {'path': 'debug.log'}), 'call_editor': (EditCommand, {}), 'call_pager': (PagerCommand, {}), 'open_taglist': (TagListCommand, {}), + 'open_thread': (OpenThreadCommand, {}), + 'search': (SearchCommand, {}), + 'search_prompt': (SearchPromptCommand, {}), + 'shell': (OpenPythonShellCommand, {}), + 'shutdown': (ShutdownCommand, {}), + 'thread_tag_prompt': (ThreadTagPromptCommand, {}), 'toggle_thread_tag': (ToggleThreadTagCommand, {'tag': 'inbox'}), + 'view_log': (PagerCommand, {'path': 'debug.log'}), } @@ -76,33 +76,47 @@ class Thread: self.newest = datetime.fromtimestamp(thread.get_newest_date()) self.tags = set([str(tag) for tag in thread.get_tags()]) + def get_thread_id(self): + return self.tid + + def get_tags(self): + return list(self.tags) + def add_tags(self, tags): - query = self.dbman.query('thread:' + self.tid, writeable=True) - for msg in query.search_messages(): - msg.freeze() + tags = filter(lambda x: x not in self.tags, tags) + if tags: + query = self.dbman.query('thread:' + self.tid, writeable=True) + for msg in query.search_messages(): + msg.freeze() + for tag in tags: + msg.add_tag(tag) + msg.thaw() for tag in tags: - msg.add_tag(tag) self.tags.add(tag) - msg.thaw() def remove_tags(self, tags): + tags = filter(lambda x: x in self.tags, tags) + if tags: + query = self.dbman.query('thread:' + self.tid, writeable=True) + for msg in query.search_messages(): + msg.freeze() + for tag in tags: + msg.remove_tag(tag) + msg.thaw() + for tag in tags: + self.tags.remove(tag) + + def set_tags(self, tags): query = self.dbman.query('thread:' + self.tid, writeable=True) + self.tags= set() for msg in query.search_messages(): msg.freeze() + msg.remove_all_tags() for tag in tags: - msg.remove_tag(tag) - try: - self.tags.remove(tag) - except KeyError: - pass # tag not in self.tags + msg.add_tag(tag) + self.tags.add(tag) msg.thaw() - def get_thread_id(self): - return self.tid - - def get_tags(self): - return list(self.tags) - def get_authors(self): return self.authors @@ -26,12 +26,13 @@ class UI: self.logger.debug('setup bindings') self.bindings = { - 'i': ('open_inbox', {}), - 'u': ('open_unread', {}), + 'i': ('search', {'query': 'tag:inbox' }), + 'u': ('search', {'query': 'tag:unread'}), 'x': ('buffer_close', {}), 'tab': ('buffer_next', {}), 'shift tab': ('buffer_prev', {}), '\\': ('open_search', {}), + 'p': ('search',{'query': (lambda: self.prompt('search for'))}), 'q': ('shutdown', {}), ';': ('buffer_list', {}), 'L': ('open_taglist', {}), @@ -50,10 +51,10 @@ class UI: """ raise urwid.ExitMainLoop() - def prompt(self, prefix): + def prompt(self, prefix='>', text=''): self.logger.info('open prompt') - prefix_widget = PromptWidget(prefix) + prefix_widget = PromptWidget(prefix,text) footer = self.mainframe.get_footer() self.mainframe.set_footer(prefix_widget) self.mainframe.set_focus('footer') diff --git a/alot/widgets.py b/alot/widgets.py index d69426d8..850eb457 100644 --- a/alot/widgets.py +++ b/alot/widgets.py @@ -22,32 +22,34 @@ class ThreadlineWidget(AttrMap): AttrMap.__init__(self, self.columns, 'threadline', 'threadline_focus') def rebuild(self): + + cols = [] datestring = pretty_datetime(self.thread.get_newest_date()) self.date_w = AttrMap(Text(datestring), 'threadline_date') + cols.append(('fixed', len(datestring), self.date_w)) mailcountstring = "(%d)" % self.thread.get_total_messages() self.mailcount_w = AttrMap(Text(mailcountstring), 'threadline_mailcount') + cols.append(('fixed', len(mailcountstring), self.mailcount_w)) tagsstring = " ".join(self.thread.get_tags()) - self.tags_w = AttrMap(Text(tagsstring), 'threadline_tags') + if tagsstring: + self.tags_w = AttrMap(Text(tagsstring), 'threadline_tags') + cols.append(('fixed', len(tagsstring), self.tags_w)) authors = self.thread.get_authors() or '(None)' authorsstring = shorten(authors, settings.authors_maxlength) self.authors_w = AttrMap(Text(authorsstring), 'threadline_authors') + cols.append(('fixed', len(authorsstring), self.authors_w)) + + subjectstring = self.thread.get_subject() + if subjectstring: + self.subject_w = AttrMap(Text(subjectstring, wrap='clip'), + 'threadline_subject') + cols.append(self.subject_w) - subjectstring = self.thread.get_subject() or '' - self.subject_w = AttrMap(Text(subjectstring, wrap='clip'), - 'threadline_subject') - - self.columns = Columns([ - ('fixed', len(datestring), self.date_w), - ('fixed', len(mailcountstring), self.mailcount_w), - ('fixed', len(tagsstring), self.tags_w), - ('fixed', len(authorsstring), self.authors_w), - self.subject_w, - ], - dividechars=1) + self.columns = Columns(cols,dividechars=1) self.original_widget = self.columns def render(self, size, focus=False): @@ -107,9 +109,9 @@ class TagWidget(Text): class PromptWidget(AttrMap): - def __init__(self, prefix): + def __init__(self, prefix, text=''): leftpart = Text(prefix, align='left') - self.editpart = Edit() + self.editpart = Edit(edit_text=text) both = Columns( [ ('fixed', len(prefix) + 1, leftpart), |