diff options
author | Bibiko <bibiko@eva.mpg.de> | 2009-10-14 11:39:31 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2009-10-14 11:39:31 +0000 |
commit | 080b6b90f0021d6f58090cc19f268f8f0df86351 (patch) | |
tree | a090deef364a730d4c5d53b7d38df5ee09a4e185 /Source/SPAppController.m | |
parent | 6ddd95658062b14de2f63746f69b6d65d05792d4 (diff) | |
download | sequelpro-080b6b90f0021d6f58090cc19f268f8f0df86351.tar.gz sequelpro-080b6b90f0021d6f58090cc19f268f8f0df86351.tar.bz2 sequelpro-080b6b90f0021d6f58090cc19f268f8f0df86351.zip |
• cleaned and improved AppleScript support
- now 'activate' & 'quit' works due to that fact that if an app is scriptable the Dock's "Quit" command calls handleQuitScriptCommand: which has to be implemened
- fixed issue that SPAppController has to be the delegate for NSApp to support AS
- added support for AS à la: "get name of first document" or "close every window" etc.
Diffstat (limited to 'Source/SPAppController.m')
-rw-r--r-- | Source/SPAppController.m | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 09bca271..15e36fc4 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -508,4 +508,60 @@ [super dealloc]; } +#pragma mark - +#pragma mark AppleScript support + +//////////////// Examples to catch AS core events - maybe for further stuff +// - (void)handleQuitEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent +// { +// [NSApp terminate:self]; +// } +// - (void)handleOpenEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent +// { +// NSLog(@"OPEN %@", [event description]); +// } +// +// - (void)applicationWillFinishLaunching:(NSNotification *)aNotification +// { +// NSAppleEventManager *aeManager = [NSAppleEventManager sharedAppleEventManager]; +// [aeManager setEventHandler:self andSelector:@selector(handleQuitEvent:withReplyEvent:) forEventClass:kCoreEventClass andEventID:kAEQuitApplication]; +// [aeManager setEventHandler:self andSelector:@selector(handleOpenEvent:withReplyEvent:) forEventClass:kCoreEventClass andEventID:kAEOpenApplication]; +// } +// + +/* + * Is needed to interact with AppleScript for set/get internal SP variables + */ +- (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key +{ + NSLog(@"Not yet implemented."); + return NO; +} + +/* + * AppleScript calls that method to get the available documents + */ +- (NSArray *)orderedDocuments +{ + return [[NSDocumentController sharedDocumentController] documents]; +} + +/* + * AppleScript calls that method to get the available windows + */ +- (NSArray *)orderedWindows +{ + return [NSApp orderedWindows]; +} +/* + * AppleScript handler to quit Sequel Pro + * This handler is needed to allow to quit SP via the Dock or AppleScript after + * activating it by using AppleScript + */ +- (id)handleQuitScriptCommand:(NSScriptCommand *)command +{ + [NSApp terminate:self]; + return nil; +} + @end |