diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2017-01-18 19:11:19 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-18 19:11:19 +0000 |
commit | d532672fcd6f226ef56b0646d6e62bcfb7c937b7 (patch) | |
tree | 473386c7d4dae5e6867240be275e28ce95d8cf22 | |
parent | 70cae61d4fa80e2090169f8cb83e69081a04f890 (diff) | |
parent | fa51908b77f3209704f5834d59c352a755d137db (diff) |
Merge pull request #980 from dcbaker/pr/fix-968-and-979
Pr/fix 968 and 979
-rw-r--r-- | alot/commands/globals.py | 58 | ||||
-rw-r--r-- | docs/source/usage/modes/global.rst | 7 |
2 files changed, 50 insertions, 15 deletions
diff --git a/alot/commands/globals.py b/alot/commands/globals.py index 396bc06b..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,9 +424,32 @@ class BufferCloseCommand(Command): @inlineCallbacks def apply(self, ui): + 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 len(ui.buffers) == 1: + one_buffer() + return + if (isinstance(self.buffer, buffers.EnvelopeBuffer) and not self.buffer.envelope.sent_time): if (not self.force and (yield ui.choice('close without sending?', @@ -425,13 +458,10 @@ class BufferCloseCommand(Command): 'no'): raise CommandCanceled() + # Because we yield above it is possible that the settings or the number + # 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: - logging.info('not closing last remaining buffer as ' - 'global.quit_on_last_bclose is set to False') + one_buffer(prompt=False) else: ui.buffer_close(self.buffer, self.redraw) diff --git a/docs/source/usage/modes/global.rst b/docs/source/usage/modes/global.rst index a5526baa..f9f0b880 100644 --- a/docs/source/usage/modes/global.rst +++ b/docs/source/usage/modes/global.rst @@ -134,7 +134,12 @@ The following commands are available globally .. describe:: exit - shut down cleanly + 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. + .. _cmd.global.flush: |