aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2018-01-17 01:04:38 +0100
committerMax <post@wickenrode.com>2018-01-17 01:04:38 +0100
commit74b18eee1821ec8ec5bd472cd5ddb80eb865c1ed (patch)
tree90a084f7f1ae5c7c408a505cfaa5a66d0076b2b6
parentc31bc038da3008d765bb07e51c5cc2dbf8448a2d (diff)
downloadsequelpro-74b18eee1821ec8ec5bd472cd5ddb80eb865c1ed.tar.gz
sequelpro-74b18eee1821ec8ec5bd472cd5ddb80eb865c1ed.tar.bz2
sequelpro-74b18eee1821ec8ec5bd472cd5ddb80eb865c1ed.zip
Work around an exception that would occur when changing Query Favorites while an unconnected connection tab existed (#2266)
-rw-r--r--Source/SPConstants.h1
-rw-r--r--Source/SPConstants.m1
-rw-r--r--Source/SPCustomQuery.m62
-rw-r--r--Source/SPDatabaseDocument.m6
-rw-r--r--Source/SPQueryFavoriteManager.h6
-rw-r--r--Source/SPQueryFavoriteManager.m6
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