2011-02-20 03:58:50 +00:00
|
|
|
/******************************************************************************
|
2012-01-14 17:12:04 +00:00
|
|
|
* Copyright (c) 2011-2012 Transmission authors and contributors
|
2011-02-20 03:58:50 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#define FILTER_TYPE_TAG_NAME 401
|
2011-02-20 03:58:50 +00:00
|
|
|
#define FILTER_TYPE_TAG_TRACKER 402
|
|
|
|
|
|
|
|
#define SEARCH_MIN_WIDTH 48.0
|
|
|
|
#define SEARCH_MAX_WIDTH 95.0
|
|
|
|
|
|
|
|
@interface FilterBarController (Private)
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)resizeBar;
|
|
|
|
- (void)updateGroupsButton;
|
|
|
|
- (void)updateGroups:(NSNotification*)notification;
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return (self = [super initWithNibName:@"FilterBar" bundle:nil]);
|
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
|
2021-08-07 07:27:56 +00:00
|
|
|
fNoFilterButton.title = NSLocalizedString(@"All", "Filter Bar -> filter button");
|
|
|
|
fActiveFilterButton.title = NSLocalizedString(@"Active", "Filter Bar -> filter button");
|
|
|
|
fDownloadFilterButton.title = NSLocalizedString(@"Downloading", "Filter Bar -> filter button");
|
|
|
|
fSeedFilterButton.title = NSLocalizedString(@"Seeding", "Filter Bar -> filter button");
|
|
|
|
fPauseFilterButton.title = NSLocalizedString(@"Paused", "Filter Bar -> filter button");
|
|
|
|
|
|
|
|
fNoFilterButton.cell.backgroundStyle = NSBackgroundStyleRaised;
|
|
|
|
fActiveFilterButton.cell.backgroundStyle = NSBackgroundStyleRaised;
|
|
|
|
fDownloadFilterButton.cell.backgroundStyle = NSBackgroundStyleRaised;
|
|
|
|
fSeedFilterButton.cell.backgroundStyle = NSBackgroundStyleRaised;
|
|
|
|
fPauseFilterButton.cell.backgroundStyle = NSBackgroundStyleRaised;
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fSearchField.searchMenuTemplate itemWithTag:FILTER_TYPE_TAG_NAME].title = NSLocalizedString(@"Name", "Filter Bar -> filter menu");
|
|
|
|
[fSearchField.searchMenuTemplate itemWithTag:FILTER_TYPE_TAG_TRACKER].title = NSLocalizedString(@"Tracker", "Filter Bar -> filter menu");
|
2021-08-07 07:27:56 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fGroupsButton.menu itemWithTag:GROUP_FILTER_ALL_TAG].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
|
|
|
[self resizeBar];
|
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;
|
|
|
|
if ([filterType isEqualToString:FILTER_ACTIVE])
|
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
currentFilterButton = fActiveFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([filterType isEqualToString:FILTER_PAUSE])
|
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
currentFilterButton = fPauseFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([filterType isEqualToString:FILTER_SEED])
|
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
currentFilterButton = fSeedFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([filterType isEqualToString:FILTER_DOWNLOAD])
|
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
currentFilterButton = fDownloadFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-02-20 03:58:50 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
//safety
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![filterType isEqualToString:FILTER_NONE])
|
|
|
|
{
|
|
|
|
[NSUserDefaults.standardUserDefaults setObject:FILTER_NONE forKey:@"Filter"];
|
|
|
|
}
|
2011-02-20 03:58:50 +00:00
|
|
|
currentFilterButton = fNoFilterButton;
|
|
|
|
}
|
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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMenu* filterSearchMenu = fSearchField.searchMenuTemplate;
|
|
|
|
NSString* filterSearchTypeTitle;
|
|
|
|
if ([filterSearchType isEqualToString:FILTER_TYPE_TRACKER])
|
|
|
|
{
|
|
|
|
filterSearchTypeTitle = [filterSearchMenu itemWithTag:FILTER_TYPE_TAG_TRACKER].title;
|
|
|
|
}
|
2011-02-20 03:58:50 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
//safety
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![filterType isEqualToString:FILTER_TYPE_NAME])
|
|
|
|
{
|
|
|
|
[NSUserDefaults.standardUserDefaults setObject:FILTER_TYPE_NAME forKey:@"FilterSearchType"];
|
|
|
|
}
|
|
|
|
filterSearchTypeTitle = [filterSearchMenu itemWithTag:FILTER_TYPE_TAG_NAME].title;
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
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"]))
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(resizeBar) name:NSWindowDidResizeNotification
|
|
|
|
object:self.view.window];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +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];
|
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;
|
|
|
|
if ([oldFilterType isEqualToString:FILTER_PAUSE])
|
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
prevFilterButton = fPauseFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([oldFilterType isEqualToString:FILTER_ACTIVE])
|
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
prevFilterButton = fActiveFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([oldFilterType isEqualToString:FILTER_SEED])
|
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
prevFilterButton = fSeedFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([oldFilterType isEqualToString:FILTER_DOWNLOAD])
|
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
prevFilterButton = fDownloadFilterButton;
|
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
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
prevFilterButton = 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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* filterType;
|
2011-02-20 03:58:50 +00:00
|
|
|
if (sender == fActiveFilterButton)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
filterType = FILTER_ACTIVE;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-02-20 03:58:50 +00:00
|
|
|
else if (sender == fDownloadFilterButton)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
filterType = FILTER_DOWNLOAD;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-02-20 03:58:50 +00:00
|
|
|
else if (sender == fPauseFilterButton)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
filterType = FILTER_PAUSE;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-02-20 03:58:50 +00:00
|
|
|
else if (sender == fSeedFilterButton)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
filterType = FILTER_SEED;
|
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
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
filterType = FILTER_NONE;
|
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;
|
|
|
|
if ([filterType isEqualToString:FILTER_NONE])
|
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
button = right ? fActiveFilterButton : fPauseFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([filterType isEqualToString:FILTER_ACTIVE])
|
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
button = right ? fDownloadFilterButton : fNoFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([filterType isEqualToString:FILTER_DOWNLOAD])
|
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
button = right ? fSeedFilterButton : fActiveFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([filterType isEqualToString:FILTER_SEED])
|
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
button = right ? fPauseFilterButton : fDownloadFilterButton;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([filterType isEqualToString:FILTER_PAUSE])
|
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
button = right ? fNoFilterButton : fSeedFilterButton;
|
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
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
button = 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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults setObject:fSearchField.stringValue forKey:@"FilterSearchString"];
|
|
|
|
[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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[self.view.window makeFirstResponder:fSearchField];
|
2011-02-20 04:34:46 +00:00
|
|
|
}
|
|
|
|
|
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];
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([oldFilterType isEqualToString:FILTER_TYPE_TRACKER])
|
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
prevTag = FILTER_TYPE_TAG_TRACKER;
|
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
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
prevTag = FILTER_TYPE_TAG_NAME;
|
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)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* filterType;
|
2011-02-20 03:58:50 +00:00
|
|
|
if (currentTag == FILTER_TYPE_TAG_TRACKER)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
filterType = FILTER_TYPE_TRACKER;
|
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
|
|
|
{
|
2011-02-20 03:58:50 +00:00
|
|
|
filterType = FILTER_TYPE_NAME;
|
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
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults setInteger:GROUP_FILTER_ALL_TAG 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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setFilter:fNoFilterButton];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fSearchField.stringValue = @"";
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setSearchText:fSearchField];
|
2012-07-25 12:49:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSUserDefaults.standardUserDefaults setObject:FILTER_NONE forKey:@"Filter"];
|
|
|
|
[NSUserDefaults.standardUserDefaults removeObjectForKey:@"FilterSearchString"];
|
2012-07-25 12:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSArray*)searchStrings
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return [fSearchField.stringValue betterComponentsSeparatedByCharactersInSet: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
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fNoFilterButton setCount:all];
|
|
|
|
[fActiveFilterButton setCount:active];
|
|
|
|
[fDownloadFilterButton setCount:downloading];
|
|
|
|
[fSeedFilterButton setCount:seeding];
|
|
|
|
[fPauseFilterButton setCount:paused];
|
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
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (menu == fGroupsButton.menu)
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
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;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (menuItem.tag == FILTER_TYPE_TAG_TRACKER)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
state = [filterType isEqualToString:FILTER_TYPE_TRACKER];
|
|
|
|
}
|
2011-02-20 03:58:50 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
state = [filterType isEqualToString:FILTER_TYPE_NAME];
|
|
|
|
}
|
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:))
|
|
|
|
{
|
2021-10-31 15:18:27 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation FilterBarController (Private)
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)resizeBar
|
2011-02-20 03:58:50 +00:00
|
|
|
{
|
|
|
|
//replace all buttons
|
|
|
|
[fNoFilterButton sizeToFit];
|
|
|
|
[fActiveFilterButton sizeToFit];
|
|
|
|
[fDownloadFilterButton sizeToFit];
|
|
|
|
[fSeedFilterButton sizeToFit];
|
|
|
|
[fPauseFilterButton sizeToFit];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
NSRect allRect = fNoFilterButton.frame;
|
|
|
|
NSRect activeRect = fActiveFilterButton.frame;
|
|
|
|
NSRect downloadRect = fDownloadFilterButton.frame;
|
|
|
|
NSRect seedRect = fSeedFilterButton.frame;
|
|
|
|
NSRect pauseRect = fPauseFilterButton.frame;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
//size search filter to not overlap buttons
|
2021-08-07 07:27:56 +00:00
|
|
|
NSRect searchFrame = fSearchField.frame;
|
2011-02-20 03:58:50 +00:00
|
|
|
searchFrame.origin.x = NSMaxX(pauseRect) + 5.0;
|
2021-08-07 07:27:56 +00:00
|
|
|
searchFrame.size.width = NSWidth(self.view.frame) - searchFrame.origin.x - 5.0;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
//make sure it is not too long
|
|
|
|
if (NSWidth(searchFrame) > SEARCH_MAX_WIDTH)
|
|
|
|
{
|
|
|
|
searchFrame.origin.x += NSWidth(searchFrame) - SEARCH_MAX_WIDTH;
|
|
|
|
searchFrame.size.width = SEARCH_MAX_WIDTH;
|
|
|
|
}
|
|
|
|
else if (NSWidth(searchFrame) < SEARCH_MIN_WIDTH)
|
|
|
|
{
|
|
|
|
searchFrame.origin.x += NSWidth(searchFrame) - SEARCH_MIN_WIDTH;
|
|
|
|
searchFrame.size.width = SEARCH_MIN_WIDTH;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
//calculate width the buttons can take up
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const allowedWidth = (searchFrame.origin.x - 5.0) - allRect.origin.x;
|
|
|
|
CGFloat const currentWidth = NSWidth(allRect) + NSWidth(activeRect) + NSWidth(downloadRect) + NSWidth(seedRect) +
|
|
|
|
NSWidth(pauseRect) + 4.0; //add 4 for space between buttons
|
|
|
|
CGFloat const ratio = allowedWidth / currentWidth;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
//decrease button widths proportionally
|
2021-08-15 09:41:48 +00:00
|
|
|
allRect.size.width = NSWidth(allRect) * ratio;
|
2011-02-20 03:58:50 +00:00
|
|
|
activeRect.size.width = NSWidth(activeRect) * ratio;
|
|
|
|
downloadRect.size.width = NSWidth(downloadRect) * ratio;
|
|
|
|
seedRect.size.width = NSWidth(seedRect) * ratio;
|
|
|
|
pauseRect.size.width = NSWidth(pauseRect) * ratio;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-20 03:58:50 +00:00
|
|
|
activeRect.origin.x = NSMaxX(allRect) + 1.0;
|
|
|
|
downloadRect.origin.x = NSMaxX(activeRect) + 1.0;
|
|
|
|
seedRect.origin.x = NSMaxX(downloadRect) + 1.0;
|
|
|
|
pauseRect.origin.x = NSMaxX(seedRect) + 1.0;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fNoFilterButton.frame = allRect;
|
|
|
|
fActiveFilterButton.frame = activeRect;
|
|
|
|
fDownloadFilterButton.frame = downloadRect;
|
|
|
|
fSeedFilterButton.frame = seedRect;
|
|
|
|
fPauseFilterButton.frame = pauseRect;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fSearchField.frame = searchFrame;
|
2011-02-20 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2011-02-20 03:58:50 +00:00
|
|
|
if (groupIndex == GROUP_FILTER_ALL_TAG)
|
|
|
|
{
|
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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fGroupsButton.menu itemAtIndex:0].image = icon;
|
2021-08-07 07:27:56 +00:00
|
|
|
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
|