[Openmcl-devel] Making a text input first responder in a modal dialog

Ron Garret ron at flownet.com
Wed Aug 29 17:48:33 PDT 2018

I’m trying to build a password-input dialog.  This works:

(defun passwd-dialog (&optional (prompt "Enter password:"))
  (let ((alert (make-instance 'ns:ns-alert))
        (input (make-instance 'ns:ns-secure-text-field)))
    (#/setMessageText: alert (ccl::%make-nsstring prompt))
    (#/addButtonWithTitle: alert (ccl::%make-nsstring "OK"))
    (#/addButtonWithTitle: alert (ccl::%make-nsstring "Cancel"))
    (#/initWithFrame: input (ns:make-ns-rect 0 0 200 24))
    (#/setAccessoryView: alert input)
    ;;; (#/makeFirstResponder: (#/window alert) input)
    (#/autorelease input)
    (if (eql (#/runModal alert) #$NSAlertFirstButtonReturn)
      (ccl::lisp-string-from-nsstring (#/stringValue input)))))

but it requires the user to click on the dialog to make the input field active.  The commented-out line is my attempt to fix this problem, but it doesn’t work.  Not only does it fail to make the input field active, it actually breaks the whole dialog so that it always returns an empty string.

Clues appreciated.


More information about the Openmcl-devel mailing list