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

rkm1000 rkm1000 at bmrc.duhs.duke.edu
Tue Feb 16 10:24:11 PST 2010



An NSView knows its window.

Try:
(#/makeFirstResponder: (#/window tf) tf)

On Feb 16, 2010, at 12:33 PM, Ron Garret wrote:
> 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
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>




More information about the Openmcl-devel mailing list