[Openmcl-devel] Creating a simple text input dialog

Ron Garret ron at flownet.com
Wed Apr 14 10:45:06 PDT 2021

Never mind, I figured it out.  (Well, actually I found some old code that does what I need.)

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

I still have no idea why this works when the other one doesn’t, so it would still be great to get that figured out.

On Apr 14, 2021, at 10:37 AM, Ron Garret <ron at flownet.com> wrote:

> I’m trying to create a password input dialog.  Tried this:
> (let ((alert (make-instance 'ns:ns-alert))
>      (input (make-instance 'ns:ns-text-field
>               :frame (ns:make-ns-rect 0 0 300 24)
>               :string (ccl::%make-nsstring "foo"))))
>  (#/setMessageText: alert (ccl::%make-nsstring "Alert!"))
>  (#/setInformativeText: alert (ccl::%make-nsstring "info"))
>  (#/addButtonWithTitle: alert (ccl::%make-nsstring "OK"))
>  (#/addButtonWithTitle: alert (ccl::%make-nsstring "Cancel"))
>  (#/setAccessoryView: alert input)
>  (#/runModal alert))
> but it doesn’t work.  For some reason the ns-text-field is not showing up.  AFAICT this is because I am not initializing it properly.  If I try to just display it in a regular (non-alert) window, it doesn’t show up either.  What am I doing wrong?
> I’ve scoured the web looking for some simple example code in ObjC that does this and come up empty.  I would not have thought that this would be that complicated.  For the record, what I’m really trying to do is to create a password input dialog.  Surely I’m not the first person to try to do this.
> Thanks,
> rg
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> https://lists.clozure.com/mailman/listinfo/openmcl-devel

More information about the Openmcl-devel mailing list