package griffon.util

import griffon.core.GriffonApplication
import com.apple.mrj.*

class GriffonMacOsSupport implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler {
    final GriffonApplication app
    final boolean noquit

    GriffonMacOsSupport(GriffonApplication app, boolean noquit) {
        this.app = app
        this.noquit = noquit
    }

    public void handleAbout() {
        app.event('OSXAbout', [app])
    }

    public void handlePrefs() throws IllegalStateException {
        app.event('OSXPrefs', [app])
    }

    public void handleQuit() throws IllegalStateException {
        noquit? app.event('OSXQuit', [app]) : app.shutdown()
    }
}

def handler = new GriffonMacOsSupport(app, skipQuit)
if(!skipAbout) MRJApplicationUtils.registerAboutHandler(handler)
if(!skipPrefs) MRJApplicationUtils.registerPrefsHandler(handler)
MRJApplicationUtils.registerQuitHandler(handler)

return handler