Search code examples
macosbuttonnsapplicationrunloop

osx and objc - running a second run loop for a plugin?


C programmer here. I'm trying to make a plugin to a running OSX app open its own window, accept a button press, close the window and come back to the plugin - not quit the app.

I've been able to get a window open using NSApp, and I've even got a button in it, but it won't DO anything.

[button setTarget: nil];      
[button setAction: @selector(fauxAction:)];

Is how I set it up. Normally, you [button setTarget: self], BUT, this is inside a normal c function, and there is no "self." I don't know how to call an objc method from c, if that's the problem I need to solve. I just want the method fauxAction to be called when the button is pressed.

This is the plugin's window -- not the main application. I can't have them crossing wires. [NSApp run] and putting the quit menu on it quits the main application, I guess because the run loop wraps the executing thread.

Any help would be appreciated. I feel like I'm drowning here.


Solution

  • I got it - NSApp runModalForWindow. That runs just the window loop, leaves the main loop unmolested.