From 3baeacb82ce02a82d501f97fed06faec7e45c879 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Thu, 22 Feb 2024 12:41:52 -0600 Subject: [PATCH] Add error dialogue for failed contact-saving --- contact.scm | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/contact.scm b/contact.scm index d43f3d6..25c3c78 100755 --- a/contact.scm +++ b/contact.scm @@ -168,11 +168,7 @@ menu-file-save "triggered()" (qt:receiver (lambda () - (call-with-output-file *vcard-pathname* - (lambda (in-port) - (vcard:write-vcard - (populate-vcard-with-window window *vcard-alist*) - in-port))))))) + (save-vcard-file window))))) ;; If they want a new contact, create a new, blank, window. ;; That is, a new process. (if menu-file-new @@ -246,6 +242,26 @@ title: "File error" type: 'critical)])))) +;; Save the window contents to the currently-selected file-path in vCard format. +(define (save-vcard-file window) + (thread-start! + (lambda () + (condition-case + (begin + (set! *vcard-alist* (populate-vcard-with-window window *vcard-alist*)) + (call-with-output-file *vcard-pathname* + (lambda (in-port) + (vcard:write-vcard *vcard-alist* + in-port)))) + [exn () + (qt:message + (string-join (list "Failed to save the file:" + ((condition-property-accessor 'exn 'message) exn) + "Try saving to a another location with “File→Save as…”.") + "\n") + title: "Saving error")])))) + + ;; Simply map vCard property-names to their corresponding name in the window’s ;; fields. (define property->formname-alist