mirror of
https://github.com/transmission/transmission.git
synced 2026-04-18 07:56:33 +01:00
#4493 improve search filter behavior
This commit is contained in:
@@ -2000,10 +2000,10 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
|
||||
const NSInteger groupFilterValue = [fDefaults integerForKey: @"FilterGroup"];
|
||||
const BOOL filterGroup = groupFilterValue != GROUP_FILTER_ALL_TAG;
|
||||
|
||||
NSString * searchString = [fFilterBar searchString];
|
||||
if (searchString && [searchString isEqualToString: @""])
|
||||
searchString = nil;
|
||||
const BOOL filterTracker = searchString && [[fDefaults stringForKey: @"FilterSearchType"] isEqualToString: FILTER_TYPE_TRACKER];
|
||||
NSArray * searchStrings = [fFilterBar searchStrings];
|
||||
if (searchStrings && [searchStrings count] == 0)
|
||||
searchStrings = nil;
|
||||
const BOOL filterTracker = searchStrings && [[fDefaults stringForKey: @"FilterSearchType"] isEqualToString: FILTER_TYPE_TRACKER];
|
||||
|
||||
NSMutableArray * allTorrents = [NSMutableArray arrayWithCapacity: [fTorrents count]];
|
||||
|
||||
@@ -2043,30 +2043,45 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
|
||||
continue;
|
||||
|
||||
//check text field
|
||||
if (searchString)
|
||||
if (searchStrings)
|
||||
{
|
||||
BOOL removeTextField = NO;
|
||||
if (filterTracker)
|
||||
{
|
||||
BOOL removeTextField = YES;
|
||||
for (NSString * tracker in [torrent allTrackersFlat])
|
||||
NSArray * trackers = [torrent allTrackersFlat];
|
||||
|
||||
//to count, we need each string in atleast 1 tracker
|
||||
for (NSString * searchString in searchStrings)
|
||||
{
|
||||
if ([tracker rangeOfString: searchString options:
|
||||
(NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch)].location != NSNotFound)
|
||||
BOOL found = NO;
|
||||
for (NSString * tracker in trackers)
|
||||
{
|
||||
removeTextField = NO;
|
||||
if ([tracker rangeOfString: searchString options:
|
||||
(NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch)].location != NSNotFound)
|
||||
{
|
||||
found = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
removeTextField = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (removeTextField)
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ([[torrent name] rangeOfString: searchString options:
|
||||
(NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch)].location == NSNotFound)
|
||||
continue;
|
||||
for (NSString * searchString in searchStrings)
|
||||
if ([[torrent name] rangeOfString: searchString options: (NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch)].location == NSNotFound)
|
||||
{
|
||||
removeTextField = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (removeTextField)
|
||||
continue;
|
||||
}
|
||||
|
||||
[allTorrents addObject: torrent];
|
||||
@@ -2152,7 +2167,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
|
||||
[fTableView selectValues: selectedValues];
|
||||
[self resetInfo]; //if group is already selected, but the torrents in it change
|
||||
|
||||
[self setBottomCountText: groupRows || filterStatus || filterGroup || searchString];
|
||||
[self setBottomCountText: groupRows || filterStatus || filterGroup || searchStrings];
|
||||
|
||||
[self setWindowSizeToFit];
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#import "FileListNode.h"
|
||||
#import "NSApplicationAdditions.h"
|
||||
#import "NSMutableArrayAdditions.h"
|
||||
#import "NSStringAdditions.h"
|
||||
#import <Quartz/Quartz.h>
|
||||
|
||||
#import "utils.h"
|
||||
@@ -112,13 +113,15 @@ typedef enum
|
||||
|
||||
- (void) setFilterText: (NSString *) text
|
||||
{
|
||||
if ([text isEqualToString: @""])
|
||||
NSArray * components = [text betterComponentsSeparatedByCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
if (!components || [components count] == 0)
|
||||
{
|
||||
text = nil;
|
||||
components = nil;
|
||||
}
|
||||
|
||||
if ((!text && !fFilterText) || (text && fFilterText && [text isEqualToString: fFilterText]))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const BOOL onLion = [NSApp isOnLionOrBetter];
|
||||
|
||||
@@ -142,7 +145,18 @@ typedef enum
|
||||
NSArray * tempList = !text ? [fTorrent fileList] : [fTorrent flatFileList];
|
||||
for (FileListNode * item in tempList)
|
||||
{
|
||||
if (!text || [[item name] rangeOfString: text options: (NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch)].location != NSNotFound)
|
||||
BOOL filter = NO;
|
||||
if (components)
|
||||
{
|
||||
for (NSString * sub in components)
|
||||
if ([[item name] rangeOfString: sub options: (NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch)].location == NSNotFound)
|
||||
{
|
||||
filter = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!filter)
|
||||
{
|
||||
FileListNode * parent = nil;
|
||||
NSUInteger previousIndex = ![item isFolder] ? [self findFileNode: item inList: fFileList inRange: NSMakeRange(currentIndex, [fFileList count]-currentIndex) currentParent: nil finalParent: &parent] : NSNotFound;
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
- (void) setSearchType: (id) sender;
|
||||
- (void) setGroupFilter: (id) sender;
|
||||
|
||||
- (NSString *) searchString;
|
||||
- (NSArray *) searchStrings;
|
||||
- (void) focusSearchField;
|
||||
|
||||
- (void) setCountAll: (NSUInteger) all active: (NSUInteger) active downloading: (NSUInteger) downloading
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#import "FilterBarController.h"
|
||||
#import "FilterButton.h"
|
||||
#import "GroupsController.h"
|
||||
#import "NSStringAdditions.h"
|
||||
|
||||
#define FILTER_TYPE_TAG_NAME 401
|
||||
#define FILTER_TYPE_TAG_TRACKER 402
|
||||
@@ -237,9 +238,9 @@
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName: @"ApplyFilter" object: nil];
|
||||
}
|
||||
|
||||
- (NSString *) searchString
|
||||
- (NSArray *) searchStrings
|
||||
{
|
||||
return [fSearchField stringValue];
|
||||
return [[fSearchField stringValue] betterComponentsSeparatedByCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
}
|
||||
|
||||
- (void) setCountAll: (NSUInteger) all active: (NSUInteger) active downloading: (NSUInteger) downloading
|
||||
|
||||
@@ -46,4 +46,6 @@
|
||||
- (NSComparisonResult) compareFinder: (NSString *) string; //how the Finder compares strings
|
||||
- (NSComparisonResult) compareNumeric: (NSString *) string; //simple compare method for strings with numbers (works for IP addresses)
|
||||
|
||||
- (NSArray *) betterComponentsSeparatedByCharactersInSet: (NSCharacterSet *) separator; //like betterComponentsSeparatedByCharactersInSet:, but excludes blank values
|
||||
|
||||
@end
|
||||
|
||||
@@ -182,6 +182,13 @@
|
||||
return [self compare: string options: comparisonOptions range: NSMakeRange(0, [self length]) locale: [NSLocale currentLocale]];
|
||||
}
|
||||
|
||||
- (NSArray *) betterComponentsSeparatedByCharactersInSet: (NSCharacterSet *) separator
|
||||
{
|
||||
NSMutableArray * components = [NSMutableArray arrayWithArray: [self componentsSeparatedByCharactersInSet: separator]];
|
||||
[components removeObject: @""];
|
||||
return components;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSString (Private)
|
||||
|
||||
Reference in New Issue
Block a user