|
From: Andrew M. <fit...@us...> - 2007-06-03 03:18:57
|
Update of /cvsroot/radmind/radmind-assistant/rsm In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv1534 Modified Files: RAEditorLauncher.m Log Message: Use bundle identifiers to launch Transcript Editor. Use AppleScript to launch Terminal-based editing sessions. Index: RAEditorLauncher.m =================================================================== RCS file: /cvsroot/radmind/radmind-assistant/rsm/RAEditorLauncher.m,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RAEditorLauncher.m 5 May 2005 18:02:57 -0000 1.6 --- RAEditorLauncher.m 3 Jun 2007 03:18:54 -0000 1.7 *************** *** 6,11 **** #import "RAEditorLauncher.h" - #include <ApplicationServices/ApplicationServices.h> - #include <sys/types.h> #include <errno.h> --- 6,9 ---- *************** *** 24,28 **** } ! return( [ sharedInstance autorelease ] ); } --- 22,26 ---- } ! return( sharedInstance ); } *************** *** 30,55 **** { NSUserDefaults *defaults; ! NSArray *altEditors, *itemArray = nil; int i; - OSStatus status; - NSMutableDictionary *term; - NSString *termPath; - LSLaunchURLSpec spec; - NSURL *transcriptURL = NULL; - CFURLRef url = NULL; ! if ( strstr(( char * )[ editor UTF8String ], "Radmind" ) != NULL ) { ! status = LSFindApplicationForInfo(( OSType )'????', ! ( CFStringRef )@"edu.umich.radmindtranscripteditor", ! NULL, NULL, &url ); - if ( status != noErr ) { - NSRunAlertPanel( @"Error launching editor", @"Error %d", - @"OK", @"", @"", ( int )status ); - return( NO ); - } - if ( tPath == nil ) { ! if ( ![[ NSWorkspace sharedWorkspace ] openURL: ( NSURL * )url ] ) { NSRunAlertPanel( @"Couldn't launch Radmind Transcript Editor", @"", @"OK", @"", @"" ); --- 28,57 ---- { NSUserDefaults *defaults; ! NSArray *altEditors; ! NSString *bundleID = @"edu.umich.radmindtranscripteditor"; ! NSString *rtepath; ! NSAppleScript *as = nil; ! NSDictionary *errorDictionary = nil; ! NSString *scriptSource = nil; int i; ! if ( [ editor isEqualToString: @"Radmind Transcript Editor" ] ) { ! if (( rtepath = [[ NSWorkspace sharedWorkspace ] ! absolutePathForAppBundleWithIdentifier: bundleID ] ) == nil ) { ! rtepath = [[ NSBundle mainBundle ] bundlePath ]; ! rtepath = [ rtepath stringByDeletingLastPathComponent ]; ! rtepath = [ rtepath stringByAppendingFormat: @"%@.app", editor ]; ! if ( rtepath == nil ) { ! NSRunAlertPanel( NSLocalizedString( @"Error", @"Error" ), ! NSLocalizedString( ! @"Couldn't locate the Radmind Transcript Editor", ! @"Couldn't locate the Radmind Transcript Editor" ), ! NSLocalizedString( @"OK", @"OK" ), @"", @"" ); ! return( NO ); ! } ! } if ( tPath == nil ) { ! if ( ![[ NSWorkspace sharedWorkspace ] openFile: rtepath ] ) { NSRunAlertPanel( @"Couldn't launch Radmind Transcript Editor", @"", @"OK", @"", @"" ); *************** *** 58,80 **** return( YES ); } ! ! transcriptURL = [ NSURL fileURLWithPath: tPath ]; ! itemArray = [ NSArray arrayWithObject: transcriptURL ]; ! ! spec.appURL = ( CFURLRef )url; ! spec.itemURLs = ( CFArrayRef )itemArray; ! spec.passThruParams = NULL; ! spec.launchFlags = kLSLaunchDefaults; ! spec.asyncRefCon = NULL; ! ! status = LSOpenFromURLSpec( &spec, NULL ); ! ! if ( status != noErr ) { NSRunAlertPanel( @"Error launching editing session.", ! @"Couldn't launch Radmind Transcript Editor: error %d", ! @"OK", @"", @"", ( int )status ); return( NO ); } ! return( YES ); } --- 60,77 ---- return( YES ); } ! /* ! * this fails if tPath isn't readable by the user. ! * should use NSWorkspace's launchAppWithBundleIdentifier... ! * and pass doc path as part of paramdescriptor ! */ ! if ( ![[ NSWorkspace sharedWorkspace ] openFile: tPath ! withApplication: rtepath ! andDeactivate: YES ] ) { NSRunAlertPanel( @"Error launching editing session.", ! @"Couldn't launch Radmind Transcript Editor", ! @"OK", @"", @"" ); return( NO ); } ! return( YES ); } *************** *** 92,96 **** NSRunAlertPanel( @"Error launching editing session.", @"Couldn't launch %@", @"OK", @"", @"", ! [[ altEditors objectAtIndex: i ] objectForKey: @"name" ] ); return( NO ); } --- 89,93 ---- NSRunAlertPanel( @"Error launching editing session.", @"Couldn't launch %@", @"OK", @"", @"", ! [[ altEditors objectAtIndex: i ] objectForKey: @"name" ] ); return( NO ); } *************** *** 98,136 **** } } - - term = [[ NSMutableDictionary alloc ] init ]; - - [ term setDictionary: [ NSDictionary dictionaryWithContentsOfFile: - [[ NSBundle mainBundle ] pathForResource: @"template" ofType: @"term" ]]]; ! [[[ term objectForKey: @"WindowSettings" ] objectAtIndex: 0 ] setObject: ! [ NSString stringWithFormat: @"/usr/bin/sudo %@ %@ ; exit", editor, tPath ] ! forKey: @"ExecutionString" ]; ! ! termPath = [ NSString stringWithFormat: @"/tmp/ra.%d.term", getpid() ]; ! ! if ( access(( char * )[ termPath UTF8String ], F_OK ) == 0 ) { ! if ( unlink(( char * )[ termPath UTF8String ] ) < 0 ) { ! NSLog( @"unlink %@: %s", termPath, strerror( errno )); ! return( NO ); ! } ! } ! ! if ( ![ term writeToFile: termPath atomically: YES ] ) { ! NSRunAlertPanel( @"Error creating terminal session.", ! @"Couldn't write .term file to /tmp", ! @"OK", @"", @"" ); ! return( NO ); ! } ! if ( ![[ NSWorkspace sharedWorkspace ] openFile: termPath ! withApplication: @"Terminal.app" ! andDeactivate: YES ] ) { ! NSRunAlertPanel( @"Error launching editing session.", ! @"Couldn't launch Terminal", ! @"OK", @"", @"" ); return( NO ); } ! return( YES ); } --- 95,112 ---- } } ! scriptSource = [ NSString stringWithFormat: ! @"tell application \"Terminal\"\r" ! @"activate\r" ! @"do script \"/usr/bin/sudo %@ \\\"%@\\\"; exit\"\r" ! @"end tell", editor, tPath ]; ! as = [[[ NSAppleScript alloc ] initWithSource: scriptSource ] autorelease ]; ! if ( [ as executeAndReturnError: &errorDictionary ] == nil ) { ! NSLog( @"Failed to open terminal with AppleScript: %@", ! [ errorDictionary objectForKey: @"NSAppleScriptErrorMessage" ] ); return( NO ); } ! return( YES ); } |