Changeset 12897


Ignore:
Timestamp:
Sep 19, 2011, 12:48:30 AM (10 years ago)
Author:
livings124
Message:

#4493 improve search filter behavior

Location:
trunk/macosx
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r12774 r12897  
    20012001    const BOOL filterGroup = groupFilterValue != GROUP_FILTER_ALL_TAG;
    20022002   
    2003     NSString * searchString = [fFilterBar searchString];
    2004     if (searchString && [searchString isEqualToString: @""])
    2005         searchString = nil;
    2006     const BOOL filterTracker = searchString && [[fDefaults stringForKey: @"FilterSearchType"] isEqualToString: FILTER_TYPE_TRACKER];
     2003    NSArray * searchStrings = [fFilterBar searchStrings];
     2004    if (searchStrings && [searchStrings count] == 0)
     2005        searchStrings = nil;
     2006    const BOOL filterTracker = searchStrings && [[fDefaults stringForKey: @"FilterSearchType"] isEqualToString: FILTER_TYPE_TRACKER];
    20072007   
    20082008    NSMutableArray * allTorrents = [NSMutableArray arrayWithCapacity: [fTorrents count]];
     
    20442044       
    20452045        //check text field
    2046         if (searchString)
    2047         {
     2046        if (searchStrings)
     2047        {
     2048            BOOL removeTextField = NO;
    20482049            if (filterTracker)
    20492050            {
    2050                 BOOL removeTextField = YES;
    2051                 for (NSString * tracker in [torrent allTrackersFlat])
     2051                NSArray * trackers = [torrent allTrackersFlat];
     2052               
     2053                //to count, we need each string in atleast 1 tracker
     2054                for (NSString * searchString in searchStrings)
    20522055                {
    2053                     if ([tracker rangeOfString: searchString options:
    2054                             (NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch)].location != NSNotFound)
     2056                    BOOL found = NO;
     2057                    for (NSString * tracker in trackers)
    20552058                    {
    2056                         removeTextField = NO;
     2059                        if ([tracker rangeOfString: searchString options:
     2060                             (NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch)].location != NSNotFound)
     2061                        {
     2062                            found = YES;
     2063                            break;
     2064                        }
     2065                    }
     2066                    if (!found)
     2067                    {
     2068                        removeTextField = YES;
    20572069                        break;
    20582070                    }
    20592071                }
    2060                
    2061                 if (removeTextField)
    2062                     continue;
    20632072            }
    20642073            else
    20652074            {
    2066                 if ([[torrent name] rangeOfString: searchString options:
    2067                         (NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch)].location == NSNotFound)
    2068                     continue;
     2075                for (NSString * searchString in searchStrings)
     2076                    if ([[torrent name] rangeOfString: searchString options: (NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch)].location == NSNotFound)
     2077                    {
     2078                        removeTextField = YES;
     2079                        break;
     2080                    }
    20692081            }
     2082           
     2083            if (removeTextField)
     2084                continue;
    20702085        }
    20712086       
     
    21532168    [self resetInfo]; //if group is already selected, but the torrents in it change
    21542169   
    2155     [self setBottomCountText: groupRows || filterStatus || filterGroup || searchString];
     2170    [self setBottomCountText: groupRows || filterStatus || filterGroup || searchStrings];
    21562171   
    21572172    [self setWindowSizeToFit];
  • trunk/macosx/FileOutlineController.m

    r12608 r12897  
    3030#import "NSApplicationAdditions.h"
    3131#import "NSMutableArrayAdditions.h"
     32#import "NSStringAdditions.h"
    3233#import <Quartz/Quartz.h>
    3334
     
    113114- (void) setFilterText: (NSString *) text
    114115{
    115     if ([text isEqualToString: @""])
     116    NSArray * components = [text betterComponentsSeparatedByCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
     117    if (!components || [components count] == 0)
     118    {
    116119        text = nil;
     120        components = nil;
     121    }
    117122   
    118123    if ((!text && !fFilterText) || (text && fFilterText && [text isEqualToString: fFilterText]))
    119     {
    120124        return;
    121     }
    122125   
    123126    const BOOL onLion = [NSApp isOnLionOrBetter];
     
    143146    for (FileListNode * item in tempList)
    144147    {
    145         if (!text || [[item name] rangeOfString: text options: (NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch)].location != NSNotFound)
     148        BOOL filter = NO;
     149        if (components)
     150        {
     151            for (NSString * sub in components)
     152                if ([[item name] rangeOfString: sub options: (NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch)].location == NSNotFound)
     153                {
     154                    filter = YES;
     155                    break;
     156                }
     157        }
     158       
     159        if (!filter)
    146160        {
    147161            FileListNode * parent = nil;
  • trunk/macosx/FilterBarController.h

    r12152 r12897  
    5656- (void) setGroupFilter: (id) sender;
    5757
    58 - (NSString *) searchString;
     58- (NSArray *) searchStrings;
    5959- (void) focusSearchField;
    6060
  • trunk/macosx/FilterBarController.m

    r12535 r12897  
    2626#import "FilterButton.h"
    2727#import "GroupsController.h"
     28#import "NSStringAdditions.h"
    2829
    2930#define FILTER_TYPE_TAG_NAME    401
     
    238239}
    239240
    240 - (NSString *) searchString
    241 {
    242     return [fSearchField stringValue];
     241- (NSArray *) searchStrings
     242{
     243    return [[fSearchField stringValue] betterComponentsSeparatedByCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
    243244}
    244245
  • trunk/macosx/NSStringAdditions.h

    r11647 r12897  
    4747- (NSComparisonResult) compareNumeric: (NSString *) string; //simple compare method for strings with numbers (works for IP addresses)
    4848
     49- (NSArray *) betterComponentsSeparatedByCharactersInSet: (NSCharacterSet *) separator; //like betterComponentsSeparatedByCharactersInSet:, but excludes blank values
     50
    4951@end
  • trunk/macosx/NSStringAdditions.m

    r12186 r12897  
    183183}
    184184
     185- (NSArray *) betterComponentsSeparatedByCharactersInSet: (NSCharacterSet *) separator
     186{
     187    NSMutableArray * components = [NSMutableArray arrayWithArray: [self componentsSeparatedByCharactersInSet: separator]];
     188    [components removeObject: @""];
     189    return components;
     190}
     191
    185192@end
    186193
Note: See TracChangeset for help on using the changeset viewer.