From 5bc2ab00e8db95b0892a272e5fd5f333df28282d Mon Sep 17 00:00:00 2001 From: kintel Date: Tue, 2 Feb 2010 01:07:02 +0000 Subject: Experimental Apple Event hack; you can now do 'tell application "OpenSCAD" to reload' git-svn-id: http://svn.clifford.at/openscad/trunk@410 b57f626f-c46c-0410-a088-ec61d464b74c diff --git a/src/AppleEvents.cc b/src/AppleEvents.cc new file mode 100644 index 0000000..470c4f3 --- /dev/null +++ b/src/AppleEvents.cc @@ -0,0 +1,32 @@ +#include +#include +#include "MainWindow.h" + +extern "C" { + OSErr eventHandler(const AppleEvent *ev, AppleEvent *reply, SRefCon refcon); +} + +OSErr eventHandler(const AppleEvent *, AppleEvent *, SRefCon ) +{ +// FIXME: Ugly hack; just using the first MainWindow we can find + MainWindow *mainwin = NULL; + foreach (QWidget *w, QApplication::topLevelWidgets()) { + mainwin = qobject_cast(w); + if (mainwin) break; + } + if (mainwin) { + mainwin->actionReloadCompile(); + } + return noErr; +} + +void installAppleEventHandlers() +{ + // Reload handler + OSErr err = AEInstallEventHandler('SCAD', 'relo', NewAEEventHandlerUPP(eventHandler), 0, true); + require_noerr(err, CantInstallAppleEventHandler); + return; + +CantInstallAppleEventHandler: + fprintf(stderr, "AEInstallEventHandler() failed: %d\n", err); ; +} diff --git a/src/AppleEvents.h b/src/AppleEvents.h new file mode 100644 index 0000000..9002399 --- /dev/null +++ b/src/AppleEvents.h @@ -0,0 +1,6 @@ +#ifndef APPLEEVENTS_H_ +#define APPLEEVENTS_H_ + +void installAppleEventHandlers(); + +#endif -- cgit v0.10.1