aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CustomQuery.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-02-05 16:41:07 +0000
committerBibiko <bibiko@eva.mpg.de>2010-02-05 16:41:07 +0000
commit843eeb2b7af11b97bdcdb9f332a9ee44dae49c0f (patch)
treee81636cae149f61f50cf07eb89cf66ec50e38581 /Source/CustomQuery.m
parent004b17bd21089d22f353a8fea7790ec4d3982325 (diff)
downloadsequelpro-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/CustomQuery.m')
-rw-r--r--Source/CustomQuery.m48
1 files changed, 16 insertions, 32 deletions
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;
}