From: Dave H. <gr...@gr...> - 2006-01-20 20:49:56
|
I'm creating a handy way of doing alert sheets for a program, so that they'd work something like this: class Main < OSX::NSObject ib_outlet :window, def applicationDidFinishLaunching(something) myAlert = AlertMessage.alloc.init.display(@window, 'Quit already?', "This program just launched! Do you want to quit already?","OK","Cancel") if myAlert then @window.close end end Assume that the window's connected to "window" in InterfaceBuilder, et cetera. Unfortunately, there's one critical piece missing, and I'm mystified on how to get this part to work. The following code will run.... require 'osx/cocoa' class AlertMessage < OSX::NSObject include OSX def display(theWindow, messageTitle, messageText, defaultOption, altOption) p "Alert: " + messageTitle theAlert = NSAlert.alloc.init theAlert.addButtonWithTitle(defaultOption) theAlert.addButtonWithTitle(altOption) if altOption theAlert.setMessageText(messageTitle) theAlert.setInformativeText(messageText) someAnswer = theAlert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextIn fo(theWindow, self, 'alertDidEnd_returnCode_contextInfo', nil) p "Answer" p someAnswer return @theResponse end def alertDidEnd_returnCode_contextInfo(theAlert) return end end Unfortunately, I can't do anything but one-button messages, because I can't get the return code back from the NSAlert. The call to 'beginSheetModalForWindow...' looks like this in Objective-C: beginSheetModalForWindow:[someWindow window] modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil How exactly can I get a parameterized selector into this thing? In other words, how do I do @selector(alertDidEnd:returnCode:contextInfo:) in RubyCocoa? |