diff options
| author | mjwybrow <mjwybrow@users.sourceforge.net> | 2008-03-11 06:02:23 +0000 |
|---|---|---|
| committer | mjwybrow <mjwybrow@users.sourceforge.net> | 2008-03-11 06:02:23 +0000 |
| commit | 5a9a61b260568c8672f72497c12f6b1cfcc03d51 (patch) | |
| tree | b2d27e890b6a896b3d8977b56ec99b4f0a374b68 /packaging/macosx/ScriptExec | |
| parent | Fixing to work with current wiki format (diff) | |
| download | inkscape-5a9a61b260568c8672f72497c12f6b1cfcc03d51.tar.gz inkscape-5a9a61b260568c8672f72497c12f6b1cfcc03d51.zip | |
* packaging/macosx/ScriptExec/main.c: Update ScriptExec with upstream fixes
and changes. X11.app now gets focus if the Inkscape icon is clicked while
Inkscape is already open (previously nothing happened).
* packaging/macosx/Resources/openDoc: If Inkscape.app is already open and
a file is dropped on the Inkscape dock icon, or an Inkscape file is
double-clicked in the Finder, that document will now be correctly opened
in a new Inkscape window (previously nothing happened).
* packaging/macosx/Resources/script: Some minor fixes, plus alert the user
about the font cache building time only if ~/.fontconfig/ doesn't exist.
* packaging/macosx/Resources/bin/inkscape: Only override the fontconfig
configuration on OSX 10.4 or earlier, since the fc-cache behaviour has
been corrected on 10.5.
* Info.plist.in: Update the copyright dates, and change Inkscape to be an
Editor for SVG files, rather than a Viewer as it was previously.
(bzr r5050)
Diffstat (limited to 'packaging/macosx/ScriptExec')
| -rw-r--r-- | packaging/macosx/ScriptExec/main.c | 90 |
1 files changed, 88 insertions, 2 deletions
diff --git a/packaging/macosx/ScriptExec/main.c b/packaging/macosx/ScriptExec/main.c index c3e14a0a1..2c4e8f301 100644 --- a/packaging/macosx/ScriptExec/main.c +++ b/packaging/macosx/ScriptExec/main.c @@ -3,6 +3,10 @@ This is the executable that goes into Platypus apps Copyright (C) 2003 Sveinbjorn Thordarson <sveinbt@hi.is> + With modifications by Aaron Voisine for gimp.app + With modifications by Marianne gagnon for Wilber-loves-apple + With modifications by Michael Wybrow for Inkscape.app + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -21,6 +25,14 @@ */ +/* + * This app laucher basically takes care of: + * - launching Inkscape and X11 when double-clicked + * - bringing X11 to the top when its icon is clicked in the dock (via a small applescript) + * - catch file dropped on icon events (and double-clicked gimp documents) and notify gimp. + * - catch quit events performed outside gimp, e.g. on the dock icon. + */ + /////////////////////////////////////// // Includes /////////////////////////////////////// @@ -89,6 +101,14 @@ static OSStatus X11FailedHandler(EventHandlerCallRef theHandlerCall, EventRef theEvent, void *userData); static OSStatus FCCacheFailedHandler(EventHandlerCallRef theHandlerCall, EventRef theEvent, void *userData); +static OSErr AppReopenAppAEHandler(const AppleEvent *theAppleEvent, + AppleEvent *reply, long refCon); + +static OSStatus CompileAppleScript(const void* text, long textLength, + AEDesc *resultData); +static OSStatus SimpleCompileAppleScript(const char* theScript); +static void runScript(); + /////////////////////////////////////// // Globals /////////////////////////////////////// @@ -137,6 +157,11 @@ int main(int argc, char* argv[]) err += AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, NewAEEventHandlerUPP(AppOpenAppAEHandler), 0, false); + + err += AEInstallEventHandler(kCoreEventClass, kAEReopenApplication, + NewAEEventHandlerUPP(AppReopenAppAEHandler), + 0, false); + err += InstallEventHandler(GetApplicationEventTarget(), NewEventHandlerUPP(X11FailedHandler), 1, &X11events, NULL, NULL); @@ -153,6 +178,9 @@ int main(int argc, char* argv[]) GetParameters(); //load data from files containing exec settings + // compile "icon clicked" script so it's ready to execute + SimpleCompileAppleScript("tell application \"X11\" to activate"); + RunApplicationEventLoop(); //Run the event loop return 0; } @@ -625,6 +653,14 @@ static OSErr AppOpenDocAEHandler(const AppleEvent *theAppleEvent, /////////////////////////////// // Handler for clicking on app icon /////////////////////////////// +// if app is already open +static OSErr AppReopenAppAEHandler(const AppleEvent *theAppleEvent, + AppleEvent *reply, long refCon) +{ + runScript(); +} + +// if app is being opened static OSErr AppOpenAppAEHandler(const AppleEvent *theAppleEvent, AppleEvent *reply, long refCon) { @@ -688,10 +724,10 @@ static OSStatus X11FailedHandler(EventHandlerCallRef theHandlerCall, StandardAlert(kAlertStopAlert, "\pFailed to start X11", "\pInkscape.app requires Apple's X11, which is freely downloadable from Apple's website for Panther (10.3.x) users and available as an optional install from the installation DVD for Tiger (10.4.x) users.\n\nPlease install X11 and restart Inkscape.", ¶ms, &itemHit); - + if (itemHit == kAlertStdAlertCancelButton) { - OpenURL("http://www.apple.com/downloads/macosx/apple/x11formacosx.html"); + OpenURL("http://www.apple.com/downloads/macosx/apple/macosx_updates/x11formacosx.html"); } ExitToShell(); @@ -699,3 +735,53 @@ static OSStatus X11FailedHandler(EventHandlerCallRef theHandlerCall, return noErr; } + + +// Compile and run a small AppleScript. The code below does no cleanup and no proper error checks +// but since it's there until the app is shut down, and since we know the script is okay, +// there should not be any problems. +ComponentInstance theComponent; +AEDesc scriptTextDesc; +OSStatus err; +OSAID scriptID, resultID; + +static OSStatus CompileAppleScript(const void* text, long textLength, + AEDesc *resultData) { + + resultData = NULL; + /* set up locals to a known state */ + theComponent = NULL; + AECreateDesc(typeNull, NULL, 0, &scriptTextDesc); + scriptID = kOSANullScript; + resultID = kOSANullScript; + + /* open the scripting component */ + theComponent = OpenDefaultComponent(kOSAComponentType, + typeAppleScript); + if (theComponent == NULL) { err = paramErr; return err; } + + /* put the script text into an aedesc */ + err = AECreateDesc(typeChar, text, textLength, &scriptTextDesc); + if (err != noErr) return err; + + /* compile the script */ + err = OSACompile(theComponent, &scriptTextDesc, + kOSAModeNull, &scriptID); + + return err; +} + +/* runs the compiled applescript */ +static void runScript() +{ + /* run the script */ + err = OSAExecute(theComponent, scriptID, kOSANullScript, + kOSAModeNull, &resultID); + return err; +} + + +/* Simple shortcut to the function that actually compiles the applescript. */ +static OSStatus SimpleCompileAppleScript(const char* theScript) { + return CompileAppleScript(theScript, strlen(theScript), NULL); +} |
