diff options
-rw-r--r-- | Source/SPQueryController.h | 3 | ||||
-rw-r--r-- | Source/SPQueryController.m | 21 | ||||
-rw-r--r-- | Source/SPQueryFavoriteManager.m | 4 |
3 files changed, 26 insertions, 2 deletions
diff --git a/Source/SPQueryController.h b/Source/SPQueryController.h index abef41de..2a15ba45 100644 --- a/Source/SPQueryController.h +++ b/Source/SPQueryController.h @@ -93,4 +93,7 @@ - (NSMutableArray *)favoritesForFileURL:(NSURL *)fileURL; - (NSMutableArray *)historyForFileURL:(NSURL *)fileURL; +- (NSArray *)queryFavoritesForFileURL:(NSURL *)fileURL andTabTrigger:(NSString *)tabTrigger includeGlobals:(BOOL)includeGlobals; + + @end diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m index 4dbd3749..a08a0906 100644 --- a/Source/SPQueryController.m +++ b/Source/SPQueryController.m @@ -569,6 +569,27 @@ static SPQueryController *sharedQueryController = nil; } +- (NSArray *)queryFavoritesForFileURL:(NSURL *)fileURL andTabTrigger:(NSString *)tabTrigger includeGlobals:(BOOL)includeGlobals +{ + + if(![tabTrigger length]) return [NSArray array]; + + NSMutableArray *result = [[NSMutableArray alloc] init]; + for(id fav in [self favoritesForFileURL:fileURL]) { + if([fav objectForKey:@"tabtrigger"] && [[fav objectForKey:@"tabtrigger"] isEqualToString:tabTrigger]) + [result addObject:fav]; + } + + if(includeGlobals && [prefs objectForKey:@"queryFavorites"]) { + for(id fav in [prefs objectForKey:@"queryFavorites"]) { + if([fav objectForKey:@"tabtrigger"] && [[fav objectForKey:@"tabtrigger"] isEqualToString:tabTrigger]) + [result addObject:fav]; + } + } + + return [result autorelease]; +} + - (void)removeFavoriteAtIndex:(NSUInteger)index forFileURL:(NSURL *)fileURL { [[favoritesContainer objectForKey:[fileURL absoluteString]] removeObjectAtIndex:index]; diff --git a/Source/SPQueryFavoriteManager.m b/Source/SPQueryFavoriteManager.m index 41276769..202cfa09 100644 --- a/Source/SPQueryFavoriteManager.m +++ b/Source/SPQueryFavoriteManager.m @@ -98,7 +98,7 @@ // change will be stored in the prefs at once) if([prefs objectForKey:@"queryFavorites"]) { for(id fav in [prefs objectForKey:@"queryFavorites"]) - [favorites addObject:[fav mutableCopy]]; + [favorites addObject:[[fav mutableCopy] autorelease]]; } [favorites addObject:[NSDictionary dictionaryWithObjectsAndKeys: @@ -109,7 +109,7 @@ if([[SPQueryController sharedQueryController] favoritesForFileURL:delegatesFileURL]) { for(id fav in [[SPQueryController sharedQueryController] favoritesForFileURL:delegatesFileURL]) - [favorites addObject:[fav mutableCopy]]; + [favorites addObject:[[fav mutableCopy] autorelease]]; } |