2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2011-2022 Transmission authors and contributors.
|
|
|
|
// It may be used under the MIT (SPDX: MIT) license.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2011-02-20 03:58:50 +00:00
|
|
|
|
|
|
|
#import "FilterBarController.h"
|
|
|
|
#import "FilterButton.h"
|
2011-02-20 04:17:46 +00:00
|
|
|
#import "GroupsController.h"
|
2011-09-19 00:48:30 +00:00
|
|
|
#import "NSStringAdditions.h"
|
2011-02-20 03:58:50 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
FilterType const FilterTypeNone = @"None";
|
|
|
|
FilterType const FilterTypeActive = @"Active";
|
|
|
|
FilterType const FilterTypeDownload = @"Download";
|
|
|
|
FilterType const FilterTypeSeed = @"Seed";
|
|
|
|
FilterType const FilterTypePause = @"Pause";
|
|
|
|
FilterType const FilterTypeError = @"Error";
|
|
|
|
|
|
|
|
FilterSearchType const FilterSearchTypeName = @"Name";
|
|
|
|
FilterSearchType const FilterSearchTypeTracker = @"Tracker";
|
|
|
|
|
|
|
|
NSInteger const kGroupFilterAllTag = -2;
|
|
|
|
|
|
|
|
typedef NS_ENUM(NSInteger, FilterTypeTag) {
|
|
|
|
FilterTypeTagName = 401,
|
|
|
|
FilterTypeTagTracker = 402,
|
|
|
|
};
|
2011-02-20 03:58:50 +00:00
|
|
|
|
2022-11-02 01:40:24 +00:00
|
|
|
@interface FilterBarController ()<NSSearchFieldDelegate>
|
2011-02-20 03:58:50 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
@property(nonatomic) IBOutlet FilterButton* fNoFilterButton;
|
|
|
|
@property(nonatomic) IBOutlet FilterButton* fActiveFilterButton;
|
|
|
|
@property(nonatomic) IBOutlet FilterButton* fDownloadFilterButton;
|
|
|
|
@property(nonatomic) IBOutlet FilterButton* fSeedFilterButton;
|
|
|
|
@property(nonatomic) IBOutlet FilterButton* fPauseFilterButton;
|
2022-03-07 06:01:01 +00:00
|
|
|
@property(nonatomic) IBOutlet FilterButton* fErrorFilterButton;
|
2022-02-22 16:04:20 +00:00
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSSearchField* fSearchField;
|
2022-11-02 01:40:24 +00:00
|
|
|
@property(nonatomic) IBOutlet NSLayoutConstraint* fSearchFieldMinWidthConstraint;
|
2022-02-22 16:04:20 +00:00
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSPopUpButton* fGroupsButton;
|
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation FilterBarController
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (instancetype)init
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
2022-04-29 22:51:40 +00:00
|
|
|
self = [super initWithNibName:@"FilterBar" bundle:nil];
|
|
|
|
return self;
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)awakeFromNib
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
2011-02-20 04:16:38 +00:00
|
|
|
//localizations
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fNoFilterButton.title = NSLocalizedString(@"All", "Filter Bar -> filter button");
|
|
|
|
self.fActiveFilterButton.title = NSLocalizedString(@"Active", "Filter Bar -> filter button");
|
|
|
|
self.fDownloadFilterButton.title = NSLocalizedString(@"Downloading", "Filter Bar -> filter button");
|
|
|
|
self.fSeedFilterButton.title = NSLocalizedString(@"Seeding", "Filter Bar -> filter button");
|
|
|
|
self.fPauseFilterButton.title = NSLocalizedString(@"Paused", "Filter Bar -> filter button");
|
2022-03-07 06:01:01 +00:00
|
|
|
self.fErrorFilterButton.title = NSLocalizedString(@"Error", "Filter Bar -> filter button");
|
2021-08-07 07:27:56 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fNoFilterButton.cell.backgroundStyle = NSBackgroundStyleRaised;
|
|
|
|
self.fActiveFilterButton.cell.backgroundStyle = NSBackgroundStyleRaised;
|
|
|
|
self.fDownloadFilterButton.cell.backgroundStyle = NSBackgroundStyleRaised;
|
|
|
|
self.fSeedFilterButton.cell.backgroundStyle = NSBackgroundStyleRaised;
|
|
|
|
self.fPauseFilterButton.cell.backgroundStyle = NSBackgroundStyleRaised;
|
2022-03-07 06:01:01 +00:00
|
|
|
self.fErrorFilterButton.cell.backgroundStyle = NSBackgroundStyleRaised;
|
2021-08-07 07:27:56 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
[self.fSearchField.searchMenuTemplate itemWithTag:FilterTypeTagName].title = NSLocalizedString(@"Name", "Filter Bar -> filter menu");
|
|
|
|
[self.fSearchField.searchMenuTemplate itemWithTag:FilterTypeTagTracker].title = NSLocalizedString(@"Tracker", "Filter Bar -> filter menu");
|
2021-08-07 07:27:56 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
[self.fGroupsButton.menu itemWithTag:kGroupFilterAllTag].title = NSLocalizedString(@"All Groups", "Filter Bar -> group filter menu");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
//set current filter
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* filterType = [NSUserDefaults.standardUserDefaults stringForKey:@"Filter"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSButton* currentFilterButton;
|
2022-10-19 19:28:21 +00:00
|
|
|
if ([filterType isEqualToString:FilterTypeActive])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
currentFilterButton = self.fActiveFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-10-19 19:28:21 +00:00
|
|
|
else if ([filterType isEqualToString:FilterTypePause])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
currentFilterButton = self.fPauseFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-10-19 19:28:21 +00:00
|
|
|
else if ([filterType isEqualToString:FilterTypeSeed])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
currentFilterButton = self.fSeedFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-10-19 19:28:21 +00:00
|
|
|
else if ([filterType isEqualToString:FilterTypeDownload])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
currentFilterButton = self.fDownloadFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-10-19 19:28:21 +00:00
|
|
|
else if ([filterType isEqualToString:FilterTypeError])
|
2022-03-07 06:01:01 +00:00
|
|
|
{
|
|
|
|
currentFilterButton = self.fErrorFilterButton;
|
|
|
|
}
|
2011-02-20 03:58:50 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
//safety
|
2022-10-19 19:28:21 +00:00
|
|
|
if (![filterType isEqualToString:FilterTypeNone])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults setObject:FilterTypeNone forKey:@"Filter"];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
currentFilterButton = self.fNoFilterButton;
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
2021-10-31 15:18:27 +00:00
|
|
|
currentFilterButton.state = NSControlStateValueOn;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
//set filter search type
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* filterSearchType = [NSUserDefaults.standardUserDefaults stringForKey:@"FilterSearchType"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSMenu* filterSearchMenu = self.fSearchField.searchMenuTemplate;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* filterSearchTypeTitle;
|
2022-10-19 19:28:21 +00:00
|
|
|
if ([filterSearchType isEqualToString:FilterSearchTypeTracker])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
filterSearchTypeTitle = [filterSearchMenu itemWithTag:FilterTypeTagTracker].title;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-02-20 03:58:50 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
//safety
|
2022-10-19 19:28:21 +00:00
|
|
|
if (![filterType isEqualToString:FilterSearchTypeName])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults setObject:FilterSearchTypeName forKey:@"FilterSearchType"];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-10-19 19:28:21 +00:00
|
|
|
filterSearchTypeTitle = [filterSearchMenu itemWithTag:FilterTypeTagName].title;
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fSearchField.placeholderString = filterSearchTypeTitle;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* searchString;
|
|
|
|
if ((searchString = [NSUserDefaults.standardUserDefaults stringForKey:@"FilterSearchString"]))
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fSearchField.stringValue = searchString;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
[self updateGroupsButton];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-11-02 01:40:24 +00:00
|
|
|
// update when groups change
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateGroups:) name:@"UpdateGroups" object:nil];
|
2022-11-02 01:40:24 +00:00
|
|
|
|
|
|
|
// update when filter change
|
|
|
|
self.fSearchField.delegate = self;
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)dealloc
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter removeObserver:self];
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setFilter:(id)sender
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* oldFilterType = [NSUserDefaults.standardUserDefaults stringForKey:@"Filter"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSButton* prevFilterButton;
|
2022-10-19 19:28:21 +00:00
|
|
|
if ([oldFilterType isEqualToString:FilterTypePause])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
prevFilterButton = self.fPauseFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-10-19 19:28:21 +00:00
|
|
|
else if ([oldFilterType isEqualToString:FilterTypeActive])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
prevFilterButton = self.fActiveFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-10-19 19:28:21 +00:00
|
|
|
else if ([oldFilterType isEqualToString:FilterTypeSeed])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
prevFilterButton = self.fSeedFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-10-19 19:28:21 +00:00
|
|
|
else if ([oldFilterType isEqualToString:FilterTypeDownload])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
prevFilterButton = self.fDownloadFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-10-19 19:28:21 +00:00
|
|
|
else if ([oldFilterType isEqualToString:FilterTypeError])
|
2022-03-07 06:01:01 +00:00
|
|
|
{
|
|
|
|
prevFilterButton = self.fErrorFilterButton;
|
|
|
|
}
|
2011-02-20 03:58:50 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
prevFilterButton = self.fNoFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
if (sender != prevFilterButton)
|
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
prevFilterButton.state = NSControlStateValueOff;
|
|
|
|
[sender setState:NSControlStateValueOn];
|
2011-02-20 03:58:50 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
FilterType filterType;
|
2022-02-22 16:04:20 +00:00
|
|
|
if (sender == self.fActiveFilterButton)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
filterType = FilterTypeActive;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
else if (sender == self.fDownloadFilterButton)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
filterType = FilterTypeDownload;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
else if (sender == self.fPauseFilterButton)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
filterType = FilterTypePause;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
else if (sender == self.fSeedFilterButton)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
filterType = FilterTypeSeed;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-03-07 06:01:01 +00:00
|
|
|
else if (sender == self.fErrorFilterButton)
|
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
filterType = FilterTypeError;
|
2022-03-07 06:01:01 +00:00
|
|
|
}
|
2011-02-20 03:58:50 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
filterType = FilterTypeNone;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-02-20 03:58:50 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults setObject:filterType forKey:@"Filter"];
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
[sender setState:NSControlStateValueOn];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"ApplyFilter" object:nil];
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)switchFilter:(BOOL)right
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* filterType = [NSUserDefaults.standardUserDefaults stringForKey:@"Filter"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSButton* button;
|
2022-10-19 19:28:21 +00:00
|
|
|
if ([filterType isEqualToString:FilterTypeNone])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-03-07 06:01:01 +00:00
|
|
|
button = right ? self.fActiveFilterButton : self.fErrorFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-10-19 19:28:21 +00:00
|
|
|
else if ([filterType isEqualToString:FilterTypeActive])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
button = right ? self.fDownloadFilterButton : self.fNoFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-10-19 19:28:21 +00:00
|
|
|
else if ([filterType isEqualToString:FilterTypeDownload])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
button = right ? self.fSeedFilterButton : self.fActiveFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-10-19 19:28:21 +00:00
|
|
|
else if ([filterType isEqualToString:FilterTypeSeed])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
button = right ? self.fPauseFilterButton : self.fDownloadFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-10-19 19:28:21 +00:00
|
|
|
else if ([filterType isEqualToString:FilterTypePause])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-03-07 06:01:01 +00:00
|
|
|
button = right ? self.fErrorFilterButton : self.fSeedFilterButton;
|
|
|
|
}
|
2022-10-19 19:28:21 +00:00
|
|
|
else if ([filterType isEqualToString:FilterTypeError])
|
2022-03-07 06:01:01 +00:00
|
|
|
{
|
|
|
|
button = right ? self.fNoFilterButton : self.fPauseFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-02-20 03:58:50 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
button = self.fNoFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setFilter:button];
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setSearchText:(id)sender
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults setObject:self.fSearchField.stringValue forKey:@"FilterSearchString"];
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"ApplyFilter" object:nil];
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)focusSearchField
|
2011-02-20 04:34:46 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.view.window makeFirstResponder:self.fSearchField];
|
2011-02-20 04:34:46 +00:00
|
|
|
}
|
|
|
|
|
2022-11-28 04:31:26 +00:00
|
|
|
- (BOOL)isFocused
|
|
|
|
{
|
|
|
|
NSTextView* textView = (NSTextView*)self.fSearchField.window.firstResponder;
|
|
|
|
return [self.fSearchField.window.firstResponder isKindOfClass:NSTextView.class] &&
|
|
|
|
[self.fSearchField.window fieldEditor:NO forObject:nil] != nil && [self.fSearchField isEqualTo:textView.delegate];
|
|
|
|
}
|
|
|
|
|
2022-11-02 01:40:24 +00:00
|
|
|
- (void)searchFieldDidStartSearching:(NSSearchField*)sender
|
|
|
|
{
|
|
|
|
[self.fSearchFieldMinWidthConstraint animator].constant = 95;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)searchFieldDidEndSearching:(NSSearchField*)sender
|
|
|
|
{
|
|
|
|
[self.fSearchFieldMinWidthConstraint animator].constant = 48;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setSearchType:(id)sender
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* oldFilterType = [NSUserDefaults.standardUserDefaults stringForKey:@"FilterSearchType"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
NSInteger prevTag, currentTag = [sender tag];
|
2022-10-19 19:28:21 +00:00
|
|
|
if ([oldFilterType isEqualToString:FilterSearchTypeTracker])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
prevTag = FilterTypeTagTracker;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-02-20 03:58:50 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
prevTag = FilterTypeTagName;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
if (currentTag != prevTag)
|
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
FilterSearchType filterType;
|
|
|
|
if (currentTag == FilterTypeTagTracker)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
filterType = FilterSearchTypeTracker;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-02-20 03:58:50 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
filterType = FilterSearchTypeName;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults setObject:filterType forKey:@"FilterSearchType"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fSearchField.placeholderString = [sender title];
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"ApplyFilter" object:nil];
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setGroupFilter:(id)sender
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults setInteger:[sender tag] forKey:@"FilterGroup"];
|
2011-02-20 03:58:50 +00:00
|
|
|
[self updateGroupsButton];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"ApplyFilter" object:nil];
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)reset:(BOOL)updateUI
|
2012-07-25 12:49:11 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults setInteger:kGroupFilterAllTag forKey:@"FilterGroup"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-07-25 12:49:11 +00:00
|
|
|
if (updateUI)
|
2017-01-24 17:53:16 +00:00
|
|
|
{
|
2012-07-25 12:49:11 +00:00
|
|
|
[self updateGroupsButton];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self setFilter:self.fNoFilterButton];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fSearchField.stringValue = @"";
|
|
|
|
[self setSearchText:self.fSearchField];
|
2012-07-25 12:49:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults setObject:FilterTypeNone forKey:@"Filter"];
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults removeObjectForKey:@"FilterSearchString"];
|
2012-07-25 12:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (NSArray<NSString*>*)searchStrings
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
2022-05-14 19:00:55 +00:00
|
|
|
return [self.fSearchField.stringValue nonEmptyComponentsSeparatedByCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setCountAll:(NSUInteger)all
|
|
|
|
active:(NSUInteger)active
|
|
|
|
downloading:(NSUInteger)downloading
|
|
|
|
seeding:(NSUInteger)seeding
|
|
|
|
paused:(NSUInteger)paused
|
2022-03-07 06:01:01 +00:00
|
|
|
error:(NSUInteger)error
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fNoFilterButton.count = all;
|
|
|
|
self.fActiveFilterButton.count = active;
|
|
|
|
self.fDownloadFilterButton.count = downloading;
|
|
|
|
self.fSeedFilterButton.count = seeding;
|
|
|
|
self.fPauseFilterButton.count = paused;
|
2022-03-07 06:01:01 +00:00
|
|
|
self.fErrorFilterButton.count = error;
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)menuNeedsUpdate:(NSMenu*)menu
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (menu == self.fGroupsButton.menu)
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
2022-10-31 14:37:34 +00:00
|
|
|
//remove all items except first three
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSInteger i = menu.numberOfItems - 1; i >= 3; i--)
|
|
|
|
{
|
|
|
|
[menu removeItemAtIndex:i];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMenu* groupMenu = [GroupsController.groups groupMenuWithTarget:self action:@selector(setGroupFilter:) isSmall:YES];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const groupMenuCount = groupMenu.numberOfItems;
|
2011-02-20 03:58:50 +00:00
|
|
|
for (NSInteger i = 0; i < groupMenuCount; i++)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMenuItem* item = [groupMenu itemAtIndex:0];
|
|
|
|
[groupMenu removeItemAtIndex:0];
|
|
|
|
[menu addItem:item];
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
SEL const action = menuItem.action;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
//check proper filter search item
|
|
|
|
if (action == @selector(setSearchType:))
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* filterType = [NSUserDefaults.standardUserDefaults stringForKey:@"FilterSearchType"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
BOOL state;
|
2022-10-19 19:28:21 +00:00
|
|
|
if (menuItem.tag == FilterTypeTagTracker)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
state = [filterType isEqualToString:FilterSearchTypeTracker];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-02-20 03:58:50 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
state = [filterType isEqualToString:FilterSearchTypeName];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
menuItem.state = state ? NSControlStateValueOn : NSControlStateValueOff;
|
2011-02-20 03:58:50 +00:00
|
|
|
return YES;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
if (action == @selector(setGroupFilter:))
|
|
|
|
{
|
2022-03-30 21:52:23 +00:00
|
|
|
menuItem.state = menuItem.tag == [NSUserDefaults.standardUserDefaults integerForKey:@"FilterGroup"] ? NSControlStateValueOn :
|
|
|
|
NSControlStateValueOff;
|
2011-02-20 03:58:50 +00:00
|
|
|
return YES;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
#pragma mark - Private
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateGroupsButton
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const groupIndex = [NSUserDefaults.standardUserDefaults integerForKey:@"FilterGroup"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSImage* icon;
|
|
|
|
NSString* toolTip;
|
2022-10-19 19:28:21 +00:00
|
|
|
if (groupIndex == kGroupFilterAllTag)
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
icon = [NSImage imageNamed:@"PinTemplate"];
|
2011-02-20 03:58:50 +00:00
|
|
|
toolTip = NSLocalizedString(@"All Groups", "Groups -> Button");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
icon = [GroupsController.groups imageForIndex:groupIndex];
|
|
|
|
NSString* groupName = groupIndex != -1 ? [GroupsController.groups nameForIndex:groupIndex] :
|
|
|
|
NSLocalizedString(@"None", "Groups -> Button");
|
|
|
|
toolTip = [NSLocalizedString(@"Group", "Groups -> Button") stringByAppendingFormat:@": %@", groupName];
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fGroupsButton.menu itemAtIndex:0].image = icon;
|
|
|
|
self.fGroupsButton.toolTip = toolTip;
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateGroups:(NSNotification*)notification
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
|
|
|
[self updateGroupsButton];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|