From cf243d99127441ce2fd3b4641427cb49ab155402 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 1 Oct 2009 16:35:44 +0000 Subject: =?UTF-8?q?=E2=80=A2=20first=20implementation=20of=20a=20Content?= =?UTF-8?q?=20Filter=20Editor=20-=20user-defined=20content=20filter=20can?= =?UTF-8?q?=20be=20saved=20globally=20(Prefs)=20or=20in=20SPF=20files=20-?= =?UTF-8?q?=20BETA=20-=20further=20tests=20are=20needed=20due=20to=20compl?= =?UTF-8?q?exity=20-=20SPQueryController=20now=20handles=20the=20local=20u?= =?UTF-8?q?ser-defined=20content=20filters=20-=20tooltips=20are=20now=20ge?= =?UTF-8?q?nerated=20automatically=20if=20not=20defined=20explicitly=20(in?= =?UTF-8?q?cl.=20if=20$BINARY=20placeholder=20was=20used)=20=E2=80=A2=20if?= =?UTF-8?q?=20user=20added=20local=20query=20favorites=20or=20content=20fi?= =?UTF-8?q?lters=20to=20an=20Untitled=20document=20and=20s/he=20wants=20to?= =?UTF-8?q?=20close=20it=20the=20standard=20sheet=20will=20be=20displayed?= =?UTF-8?q?=20(Don't=20Save=20-=20Cancel=20-=20Save)=20-=20due=20to=20that?= =?UTF-8?q?=20changed=20old=20[TableDocument=20displayName]=20to=20'displa?= =?UTF-8?q?ySPName'=20to=20be=20conform=20with=20Cocoa=20=E2=80=A2=20chang?= =?UTF-8?q?ed=20behavior=20while=20importing=20query=20favorites=20-=20now?= =?UTF-8?q?=20they=20will=20append=20at=20the=20list=20(not=20inserted=20a?= =?UTF-8?q?fter=20selected=20row=20-=20makes=20more=20sense)=20=E2=80=A2?= =?UTF-8?q?=20introduced=20to=20history=20filter=20dict=20the=20key=20'men?= =?UTF-8?q?uLabel'=20which=20will=20be=20set=20to=20[TableContent=20tableF?= =?UTF-8?q?ilterString]=20for=20displaying=20the=20history=20menu=20title?= =?UTF-8?q?=20and=20simplified=20the=20SPHistoryController=20logic=20for?= =?UTF-8?q?=20that=20=E2=80=A2=20minor=20code=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPContentFilterManager.m | 78 +++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 42 deletions(-) (limited to 'Source/SPContentFilterManager.m') diff --git a/Source/SPContentFilterManager.m b/Source/SPContentFilterManager.m index 4d15823b..79c629bc 100644 --- a/Source/SPContentFilterManager.m +++ b/Source/SPContentFilterManager.m @@ -27,6 +27,7 @@ #import "ImageAndTextCell.h" #import "RegexKitLite.h" #import "SPQueryController.h" +#import "TableContent.h" #define DEFAULT_SEQUELPRO_FILE_EXTENSION @"spf" @@ -58,6 +59,7 @@ return nil; } delegatesFileURL = [[managerDelegate valueForKeyPath:@"tableDocumentInstance"] fileURL]; + filterType = [NSString stringWithString:compareType]; } @@ -96,7 +98,7 @@ @"", @"ConjunctionLabel", nil]]; - // Build data source for global queryFavorites (as mutable copy! otherwise each + // Build data source for global content filter (as mutable copy! otherwise each // change will be stored in the prefs at once) if([[prefs objectForKey:@"ContentFilters"] objectForKey:filterType]) { for(id fav in [[prefs objectForKey:@"ContentFilters"] objectForKey:filterType]) { @@ -107,16 +109,18 @@ } } + // Build doc-based filters [contentFilters addObject:[NSDictionary dictionaryWithObjectsAndKeys: [[[delegatesFileURL absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] lastPathComponent], @"MenuLabel", [delegatesFileURL absoluteString], @"headerOfFileURL", @"", @"Clause", nil]]; - - // if([[SPQueryController sharedQueryController] favoritesForFileURL:delegatesFileURL]) { - // for(id fav in [[SPQueryController sharedQueryController] favoritesForFileURL:delegatesFileURL]) - // [contentFilters addObject:[[fav mutableCopy] autorelease]]; - // } + if([[SPQueryController sharedQueryController] contentFilterForFileURL:delegatesFileURL]) { + id filters = [[SPQueryController sharedQueryController] contentFilterForFileURL:delegatesFileURL]; + if([filters objectForKey:filterType]) + for(id fav in [filters objectForKey:filterType]) + [contentFilters addObject:[[fav mutableCopy] autorelease]]; + } // Select the first query if any @@ -351,23 +355,23 @@ // Ensure that last changes will be written back // if only one filter is selected; otherwise unstable state - if ([contentFilterTableView numberOfSelectedRows] == 1) { + if ([contentFilterTableView numberOfSelectedRows] == 1) [[self window] makeFirstResponder:contentFilterTableView]; - } - + // Update current document's content filters in the SPQueryController - // [[SPQueryController sharedQueryController] replaceFavoritesByArray: - // [self contentFilterForFileURL:delegatesFileURL] forFileURL:delegatesFileURL]; - // + [[SPQueryController sharedQueryController] replaceContentFilterByArray: + [self contentFilterForFileURL:delegatesFileURL] ofType:filterType forFileURL:delegatesFileURL]; + // Update global preferences' list id cf = [[prefs objectForKey:@"ContentFilters"] mutableCopy]; [cf setObject:[self contentFilterForFileURL:nil] forKey:filterType]; [prefs setObject:cf forKey:@"ContentFilters"]; - - // // Inform all opened documents to update the query favorites list - // for(id doc in [[NSDocumentController sharedDocumentController] documents]) - // if([[doc valueForKeyPath:@"customQueryInstance"] respondsToSelector:@selector(queryFavoritesHaveBeenUpdated:)]) - // [[doc valueForKeyPath:@"customQueryInstance"] queryFavoritesHaveBeenUpdated:self]; + [cf release]; + + // Inform all opened documents to update the query favorites list + for(id doc in [[NSDocumentController sharedDocumentController] documents]) + if([[doc valueForKeyPath:@"tableContentInstance"] respondsToSelector:@selector(setCompareTypes:)]) + [[doc valueForKeyPath:@"tableContentInstance"] setCompareTypes:nil]; } @@ -762,17 +766,17 @@ } if([[spf objectForKey:@"ContentFilters"] objectForKey:filterType] && [[[spf objectForKey:@"ContentFilters"] objectForKey:filterType] count]) { - if([contentFilterTableView numberOfSelectedRows] > 0) { - // Insert imported filters after the last selected filter - NSUInteger insertIndex = [[contentFilterTableView selectedRowIndexes] lastIndex] + 1; - NSUInteger i; - for(i=0; i<[[[spf objectForKey:@"ContentFilters"] objectForKey:filterType] count]; i++) { - [contentFilters insertObject:[[spf objectForKey:@"queryFavorites"] objectAtIndex:i] atIndex:insertIndex+i]; - } - } else { - // If no selection add them - [contentFilters addObjectsFromArray:[[spf objectForKey:@"ContentFilters"] objectForKey:filterType]]; - } + // if([contentFilterTableView numberOfSelectedRows] > 0) { + // // Insert imported filters after the last selected filter + // NSUInteger insertIndex = [[contentFilterTableView selectedRowIndexes] lastIndex] + 1; + // NSUInteger i; + // for(i=0; i<[[[spf objectForKey:@"ContentFilters"] objectForKey:filterType] count]; i++) { + // [contentFilters insertObject:[[spf objectForKey:@"queryFavorites"] objectAtIndex:i] atIndex:insertIndex+i]; + // } + // } else { + // // If no selection add them + [contentFilters addObjectsFromArray:[[spf objectForKey:@"ContentFilters"] objectForKey:filterType]]; + // } [contentFilterArrayController rearrangeObjects]; [contentFilterTableView reloadData]; } else { @@ -797,23 +801,12 @@ - (void)savePanelDidEnd:(NSSavePanel *)panel returnCode:(int)returnCode contextInfo:(NSString *)contextInfo { - if([contextInfo isEqualToString:@"saveQuery"]) { - if (returnCode == NSOKButton) { - NSError *error = nil; - - [prefs setInteger:[[encodingPopUp selectedItem] tag] forKey:@"lastSqlFileEncoding"]; - [prefs synchronize]; - - [[contentFilterTextView string] writeToFile:[panel filename] atomically:YES encoding:[[encodingPopUp selectedItem] tag] error:&error]; - - if (error) [[NSAlert alertWithError:error] runModal]; - } - } - else if([contextInfo isEqualToString:@"exportFavorites"]) { + if([contextInfo isEqualToString:@"exportFilter"]) { if (returnCode == NSOKButton) { // Build a SPF with format = "content filters" NSMutableDictionary *spfdata = [NSMutableDictionary dictionary]; + NSMutableDictionary *cfdata = [NSMutableDictionary dictionary]; NSMutableArray *filterData = [NSMutableArray array]; @@ -829,7 +822,8 @@ if([indexes containsIndex:i]) [filterData addObject:[contentFilters objectAtIndex:i]]; - [spfdata setObject:filterData forKey:@"ContentFilter"]; + [cfdata setObject:filterData forKey:filterType]; + [spfdata setObject:cfdata forKey:@"ContentFilters"]; NSString *err = nil; NSData *plist = [NSPropertyListSerialization dataFromPropertyList:spfdata -- cgit v1.2.3