aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPCustomQuery.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/SPCustomQuery.m')
-rw-r--r--Source/SPCustomQuery.m75
1 files changed, 45 insertions, 30 deletions
diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m
index 0f880e8c..bddb0b6c 100644
--- a/Source/SPCustomQuery.m
+++ b/Source/SPCustomQuery.m
@@ -70,6 +70,8 @@
- (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;
+- (void)historyItemsHaveBeenUpdated:(NSNotification *)notification;
@end
@@ -1619,7 +1621,7 @@
#ifndef SP_CODA
if ( [[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]] )
- [self performSelectorOnMainThread:@selector(historyItemsHaveBeenUpdated:) withObject:self waitUntilDone:YES];
+ [self performSelectorOnMainThread:@selector(historyItemsHaveBeenUpdated:) withObject:nil waitUntilDone:YES];
// Populate query favorites
[self queryFavoritesHaveBeenUpdated:nil];
@@ -3367,8 +3369,12 @@
/**
* Rebuild history popup menu.
+ *
+ * Warning: notification may be nil if invoked directly from within this class.
+ *
+ * MUST BE CALLED ON THE UI THREAD!
*/
-- (void)historyItemsHaveBeenUpdated:(id)manager
+- (void)historyItemsHaveBeenUpdated:(NSNotification *)notification
{
// Abort if the connection has been closed already - sign of a closed window
if (![mySQLConnection isConnected]) return;
@@ -3390,9 +3396,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
@@ -3400,28 +3411,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"]]];
@@ -3433,21 +3439,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"]]];
@@ -3990,6 +3997,14 @@
selector:@selector(documentWillClose:)
name:SPDocumentWillCloseNotification
object:tableDocumentInstance];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(queryFavoritesHaveBeenUpdated:)
+ name:SPQueryFavoritesHaveBeenUpdatedNotification
+ object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(historyItemsHaveBeenUpdated:)
+ name:SPHistoryItemsHaveBeenUpdatedNotification
+ object:nil];
#ifndef SP_CODA
[prefs addObserver:self forKeyPath:SPGlobalResultTableFont options:NSKeyValueObservingOptionNew context:NULL];