1
0
Fork 0

- asking for confirmation when quitting the program using 'q'.

This commit is contained in:
cage 2022-02-25 11:28:24 +01:00
parent 1acad1fad9
commit 74f363af3a
3 changed files with 19 additions and 7 deletions

View File

@ -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)

View File

@ -2620,6 +2620,7 @@
:open-manual
:quit-program
:clean-close-program
:confirm-and-clean-close-program
:notify
:notify-procedure
:with-blocking-notify-procedure

View File

@ -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)