I can't figure out how to post and catch "NSApplicationDefined" events. The problem is in just demonstrating that I can intercept any event. To do this I am trying to subclass NSApplication, but I can't make the project accept the subclass. The following appears in "Interface Builder: Frequently Asked Questions"
"Many widgets have a Custom Class pane in the Info window. You can use this pane to specify that, at runtime, an object should be instantiated as a specific subclass. For example, you could make a subclass of NSApplication called MyApplication. To ensure that an instance of MyApplication is used at runtime, click the Files Owner of your main nib file. Bring up the Custom Class pane and select MyApplication."
My project was created as a "Cocoa Document Based Application" and the closest thing I can find to a "main nib file" is MainMenu.nib which does have a "File's Owner" but applying the above Custom Class pane procedure and then running the program with the following subclass produces no NSLog messages during key or menu events. Where am I going wrong?
#import "MyApplication.h"
@implementation MyApplication
- (void)sendEvent
NSEvent *)theEvent {
NSLog(@"This is getting sendEvent:");
[super sendEvent:theEvent];
}
@end
BTW, I was originally trying to call NSRunAlertPanel from multiple subthreads, guarded by NSLock, but had some unexpected problems when all my threads locked up and my alert panel only partially displayed. I'm trying to solve that by calling all NSRunAlertPanels from the main thread via an application defined event, passing the information by subclassing NSEvent, and delaying the subthread with an NSLock until the AlertPanel is OKd. I didn't expect to have problems just positioning a method to intercept events.
"Many widgets have a Custom Class pane in the Info window. You can use this pane to specify that, at runtime, an object should be instantiated as a specific subclass. For example, you could make a subclass of NSApplication called MyApplication. To ensure that an instance of MyApplication is used at runtime, click the Files Owner of your main nib file. Bring up the Custom Class pane and select MyApplication."
My project was created as a "Cocoa Document Based Application" and the closest thing I can find to a "main nib file" is MainMenu.nib which does have a "File's Owner" but applying the above Custom Class pane procedure and then running the program with the following subclass produces no NSLog messages during key or menu events. Where am I going wrong?
#import "MyApplication.h"
@implementation MyApplication
- (void)sendEvent
NSLog(@"This is getting sendEvent:");
[super sendEvent:theEvent];
}
@end
BTW, I was originally trying to call NSRunAlertPanel from multiple subthreads, guarded by NSLock, but had some unexpected problems when all my threads locked up and my alert panel only partially displayed. I'm trying to solve that by calling all NSRunAlertPanels from the main thread via an application defined event, passing the information by subclassing NSEvent, and delaying the subthread with an NSLock until the AlertPanel is OKd. I didn't expect to have problems just positioning a method to intercept events.