@@ -71,6 +71,7 @@ @interface SPCustomQuery (PrivateAPI)
71
71
- (id)_resultDataItemAtRow:(NSInteger)row columnIndex:(NSUInteger)column preserveNULLs:(BOOL)preserveNULLs asPreview:(BOOL)asPreview;
72
72
+ (NSString *)linkToHelpTopic:(NSString *)aTopic;
73
73
- (void)documentWillClose:(NSNotification *)notification;
74
+ - (void)queryFavoritesHaveBeenUpdated:(NSNotification *)notification;
74
75
75
76
@end
76
77
@@ -3391,38 +3392,38 @@ - (void)historyItemsHaveBeenUpdated:(id)manager
3391
3392
/**
3392
3393
* Called by the query favorites manager whenever the query favorites have been updated.
3393
3394
*/
3394
- - (void)queryFavoritesHaveBeenUpdated:(id)manager
3395
+ - (void)queryFavoritesHaveBeenUpdated:(NSNotification *)notification
3395
3396
{
3396
- NSMenuItem *headerMenuItem;
3397
+ NSURL *fileURL = [tableDocumentInstance fileURL];
3398
+
3399
+ // Warning: This method may be called before any connection has been made in the current tab (triggered by another tab)!
3400
+ // There doesn't seem to be a real indicator for this, but fileURL is the closest thing plus we need it below (#2266)
3401
+ if(!fileURL) return;
3402
+
3397
3403
NSMenu *menu = [queryFavoritesButton menu];
3398
3404
3399
3405
// Remove all favorites beginning from the end
3400
3406
while([queryFavoritesButton numberOfItems] > 7)
3401
3407
[queryFavoritesButton removeItemAtIndex:[queryFavoritesButton numberOfItems]-1];
3402
3408
3403
3409
// Build document-based list
3404
- NSString *tblDocName = [[[[tableDocumentInstance fileURL] absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] lastPathComponent];
3405
- if(!tblDocName) {
3406
- //NSMenuItem will not accept nil as title
3407
- @throw [NSException exceptionWithName:NSInternalInconsistencyException
3408
- reason:[NSString stringWithFormat:@"Document name conversion resulted in nil string!? tableDocumentInstance=%@ fileURL=%@",tableDocumentInstance,[tableDocumentInstance fileURL]]
3409
- userInfo:nil];
3410
- }
3411
- headerMenuItem = [[NSMenuItem alloc] initWithTitle:tblDocName action:NULL keyEquivalent:@""];
3412
- [headerMenuItem setTag:SP_FAVORITE_HEADER_MENUITEM_TAG];
3413
- [headerMenuItem setToolTip:[NSString stringWithFormat:NSLocalizedString(@"‘%@’ based favorites",@"Query Favorites : List : Section Heading : current connection document : tooltip (arg is the name of the spf file)"), tblDocName]];
3414
- [headerMenuItem setIndentationLevel:0];
3415
- [menu addItem:headerMenuItem];
3416
- [headerMenuItem release];
3417
- for (NSDictionary *favorite in [[SPQueryController sharedQueryController] favoritesForFileURL:[tableDocumentInstance fileURL]]) {
3410
+ NSString *tblDocName = [[[fileURL absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] lastPathComponent];
3411
+ {
3412
+ NSMenuItem *headerMenuItem = [[NSMenuItem alloc] initWithTitle:tblDocName action:NULL keyEquivalent:@""];
3413
+ [headerMenuItem setTag:SP_FAVORITE_HEADER_MENUITEM_TAG];
3414
+ [headerMenuItem setToolTip:[NSString stringWithFormat:NSLocalizedString(@"‘%@’ based favorites",@"Query Favorites : List : Section Heading : current connection document : tooltip (arg is the name of the spf file)"), tblDocName]];
3415
+ [headerMenuItem setIndentationLevel:0];
3416
+ [menu addItem:headerMenuItem];
3417
+ [headerMenuItem release];
3418
+ }
3419
+ for (NSDictionary *favorite in [[SPQueryController sharedQueryController] favoritesForFileURL:fileURL]) {
3418
3420
if (![favorite isKindOfClass:[NSDictionary class]] || ![favorite objectForKey:@"name"]) continue;
3419
3421
NSMutableParagraphStyle *paraStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
3420
3422
[paraStyle setTabStops:@[]];
3421
3423
[paraStyle addTabStop:[[[NSTextTab alloc] initWithType:NSRightTabStopType location:190.0f] autorelease]];
3422
3424
NSDictionary *attributes = @{NSParagraphStyleAttributeName : paraStyle, NSFontAttributeName : [NSFont systemFontOfSize:11]};
3423
- NSAttributedString *titleString = [[[NSAttributedString alloc]
3424
- initWithString:([favorite objectForKey:@"tabtrigger"] && [(NSString*)[favorite objectForKey:@"tabtrigger"] length]) ? [NSString stringWithFormat:@"%@\t%@⇥", [favorite objectForKey:@"name"], [favorite objectForKey:@"tabtrigger"]] : [favorite objectForKey:@"name"]
3425
- attributes:attributes] autorelease];
3425
+ NSAttributedString *titleString = [[[NSAttributedString alloc] initWithString:([favorite objectForKey:@"tabtrigger"] && [(NSString*)[favorite objectForKey:@"tabtrigger"] length]) ? [NSString stringWithFormat:@"%@\t%@⇥", [favorite objectForKey:@"name"], [favorite objectForKey:@"tabtrigger"]] : [favorite objectForKey:@"name"]
3426
+ attributes:attributes] autorelease];
3426
3427
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
3427
3428
if ([favorite objectForKey:@"query"]) {
3428
3429
[item setToolTip:[NSString stringWithString:[favorite objectForKey:@"query"]]];
@@ -3434,21 +3435,22 @@ - (void)queryFavoritesHaveBeenUpdated:(id)manager
3434
3435
}
3435
3436
3436
3437
// Build global list
3437
- headerMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Global",@"Query Favorites : List : Section Heading : global query favorites") action:NULL keyEquivalent:@""];
3438
- [headerMenuItem setTag:SP_FAVORITE_HEADER_MENUITEM_TAG];
3439
- [headerMenuItem setToolTip:NSLocalizedString(@"Globally stored favorites",@"Query Favorites : List : Section Heading : global : tooltip")];
3440
- [headerMenuItem setIndentationLevel:0];
3441
- [menu addItem:headerMenuItem];
3442
- [headerMenuItem release];
3438
+ {
3439
+ NSMenuItem *headerMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Global",@"Query Favorites : List : Section Heading : global query favorites") action:NULL keyEquivalent:@""];
3440
+ [headerMenuItem setTag:SP_FAVORITE_HEADER_MENUITEM_TAG];
3441
+ [headerMenuItem setToolTip:NSLocalizedString(@"Globally stored favorites",@"Query Favorites : List : Section Heading : global : tooltip")];
3442
+ [headerMenuItem setIndentationLevel:0];
3443
+ [menu addItem:headerMenuItem];
3444
+ [headerMenuItem release];
3445
+ }
3443
3446
for (NSDictionary *favorite in [prefs objectForKey:SPQueryFavorites]) {
3444
3447
if (![favorite isKindOfClass:[NSDictionary class]] || ![favorite objectForKey:@"name"]) continue;
3445
3448
NSMutableParagraphStyle *paraStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
3446
3449
[paraStyle setTabStops:@[]];
3447
3450
[paraStyle addTabStop:[[[NSTextTab alloc] initWithType:NSRightTabStopType location:190.0f] autorelease]];
3448
3451
NSDictionary *attributes = @{NSParagraphStyleAttributeName : paraStyle, NSFontAttributeName : [NSFont systemFontOfSize:11]};
3449
- NSAttributedString *titleString = [[[NSAttributedString alloc]
3450
- initWithString:([favorite objectForKey:@"tabtrigger"] && [(NSString*)[favorite objectForKey:@"tabtrigger"] length]) ? [NSString stringWithFormat:@"%@\t%@⇥", [favorite objectForKey:@"name"], [favorite objectForKey:@"tabtrigger"]] : [favorite objectForKey:@"name"]
3451
- attributes:attributes] autorelease];
3452
+ NSAttributedString *titleString = [[[NSAttributedString alloc] initWithString:([favorite objectForKey:@"tabtrigger"] && [(NSString*)[favorite objectForKey:@"tabtrigger"] length]) ? [NSString stringWithFormat:@"%@\t%@⇥", [favorite objectForKey:@"name"], [favorite objectForKey:@"tabtrigger"]] : [favorite objectForKey:@"name"]
3453
+ attributes:attributes] autorelease];
3452
3454
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
3453
3455
if ([favorite objectForKey:@"query"]) {
3454
3456
[item setToolTip:[NSString stringWithString:[favorite objectForKey:@"query"]]];
@@ -3991,6 +3993,10 @@ - (void)awakeFromNib
3991
3993
selector:@selector(documentWillClose:)
3992
3994
name:SPDocumentWillCloseNotification
3993
3995
object:tableDocumentInstance];
3996
+ [[NSNotificationCenter defaultCenter] addObserver:self
3997
+ selector:@selector(queryFavoritesHaveBeenUpdated:)
3998
+ name:SPQueryFavoritesHaveBeenUpdatedNotification
3999
+ object:nil];
3994
4000
3995
4001
#ifndef SP_CODA
3996
4002
[prefs addObserver:self forKeyPath:SPGlobalResultTableFont options:NSKeyValueObservingOptionNew context:NULL];
0 commit comments