From 74f363af3a12e834214a4f35bc0744f16cf471fa Mon Sep 17 00:00:00 2001 From: cage Date: Fri, 25 Feb 2022 11:28:24 +0100 Subject: [PATCH] - asking for confirmation when quitting the program using 'q'. --- etc/init.lisp | 7 ++++--- src/package.lisp | 1 + src/ui-goodies.lisp | 18 ++++++++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/etc/init.lisp b/etc/init.lisp index d1cee74..af3095e 100644 --- a/etc/init.lisp +++ b/etc/init.lisp @@ -137,10 +137,11 @@ ;; global keymap -(define-key "q" #'quit) ; here we are calling the custom - ; function defined above ... +(define-key "q" #'confirm-and-clean-close-program) -(define-key "C-q" #'quit) ; ...also here + +(define-key "C-q" #'quit) ; here we are calling the custom + ; function defined above (define-key "C-a" #'show-about-window) diff --git a/src/package.lisp b/src/package.lisp index f5d2c49..0c7c3f5 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -2620,6 +2620,7 @@ :open-manual :quit-program :clean-close-program + :confirm-and-clean-close-program :notify :notify-procedure :with-blocking-notify-procedure diff --git a/src/ui-goodies.lisp b/src/ui-goodies.lisp index 851e921..2d515cb 100644 --- a/src/ui-goodies.lisp +++ b/src/ui-goodies.lisp @@ -47,10 +47,11 @@ (defmacro with-valid-yes-at-prompt ((input-text y-pressed-p) &body body) (with-gensyms (not-null-input-p) - `(multiple-value-bind (,y-pressed-p ,not-null-input-p) - (boolean-input-accepted-p ,input-text) - (when ,not-null-input-p - ,@body)))) + `(multiple-value-bind (,y-pressed-p ,not-null-input-p) + (boolean-input-accepted-p ,input-text) + (declare (ignorable ,y-pressed-p)) + (when ,not-null-input-p + ,@body)))) (defun clean-temporary-files () "Use this to close the program" @@ -82,6 +83,15 @@ temporary-files-count))) (push-event (make-instance 'quit-program-event)))))) +(defun confirm-and-clean-close-program () + (flet ((on-input-complete (maybe-accepted) + (with-valid-yes-at-prompt (maybe-accepted y-pressed-p) + (when y-pressed-p + (db-utils:with-ready-database (:connect nil) + (clean-close-program)))))) + (ask-string-input #'on-input-complete + :prompt (format nil (_ "Quit ~a? [y/N] ") +program-name+)))) + (defun clean-close-program () "Use this to close the program" (flet ((on-input-complete (maybe-accepted)