summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-01-17 15:09:40 -0800
committerDylan Baker <dylan@pnwbakers.com>2017-01-17 15:29:05 -0800
commitfa51908b77f3209704f5834d59c352a755d137db (patch)
treed36fd437c00a8428899807ff07277871ce33ced4 /alot
parent044c2c3362193e140cb7f7c40bfc6feb51a3243b (diff)
commands/global: Don't double prompt to close last buffer
Currently if global.quit_on_last_bclose is set to True (not the default), and the last buffer is an envelope, then when 'd' or ':bclose' is called, the user will be prompted twice to 'close without sending?'. This patch fixes that by skipping the prompt in BufferCloseCommand, if there is 1 buffer, and global.quit_on_last_bclose is True. It does this by adding a private keyword to the ExitCommand() constructor, telling that classes apply method to not prompt. Fixes #979
Diffstat (limited to 'alot')
-rw-r--r--alot/commands/globals.py66
1 files changed, 40 insertions, 26 deletions
diff --git a/alot/commands/globals.py b/alot/commands/globals.py
index 9c060bfb..91808ade 100644
--- a/alot/commands/globals.py
+++ b/alot/commands/globals.py
@@ -38,8 +38,17 @@ MODE = 'global'
@registerCommand(MODE, 'exit')
class ExitCommand(Command):
+ """Shut down cleanly.
+
+ The _prompt variable is for internal use only, it's used to control
+ prompting to close without sending, and is used by the BufferCloseCommand
+ if settings change after yielding to the UI.
+ """
+
+ def __init__(self, _prompt=True, **kwargs):
+ super(ExitCommand, self).__init__(**kwargs)
+ self.prompt_to_send = _prompt
- """shut down cleanly"""
@inlineCallbacks
def apply(self, ui):
if settings.get('bug_on_exit'):
@@ -49,13 +58,14 @@ class ExitCommand(Command):
return
# check if there are any unsent messages
- for buffer in ui.buffers:
- if (isinstance(buffer, buffers.EnvelopeBuffer) and
- not buffer.envelope.sent_time):
- if (yield ui.choice('quit without sending message?',
- select='yes', cancel='no',
- msg_position='left')) == 'no':
- raise CommandCanceled()
+ if self.prompt_to_send:
+ for buffer in ui.buffers:
+ if (isinstance(buffer, buffers.EnvelopeBuffer) and
+ not buffer.envelope.sent_time):
+ if (yield ui.choice('quit without sending message?',
+ select='yes', cancel='no',
+ msg_position='left')) == 'no':
+ raise CommandCanceled()
for b in ui.buffers:
b.cleanup()
@@ -414,22 +424,30 @@ class BufferCloseCommand(Command):
@inlineCallbacks
def apply(self, ui):
- def last_buffer_no_close():
- """Helper that prints a message to the log and notifies if this is
- the last buffer and the settings don't allow closebuffer to
- exit."""
- msg = ('not closing last remaining buffer as '
- 'global.quit_on_last_bclose is set to False')
- logging.info(msg)
- ui.notify(msg, priority='error')
+ def one_buffer(prompt=True):
+ """Helper to handle the case on only one buffer being opened.
+
+ prompt is a boolean that is passed to ExitCommand() as the _prompt
+ keyword argument.
+ """
+ # If there is only one buffer and the settings don't allow using
+ # closebuffer to exit, then just stop.
+ if not settings.get('quit_on_last_bclose'):
+ msg = ('not closing last remaining buffer as '
+ 'global.quit_on_last_bclose is set to False')
+ logging.info(msg)
+ ui.notify(msg, priority='error')
+ # Otherwise pass directly to exit command, which also prommpts for
+ # 'close without sending'
+ else:
+ logging.info('closing the last buffer, exiting')
+ ui.apply_command(ExitCommand(_prompt=prompt))
if self.buffer is None:
self.buffer = ui.current_buffer
- # If there is only one buffer and the settings don't allow using
- # closebuffer to exit, then just stop.
- if len(ui.buffers) == 1 and not settings.get('quit_on_last_bclose'):
- last_buffer_no_close()
+ if len(ui.buffers) == 1:
+ one_buffer()
return
if (isinstance(self.buffer, buffers.EnvelopeBuffer) and
@@ -441,13 +459,9 @@ class BufferCloseCommand(Command):
raise CommandCanceled()
# Because we yield above it is possible that the settings or the number
- # of buffer chould change, so retest
+ # of buffers chould change, so retest.
if len(ui.buffers) == 1:
- if settings.get('quit_on_last_bclose'):
- logging.info('closing the last buffer, exiting')
- ui.apply_command(ExitCommand())
- else:
- last_buffer_no_close()
+ one_buffer(prompt=False)
else:
ui.buffer_close(self.buffer, self.redraw)