From c661b409eaa0e29d9e012b79e7a66574a554817a Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sun, 23 May 2010 21:44:59 +0000 Subject: Initial implementation of tabs: - Addition of PSMTabBar framework - Rework away from a document-based TableDocument - Support tabs throughout the application - Add menu items for creating tabs, and add support for dragging tabs to different windows --- Source/SPGrowlController.m | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'Source/SPGrowlController.m') diff --git a/Source/SPGrowlController.m b/Source/SPGrowlController.m index b4f84780..50ca4906 100644 --- a/Source/SPGrowlController.m +++ b/Source/SPGrowlController.m @@ -31,6 +31,8 @@ static SPGrowlController *sharedGrowlController = nil; +@class SPWindowController; + @implementation SPGrowlController /** @@ -84,21 +86,21 @@ static SPGrowlController *sharedGrowlController = nil; * Calls the notification after a tiny delay to allow isKeyWindow to have updated * after tasks. */ -- (void)notifyWithTitle:(NSString *)title description:(NSString *)description window:(NSWindow *)window notificationName:(NSString *)name +- (void)notifyWithTitle:(NSString *)title description:(NSString *)description document:(TableDocument *)document notificationName:(NSString *)name { // Ensure that the delayed notification call is made on the main thread if (![NSThread isMainThread]) { - [[self onMainThread] notifyWithTitle:title description:description window:window notificationName:name]; + [[self onMainThread] notifyWithTitle:title description:description document:document notificationName:name]; return; } NSMutableDictionary *notificationDictionary = [NSMutableDictionary dictionary]; [notificationDictionary setObject:title forKey:@"title"]; [notificationDictionary setObject:description forKey:@"description"]; - [notificationDictionary setObject:window forKey:@"window"]; + [notificationDictionary setObject:document forKey:@"document"]; [notificationDictionary setObject:name forKey:@"name"]; - [notificationDictionary setObject:[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:[window windowNumber]] forKey:@"notificationWindow"] forKey:@"clickContext"]; + [notificationDictionary setObject:[NSDictionary dictionaryWithObject:[NSNumber numberWithUnsignedInteger:[document hash]] forKey:@"notificationDocumentHash"] forKey:@"clickContext"]; [self performSelector:@selector(notifyWithObject:) withObject:notificationDictionary afterDelay:0.1]; } @@ -112,7 +114,7 @@ static SPGrowlController *sharedGrowlController = nil; { [self notifyWithTitle:[notificationDictionary objectForKey:@"title"] description:[notificationDictionary objectForKey:@"description"] - window:[notificationDictionary objectForKey:@"window"] + document:[notificationDictionary objectForKey:@"document"] notificationName:[notificationDictionary objectForKey:@"name"] iconData:nil priority:0 @@ -123,13 +125,17 @@ static SPGrowlController *sharedGrowlController = nil; /** * Posts a Growl notification using the supplied details and effectively ignoring the default values. */ -- (void)notifyWithTitle:(NSString *)title description:(NSString *)description window:(NSWindow *)window notificationName:(NSString *)name iconData:(NSData *)data priority:(NSInteger)priority isSticky:(BOOL)sticky clickContext:(id)clickContext +- (void)notifyWithTitle:(NSString *)title description:(NSString *)description document:(TableDocument *)document notificationName:(NSString *)name iconData:(NSData *)data priority:(NSInteger)priority isSticky:(BOOL)sticky clickContext:(id)clickContext { BOOL postNotification = YES; - // Don't post the notification if the notification window is key and order front + // Don't post the notification if the notification document is frontmost // as that suggests the user is already viewing the notification result. - if ([window isKeyWindow]) postNotification = NO; + if ([[document parentWindow] isKeyWindow] + && [[[document parentTabViewItem] tabView] selectedTabViewItem] == [document parentTabViewItem]) + { + postNotification = NO; + } // If a timing notification name exists, check to see if it matches the notification name; // if it does, and the time exceeds the threshold, display the notification even for @@ -158,11 +164,20 @@ static SPGrowlController *sharedGrowlController = nil; */ - (void)growlNotificationWasClicked:(NSDictionary *)clickContext { - if (clickContext && [clickContext objectForKey:@"notificationWindow"]) { - NSWindow *targetWindow = [NSApp windowWithWindowNumber:[[clickContext objectForKey:@"notificationWindow"] integerValue]]; - if (targetWindow) { - [NSApp activateIgnoringOtherApps:YES]; - [targetWindow makeKeyAndOrderFront:self]; + if (clickContext && [clickContext objectForKey:@"notificationDocumentHash"]) { + NSUInteger documentHash = [[clickContext objectForKey:@"notificationDocumentHash"] unsignedIntegerValue]; + + // Loop through the windows, looking for the document + for (NSWindow *eachWindow in [NSApp orderedWindows]) { + if ([[eachWindow windowController] isKindOfClass:[SPWindowController class]]) { + for (TableDocument *eachDocument in [[eachWindow windowController] documents]) { + if ([eachDocument hash] == documentHash) { + [NSApp activateIgnoringOtherApps:YES]; + [eachDocument makeKeyDocument]; + return; + } + } + } } } } -- cgit v1.2.3