Ignore:
Timestamp:
Jul 15, 2006, 4:22:42 PM (16 years ago)
Author:
livings124
Message:

First attempt at a filter bar.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r571 r576  
    105105    [fPrefsController setPrefs: fLib];
    106106   
     107    //ensure filter buttons display correctly
     108    [fWindow setAcceptsMouseMovedEvents: YES];
     109   
    107110    [fAdvancedBarItem setState: [fDefaults boolForKey: @"UseAdvancedBar"]];
    108111
     
    133136    [fPrevInfoTabItem setKeyEquivalent: [NSString stringWithCharacters: & ch length: 1]];
    134137   
     138    //set up filter bar
     139    NSView * contentView = [fWindow contentView];
     140   
     141    fFilterBarVisible = NO;
     142    NSRect filterBarFrame = [fFilterBar frame];
     143    filterBarFrame.size.width = [fWindow frame].size.width;
     144    [fFilterBar setFrame: filterBarFrame];
     145   
     146    [contentView addSubview: fFilterBar];
     147    [fFilterBar setFrameOrigin: NSMakePoint(0, [contentView frame].origin.y + [contentView frame].size.height)];
     148    [self showFilterBar: [fDefaults boolForKey: @"FilterBar"] animate: NO];
     149   
    135150    //set up status bar
     151    fStatusBarVisible = NO;
    136152    NSRect statusBarFrame = [fStatusBar frame];
    137153    statusBarFrame.size.width = [fWindow frame].size.width;
    138154    [fStatusBar setFrame: statusBarFrame];
    139155   
    140     NSView * contentView = [fWindow contentView];
    141156    [contentView addSubview: fStatusBar];
    142     [fStatusBar setFrameOrigin: NSMakePoint(0, [fScrollView frame].origin.y + [fScrollView frame].size.height)];
     157    [fStatusBar setFrameOrigin: NSMakePoint(0, [contentView frame].origin.y + [contentView frame].size.height)];
    143158    [self showStatusBar: [fDefaults boolForKey: @"StatusBar"] animate: NO];
    144159   
     
    201216    fFilterType = [[fDefaults stringForKey: @"Filter"] retain];
    202217
     218    [fNoFilterButton setText: @"All"];
     219    [fPauseFilterButton setText: @"Paused"];
     220    [fSeedFilterButton setText: @"Seeding"];
     221    [fDownloadFilterButton setText: @"Downloading"];
     222
    203223    NSMenuItem * currentFilterItem;
     224    BarButton * currentFilterButton;
    204225    if ([fFilterType isEqualToString: @"Pause"])
     226    {
    205227        currentFilterItem = fPauseFilterItem;
     228        currentFilterButton = fPauseFilterButton;
     229    }
    206230    else if ([fFilterType isEqualToString: @"Seed"])
     231    {
    207232        currentFilterItem = fSeedFilterItem;
     233        currentFilterButton = fSeedFilterButton;
     234    }
    208235    else if ([fFilterType isEqualToString: @"Download"])
     236    {
    209237        currentFilterItem = fDownloadFilterItem;
     238        currentFilterButton = fDownloadFilterButton;
     239    }
    210240    else
     241    {
    211242        currentFilterItem = fNoFilterItem;
     243        currentFilterButton = fNoFilterButton;
     244    }
    212245   
    213246    [currentFilterItem setState: NSOnState];
     247    [currentFilterButton setEnabled: YES];
    214248   
    215249    //set upload limit action button
     
    360394    [[NSApp windows] makeObjectsPerformSelector: @selector(close)];
    361395    [self showStatusBar: NO animate: NO];
     396    [self showFilterBar: NO animate: NO];
    362397   
    363398    //clear badge
     
    10221057{
    10231058    NSMenuItem * prevFilterItem;
     1059    BarButton * prevFilterButton;
    10241060    if ([fFilterType isEqualToString: @"Pause"])
     1061    {
    10251062        prevFilterItem = fPauseFilterItem;
     1063        prevFilterButton = fPauseFilterButton;
     1064    }
    10261065    else if ([fFilterType isEqualToString: @"Seed"])
     1066    {
    10271067        prevFilterItem = fSeedFilterItem;
     1068        prevFilterButton = fSeedFilterButton;
     1069    }
    10281070    else if ([fFilterType isEqualToString: @"Download"])
     1071    {
    10291072        prevFilterItem = fDownloadFilterItem;
     1073        prevFilterButton = fDownloadFilterButton;
     1074    }
    10301075    else
     1076    {
    10311077        prevFilterItem = fNoFilterItem;
    1032    
    1033     if (sender != prevFilterItem)
     1078        prevFilterButton = fNoFilterButton;
     1079    }
     1080   
     1081    if (sender != prevFilterItem && sender != prevFilterButton)
    10341082    {
    10351083        [prevFilterItem setState: NSOffState];
    1036         [sender setState: NSOnState];
    1037 
     1084        [prevFilterButton setEnabled: NO];
     1085
     1086        NSMenuItem * currentFilterItem;
     1087        BarButton * currentFilterButton;
    10381088        [fFilterType release];
    1039         if (sender == fNoFilterItem)
     1089        if (sender == fDownloadFilterItem || sender == fDownloadFilterButton)
     1090        {
     1091            fFilterType = [[NSString alloc] initWithString: @"Download"];
     1092            currentFilterItem = fDownloadFilterItem;
     1093            currentFilterButton = fDownloadFilterButton;
     1094        }
     1095        else if (sender == fPauseFilterItem || sender == fPauseFilterButton)
     1096        {
     1097            fFilterType = [[NSString alloc] initWithString: @"Pause"];
     1098            currentFilterItem = fPauseFilterItem;
     1099            currentFilterButton = fPauseFilterButton;
     1100        }
     1101        else if (sender == fSeedFilterItem || sender == fSeedFilterButton)
     1102        {
     1103            fFilterType = [[NSString alloc] initWithString: @"Seed"];
     1104            currentFilterItem = fSeedFilterItem;
     1105            currentFilterButton = fSeedFilterButton;
     1106        }
     1107        else
     1108        {
    10401109            fFilterType = [[NSString alloc] initWithString: @"None"];
    1041         else if (sender == fPauseFilterItem)
    1042             fFilterType = [[NSString alloc] initWithString: @"Pause"];
    1043         else if (sender == fSeedFilterItem)
    1044             fFilterType = [[NSString alloc] initWithString: @"Seed"];
    1045         else
    1046             fFilterType = [[NSString alloc] initWithString: @"Download"];
    1047            
     1110            currentFilterItem = fNoFilterItem;
     1111            currentFilterButton = fNoFilterButton;
     1112        }
     1113       
     1114        [currentFilterItem setState: NSOnState];
     1115        [currentFilterButton setEnabled: YES];
    10481116        [fDefaults setObject: fFilterType forKey: @"Filter"];
    10491117    }
     
    14841552    //set views to not autoresize
    14851553    unsigned int statsMask = [fStatusBar autoresizingMask];
     1554    unsigned int filterMask = [fFilterBar autoresizingMask];
    14861555    unsigned int scrollMask = [fScrollView autoresizingMask];
    14871556    [fStatusBar setAutoresizingMask: 0];
     1557    [fFilterBar setAutoresizingMask: 0];
    14881558    [fScrollView setAutoresizingMask: 0];
    14891559   
     
    14921562    //re-enable autoresize
    14931563    [fStatusBar setAutoresizingMask: statsMask];
     1564    [fFilterBar setAutoresizingMask: filterMask];
     1565    [fScrollView setAutoresizingMask: scrollMask];
     1566   
     1567    //change min size
     1568    NSSize minSize = [fWindow contentMinSize];
     1569    minSize.height += heightChange;
     1570    [fWindow setContentMinSize: minSize];
     1571}
     1572
     1573- (void) toggleFilterBar: (id) sender
     1574{
     1575    [self showFilterBar: !fFilterBarVisible animate: YES];
     1576    [fDefaults setBool: fFilterBarVisible forKey: @"FilterBar"];
     1577}
     1578
     1579- (void) showFilterBar: (BOOL) show animate: (BOOL) animate
     1580{
     1581    if (show == fFilterBarVisible)
     1582        return;
     1583
     1584    NSRect frame = [fWindow frame];
     1585    float heightChange = [fFilterBar frame].size.height;
     1586    if (!show)
     1587        heightChange *= -1;
     1588
     1589    frame.size.height += heightChange;
     1590    frame.origin.y -= heightChange;
     1591       
     1592    fFilterBarVisible = !fFilterBarVisible;
     1593   
     1594    //set views to not autoresize
     1595    unsigned int filterMask = [fFilterBar autoresizingMask];
     1596    unsigned int scrollMask = [fScrollView autoresizingMask];
     1597    [fFilterBar setAutoresizingMask: 0];
     1598    [fScrollView setAutoresizingMask: 0];
     1599   
     1600    [fWindow setFrame: frame display: YES animate: animate];
     1601   
     1602    //re-enable autoresize
     1603    [fFilterBar setAutoresizingMask: filterMask];
    14941604    [fScrollView setAutoresizingMask: scrollMask];
    14951605   
     
    16911801    {
    16921802        NSString * title = fStatusBarVisible ? @"Hide Status Bar" : @"Show Status Bar";
     1803        if (![[menuItem title] isEqualToString: title])
     1804                [menuItem setTitle: title];
     1805
     1806        return canUseMenu;
     1807    }
     1808   
     1809    //enable toggle filter bar
     1810    if (action == @selector(toggleFilterBar:))
     1811    {
     1812        NSString * title = fFilterBarVisible ? @"Hide Filter Bar" : @"Show Filter Bar";
    16931813        if (![[menuItem title] isEqualToString: title])
    16941814                [menuItem setTitle: title];
Note: See TracChangeset for help on using the changeset viewer.