diff options
-rw-r--r-- | Source/SPConstants.h | 1 | ||||
-rw-r--r-- | Source/SPConstants.m | 1 | ||||
-rw-r--r-- | Source/SPCustomQuery.m | 62 | ||||
-rw-r--r-- | Source/SPDatabaseDocument.m | 6 | ||||
-rw-r--r-- | Source/SPQueryFavoriteManager.h | 6 | ||||
-rw-r--r-- | Source/SPQueryFavoriteManager.m | 6 |
6 files changed, 37 insertions, 45 deletions
diff --git a/Source/SPConstants.h b/Source/SPConstants.h index 34da4f65..9316413d 100644 --- a/Source/SPConstants.h +++ b/Source/SPConstants.h @@ -451,6 +451,7 @@ extern NSString *SPSelectionDetailTypePrimaryKeyed; extern NSString *SPSSHEnableMuxingPreference; extern NSString *SPSSHClientPath; extern NSString *SPSSLCipherListKey; +extern NSString *SPQueryFavoritesHaveBeenUpdatedNotification; // URLs extern NSString *SPDonationsURL; diff --git a/Source/SPConstants.m b/Source/SPConstants.m index 1f27e5f1..5e0cdd2e 100644 --- a/Source/SPConstants.m +++ b/Source/SPConstants.m @@ -248,6 +248,7 @@ NSString *SPSelectionDetailTypePrimaryKeyed = @"SelectionDetailTypePrimaryK NSString *SPSSHEnableMuxingPreference = @"SSHMultiplexingEnabled"; NSString *SPSSHClientPath = @"SSHClientPath"; NSString *SPSSLCipherListKey = @"SSLCipherList"; +NSString *SPQueryFavoritesHaveBeenUpdatedNotification = @"QueryFavoritesHaveBeenUpdatedNotification"; // URLs NSString *SPDonationsURL = @"http://www.sequelpro.com/donate/"; diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m index c14c275d..abd4c2a8 100644 --- a/Source/SPCustomQuery.m +++ b/Source/SPCustomQuery.m @@ -71,6 +71,7 @@ - (id)_resultDataItemAtRow:(NSInteger)row columnIndex:(NSUInteger)column preserveNULLs:(BOOL)preserveNULLs asPreview:(BOOL)asPreview; + (NSString *)linkToHelpTopic:(NSString *)aTopic; - (void)documentWillClose:(NSNotification *)notification; +- (void)queryFavoritesHaveBeenUpdated:(NSNotification *)notification; @end @@ -3391,9 +3392,14 @@ /** * Called by the query favorites manager whenever the query favorites have been updated. */ -- (void)queryFavoritesHaveBeenUpdated:(id)manager +- (void)queryFavoritesHaveBeenUpdated:(NSNotification *)notification { - NSMenuItem *headerMenuItem; + NSURL *fileURL = [tableDocumentInstance fileURL]; + + // Warning: This method may be called before any connection has been made in the current tab (triggered by another tab)! + // There doesn't seem to be a real indicator for this, but fileURL is the closest thing plus we need it below (#2266) + if(!fileURL) return; + NSMenu *menu = [queryFavoritesButton menu]; // Remove all favorites beginning from the end @@ -3401,28 +3407,23 @@ [queryFavoritesButton removeItemAtIndex:[queryFavoritesButton numberOfItems]-1]; // Build document-based list - NSString *tblDocName = [[[[tableDocumentInstance fileURL] absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] lastPathComponent]; - if(!tblDocName) { - //NSMenuItem will not accept nil as title - @throw [NSException exceptionWithName:NSInternalInconsistencyException - reason:[NSString stringWithFormat:@"Document name conversion resulted in nil string!? tableDocumentInstance=%@ fileURL=%@",tableDocumentInstance,[tableDocumentInstance fileURL]] - userInfo:nil]; - } - headerMenuItem = [[NSMenuItem alloc] initWithTitle:tblDocName action:NULL keyEquivalent:@""]; - [headerMenuItem setTag:SP_FAVORITE_HEADER_MENUITEM_TAG]; - [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]]; - [headerMenuItem setIndentationLevel:0]; - [menu addItem:headerMenuItem]; - [headerMenuItem release]; - for (NSDictionary *favorite in [[SPQueryController sharedQueryController] favoritesForFileURL:[tableDocumentInstance fileURL]]) { + NSString *tblDocName = [[[fileURL absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] lastPathComponent]; + { + NSMenuItem *headerMenuItem = [[NSMenuItem alloc] initWithTitle:tblDocName action:NULL keyEquivalent:@""]; + [headerMenuItem setTag:SP_FAVORITE_HEADER_MENUITEM_TAG]; + [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]]; + [headerMenuItem setIndentationLevel:0]; + [menu addItem:headerMenuItem]; + [headerMenuItem release]; + } + for (NSDictionary *favorite in [[SPQueryController sharedQueryController] favoritesForFileURL:fileURL]) { if (![favorite isKindOfClass:[NSDictionary class]] || ![favorite objectForKey:@"name"]) continue; NSMutableParagraphStyle *paraStyle = [[[NSMutableParagraphStyle alloc] init] autorelease]; [paraStyle setTabStops:@[]]; [paraStyle addTabStop:[[[NSTextTab alloc] initWithType:NSRightTabStopType location:190.0f] autorelease]]; NSDictionary *attributes = @{NSParagraphStyleAttributeName : paraStyle, NSFontAttributeName : [NSFont systemFontOfSize:11]}; - 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"] - attributes:attributes] autorelease]; + 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"] + attributes:attributes] autorelease]; NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""]; if ([favorite objectForKey:@"query"]) { [item setToolTip:[NSString stringWithString:[favorite objectForKey:@"query"]]]; @@ -3434,21 +3435,22 @@ } // Build global list - headerMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Global",@"Query Favorites : List : Section Heading : global query favorites") action:NULL keyEquivalent:@""]; - [headerMenuItem setTag:SP_FAVORITE_HEADER_MENUITEM_TAG]; - [headerMenuItem setToolTip:NSLocalizedString(@"Globally stored favorites",@"Query Favorites : List : Section Heading : global : tooltip")]; - [headerMenuItem setIndentationLevel:0]; - [menu addItem:headerMenuItem]; - [headerMenuItem release]; + { + NSMenuItem *headerMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Global",@"Query Favorites : List : Section Heading : global query favorites") action:NULL keyEquivalent:@""]; + [headerMenuItem setTag:SP_FAVORITE_HEADER_MENUITEM_TAG]; + [headerMenuItem setToolTip:NSLocalizedString(@"Globally stored favorites",@"Query Favorites : List : Section Heading : global : tooltip")]; + [headerMenuItem setIndentationLevel:0]; + [menu addItem:headerMenuItem]; + [headerMenuItem release]; + } for (NSDictionary *favorite in [prefs objectForKey:SPQueryFavorites]) { if (![favorite isKindOfClass:[NSDictionary class]] || ![favorite objectForKey:@"name"]) continue; NSMutableParagraphStyle *paraStyle = [[[NSMutableParagraphStyle alloc] init] autorelease]; [paraStyle setTabStops:@[]]; [paraStyle addTabStop:[[[NSTextTab alloc] initWithType:NSRightTabStopType location:190.0f] autorelease]]; NSDictionary *attributes = @{NSParagraphStyleAttributeName : paraStyle, NSFontAttributeName : [NSFont systemFontOfSize:11]}; - 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"] - attributes:attributes] autorelease]; + 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"] + attributes:attributes] autorelease]; NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""]; if ([favorite objectForKey:@"query"]) { [item setToolTip:[NSString stringWithString:[favorite objectForKey:@"query"]]]; @@ -3991,6 +3993,10 @@ selector:@selector(documentWillClose:) name:SPDocumentWillCloseNotification object:tableDocumentInstance]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(queryFavoritesHaveBeenUpdated:) + name:SPQueryFavoritesHaveBeenUpdatedNotification + object:nil]; #ifndef SP_CODA [prefs addObserver:self forKeyPath:SPGlobalResultTableFont options:NSKeyValueObservingOptionNew context:NULL]; diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 358f9946..d436fbd1 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -425,8 +425,6 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; #ifndef SP_CODA // Set the fileURL and init the preferences (query favs, filters, and history) if available for that URL NSURL *newURL = [[SPQueryController sharedQueryController] registerDocumentWithFileURL:[self fileURL] andContextInfo:spfPreferences]; -#warning debug code for #2266 - if(!newURL) NSLog(@"#2266: Trying to set nil fileURL in %s from queryController=%@ oldFileURL=%@ contextInfo=%@", __func__, [SPQueryController sharedQueryController], [self fileURL], spfPreferences); [self setFileURL:newURL]; // ...but hide the icon while the document is temporary @@ -3569,8 +3567,6 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; [[SPQueryController sharedQueryController] registerDocumentWithFileURL:[NSURL fileURLWithPath:fileName] andContextInfo:preferences]; NSURL *newURL = [NSURL fileURLWithPath:fileName]; -#warning debug code for #2266 - if(!newURL) NSLog(@"#2266: Trying to set nil fileURL in %s from fileName=%@", __func__, fileName); [self setFileURL:newURL]; [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL fileURLWithPath:fileName]]; @@ -5132,8 +5128,6 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; if (![self isSaveInBundle]) { NSURL *newURL = [NSURL fileURLWithPath:path]; -#warning debug code for #2266 - if(!newURL) NSLog(@"#2266: Trying to set nil fileURL in %s from path=%@", __func__, path); [self setFileURL:newURL]; } diff --git a/Source/SPQueryFavoriteManager.h b/Source/SPQueryFavoriteManager.h index 0f0141bf..f1527b40 100644 --- a/Source/SPQueryFavoriteManager.h +++ b/Source/SPQueryFavoriteManager.h @@ -32,12 +32,6 @@ @class SPDatabaseDocument; @class SPSplitView; -@interface NSObject (SPQueryFavoriteManagerDelegate) - -- (void)queryFavoritesHaveBeenUpdated:(id)manager; - -@end - @interface SPQueryFavoriteManager : NSWindowController <NSOpenSavePanelDelegate> { #ifndef SP_CODA /* ivars */ diff --git a/Source/SPQueryFavoriteManager.m b/Source/SPQueryFavoriteManager.m index 4351ae52..296f465e 100644 --- a/Source/SPQueryFavoriteManager.m +++ b/Source/SPQueryFavoriteManager.m @@ -38,8 +38,6 @@ #import "RegexKitLite.h" #import "SPTextView.h" #import "SPSplitView.h" -#import "SPAppController.h" -#import "SPAppleScriptSupport.h" #define SP_MULTIPLE_SELECTION_PLACEHOLDER_STRING NSLocalizedString(@"[multiple selection]", @"[multiple selection]") #define SP_NO_SELECTION_PLACEHOLDER_STRING NSLocalizedString(@"[no selection]", @"[no selection]") @@ -486,9 +484,7 @@ [prefs setObject:[self queryFavoritesForFileURL:nil] forKey:SPQueryFavorites]; // Inform all opened documents to update the query favorites list - for(id doc in [SPAppDelegate orderedDocuments]) - if([[doc valueForKeyPath:@"customQueryInstance"] respondsToSelector:@selector(queryFavoritesHaveBeenUpdated:)]) - [[doc valueForKeyPath:@"customQueryInstance"] queryFavoritesHaveBeenUpdated:self]; + [[NSNotificationCenter defaultCenter] postNotificationName:SPQueryFavoritesHaveBeenUpdatedNotification object:self]; } #endif |