From bd8dea5021791b4f9347b27e91c455b306b0ee03 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Sat, 10 Feb 2024 00:45:09 -0600 Subject: [PATCH] =?UTF-8?q?Open=20File-menu=20=E2=80=9CNew=E2=80=A6?= =?UTF-8?q?=E2=80=9D=20and=20=E2=80=9COpen=E2=80=A6=E2=80=9D=20in=20new=20?= =?UTF-8?q?process?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … instead of overburdening our own with several windows and contact states. :^) --- contact.scm | 42 +++++++++++++++++++++++++++++++++++------- contact.ui | 6 ++++++ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/contact.scm b/contact.scm index 1cff122..f872235 100644 --- a/contact.scm +++ b/contact.scm @@ -18,12 +18,14 @@ (chicken condition) (chicken file) (chicken pathname) + (chicken process) (chicken io) (chicken repl) (chicken process-context) (chicken string) (chicken time) (srfi 1) + (srfi 13) (srfi 18) (prefix getopt-long getopt:) (prefix nrepl nrepl:) @@ -38,6 +40,7 @@ ;; Start & run the application. (define (init) + (print (argv)) (let [(cli-args (parse-cli-args (command-line-arguments)))] ;; If --help, then print a usage message and quit. (if (alist-ref 'help cli-args) @@ -59,7 +62,7 @@ ;; That is, like `$ contact freeArgFile.vcf`. (let [(qt-thread (thread-start! qt-loop)) (last-free-arg (condition-case (last (car cli-args)) (var () #f)))] - (if last-free-arg + (if (and last-free-arg (string? last-free-arg) (file-exists? last-free-arg)) (open-vcard-file qt-win last-free-arg)) qt-thread)) @@ -137,28 +140,53 @@ (define (menubar-callbacks window) (let* [(menu-file-exit (qt:find window "actionQuit")) (menu-file-save (qt:find window "actionSave")) - (menu-file-open (qt:find window "actionOpen"))] + (menu-file-open (qt:find window "actionOpen")) + (menu-file-new (qt:find window "actionNew"))] ;; We connect to https://doc.qt.io/qt-6/qaction.html#triggered + ;; Simply kill the program. (if menu-file-exit (qt:connect menu-file-exit "triggered()" (qt:receiver exit))) + ;; If they try to Save, tell them it’s not supported. (if menu-file-save (qt:connect menu-file-save "triggered()" (qt:receiver (lambda () (qt:message "Saving is not implemented."))))) + ;; If they want a new contact, create a new, blank, window. + ;; That is, a new process. + (if menu-file-new + (qt:connect + menu-file-new "triggered()" + (qt:receiver + (lambda () + (let [(program-args + ;; If we opened a pre-existing contact (last arg is a file), + ;; remove that argument. + (drop-right (cdr (argv)) + (if (file-exists? (last (argv))) + 1 + 0)))] + (process-run (executable-pathname) program-args)))))) + ;; If they want to open a contact through the Open… dialogue, we should open + ;; the contact in a new window. (if menu-file-open (qt:connect menu-file-open "triggered()" (qt:receiver (lambda () - (open-vcard-file - window - (qt:get-open-filename - "Select a contact file…" - (conc (get-environment-variable "HOME") "/Contacts"))))))))) + (let* [(contacts-dir (conc (get-environment-variable "HOME") "/Contacts")) + (selected-file (qt:get-open-filename + "Select a contact file to open…" + contacts-dir)) + (program-args (append (cdr (argv)) (list selected-file)))] + (if (not (string-null? selected-file)) + (process-run + (executable-pathname) + program-args))))))))) + ;; Parse a vCard file and populate the window’s forms with its contents. diff --git a/contact.ui b/contact.ui index 5ddcb90..9f6f3d8 100644 --- a/contact.ui +++ b/contact.ui @@ -225,6 +225,7 @@ File + @@ -251,6 +252,11 @@ Open… + + + New… + +