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

Raffael Cavallaro raffaelcavallaro at mac.com
Tue Feb 16 11:31:15 PST 2010


On Feb 16, 2010, at 1:43 PM, Ron Garret wrote:

> The problem with trying to do this in the obvious way is that the window doesn't actually exist until #/runModal is called.  But by then it's too late.

Right you are. Reading the docs, the key is to call #/layout before #/runModal:

(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)
   (#/layout alert)
   (#/makeFirstResponder: (#/window alert) tf) 
   (#/runModal alert) 
   (CCL::LISP-STRING-FROM-NSSTRING (#/stringValue tf))))

This ensures that the alert window is actually composed eagerly rather than lazily just prior to display. As long as you call #/layout, then #/makeFirstResponder:, then #/runModal, you get the desired result (at least, it works correctly for me on Clozure CL64 and Clozure CL32.

warmest regards,

Ralph



Raffael Cavallaro
raffaelcavallaro at me.com








More information about the Openmcl-devel mailing list