diff options
-rw-r--r-- | alot/buffer.py | 3 | ||||
-rw-r--r-- | alot/command.py | 28 | ||||
-rw-r--r-- | alot/settings.py | 1 | ||||
-rw-r--r-- | alot/ui.py | 31 | ||||
-rw-r--r-- | alot/widgets.py | 26 |
5 files changed, 63 insertions, 26 deletions
diff --git a/alot/buffer.py b/alot/buffer.py index 03e13387..7e5eca5a 100644 --- a/alot/buffer.py +++ b/alot/buffer.py @@ -228,6 +228,9 @@ class ThreadBuffer(Buffer): def get_message_widgets(self): return self.body.body.contents + def get_focus(self): + return self.body.get_focus() + class TagListBuffer(Buffer): def __init__(self, ui, alltags=[], filtfun=None): diff --git a/alot/command.py b/alot/command.py index 523d9c74..7161971f 100644 --- a/alot/command.py +++ b/alot/command.py @@ -31,6 +31,7 @@ from email.header import Header import buffer import settings +import widgets from db import DatabaseROError from db import DatabaseLockedError from completion import ContactsCompleter @@ -602,13 +603,33 @@ class FoldMessagesCommand(Command): for widget in lines: # in case the thread is yet unread, remove this tag msg = widget.get_message() - if 'unread' in msg.get_tags(): + if 'unread' in msg.get_tags() and self.visible: msg.remove_tags(['unread']) ui.apply_command(FlushCommand()) widget.rebuild() widget.fold(self.visible) +class OpenAttachmentCommand(Command): + def __init__(self, attachment, **kwargs): + Command.__init__(self, **kwargs) + self.attachment = attachment + + def apply(self, ui): + lines = [] +#save to tmpfile +#find out mimehandler +#eternalcommand + +class ThreadSelectCommand(Command): + def apply(self, ui): + focus = ui.get_deep_focus() + if isinstance(focus, widgets.MessageSummaryWidget): + ui.apply_command(FoldMessagesCommand()) + elif isinstance(focus, widgets.AttachmentWidget): + ui.apply_command(OpenAttachmentCommand(focus.get_attachment())) + + ### ENVELOPE class EnvelopeOpenCommand(Command): """open a new envelope buffer""" @@ -765,6 +786,7 @@ COMMANDS = { 'forward': (ForwardCommand, {}), 'fold': (FoldMessagesCommand, {'visible': True}), 'unfold': (FoldMessagesCommand, {'visible': False}), + 'select': (ThreadSelectCommand, {}), }, 'global': { 'bnext': (BufferFocusCommand, {'offset': 1}), @@ -811,7 +833,7 @@ def interpret_commandline(cmdline, mode): if not cmdline: return None logging.debug('mode:%s got commandline "%s"' % (mode, cmdline)) - args = cmdline.strip().split(' ', 1) + args = cmdline.split(' ', 1) cmd = args[0] if args[1:]: params = args[1] @@ -862,7 +884,7 @@ def interpret_commandline(cmdline, mode): elif not params and cmd in ['exit', 'flush', 'pyshell', 'taglist', 'close', 'compose', 'openfocussed', 'closefocussed', 'bnext', 'bprevious', 'retag', 'refresh', - 'bufferlist', 'refineprompt', 'reply', + 'bufferlist', 'refineprompt', 'reply', 'open', 'forward', 'groupreply', 'bounce', 'openthread', 'send', 'reedit', 'select', 'retagprompt']: return commandfactory(cmd, mode=mode) diff --git a/alot/settings.py b/alot/settings.py index d34d949e..048da3e0 100644 --- a/alot/settings.py +++ b/alot/settings.py @@ -231,6 +231,7 @@ DEFAULTS = { 'r': 'reply', 'R': 'unfold all', 'M': 'fold all', + 'enter': 'select', }, 'taglist-maps': { 'enter': 'select', @@ -27,6 +27,19 @@ from command import interpret_commandline from widgets import CompleteEdit from completion import CommandLineCompleter +class MainWidget(urwid.Frame): + def __init__(self, ui, *args, **kwargs): + urwid.Frame.__init__(self, urwid.SolidFill(' '), *args, **kwargs) + self.ui = ui + + def keypress(self, size, key): + cmdline = config.get_mapping(self.ui.mode, key) + if cmdline: + cmd = interpret_commandline(cmdline, self.ui.mode) + if cmd: + self.ui.apply_command(cmd) + else: + urwid.Frame.keypress(self, size, key) class UI: buffers = [] @@ -41,7 +54,7 @@ class UI: if not colourmode: colourmode = config.getint('general', 'colourmode') self.logger.info('setup gui in %d colours' % colourmode) - self.mainframe = urwid.Frame(urwid.SolidFill(' ')) + self.mainframe = MainWidget(self) for l in config.get_palette(): log.info(l) self.mainloop = urwid.MainLoop(self.mainframe, @@ -59,6 +72,9 @@ class UI: self.apply_command(cmd) self.mainloop.run() + def keypress(self, key): + self.logger.debug('unhandeled input: %s' % key) + def shutdown(self): """ close the ui. this is _not_ the main shutdown procedure: @@ -255,19 +271,6 @@ class UI: ('fixed', len(righttxt), footerright)]) return urwid.AttrMap(columns, 'footer') - def keypress(self, key): - cmdline = config.get_mapping(self.mode, key) - if cmdline: - self.logger.debug("handle %s in %s mode" % (key, self.mode)) - if cmdline.startswith('prompt'): - self.commandprompt(cmdline[7:]) - else: - cmd = interpret_commandline(cmdline, self.mode) - if cmd: - self.apply_command(cmd) - else: - self.logger.debug('unhandeled input: %s' % input) - def apply_command(self, cmd): if cmd: if cmd.prehook: diff --git a/alot/widgets.py b/alot/widgets.py index 6aa519c4..aa8fb3e9 100644 --- a/alot/widgets.py +++ b/alot/widgets.py @@ -184,6 +184,7 @@ class CompleteEdit(urwid.Edit): class MessageWidget(urwid.WidgetWrap): """flow widget that displays a single message""" + #TODO: subclass urwid.Pile def __init__(self, message, even=False, unfold_body=False, unfold_attachments=False, unfold_header=False, depth=0, bars_at=[]): @@ -224,6 +225,9 @@ class MessageWidget(urwid.WidgetWrap): self.pile = urwid.Pile(self.displayed_list) urwid.WidgetWrap.__init__(self, self.pile) + def get_focus(self): + return self.pile.get_focus() + #TODO re-read tags def rebuild(self): self.pile = urwid.Pile(self.displayed_list) @@ -231,11 +235,7 @@ class MessageWidget(urwid.WidgetWrap): def _build_sum_line(self): """creates/returns the widget that displays the summary line.""" - self.sumw = MessageSummaryWidget(self.message) - if self.even: - attr = 'messagesummary_even' - else: - attr = 'messagesummary_odd' + self.sumw = MessageSummaryWidget(self.message, even=self.even) cols = [] bc = list() # box_columns if self.depth > 1: @@ -248,8 +248,7 @@ class MessageWidget(urwid.WidgetWrap): arrowhead = u'\u2514\u25b6' cols.append(('fixed', 2, urwid.Text(arrowhead))) cols.append(self.sumw) - line = urwid.AttrMap(urwid.Columns(cols, box_columns=bc), - attr, 'messagesummary_focus') + line = urwid.Columns(cols, box_columns=bc) return line def _get_header_widget(self): @@ -371,14 +370,20 @@ class MessageWidget(urwid.WidgetWrap): class MessageSummaryWidget(urwid.WidgetWrap): """a one line summary of a message""" - def __init__(self, message): + def __init__(self, message, even=True): """ :param message: the message to summarize :type message: alot.db.Message """ self.message = message + self.even = even + if even: + attr = 'messagesummary_even' + else: + attr = 'messagesummary_odd' sumstr = self.__str__() - urwid.WidgetWrap.__init__(self, urwid.Text(sumstr)) + txt = urwid.urwid.AttrMap(urwid.Text(sumstr), attr, 'messagesummary_focus') + urwid.WidgetWrap.__init__(self, txt) def __str__(self): return u"%s" % (unicode(self.message)) @@ -475,6 +480,9 @@ class AttachmentWidget(urwid.WidgetWrap): 'message_attachment') urwid.WidgetWrap.__init__(self, widget) + def get_attachment(self): + return self.attachment + def selectable(self): return True |