diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2017-01-17 14:40:46 -0800 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2017-01-17 14:46:26 -0800 |
commit | 044c2c3362193e140cb7f7c40bfc6feb51a3243b (patch) | |
tree | 053abb85eeca0d821f4bae908e796e9fccfc0991 /alot/commands/globals.py | |
parent | 2db55f22afe1fec8d53711a8d31f3ebaea577e1a (diff) |
Print error when trying to close last buffer without enabling setting
If the last buffer if closed (using 'd' or ':bclose'), by default either
nothing will happen, or the user will be prompted whether he/she wants
to close without saving, and then nothing happens. This can be changed
by setting global.quit_on_last_bclose to True (it defaults to False).
This patch changes that behavior to preempt the prompt and adds a UI
notification that the relevant option is unset, and returns. It will
check the same conditions again after the yield statement since the
number of buffers or the options might have changed (it seems rather
unlikely that the options will change, but it's a tiny amount of code
with minimal performance impact and it's better to be safe).
Fixes #968
Diffstat (limited to 'alot/commands/globals.py')
-rw-r--r-- | alot/commands/globals.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/alot/commands/globals.py b/alot/commands/globals.py index 396bc06b..9c060bfb 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -414,9 +414,24 @@ 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') + 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() + 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 +440,14 @@ class BufferCloseCommand(Command): 'no'): raise CommandCanceled() + # Because we yield above it is possible that the settings or the number + # of buffer 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') + last_buffer_no_close() else: ui.buffer_close(self.buffer, self.redraw) |