From 843eeb2b7af11b97bdcdb9f332a9ee44dae49c0f Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 5 Feb 2010 16:41:07 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20synchronisation=20of=20history=20li?= =?UTF-8?q?sts=20if=20more=20than=20one=20instance=20of=20the=20same=20SPF?= =?UTF-8?q?=20file=20is=20open=20-=20=20simplified=20code=20a=20bit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CustomQuery.m | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) (limited to 'Source/CustomQuery.m') 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]; @@ -2712,11 +2693,24 @@ #pragma mark - #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; } -- cgit v1.2.3