[Openmcl-devel] How to make an alert accessory view be first responder

Ron Garret ron at flownet.com
Tue Feb 16 09:33:30 PST 2010


This is more of a Cocoa question than a Lisp question, but I haven't been able to get an answer from the Apple forums so I thought I'd try here.  I have this code to put up a dialog that asks the user to enter a string:

(defun get-string-dialog (msg &optional (default ""))
  (let ((alert (make-instance 'ns:ns-alert))
        (tf (#/initWithFrame: (make-instance 'ns:ns-text-field)
                              (ns:make-ns-rect 0 0 400 25))))
      (#/setStringValue: tf (ccl::%make-nsstring default))
      (#/setEditable: tf #$YES)
      (#/setMessageText: alert (ccl::%make-nsstring msg))
      (#/addButtonWithTitle: alert #@"OK")
      (#/setAccessoryView: alert tf)
      ; (#/makeFirstResponder: alert tf)
      (#/runModal alert)
      (CCL::LISP-STRING-FROM-NSSTRING (#/stringValue tf))))

It works, but the text field is not first responder so the user has to click on it before typing, which is annoying.  Normally one would fix this with the line of code that is commented out, but it doesn't work because makeFirstResponder: is a method on NSWindow, and NSAlert is not an NSWindow.  I could, of course, make this work by re-inventing the runModal wheel so that I can get a handle on the generated NSWindow object, but I was hoping someone would know of an easier way.

Thanks,
rg




More information about the Openmcl-devel mailing list