aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--Resources/English.lproj/ContentFilters.plist32
-rw-r--r--Source/TableContent.h1
-rw-r--r--Source/TableContent.m30
3 files changed, 53 insertions, 10 deletions
diff --git a/Resources/English.lproj/ContentFilters.plist b/Resources/English.lproj/ContentFilters.plist
index 7ee9e8b1..5d79edc0 100644
--- a/Resources/English.lproj/ContentFilters.plist
+++ b/Resources/English.lproj/ContentFilters.plist
@@ -105,7 +105,9 @@
<key>NumberOfArguments</key>
<integer>1</integer>
<key>Clause</key>
- <string>LIKE '${}'</string>
+ <string>LIKE $BINARY '${}'</string>
+ <key>Tooltip</key>
+ <string>Press ⇧ for case-sensitive search.</string>
</dict>
<dict>
<key>MenuLabel</key>
@@ -113,7 +115,9 @@
<key>NumberOfArguments</key>
<integer>1</integer>
<key>Clause</key>
- <string>NOT LIKE '${}'</string>
+ <string>NOT LIKE $BINARY '${}'</string>
+ <key>Tooltip</key>
+ <string>Press ⇧ for case-sensitive search.</string>
</dict>
<dict>
<key>MenuLabel</key>
@@ -121,7 +125,9 @@
<key>NumberOfArguments</key>
<integer>1</integer>
<key>Clause</key>
- <string>LIKE '%${}%'</string>
+ <string>LIKE $BINARY '%${}%'</string>
+ <key>Tooltip</key>
+ <string>Press ⇧ for case-sensitive search.</string>
</dict>
<dict>
<key>MenuLabel</key>
@@ -129,7 +135,9 @@
<key>NumberOfArguments</key>
<integer>1</integer>
<key>Clause</key>
- <string>NOT LIKE '%${}%'</string>
+ <string>NOT LIKE $BINARY '%${}%'</string>
+ <key>Tooltip</key>
+ <string>Press ⇧ for case-sensitive search.</string>
</dict>
<dict>
<key>MenuLabel</key>
@@ -137,7 +145,9 @@
<key>NumberOfArguments</key>
<integer>1</integer>
<key>Clause</key>
- <string>LIKE '${}'</string>
+ <string>LIKE $BINARY '${}'</string>
+ <key>Tooltip</key>
+ <string>Press ⇧ for case-sensitive search.</string>
</dict>
<dict>
<key>MenuLabel</key>
@@ -145,7 +155,9 @@
<key>NumberOfArguments</key>
<integer>1</integer>
<key>Clause</key>
- <string>NOT LIKE '${}'</string>
+ <string>NOT LIKE $BINARY '${}'</string>
+ <key>Tooltip</key>
+ <string>Press ⇧ for case-sensitive search.</string>
</dict>
<dict>
<key>MenuLabel</key>
@@ -167,7 +179,9 @@
<string>AND</string>
</array>
<key>Clause</key>
- <string>BETWEEN '${}' AND '${}'</string>
+ <string>BETWEEN $BINARY '${}' AND '${}'</string>
+ <key>Tooltip</key>
+ <string>Press ⇧ for case-sensitive search.</string>
</dict>
<dict>
<key>MenuLabel</key>
@@ -187,7 +201,7 @@
</dict>
<dict>
<key>MenuLabel</key>
- <string>IS EMPTY</string>
+ <string>is empty</string>
<key>NumberOfArguments</key>
<integer>0</integer>
<key>Clause</key>
@@ -195,7 +209,7 @@
</dict>
<dict>
<key>MenuLabel</key>
- <string>IS NOT EMPTY</string>
+ <string>is not empty</string>
<key>NumberOfArguments</key>
<integer>0</integer>
<key>Clause</key>
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];