aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPContentFilterManager.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-10-01 16:35:44 +0000
committerBibiko <bibiko@eva.mpg.de>2009-10-01 16:35:44 +0000
commitcf243d99127441ce2fd3b4641427cb49ab155402 (patch)
treef06c68cc3abfe7e5fb0695b4203a683147ab83b3 /Source/SPContentFilterManager.m
parent11c7eea329acef790b667a27312a09528364140c (diff)
downloadsequelpro-cf243d99127441ce2fd3b4641427cb49ab155402.tar.gz
sequelpro-cf243d99127441ce2fd3b4641427cb49ab155402.tar.bz2
sequelpro-cf243d99127441ce2fd3b4641427cb49ab155402.zip
• first implementation of a Content Filter Editor
- user-defined content filter can be saved globally (Prefs) or in SPF files - BETA - further tests are needed due to complexity - SPQueryController now handles the local user-defined content filters - tooltips are now generated automatically if not defined explicitly (incl. if $BINARY placeholder was used) • if user added local query favorites or content filters to an Untitled document and s/he wants to close it the standard sheet will be displayed (Don't Save - Cancel - Save) - due to that changed old [TableDocument displayName] to 'displaySPName' to be conform with Cocoa • changed behavior while importing query favorites - now they will append at the list (not inserted after selected row - makes more sense) • introduced to history filter dict the key 'menuLabel' which will be set to [TableContent tableFilterString] for displaying the history menu title and simplified the SPHistoryController logic for that • minor code changes
Diffstat (limited to 'Source/SPContentFilterManager.m')
-rw-r--r--Source/SPContentFilterManager.m78
1 files changed, 36 insertions, 42 deletions
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