diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-11-29 21:25:52 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-11-29 21:25:52 +0000 |
commit | c1cb48f6afa93b8ed26baa434d66d1ca3e0afca7 (patch) | |
tree | f3b1a2864fbead4c7810303eb60b83b2457d677e /Source/SPStringAdditions.m | |
parent | cef5a0200f433e53bd27b2516e5ac269205f0420 (diff) | |
download | sequelpro-c1cb48f6afa93b8ed26baa434d66d1ca3e0afca7.tar.gz sequelpro-c1cb48f6afa93b8ed26baa434d66d1ca3e0afca7.tar.bz2 sequelpro-c1cb48f6afa93b8ed26baa434d66d1ca3e0afca7.zip |
• Bundle commands
- register running commands for each SPDatabaseDocument or if the command runs via 'General' for NSApp delegate
- kill all running commands before SP will be terminated
Diffstat (limited to 'Source/SPStringAdditions.m')
-rw-r--r-- | Source/SPStringAdditions.m | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index 907ebc05..658baadb 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -444,10 +444,14 @@ * * @param path The current directory for the bash command. If path is nil, the current directory is inherited from the process that created the receiver (normally /). * + * @param caller The SPDatabaseDocument which invoked that command to register the command for cancelling; if nil the command won't be registered. + * + * @param name The menu title of the command. + * * @param theError If not nil and the bash command failed it contains the returned error message as NSLocalizedDescriptionKey * */ -- (NSString *)runBashCommandWithEnvironment:(NSDictionary*)shellEnvironment atCurrentDirectoryPath:(NSString*)path error:(NSError**)theError +- (NSString *)runBashCommandWithEnvironment:(NSDictionary*)shellEnvironment atCurrentDirectoryPath:(NSString*)path callerDocument:(id)caller withName:(NSString*)name error:(NSError**)theError { BOOL userTerminated = NO; @@ -544,6 +548,16 @@ [bashTask setStandardError:stderr_pipe]; NSFileHandle *stderr_file = [stderr_pipe fileHandleForReading]; [bashTask launch]; + NSInteger pid = -1; + if(caller != nil && [caller respondsToSelector:@selector(registerBASHCommand:)]) { + // register command + pid = [bashTask processIdentifier]; + NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInteger:pid], @"pid", + name, @"name", + [[NSDate date] descriptionWithCalendarFormat:@"%H:%M:%S" timeZone:nil locale:[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]], @"starttime", + nil]; + [caller registerBASHCommand:dict]; + } // Listen to ⌘. to terminate while(1) { @@ -569,6 +583,9 @@ [bashTask waitUntilExit]; + // unregister BASH command if it was registered + if(pid >= 0) [caller unRegisterBASHCommand:pid]; + if(userTerminated) { if(bashTask) [bashTask release]; NSBeep(); @@ -639,6 +656,22 @@ } /** + * Run self as BASH command(s) and return the result. + * This task can be interrupted by pressing ⌘. + * + * @param shellEnvironment A dictionary of environment variable values whose keys are the variable names. + * + * @param path The current directory for the bash command. If path is nil, the current directory is inherited from the process that created the receiver (normally /). + * + * @param theError If not nil and the bash command failed it contains the returned error message as NSLocalizedDescriptionKey + * + */ +- (NSString *)runBashCommandWithEnvironment:(NSDictionary*)shellEnvironment atCurrentDirectoryPath:(NSString*)path error:(NSError**)theError +{ + return [self runBashCommandWithEnvironment:shellEnvironment atCurrentDirectoryPath:path callerDocument:nil withName:@"" error:theError]; +} + +/** * Returns the minimum of a, b and c. */ - (NSInteger)smallestOf:(NSInteger)a andOf:(NSInteger)b andOf:(NSInteger)c |