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

Ron Garret ron at flownet.com
Tue Feb 16 19:40:03 UTC 2010


Cool!  That works!  Thanks!  I didn't realize that "doing layout" meant actually creating the window object.  (This has theological implications: it proves that just because you can't see something doesn't mean it doesn't exist ;-)

(Hm, still has an odd behavior.  The cursor doesn't start blinking until you type something.  Certainly not a show stopper, but kind of weird.)

rg

On Feb 16, 2010, at 11:31 AM, Raffael Cavallaro wrote:

> 
> 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