From 4a132c2c7a1f65893b23fa3684727f475c867754 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 27 Sep 2010 15:11:13 +0000 Subject: =?UTF-8?q?=E2=80=A2=20some=20progress=20on=20the=20filter=20table?= =?UTF-8?q?=20approach?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/DBView.xib | 36 ++++++++++-------- Source/SPTableContent.h | 2 +- Source/SPTableContent.m | 74 ++++++++++++++++++++++++++++--------- 3 files changed, 79 insertions(+), 33 deletions(-) diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index b7d518b6..b8a999ce 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -3,7 +3,7 @@ 1050 10F569 - 804 + 788 1038.29 461.00 @@ -16,13 +16,14 @@ YES - 804 - 804 + 788 + 788 1.2.5 YES + @@ -9283,7 +9284,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {3.40282e+38, 3.40282e+38} {240, 170} - + 256 YES @@ -9484,8 +9485,8 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 MQA - 14 - -624918528 + 16 + -893353984 1 @@ -9550,7 +9551,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 - QSAAAEEgAABBgAAAQYAAAA + QSAAAEEgAABBkAAAQZAAAA {480, 106} @@ -9740,6 +9741,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {480, 270} + {{0, 0}, {1280, 778}} {240, 189} @@ -10113,7 +10115,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 NSView - + 265 YES @@ -10134,7 +10136,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{5, -2}, {101, 22}} - YES 130560 @@ -10151,7 +10152,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 258 {{2, 2}, {105, 14}} - YES 68288064 @@ -10173,8 +10173,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {110, 20} - - NSView @@ -15324,6 +15322,14 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 7535 + + + initialFirstResponder + + + + 7536 + @@ -23690,7 +23696,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin - {{603, 458}, {237, 73}} + {{503, 458}, {237, 73}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -24124,7 +24130,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{59, 203}, {943, 549}} + {{977, 203}, {943, 549}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -24510,7 +24516,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 - 7535 + 7536 diff --git a/Source/SPTableContent.h b/Source/SPTableContent.h index 13ca3d92..fca3fdae 100644 --- a/Source/SPTableContent.h +++ b/Source/SPTableContent.h @@ -203,6 +203,6 @@ - (NSArray*)fieldEditStatusForRow:(NSInteger)rowIndex andColumn:(NSInteger)columnIndex; -- (void)updateFilterTableClause; +- (void)updateFilterTableClause:(NSString*)currentValue; @end diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index b7bcd0f9..295dca4b 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -2820,6 +2820,16 @@ - (IBAction)showTableFilter:(id)sender { [filterTableWindow makeKeyAndOrderFront:nil]; + [filterTableWhereClause setContinuousSpellCheckingEnabled:NO]; + [filterTableWhereClause setAutoindent:NO]; + [filterTableWhereClause setAutoindentIgnoresEnter:NO]; + [filterTableWhereClause setAutopair:[prefs boolForKey:SPCustomQueryAutoPairCharacters]]; + [filterTableWhereClause setAutohelp:NO]; + [filterTableWhereClause setAutouppercaseKeywords:[prefs boolForKey:SPCustomQueryAutoUppercaseKeywords]]; + [filterTableWhereClause setCompletionWasReinvokedAutomatically:NO]; + [filterTableWhereClause insertText:@""]; + [filterTableWhereClause didChangeText]; + [[NSApp keyWindow] makeFirstResponder:filterTableView]; } #pragma mark - @@ -3273,7 +3283,7 @@ { if(aTableView == filterTableView) { [[[filterTableData objectForKey:[aTableColumn identifier]] objectForKey:@"filter"] replaceObjectAtIndex:rowIndex withObject:(NSString*)anObject]; - [self updateFilterTableClause]; + [self updateFilterTableClause:nil]; return; } else if(aTableView == tableContentView) { @@ -3876,7 +3886,7 @@ - (void)controlTextDidChange:(NSNotification *)notification { if ([notification object] == filterTableView) { - [self updateFilterTableClause]; + [self updateFilterTableClause:[[[[notification userInfo] objectForKey:@"NSFieldEditor"] textStorage] string]]; } } /** @@ -4022,42 +4032,72 @@ /** * Update WHERE clause in Filter Table Window - TODO not yet finished - initial approach only by HansJB */ -- (void)updateFilterTableClause +- (void)updateFilterTableClause:(NSString*)currentValue { NSMutableString *clause = [NSMutableString string]; NSInteger numberOfRows = [self numberOfRowsInTableView:filterTableView]; NSInteger numberOfCols = [[filterTableView tableColumns] count]; NSInteger numberOfValues = 0; NSRange opRange; + + NSString *re1 = @"^\\s*(<|>|!?=)\\s*(.*?)\\s*$"; + NSString *re2 = @"(?i)^\\s*(.*)\\s+(.*?)\\s*$"; + NSString *defaultOperator = @"LIKE '%%%@%%'"; + NSCharacterSet *whiteSpaceCharSet = [NSCharacterSet whitespaceAndNewlineCharacterSet]; + for(NSInteger i=0; i"] || - [op isEqualToString:@"<"] || - [op isEqualToString:@"="]) { - [clause appendFormat:@"%@ %@ %@", [[filterCellData objectForKey:@"name"] backtickQuotedString], op, pattern]; - } - } else { - [clause appendFormat:@"%@ LIKE '%%%@%%'", [[filterCellData objectForKey:@"name"] backtickQuotedString], filterCell]; + NSString *fieldName = [[filterCellData objectForKey:@"name"] backtickQuotedString]; + + opRange = [filterCell rangeOfString:@"`@`"]; + if(opRange.length) { + filterCell = [filterCell stringByReplacingOccurrencesOfString:@"`@`" withString:fieldName]; + [clause appendString:[filterCell stringByReplacingOccurrencesOfString:@"`@`" withString:fieldName]]; + } + else if([filterCell isMatchedByRegex:@"(?i)^\\s*null\\s*$"]) { + [clause appendFormat:@"%@ IS NULL", fieldName]; + } + else if([filterCell isMatchedByRegex:re1]) { + NSArray *matches = [filterCell arrayOfCaptureComponentsMatchedByRegex:re1]; + if([matches count] && [matches = NSArrayObjectAtIndex(matches,0) count] == 3) + [clause appendFormat:@"%@ %@ %@", fieldName, NSArrayObjectAtIndex(matches, 1), NSArrayObjectAtIndex(matches, 2)]; + } + else if([filterCell isMatchedByRegex:re2]) { + NSArray *matches = [filterCell arrayOfCaptureComponentsMatchedByRegex:re2]; + if([matches count] && [matches = NSArrayObjectAtIndex(matches,0) count] == 3) + [clause appendFormat:@"%@ %@ %@", fieldName, [NSArrayObjectAtIndex(matches, 1) uppercaseString], NSArrayObjectAtIndex(matches, 2)]; } + else { + [clause appendFormat:[NSString stringWithFormat:@"%%@ %@", defaultOperator], fieldName, filterCell]; + } + numberOfValues++; } } if(numberOfValues) [clause appendString:@"\nOR\n"]; } - [filterTableWhereClause setString:[clause substringToIndex:([clause length]-4)]]; - [filterTableWhereClause insertText:@""]; + if([clause length] > 3) + [filterTableWhereClause setString:[clause substringToIndex:([clause length]-4)]]; + else + [filterTableWhereClause setString:@""]; + [filterTableWhereClause insertText:@" "]; [filterTableWhereClause didChangeText]; [filterTableWhereClause scrollRangeToVisible:NSMakeRange(0, 0)]; } -- cgit v1.2.3