On Fri, 2 Jun 2006 13:16:53 -0500, Chip Howland <email@hidden> said:
>I am writing an application that allows the user to search using a
>keyword, then populates a table view with the results. I have used a
>text field for the keyword entry and a button mapped to the return
>key to initiate the search.
>
>I would like the application to switch focus to the table view once
>it is populated. However, the text field seems to intercept the
>return key and steals focus back from the table view even after the
>script changes the first responder of the window. The focus works as
>expected if I use a different keyboard shortcut for the search
>button. It is only the return key that causes the focus to return to
>the text field.
>
>Does anyone have a suggestion for fixing this problem? I would
>appreciate any ideas you might have.
>
>I have included a portion of the script below:
>
>on clicked theObject
> if name of theObject is "search_button" then
> delete image of image view "viewer" of window "import_window"
> set shortname to contents of text field "search_field" of
>window "import_window"
> set imagename to shortname
> my getImages(imagename)
> tell window "import_window"
> set first responder to table view "tableView" of scroll view
>"scrollView"
> end tell
> else if name of theObject is "cancel_button" then
> quit
> end if
>end clicked
The problem is that you're changing the first responder while the return key
is still being processed. Thus the framework is still messing with the
business of who's got the focus and restores it to the text field as part of
its own cleanup, which takes place after you've changed it. The solution is
to use "delayed performance" so that the change of first responder you're
after doesn't happen until *after* we return completely from the clicked
handler. You can do this with an idle handler, probably; the Cocoa way is to
call performSelector:withObject:afterDelay:, which is a lot easier.
<http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes
/NSObject_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/perf
ormSelector:withObject:afterDelay:>
m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-studio mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/email@hidden
This email sent to email@hidden