diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-02-05 16:41:07 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-02-05 16:41:07 +0000 |
commit | 843eeb2b7af11b97bdcdb9f332a9ee44dae49c0f (patch) | |
tree | e81636cae149f61f50cf07eb89cf66ec50e38581 /Source | |
parent | 004b17bd21089d22f353a8fea7790ec4d3982325 (diff) | |
download | sequelpro-843eeb2b7af11b97bdcdb9f332a9ee44dae49c0f.tar.gz sequelpro-843eeb2b7af11b97bdcdb9f332a9ee44dae49c0f.tar.bz2 sequelpro-843eeb2b7af11b97bdcdb9f332a9ee44dae49c0f.zip |
• fixed synchronisation of history lists if more than one instance of the same SPF file is open
- simplified code a bit
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CustomQuery.h | 3 | ||||
-rw-r--r-- | Source/CustomQuery.m | 48 | ||||
-rw-r--r-- | Source/SPQueryController.m | 6 |
3 files changed, 25 insertions, 32 deletions
diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h index 8994a7e3..15f0dba6 100644 --- a/Source/CustomQuery.h +++ b/Source/CustomQuery.h @@ -210,6 +210,9 @@ - (NSString *)usedQuery; - (NSString *)argumentForRow:(NSUInteger)rowIndex ofTable:(NSString *)tableForColumn andDatabase:(NSString *)database; - (NSUInteger)numberOfQueries; + - (NSString *)buildHistoryString; +- (void)historyItemsHaveBeenUpdated:(id)manager; + @end diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 4a0d343a..656b3063 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -267,8 +267,6 @@ currentHistoryOffsetIndex++; if ( numberOfHistoryItems > 0 && currentHistoryOffsetIndex < numberOfHistoryItems && currentHistoryOffsetIndex >= 0) { historyItemWasJustInserted = YES; - // if(![textView selectedRange].length) - // [textView setSelectedRange:currentQueryRange]; [textView breakUndoCoalescing]; NSString *historyString = [[[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]] objectAtIndex:currentHistoryOffsetIndex]; NSRange rangeOfInsertedString = NSMakeRange([textView selectedRange].location, [historyString length]); @@ -286,8 +284,6 @@ currentHistoryOffsetIndex--; if ( numberOfHistoryItems > 0 && currentHistoryOffsetIndex < numberOfHistoryItems && currentHistoryOffsetIndex >= 0) { historyItemWasJustInserted = YES; - // if(![textView selectedRange].length) - // [textView setSelectedRange:currentQueryRange]; [textView breakUndoCoalescing]; NSString *historyString = [[[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]] objectAtIndex:currentHistoryOffsetIndex]; NSRange rangeOfInsertedString = NSMakeRange([textView selectedRange].location, [historyString length]); @@ -721,13 +717,7 @@ [[SPQueryController sharedQueryController] addHistory:usedQuery forFileURL:[tableDocumentInstance fileURL]]; // Refresh history popup menu - NSMenu* historyMenu = [queryHistoryButton menu]; - while([queryHistoryButton numberOfItems] > 7) - [queryHistoryButton removeItemAtIndex:[queryHistoryButton numberOfItems]-1]; - - for(id historyMenuItem in [[SPQueryController sharedQueryController] historyMenuItemsForFileURL:[tableDocumentInstance fileURL]]) - [historyMenu addItem:historyMenuItem]; - + [self historyItemsHaveBeenUpdated:self]; } // Error checking @@ -1327,17 +1317,8 @@ [autouppercaseKeywordsMenuItem setState:([prefs boolForKey:SPCustomQueryAutoUppercaseKeywords]?NSOnState:NSOffState)]; if ( [[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]] ) - { - NSMenu* historyMenu = [queryHistoryButton menu]; - // remove items up to the last separator beginning from the end - while([queryHistoryButton numberOfItems] > 7) - [queryHistoryButton removeItemAtIndex:[queryHistoryButton numberOfItems]-1]; + [self historyItemsHaveBeenUpdated:self]; - // Add history items - for(id historyMenuItem in [[SPQueryController sharedQueryController] historyMenuItemsForFileURL:[tableDocumentInstance fileURL]]) - [historyMenu addItem:historyMenuItem]; - } - // Populate query favorites [self queryFavoritesHaveBeenUpdated:nil]; @@ -2713,10 +2694,23 @@ #pragma mark Query favorites manager delegate methods /** + * Rebuild history popup menu. + */ +- (void)historyItemsHaveBeenUpdated:(id)manager +{ + // Refresh history popup menu + NSMenu* historyMenu = [queryHistoryButton menu]; + while([queryHistoryButton numberOfItems] > 7) + [queryHistoryButton removeItemAtIndex:[queryHistoryButton numberOfItems]-1]; + + for(id historyMenuItem in [[SPQueryController sharedQueryController] historyMenuItemsForFileURL:[tableDocumentInstance fileURL]]) + [historyMenu addItem:historyMenuItem]; +} +/** * Called by the query favorites manager whenever the query favorites have been updated. */ - (void)queryFavoritesHaveBeenUpdated:(id)manager -{ +{ NSMenuItem *headerMenuItem; NSMenu *menu = [queryFavoritesButton menu]; @@ -2856,18 +2850,8 @@ if ([contextInfo isEqualToString:@"clearHistory"]) { if (returnCode == NSOKButton) { - - // Remove all history buttons up to the search field and separator beginning from the end - while([queryHistoryButton numberOfItems] > 7) - [queryHistoryButton removeItemAtIndex:[queryHistoryButton numberOfItems]-1]; - - // Clear the global history list if doc is Untitled - if ([tableDocumentInstance isUntitled]) - [prefs setObject:[NSArray array] forKey:SPQueryHistory]; - // Remove items in the query controller [[SPQueryController sharedQueryController] replaceHistoryByArray:[NSMutableArray array] forFileURL:[tableDocumentInstance fileURL]]; - } return; } diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m index ae83a25d..0ff0fac7 100644 --- a/Source/SPQueryController.m +++ b/Source/SPQueryController.m @@ -584,6 +584,12 @@ static SPQueryController *sharedQueryController = nil; { if([historyContainer objectForKey:[fileURL absoluteString]]) [historyContainer setObject:historyArray forKey:[fileURL absoluteString]]; + + // Inform all opened documents to update the history list + for(id doc in [[NSDocumentController sharedDocumentController] documents]) + if([[doc valueForKeyPath:@"customQueryInstance"] respondsToSelector:@selector(historyItemsHaveBeenUpdated:)]) + [[doc valueForKeyPath:@"customQueryInstance"] historyItemsHaveBeenUpdated:self]; + } - (void)addFavorite:(NSDictionary *)favorite forFileURL:(NSURL *)fileURL |