Add a placeholder File→Save menubar item

It is toggled enabled when the user edits text,
and provisionally displays a pop-up message
saying “I do nothing lol”.
This commit is contained in:
Jaidyn Ann 2024-02-04 22:00:06 -06:00
parent 0259e06b99
commit 65e48e7f2d
2 changed files with 34 additions and 6 deletions

View File

@ -48,13 +48,26 @@
;; Connect callback functions to widgets signals. ;; Connect callback functions to widgets signals.
(define (window-callbacks window) (define (window-callbacks window)
(let* ([fileexit (qt:find window "actionQuit")]) (menubar-callbacks window)
(textbox-callbacks window))
;; Connect callback functions to menubar items.
(define (menubar-callbacks window)
(let* ([fileexit (qt:find window "actionQuit")]
[filesave (qt:find window "actionSave")])
;; We connect to https://doc.qt.io/qt-6/qaction.html#triggered ;; We connect to https://doc.qt.io/qt-6/qaction.html#triggered
(if fileexit (if fileexit
(qt:connect (qt:connect
fileexit "triggered()" fileexit "triggered()"
(qt:receiver exit)))) (qt:receiver exit)))
(textbox-callbacks window)) (if filesave
(qt:connect
filesave "triggered()"
(qt:receiver
(lambda ()
(qt:message "Saving is not implemented." "Saving")))))))
;; Connect a text-printing callback to each textbox. ;; Connect a text-printing callback to each textbox.
@ -71,12 +84,18 @@
;; Cycle through each textbox, connecting them to a callback that prints ;; Cycle through each textbox, connecting them to a callback that prints
;; their contents each time you type in text. ;; their contents each time you type in text.
(map (lambda (textbox) (map (lambda (textbox)
(if textbox
;; We connect to https://doc.qt.io/qt-6/qlineedit.html#textChanged ;; We connect to https://doc.qt.io/qt-6/qlineedit.html#textChanged
;; … and print the value of https://doc.qt.io/qt-6/qlineedit.html#text-prop ;; … and print the value of https://doc.qt.io/qt-6/qlineedit.html#text-prop
;; Also enable the File→Save menu-item (since, yknow, the user
;; changed something). It defaults to disabled in the contact.ui file.
(if textbox
(qt:connect textbox "textChanged(QString)" (qt:connect textbox "textChanged(QString)"
(qt:receiver (qt:receiver
(lambda () (print (qt:property textbox "text"))))))) (lambda ()
(let ([filesave (qt:find window "actionSave")])
(if filesave
(set! (qt:property filesave "enabled") #t)))
(print (qt:property textbox "text")))))))
textboxes))) textboxes)))

View File

@ -225,6 +225,7 @@
<property name="title"> <property name="title">
<string>File</string> <string>File</string>
</property> </property>
<addaction name="actionSave"/>
<addaction name="actionQuit"/> <addaction name="actionQuit"/>
</widget> </widget>
<addaction name="menuFile"/> <addaction name="menuFile"/>
@ -235,6 +236,14 @@
<string>Exit</string> <string>Exit</string>
</property> </property>
</action> </action>
<action name="actionSave">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Save</string>
</property>
</action>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>