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

Ron Garret ron at flownet.com
Tue Feb 16 10:43:07 PST 2010


Nope, doesn't work.  (#/window tf) is null.

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.

rg

On Feb 16, 2010, at 10:24 AM, rkm1000 wrote:

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