aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
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];