summaryrefslogtreecommitdiff
path: root/alot/ui.py
diff options
context:
space:
mode:
authorYann Rouillard <yann@pleiades.fr.eu.org>2013-06-28 20:51:48 +0200
committerPatrick Totzke <patricktotzke@gmail.com>2013-10-30 20:54:13 +0000
commitb1ccf65f4cf1ee14322b775fcbeacfd2035fe26a (patch)
tree75f68d6891294c0b9feacfe5b2a97506494ab4bf /alot/ui.py
parent10ad2f1feead866348b5bc0166d019950f334433 (diff)
canceling a command in a sequence will now stop the subsequent commands from being run
Conflicts: alot/commands/globals.py alot/ui.py
Diffstat (limited to 'alot/ui.py')
-rw-r--r--alot/ui.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/alot/ui.py b/alot/ui.py
index 971345ac..682c37e6 100644
--- a/alot/ui.py
+++ b/alot/ui.py
@@ -7,6 +7,8 @@ from twisted.internet import reactor, defer
from settings import settings
from buffers import BufferlistBuffer
+from commands import commandfactory
+from commands import CommandCanceled
from alot.commands import CommandParseError
from alot.commands.globals import CommandSequenceCommand
from alot.helper import string_decode
@@ -563,7 +565,7 @@ class UI(object):
footer_att = settings.get_theming_attribute('global', 'footer')
return urwid.AttrMap(columns, footer_att)
- def apply_command(self, cmd):
+ def apply_command(self, cmd, handle_error=True):
"""
applies a command
@@ -572,6 +574,11 @@ class UI(object):
:param cmd: an applicable command
:type cmd: :class:`~alot.commands.Command`
+ :param handle_error: if True, the caller wants to rely on the default
+ error handling mechanism to process the eventual
+ errors raised while the command is applied.
+ This is the default.
+ :type handle_error: bool
"""
if cmd:
# define (callback) function that invokes post-hook
@@ -581,15 +588,18 @@ class UI(object):
return defer.maybeDeferred(cmd.posthook, ui=self,
dbm=self.dbman)
- # define error handler for Failures/Exceptions
+ # define a generic error handler for Failures/Exceptions
# raised in cmd.apply()
def errorHandler(failure):
- logging.error(failure.getTraceback())
- errmsg = failure.getErrorMessage()
- if errmsg:
- msg = "%s\n(check the log for details)"
- self.notify(
- msg % failure.getErrorMessage(), priority='error')
+ if failure.check(CommandCanceled):
+ self.notify('canceled')
+ else:
+ logging.error(failure.getTraceback())
+ errmsg = failure.getErrorMessage()
+ if errmsg:
+ msg = "%s\n(check the log for details)"
+ self.notify(
+ msg % failure.getErrorMessage(), priority='error')
# call cmd.apply
def call_apply(ignored):
@@ -599,5 +609,6 @@ class UI(object):
d = defer.maybeDeferred(prehook, ui=self, dbm=self.dbman)
d.addCallback(call_apply)
d.addCallback(call_posthook)
- d.addErrback(errorHandler)
+ if handle_error:
+ d.addErrback(errorHandler)
return d