aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-09-28 15:40:26 +0000
committerBibiko <bibiko@eva.mpg.de>2009-09-28 15:40:26 +0000
commita35320cccdf35ed167c65000f76f2cb4127e55ea (patch)
tree8e979e8f6c547b3511c29004c39fb1f3a0c5d46e /Source
parente924e2ece4512233fa5ad020fecce25307c715a2 (diff)
downloadsequelpro-a35320cccdf35ed167c65000f76f2cb4127e55ea.tar.gz
sequelpro-a35320cccdf35ed167c65000f76f2cb4127e55ea.tar.bz2
sequelpro-a35320cccdf35ed167c65000f76f2cb4127e55ea.zip
• fixed an issue of double-loading user-defined filters
• introduce a new placeholder $BINARY to the filter definition - if user presses ⇧ while invoking the table filter and a filter had defined that placeholder the search will be case-sensitive; otherwise the placeholder $BINARY will be simply removed to search case-insensitive - added tooltip for these string filters in ContentFilters.plist
Diffstat (limited to 'Source')
-rw-r--r--Source/TableContent.h1
-rw-r--r--Source/TableContent.m30
2 files changed, 30 insertions, 1 deletions
diff --git a/Source/TableContent.h b/Source/TableContent.h
index 0993110a..e2d7237b 100644
--- a/Source/TableContent.h
+++ b/Source/TableContent.h
@@ -68,6 +68,7 @@
int currentlyEditingRow, maxNumRows;
NSMutableDictionary *contentFilters;
+ NSMutableDictionary *numberOfDefaultFilters;
BOOL sortColumnToRestoreIsAsc;
NSString *sortColumnToRestore;
diff --git a/Source/TableContent.m b/Source/TableContent.m
index ccf26181..9d3110b4 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -87,18 +87,26 @@
// Init default filters for Content Browser
contentFilters = nil;
+ contentFilters = [[NSMutableDictionary alloc] init];
+ numberOfDefaultFilters = [[NSMutableDictionary alloc] init];
+
NSError *readError = nil;
NSString *convError = nil;
NSPropertyListFormat format;
NSData *defaultFilterData = [NSData dataWithContentsOfFile:[NSBundle pathForResource:@"ContentFilters.plist" ofType:nil inDirectory:[[NSBundle mainBundle] bundlePath]]
options:NSMappedRead error:&readError];
- contentFilters = [[NSMutableDictionary alloc] init];
+
[contentFilters setDictionary:[NSPropertyListSerialization propertyListFromData:defaultFilterData
mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&convError]];
if(contentFilters == nil || readError != nil || convError != nil) {
NSLog(@"Error while reading 'ContentFilters.plist':\n%@\n%@", [readError localizedDescription], convError);
NSBeep();
+ } else {
+ [numberOfDefaultFilters setObject:[NSNumber numberWithInt:[[contentFilters objectForKey:@"number"] count]] forKey:@"number"];
+ [numberOfDefaultFilters setObject:[NSNumber numberWithInt:[[contentFilters objectForKey:@"date"] count]] forKey:@"date"];
+ [numberOfDefaultFilters setObject:[NSNumber numberWithInt:[[contentFilters objectForKey:@"string"] count]] forKey:@"string"];
}
+
}
@@ -514,6 +522,12 @@
- (NSString *)tableFilterString
{
+ // If the clause has the placeholder $BINARY that placeholder will be replaced
+ // by BINARY if the user pressed ⇧ while invoking 'Filter' otherwise it will
+ // replaced by @"".
+ BOOL caseSensitive = (([[NSApp currentEvent] modifierFlags]
+ & (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask)) > 0);
+
NSString *filterString;
if(contentFilters == nil) {
@@ -567,6 +581,9 @@
NSMutableString *clause = [[NSMutableString alloc] init];
[clause setString:[filter objectForKey:@"Clause"]];
+ [clause replaceOccurrencesOfRegex:@"\\$BINARY" withString:(caseSensitive) ? @"BINARY" : @""];
+ [clause flushCachedRegexData];
+
// Escape % sign
[clause replaceOccurrencesOfRegex:@"%" withString:@"%%"];
[clause flushCachedRegexData];
@@ -719,6 +736,7 @@
*/
- (IBAction)filterTable:(id)sender
{
+
// Check whether a save of the current row is required.
if (![self saveRowOnDeselect]) return;
@@ -1158,6 +1176,15 @@
// [compareField addItemWithTitle:@"IS NULL"];
// [compareField addItemWithTitle:@"IS NOT NULL"];
+ // Remove user-defined filters first
+ if([numberOfDefaultFilters objectForKey:compareType]) {
+ NSUInteger cycles = [[contentFilters objectForKey:compareType] count] - [[numberOfDefaultFilters objectForKey:compareType] intValue];
+ while(cycles > 0) {
+ [[contentFilters objectForKey:compareType] removeLastObject];
+ cycles--;
+ }
+ }
+
// Load user-defined content filters
if([prefs objectForKey:@"ContentFilters"]
&& [contentFilters objectForKey:compareType]
@@ -2412,6 +2439,7 @@
[dataColumns release];
[oldRow release];
if (contentFilters) [contentFilters release];
+ if (numberOfDefaultFilters) [numberOfDefaultFilters release];
if (keys) [keys release];
if (sortCol) [sortCol release];
[usedQuery release];