From 931a46891ac3f0610363105419b01eb7b40b034f Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 4 Sep 2009 08:45:47 +0000 Subject: =?UTF-8?q?=E2=80=A2=20implementation=20of=20a=20new=20history=20c?= =?UTF-8?q?ontroller=20-=20each=20history=20is=20doc-based=20even=20if=20y?= =?UTF-8?q?ou=20have=20opened=20not=20only=20one=20instance=20of=20the=20s?= =?UTF-8?q?ame=20spf=20file=20-=20for=20each=20SPF=20file=20identified=20b?= =?UTF-8?q?y=20its=20file=20URL=20SP=20remembers=20each=20history=20item?= =?UTF-8?q?=20regardless=20from=20which=20doc=20instance=20it=20comes=20fr?= =?UTF-8?q?om=20internally=20(=20to=20make=20sure=20that=20after=20closing?= =?UTF-8?q?=20the=20last=20instance=20of=20a=20doc=20all=20executed=20quer?= =?UTF-8?q?ies=20are=20saved=20in=20that=20file=20-=20if=20the=20user=20wa?= =?UTF-8?q?nts=20to=20change=20that=20s/he=20has=20to=20save=20that=20file?= =?UTF-8?q?=20under=20a=20different=20name=20)=20-=20the=20history=20list?= =?UTF-8?q?=20for=20each=20Untitled=20doc=20will=20be=20initialized=20by?= =?UTF-8?q?=20the=20items=20stored=20in=20the=20global=20SP's=20prefs=20-?= =?UTF-8?q?=20the=20history=20list=20for=20each=20SPF=20doc=20will=20be=20?= =?UTF-8?q?initialized=20by=20the=20items=20stored=20in=20the=20SPF=20file?= =?UTF-8?q?=20unless=20an=20instance=20of=20the=20same=20file=20is=20alrea?= =?UTF-8?q?dy=20open=20-=20then=20the=20new=20instance=20inherits=20the=20?= =?UTF-8?q?history=20list=20from=20the=20opened=20one(s)=20-=20all=20histo?= =?UTF-8?q?ry=20items=20executed=20in=20any=20Untitled=20docs=20will=20be?= =?UTF-8?q?=20added=20to=20SP's=20prefs=20-=20in=20other=20words=20SP's=20?= =?UTF-8?q?global=20prefs=20plist=20is=20the=20historyrepository=20for=20e?= =?UTF-8?q?ach=20new=20Untitled=20doc=20-=20if=20the=20user=20saves=20an?= =?UTF-8?q?=20untitled=20doc=20or=20rename=20an=20opened=20SPF=20file=20th?= =?UTF-8?q?e=20=5Fcurrent=5F=20history=20list=20for=20that=20doc=20will=20?= =?UTF-8?q?be=20saved=20to=20the=20chosen=20file=20unless=20an=20other=20d?= =?UTF-8?q?oc=20instance=20is=20still=20open=20-=20all=20history=20lists?= =?UTF-8?q?=20are=20saved=20automatically=20if=20SP=20quits=20or=20the=20u?= =?UTF-8?q?ser=20closes=20a=20doc=20window?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note: This should be tested for any logical pitfalls - each desired logic can be implemented :) --- Source/CustomQuery.m | 50 ++++++++++++++------------------------------------ 1 file changed, 14 insertions(+), 36 deletions(-) (limited to 'Source/CustomQuery.m') diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 8b8a8968..d679a1de 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -38,6 +38,7 @@ #import "SPTextAndLinkCell.h" #import "SPTooltip.h" #import "SPQueryFavoriteManager.h" +#import "SPQueryController.h" #define SP_MYSQL_DEV_SEARCH_URL @"http://search.mysql.com/search?q=%@&site=refman-%@" #define SP_HELP_SEARCH_IN_MYSQL 0 @@ -238,13 +239,14 @@ { // "Clear History" menu item - clear query history if (sender == clearHistoryMenuItem) { - // Remove all history buttons beginning from the end + + // Remove all history buttons except the search field beginning from the end while([queryHistoryButton numberOfItems] > 2) [queryHistoryButton removeItemAtIndex:[queryHistoryButton numberOfItems]-1]; - // [queryHistoryButton addItemWithTitle:NSLocalizedString(@"Query History…",@"Title of query history popup button")]; - [prefs setObject:[NSArray array] forKey:@"queryHistory"]; - [prefs synchronize]; + // Remove all items from the queryController + [[SPQueryController sharedQueryController] replaceHistoryByArray:[NSMutableArray array] forFileURL:[tableDocumentInstance fileURL]]; + } // "Shift Right" menu item - indent the selection with an additional tab. @@ -340,7 +342,6 @@ NSArray *theColumns; NSTableColumn *theCol; MCPStreamingResult *streamingResult = nil; - NSMutableArray *menuItems = [NSMutableArray array]; NSMutableString *errors = [NSMutableString string]; int i, totalQueriesRun = 0, totalAffectedRows = 0; @@ -491,17 +492,17 @@ // if(!queriesSeparatedByDelimiter) { // TODO only add to history if no “delimiter” command was used if(!tableReloadAfterEditing && [usedQuery length]) { - [queryHistoryButton insertItemWithTitle:usedQuery atIndex:2]; + // Register new history item + [[SPQueryController sharedQueryController] addHistory:usedQuery forFileURL:[tableDocumentInstance fileURL]]; - int maxHistoryItems = [[prefs objectForKey:@"CustomQueryMaxHistoryItems"] intValue]; + // Add it to the document's current popup list + [queryHistoryButton insertItemWithTitle:usedQuery atIndex:2]; + // Check for max history + NSUInteger maxHistoryItems = [[prefs objectForKey:@"CustomQueryMaxHistoryItems"] intValue]; while ( [queryHistoryButton numberOfItems] > maxHistoryItems + 2 ) [queryHistoryButton removeItemAtIndex:[queryHistoryButton numberOfItems]-1]; - for ( i = 2 ; i < [queryHistoryButton numberOfItems] ; i++ ) - [menuItems addObject:[queryHistoryButton itemTitleAtIndex:i]]; - - [prefs setObject:menuItems forKey:@"queryHistory"]; } // Error checking @@ -1057,23 +1058,6 @@ return currentResult; } -/* - * Return the document-based favourites - */ -- (NSArray *)localFavorites -{ - return localFavorites; -} - -/* - * Return the document-based history items - */ -- (NSArray *)localHistoryItems -{ - return localHistoryItems; -} - - #pragma mark - #pragma mark Additional methods @@ -1113,9 +1097,9 @@ [autouppercaseKeywordsMenuItem setState:([prefs boolForKey:@"CustomQueryAutoUppercaseKeywords"]?NSOnState:NSOffState)]; [textView setAutouppercaseKeywords:[prefs boolForKey:@"CustomQueryAutoUppercaseKeywords"]]; - if ( [prefs objectForKey:@"queryHistory"] ) + if ( [[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]] ) { - [queryHistoryButton addItemsWithTitles:[prefs objectForKey:@"queryHistory"]]; + [queryHistoryButton addItemsWithTitles:[[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]]]; } // Disable runSelectionMenuItem in the gear menu @@ -2575,10 +2559,6 @@ // init tableView's data source fullResult = [[NSMutableArray alloc] init]; - // init local favorite and history item array - localHistoryItems = [[NSMutableArray alloc] init]; - localFavorites = [[NSMutableArray alloc] init]; - prefs = [NSUserDefaults standardUserDefaults]; } @@ -2627,8 +2607,6 @@ [usedQuery release]; [fullResult release]; [favoritesManager release]; - if (localFavorites) [localFavorites release]; - if (localHistoryItems) [localHistoryItems release]; if (sortField) [sortField release]; [super dealloc]; -- cgit v1.2.3