Tim Perrett <freestyle_kayaker / hotmail.com> writes:

> In ligt of your suggestions I have reworked it so my couple of methods 
> are
>
>   def showConnectionSheet
>   NSBundle.loadNibNamed_owner('Connection', self)
>   NSApp.beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo(@connection, 
> self.window, self, 'didEndSheet:returnCode:contextInfo:', nil)
>   end
>
>   def didEndSheet_returnCode_contextInfo(sheet, code, context)
>     return
>   end
>
> But then I get an assertion error:
>
> *** Assertion failure in -[NSApplication 
> _commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndSelector:contextInfo:], 
> AppKit.subproj/NSApplication.m:3057
>
> In the initial Apple example code there method is marked as (void) and 
> not an (IBAction), can this method not be called directly?

It's a callback - you don't actually connect an event to it, or call it
yourself. In your action method, you'd call:

    OSX.NSApp.endSheet_returnCode(@connection, 0)

Then, Cocoa will call your callback, passing along whatever return code
you've specified. This allows your action methods to perform whatever
action is specific to the action that was performed, then the callback
does whatever action-neutral cleanup is needed - including sending an
orderOut message to @connection to make it go away.

> Also, I have 
> establised an IB outlet which im guessing the nib is loaded into?

What are you referring to when you say "established an outlet"? Have you
declared it in Ruby with ib_outlets? Have you *also* connected it in
Interface Builder? I've a suspicion that you might have forgotten that
second part, so...

In IB, double-click the "file's owner" to edit the class definition. Choose
"Classes/Subclass NSObject", and enter the name of your Ruby class. Then,
add the outlet to the class in the "attributes" pane of the inspector panel.
That doesn't actually declare your class or add an outlet to it, it simply
lets IB know about it.

Objective-C programmers can simply drag and drop .h files to do this step,
or do this step manually and let IB create the .h files, but IB doesn't
grok scripting languages... so we have to do both steps by hand, connecting
the outlet in IB and declaring it in our code.

To make the connection, click back over to the "instances" tab. Then, control-
drag a connection starting with "file's owner" and ending on the window you're
using as a sheet. The inspector panel should switch over to its "connections"
pane - there, double-click the outlet you just added, or click the "connect"
button.

> Are there any tutorials at all out there on using sheets?!

None that I know of. But then, I'm biased - I wrote CamelBones, and I've only
recently started looking at "other" bridges. :-)

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net