Ignore:
Timestamp:
Feb 20, 2011, 3:58:50 AM (11 years ago)
Author:
livings124
Message:

move the filter bar into its own xib

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r11992 r11993  
    4646#import "BlocklistDownloader.h"
    4747#import "StatusBarController.h"
    48 #import "FilterBarView.h"
    49 #import "FilterButton.h"
     48#import "FilterBarController.h"
    5049#import "BonjourController.h"
    5150#import "Badger.h"
     
    108107} sortOrderTag;
    109108
    110 #define FILTER_NONE     @"None"
    111 #define FILTER_ACTIVE   @"Active"
    112 #define FILTER_DOWNLOAD @"Download"
    113 #define FILTER_SEED     @"Seed"
    114 #define FILTER_PAUSE    @"Pause"
    115 
    116 #define FILTER_TYPE_NAME    @"Name"
    117 #define FILTER_TYPE_TRACKER @"Tracker"
    118 
    119 #define FILTER_TYPE_TAG_NAME    401
    120 #define FILTER_TYPE_TAG_TRACKER 402
    121 
    122 #define GROUP_FILTER_ALL_TAG    -2
    123 
    124109#define GROWL_DOWNLOAD_COMPLETE @"Download Complete"
    125110#define GROWL_SEEDING_COMPLETE  @"Seeding Complete"
     
    132117#define ROW_HEIGHT_SMALL        22.0
    133118#define WINDOW_REGULAR_WIDTH    468.0
    134 
    135 #define SEARCH_FILTER_MIN_WIDTH 48.0
    136 #define SEARCH_FILTER_MAX_WIDTH 95.0
    137119
    138120#define UPDATE_UI_SECONDS   1.0
     
    415397    [[fTotalTorrentsField cell] setBackgroundStyle: NSBackgroundStyleRaised];
    416398   
    417     [self updateGroupsFilterButton];
    418    
    419399    //set up filter bar
    420     NSView * contentView = [fWindow contentView];
    421     NSSize windowSize = [contentView convertSize: [fWindow frame].size fromView: nil];
    422     [fFilterBar setHidden: YES];
    423    
    424     NSRect filterBarFrame = [fFilterBar frame];
    425     filterBarFrame.size.width = windowSize.width;
    426     [fFilterBar setFrame: filterBarFrame];
    427    
    428     [contentView addSubview: fFilterBar];
    429     [fFilterBar setFrameOrigin: NSMakePoint(0, NSMaxY([contentView frame]))];
    430 
    431400    [self showFilterBar: [fDefaults boolForKey: @"FilterBar"] animate: NO];
    432401   
     
    473442    }
    474443   
    475     //set filter
    476     NSString * filterType = [fDefaults stringForKey: @"Filter"];
    477    
    478     NSButton * currentFilterButton;
    479     if ([filterType isEqualToString: FILTER_ACTIVE])
    480         currentFilterButton = fActiveFilterButton;
    481     else if ([filterType isEqualToString: FILTER_PAUSE])
    482         currentFilterButton = fPauseFilterButton;
    483     else if ([filterType isEqualToString: FILTER_SEED])
    484         currentFilterButton = fSeedFilterButton;
    485     else if ([filterType isEqualToString: FILTER_DOWNLOAD])
    486         currentFilterButton = fDownloadFilterButton;
    487     else
    488     {
    489         //safety
    490         if (![filterType isEqualToString: FILTER_NONE])
    491             [fDefaults setObject: FILTER_NONE forKey: @"Filter"];
    492         currentFilterButton = fNoFilterButton;
    493     }
    494     [currentFilterButton setState: NSOnState];
    495    
    496     //set filter search type
    497     NSString * filterSearchType = [fDefaults stringForKey: @"FilterSearchType"];
    498    
    499     NSMenu * filterSearchMenu = [[fSearchFilterField cell] searchMenuTemplate];
    500     NSString * filterSearchTypeTitle;
    501     if ([filterSearchType isEqualToString: FILTER_TYPE_TRACKER])
    502         filterSearchTypeTitle = [[filterSearchMenu itemWithTag: FILTER_TYPE_TAG_TRACKER] title];
    503     else
    504     {
    505         //safety
    506         if (![filterType isEqualToString: FILTER_TYPE_NAME])
    507             [fDefaults setObject: FILTER_TYPE_NAME forKey: @"FilterSearchType"];
    508         filterSearchTypeTitle = [[filterSearchMenu itemWithTag: FILTER_TYPE_TAG_NAME] title];
    509     }
    510     [[fSearchFilterField cell] setPlaceholderString: filterSearchTypeTitle];
    511    
    512444    fBadger = [[Badger alloc] initWithLib: fLib];
    513445   
     
    546478                    name: @"UpdateQueue" object: nil];
    547479   
     480    [nc addObserver: self selector: @selector(applyFilter)
     481                    name: @"ApplyFilter" object: nil];
     482   
    548483    //open newly created torrent file
    549484    [nc addObserver: self selector: @selector(beginCreateFile:)
     
    553488    [nc addObserver: self selector: @selector(openCreatedFile:)
    554489                    name: @"OpenCreatedTorrentFile" object: nil];
    555    
    556     //update when groups change
    557     [nc addObserver: self selector: @selector(updateGroupsFilters:)
    558                     name: @"UpdateGroups" object: nil];
    559490
    560491    //timer to update the interface every second
     
    565496    [[NSRunLoop currentRunLoop] addTimer: fTimer forMode: NSEventTrackingRunLoopMode];
    566497   
    567     [self applyFilter: nil];
     498    [self applyFilter];
    568499   
    569500    [fWindow makeKeyAndOrderFront: nil];
    570501   
     502    #warning still needed?
    571503    //can't be done earlier
    572     if (![fFilterBar isHidden])
    573         [self resizeFilterBar];
     504    /*if (![fFilterBar isHidden])
     505        [self resizeFilterBar];*/
    574506   
    575507    if ([fDefaults boolForKey: @"InfoVisible"])
     
    12671199   
    12681200    [self updateUI];
    1269     [self applyFilter: nil];
     1201    [self applyFilter];
    12701202    [[fWindow toolbar] validateVisibleItems];
    12711203    [self updateTorrentHistory];
     
    12911223   
    12921224    [self updateUI];
    1293     [self applyFilter: nil];
     1225    [self applyFilter];
    12941226    [[fWindow toolbar] validateVisibleItems];
    12951227    [self updateTorrentHistory];
     
    16061538        [torrent resetCache];
    16071539   
    1608     [self applyFilter: nil];
     1540    [self applyFilter];
    16091541}
    16101542
     
    17611693   
    17621694    [self updateUI];
    1763     [self applyFilter: nil];
     1695    [self applyFilter];
    17641696    [[fWindow toolbar] validateVisibleItems];
    17651697    [self updateTorrentHistory];
     
    19241856   
    19251857    [fDefaults setObject: sortType forKey: @"Sort"];
    1926     [self applyFilter: nil]; //better than calling sortTorrents because it will even apply to queue order
     1858    [self applyFilter]; //better than calling sortTorrents because it will even apply to queue order
    19271859}
    19281860
     
    19361868        [fTableView removeAllCollapsedGroups];
    19371869   
    1938     [self applyFilter: nil];
     1870    [self applyFilter];
    19391871}
    19401872
     
    20281960}
    20291961
    2030 - (void) applyFilter: (id) sender
     1962- (void) applyFilter
    20311963{
    20321964    //get all the torrents in the table
     
    20611993    const BOOL filterGroup = groupFilterValue != GROUP_FILTER_ALL_TAG;
    20621994   
    2063     NSString * searchString = [fSearchFilterField stringValue];
    2064     const BOOL filterText = [searchString length] > 0,
     1995    NSString * searchString = fFilterBar ? [fFilterBar searchString] : @"";
     1996    const BOOL filterText = ![searchString isEqualToString: @""],
    20651997            filterTracker = filterText && [[fDefaults stringForKey: @"FilterSearchType"] isEqualToString: FILTER_TYPE_TRACKER];
    20661998   
     
    21332065   
    21342066    //set button tooltips
    2135     [fNoFilterButton setCount: [fTorrents count]];
    2136     [fActiveFilterButton setCount: active];
    2137     [fDownloadFilterButton setCount: downloading];
    2138     [fSeedFilterButton setCount: seeding];
    2139     [fPauseFilterButton setCount: paused];
     2067    [fFilterBar setCountAll: [fTorrents count] active: active downloading: downloading seeding: seeding paused: paused];
    21402068   
    21412069    //clear display cache for not-shown torrents
     
    22202148}
    22212149
    2222 //resets filter and sorts torrents
    2223 - (void) setFilter: (id) sender
    2224 {
    2225     NSString * oldFilterType = [fDefaults stringForKey: @"Filter"];
    2226    
    2227     NSButton * prevFilterButton;
    2228     if ([oldFilterType isEqualToString: FILTER_PAUSE])
    2229         prevFilterButton = fPauseFilterButton;
    2230     else if ([oldFilterType isEqualToString: FILTER_ACTIVE])
    2231         prevFilterButton = fActiveFilterButton;
    2232     else if ([oldFilterType isEqualToString: FILTER_SEED])
    2233         prevFilterButton = fSeedFilterButton;
    2234     else if ([oldFilterType isEqualToString: FILTER_DOWNLOAD])
    2235         prevFilterButton = fDownloadFilterButton;
    2236     else
    2237         prevFilterButton = fNoFilterButton;
    2238    
    2239     if (sender != prevFilterButton)
    2240     {
    2241         [prevFilterButton setState: NSOffState];
    2242         [sender setState: NSOnState];
    2243 
    2244         NSString * filterType;
    2245         if (sender == fActiveFilterButton)
    2246             filterType = FILTER_ACTIVE;
    2247         else if (sender == fDownloadFilterButton)
    2248             filterType = FILTER_DOWNLOAD;
    2249         else if (sender == fPauseFilterButton)
    2250             filterType = FILTER_PAUSE;
    2251         else if (sender == fSeedFilterButton)
    2252             filterType = FILTER_SEED;
    2253         else
    2254             filterType = FILTER_NONE;
    2255 
    2256         [fDefaults setObject: filterType forKey: @"Filter"];
    2257     }
    2258     else
    2259         [sender setState: NSOnState];
    2260 
    2261     [self applyFilter: nil];
    2262 }
    2263 
    2264 - (void) setFilterSearchType: (id) sender
    2265 {
    2266     NSString * oldFilterType = [fDefaults stringForKey: @"FilterSearchType"];
    2267    
    2268     NSInteger prevTag, currentTag = [sender tag];
    2269     if ([oldFilterType isEqualToString: FILTER_TYPE_TRACKER])
    2270         prevTag = FILTER_TYPE_TAG_TRACKER;
    2271     else
    2272         prevTag = FILTER_TYPE_TAG_NAME;
    2273    
    2274     if (currentTag != prevTag)
    2275     {
    2276         NSString * filterType;
    2277         if (currentTag == FILTER_TYPE_TAG_TRACKER)
    2278             filterType = FILTER_TYPE_TRACKER;
    2279         else
    2280             filterType = FILTER_TYPE_NAME;
    2281        
    2282         [fDefaults setObject: filterType forKey: @"FilterSearchType"];
    2283        
    2284         [[fSearchFilterField cell] setPlaceholderString: [sender title]];
    2285     }
    2286    
    2287     [self applyFilter: nil];
    2288 }
    2289 
    22902150- (void) switchFilter: (id) sender
    22912151{
    2292     NSString * filterType = [fDefaults stringForKey: @"Filter"];
    2293    
    2294     NSButton * button;
    2295     if ([filterType isEqualToString: FILTER_NONE])
    2296         button = sender == fNextFilterItem ? fActiveFilterButton : fPauseFilterButton;
    2297     else if ([filterType isEqualToString: FILTER_ACTIVE])
    2298         button = sender == fNextFilterItem ? fDownloadFilterButton : fNoFilterButton;
    2299     else if ([filterType isEqualToString: FILTER_DOWNLOAD])
    2300         button = sender == fNextFilterItem ? fSeedFilterButton : fActiveFilterButton;
    2301     else if ([filterType isEqualToString: FILTER_SEED])
    2302         button = sender == fNextFilterItem ? fPauseFilterButton : fDownloadFilterButton;
    2303     else if ([filterType isEqualToString: FILTER_PAUSE])
    2304         button = sender == fNextFilterItem ? fNoFilterButton : fSeedFilterButton;
    2305     else
    2306         button = fNoFilterButton;
    2307    
    2308     [self setFilter: button];
     2152    [fFilterBar switchFilter: sender == fNextFilterItem];
    23092153}
    23102154
    23112155- (void) menuNeedsUpdate: (NSMenu *) menu
    23122156{
    2313     if (menu == fGroupsSetMenu || menu == fGroupsSetContextMenu || menu == fGroupFilterMenu)
    2314     {
    2315         const BOOL filter = menu == fGroupFilterMenu;
    2316        
    2317         const NSInteger remaining = filter ? 3 : 0;
    2318         for (NSInteger i = [menu numberOfItems]-1; i >= remaining; i--)
     2157    if (menu == fGroupsSetMenu || menu == fGroupsSetContextMenu)
     2158    {
     2159        for (NSInteger i = [menu numberOfItems]-1; i >= 0; i--)
    23192160            [menu removeItemAtIndex: i];
    23202161       
    2321         NSMenu * groupMenu;
    2322         if (!filter)
    2323             groupMenu = [[GroupsController groups] groupMenuWithTarget: self action: @selector(setGroup:) isSmall: NO];
    2324         else
    2325             groupMenu = [[GroupsController groups] groupMenuWithTarget: self action: @selector(setGroupFilter:) isSmall: YES];
     2162        NSMenu * groupMenu = [[GroupsController groups] groupMenuWithTarget: self action: @selector(setGroup:) isSmall: NO];
    23262163       
    23272164        const NSInteger groupMenuCount = [groupMenu numberOfItems];
     
    23832220    }
    23842221   
    2385     [self applyFilter: nil];
     2222    [self applyFilter];
    23862223    [self updateUI];
    23872224    [self updateTorrentHistory];
    2388 }
    2389 
    2390 - (void) setGroupFilter: (id) sender
    2391 {
    2392     [fDefaults setInteger: [sender tag] forKey: @"FilterGroup"];
    2393     [self updateGroupsFilterButton];
    2394     [self applyFilter: nil];
    2395 }
    2396 
    2397 - (void) updateGroupsFilterButton
    2398 {
    2399     NSInteger groupIndex = [fDefaults integerForKey: @"FilterGroup"];
    2400    
    2401     NSImage * icon;
    2402     NSString * toolTip;
    2403     if (groupIndex == GROUP_FILTER_ALL_TAG)
    2404     {
    2405         icon = [NSImage imageNamed: @"PinTemplate.png"];
    2406         toolTip = NSLocalizedString(@"All Groups", "Groups -> Button");
    2407     }
    2408     else
    2409     {
    2410         icon = [[GroupsController groups] imageForIndex: groupIndex];
    2411         NSString * groupName = groupIndex != -1 ? [[GroupsController groups] nameForIndex: groupIndex]
    2412                                                 : NSLocalizedString(@"None", "Groups -> Button");
    2413         toolTip = [NSLocalizedString(@"Group", "Groups -> Button") stringByAppendingFormat: @": %@", groupName];
    2414     }
    2415    
    2416     [[fGroupFilterMenu itemAtIndex: 0] setImage: icon];
    2417     [fGroupsButton setToolTip: toolTip];
    2418 }
    2419 
    2420 - (void) updateGroupsFilters: (NSNotification *) notification
    2421 {
    2422     [self updateGroupsFilterButton];
    2423     [self applyFilter: nil];
    24242225}
    24252226
     
    27872588        }
    27882589       
    2789         [self applyFilter: nil];
     2590        [self applyFilter];
    27902591        [fTableView selectValues: selectedValues];
    27912592    }
     
    29852786            if (!fStatusBar)
    29862787                maxSize.height -= [[fStatusBar view] frame].size.height;
    2987             if ([fFilterBar isHidden])
    2988                 maxSize.height -= [fFilterBar frame].size.height;
     2788            if (!fFilterBar)
     2789                maxSize.height -= [[fFilterBar view] frame].size.height;
    29892790            if (windowSize.height > maxSize.height)
    29902791                windowSize.height = maxSize.height;
     
    30262827       
    30272828        [contentView addSubview: [fStatusBar view]];
    3028         [[fStatusBar view] setFrameOrigin: NSMakePoint(0, NSMaxY([contentView frame]))];
     2829        [[fStatusBar view] setFrameOrigin: NSMakePoint(0.0, NSMaxY([contentView frame]))];
    30292830    }
    30302831   
     
    30552856    const NSUInteger statsMask = [[fStatusBar view] autoresizingMask];
    30562857    [[fStatusBar view] setAutoresizingMask: NSViewNotSizable];
    3057     const NSUInteger filterMask = [fFilterBar autoresizingMask];
    3058     [fFilterBar setAutoresizingMask: NSViewNotSizable];
     2858    NSUInteger filterMask;
     2859    if (fFilterBar)
     2860    {
     2861        filterMask = [[fFilterBar view] autoresizingMask];
     2862        [[fFilterBar view] setAutoresizingMask: NSViewNotSizable];
     2863    }
    30592864    const NSUInteger scrollMask = [scrollView autoresizingMask];
    30602865    [scrollView setAutoresizingMask: NSViewNotSizable];
     
    30652870    //re-enable autoresize
    30662871    [[fStatusBar view] setAutoresizingMask: statsMask];
    3067     [fFilterBar setAutoresizingMask: filterMask];
     2872    if (fFilterBar)
     2873        [[fFilterBar view] setAutoresizingMask: filterMask];
    30682874    [scrollView setAutoresizingMask: scrollMask];
    30692875   
     
    30752881    if (!show)
    30762882    {
     2883        [[fStatusBar view] removeFromSuperview];
    30772884        [fStatusBar release];
    30782885        fStatusBar = nil;
     
    30822889- (void) toggleFilterBar: (id) sender
    30832890{
     2891    const BOOL show = fFilterBar == nil;
     2892   
     2893    [self showFilterBar: show animate: YES];
     2894    [fDefaults setBool: show forKey: @"FilterBar"];
     2895    [[fWindow toolbar] validateVisibleItems];
     2896   
    30842897    //disable filtering when hiding
    3085     if (![fFilterBar isHidden])
    3086     {
    3087         [fSearchFilterField setStringValue: @""];
    3088         [self setFilter: fNoFilterButton];
    3089         [self setGroupFilter: [fGroupFilterMenu itemWithTag: GROUP_FILTER_ALL_TAG]];
    3090     }
    3091 
    3092     [self showFilterBar: [fFilterBar isHidden] animate: YES];
    3093     [fDefaults setBool: ![fFilterBar isHidden] forKey: @"FilterBar"];
    3094     [[fWindow toolbar] validateVisibleItems];
     2898    if (!show)
     2899    {
     2900        [[NSUserDefaults standardUserDefaults] setObject: FILTER_NONE forKey: @"Filter"];
     2901        [[NSUserDefaults standardUserDefaults] setInteger: GROUP_FILTER_ALL_TAG forKey: @"FilterGroup"];
     2902        [self applyFilter];
     2903    }
    30952904}
    30962905
     
    30982907- (void) showFilterBar: (BOOL) show animate: (BOOL) animate
    30992908{
    3100     if (show != [fFilterBar isHidden])
     2909    const BOOL prevShown = fFilterBar != nil;
     2910    if (show == prevShown)
    31012911        return;
    3102 
     2912   
    31032913    if (show)
    3104         [fFilterBar setHidden: NO];
    3105 
    3106     NSRect frame;
    3107     CGFloat heightChange = [fFilterBar frame].size.height;
     2914    {
     2915        fFilterBar = [[FilterBarController alloc] init];
     2916       
     2917        NSView * contentView = [fWindow contentView];
     2918        const NSSize windowSize = [contentView convertSize: [fWindow frame].size fromView: nil];
     2919       
     2920        NSRect filterBarFrame = [[fFilterBar view] frame];
     2921        filterBarFrame.size.width = windowSize.width;
     2922        [[fFilterBar view] setFrame: filterBarFrame];
     2923       
     2924        if (fStatusBar)
     2925            [contentView addSubview: [fFilterBar view] positioned: NSWindowBelow relativeTo: [fStatusBar view]];
     2926        else
     2927            [contentView addSubview: [fFilterBar view]];
     2928        const CGFloat originY = fStatusBar ? NSMinY([[fStatusBar view] frame]) : NSMaxY([contentView frame]);
     2929        [[fFilterBar view] setFrameOrigin: NSMakePoint(0.0, originY)];
     2930    }
     2931   
     2932    CGFloat heightChange = NSHeight([[fFilterBar view] frame]);
    31082933    if (!show)
    31092934        heightChange *= -1;
     
    31122937    if (show && ![fDefaults boolForKey: @"AutoSize"])
    31132938    {
    3114         frame = [self windowFrameByAddingHeight: heightChange checkLimits: NO];
    3115         CGFloat change = [[fWindow screen] visibleFrame].size.height - frame.size.height;
     2939        NSRect frame = [self windowFrameByAddingHeight: heightChange checkLimits: NO];
     2940        const CGFloat change = NSHeight([[fWindow screen] visibleFrame]) - NSHeight(frame);
    31162941        if (change < 0.0)
    31172942        {
     
    31262951
    31272952    //set views to not autoresize
    3128     NSUInteger filterMask = [fFilterBar autoresizingMask];
    3129     NSUInteger scrollMask = [scrollView autoresizingMask];
    3130     [fFilterBar setAutoresizingMask: NSViewNotSizable];
     2953    const NSUInteger filterMask = [[fFilterBar view] autoresizingMask];
     2954    const NSUInteger scrollMask = [scrollView autoresizingMask];
     2955    [[fFilterBar view] setAutoresizingMask: NSViewNotSizable];
    31312956    [scrollView setAutoresizingMask: NSViewNotSizable];
    31322957   
    3133     frame = [self windowFrameByAddingHeight: heightChange checkLimits: NO];
     2958    const NSRect frame = [self windowFrameByAddingHeight: heightChange checkLimits: NO];
    31342959    [fWindow setFrame: frame display: YES animate: animate];
    31352960   
    31362961    //re-enable autoresize
    3137     [fFilterBar setAutoresizingMask: filterMask];
     2962    [[fFilterBar view] setAutoresizingMask: filterMask];
    31382963    [scrollView setAutoresizingMask: scrollMask];
    31392964   
     
    31452970    if (!show)
    31462971    {
    3147         [fFilterBar setHidden: YES];
     2972        [[fFilterBar view] removeFromSuperview];
     2973        [fFilterBar release];
     2974        fFilterBar = nil;
    31482975        [fWindow makeFirstResponder: fTableView];
    31492976    }
    31502977}
    31512978
     2979#warning fix?
    31522980- (void) focusFilterField
    31532981{
    3154     [fWindow makeFirstResponder: fSearchFilterField];
     2982    /*[fWindow makeFirstResponder: fSearchFilterField];
    31552983    if ([fFilterBar isHidden])
    3156         [self toggleFilterBar: self];
     2984        [self toggleFilterBar: self];*/
    31572985}
    31582986
     
    35513379    if ([ident isEqualToString: TOOLBAR_FILTER])
    35523380    {
    3553         [(NSButton *)[toolbarItem view] setState: ![fFilterBar isHidden]];
     3381        [(NSButton *)[toolbarItem view] setState: fFilterBar != nil];
    35543382        return YES;
    35553383    }
     
    36343462    }
    36353463   
    3636     if (action == @selector(setGroupFilter:))
    3637     {
    3638         [menuItem setState: [menuItem tag] == [fDefaults integerForKey: @"FilterGroup"] ? NSOnState : NSOffState];
    3639         return YES;
    3640     }
    3641    
    36423464    if (action == @selector(toggleSmallView:))
    36433465    {
     
    37253547    if (action == @selector(toggleFilterBar:))
    37263548    {
    3727         NSString * title = [fFilterBar isHidden] ? NSLocalizedString(@"Show Filter Bar", "View menu -> Filter Bar")
     3549        NSString * title = !fFilterBar ? NSLocalizedString(@"Show Filter Bar", "View menu -> Filter Bar")
    37283550                            : NSLocalizedString(@"Hide Filter Bar", "View menu -> Filter Bar");
    37293551        [menuItem setTitle: title];
     
    37343556    //enable prev/next filter button
    37353557    if (action == @selector(switchFilter:))
    3736         return [fWindow isVisible] && ![fFilterBar isHidden];
     3558        return [fWindow isVisible] && fFilterBar;
    37373559   
    37383560    //enable reveal in finder
     
    39043726    {
    39053727        [menuItem setState: [fDefaults boolForKey: @"SortByGroup"] ? NSOnState : NSOffState];
    3906         return YES;
    3907     }
    3908    
    3909     //check proper filter search item
    3910     if (action == @selector(setFilterSearchType:))
    3911     {
    3912         NSString * filterType = [fDefaults stringForKey: @"FilterSearchType"];
    3913        
    3914         BOOL state;
    3915         if ([menuItem tag] == FILTER_TYPE_TAG_TRACKER)
    3916             state = [filterType isEqualToString: FILTER_TYPE_TRACKER];
    3917         else
    3918             state = [filterType isEqualToString: FILTER_TYPE_NAME];
    3919        
    3920         [menuItem setState: state ? NSOnState : NSOffState];
    39213728        return YES;
    39223729    }
     
    40863893}
    40873894
    4088 - (void) resizeFilterBar
    4089 {
    4090     //replace all buttons
    4091     [fNoFilterButton sizeToFit];
    4092     [fActiveFilterButton sizeToFit];
    4093     [fDownloadFilterButton sizeToFit];
    4094     [fSeedFilterButton sizeToFit];
    4095     [fPauseFilterButton sizeToFit];
    4096    
    4097     NSRect allRect = [fNoFilterButton frame];
    4098     NSRect activeRect = [fActiveFilterButton frame];
    4099     NSRect downloadRect = [fDownloadFilterButton frame];
    4100     NSRect seedRect = [fSeedFilterButton frame];
    4101     NSRect pauseRect = [fPauseFilterButton frame];
    4102    
    4103     //size search filter to not overlap buttons
    4104     NSRect searchFrame = [fSearchFilterField frame];
    4105     searchFrame.origin.x = NSMaxX(pauseRect) + 5.0;
    4106     searchFrame.size.width = [fFilterBar frame].size.width - searchFrame.origin.x - 5.0;
    4107    
    4108     //make sure it is not too long
    4109     if (searchFrame.size.width > SEARCH_FILTER_MAX_WIDTH)
    4110     {
    4111         searchFrame.origin.x += searchFrame.size.width - SEARCH_FILTER_MAX_WIDTH;
    4112         searchFrame.size.width = SEARCH_FILTER_MAX_WIDTH;
    4113     }
    4114     else if (searchFrame.size.width < SEARCH_FILTER_MIN_WIDTH)
    4115     {
    4116         searchFrame.origin.x += searchFrame.size.width - SEARCH_FILTER_MIN_WIDTH;
    4117         searchFrame.size.width = SEARCH_FILTER_MIN_WIDTH;
    4118        
    4119         //calculate width the buttons can take up
    4120         const CGFloat allowedWidth = (searchFrame.origin.x - 5.0) - allRect.origin.x;
    4121         const CGFloat currentWidth = NSWidth(allRect) + NSWidth(activeRect) + NSWidth(downloadRect) + NSWidth(seedRect)
    4122                                         + NSWidth(pauseRect) + 4.0; //add 4 for space between buttons
    4123         const CGFloat ratio = allowedWidth / currentWidth;
    4124        
    4125         //decrease button widths proportionally
    4126         allRect.size.width  = NSWidth(allRect) * ratio;
    4127         activeRect.size.width = NSWidth(activeRect) * ratio;
    4128         downloadRect.size.width = NSWidth(downloadRect) * ratio;
    4129         seedRect.size.width = NSWidth(seedRect) * ratio;
    4130         pauseRect.size.width = NSWidth(pauseRect) * ratio;
    4131     }
    4132     else;
    4133    
    4134     activeRect.origin.x = NSMaxX(allRect) + 1.0;
    4135     downloadRect.origin.x = NSMaxX(activeRect) + 1.0;
    4136     seedRect.origin.x = NSMaxX(downloadRect) + 1.0;
    4137     pauseRect.origin.x = NSMaxX(seedRect) + 1.0;
    4138    
    4139     [fNoFilterButton setFrame: allRect];
    4140     [fActiveFilterButton setFrame: activeRect];
    4141     [fDownloadFilterButton setFrame: downloadRect];
    4142     [fSeedFilterButton setFrame: seedRect];
    4143     [fPauseFilterButton setFrame: pauseRect];
    4144    
    4145     [fSearchFilterField setFrame: searchFrame];
    4146 }
    4147 
    41483895- (void) updateForExpandCollape
    41493896{
     
    41693916        proposedFrameSize.height = [fWindow frame].size.height;
    41703917    return proposedFrameSize;
    4171 }
    4172 
    4173 - (void) windowDidResize: (NSNotification *) notification
    4174 {
    4175     if (![fFilterBar isHidden])
    4176         [self resizeFilterBar];
    41773918}
    41783919
     
    43504091   
    43514092    [self updateUI];
    4352     [self applyFilter: nil];
     4093    [self applyFilter];
    43534094    [self updateTorrentHistory];
    43544095}
Note: See TracChangeset for help on using the changeset viewer.