Changeset 4083


Ignore:
Timestamp:
Dec 6, 2007, 8:25:38 PM (14 years ago)
Author:
livings124
Message:

more cleanup of the group toolbar button code

Location:
trunk/macosx
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/ButtonGroupToolbarItem.h

    r4082 r4083  
    2828{
    2929    NSArray * fLabels, * fIdentifiers;
     30   
     31    BOOL fMenuCreated;
    3032}
    3133
  • trunk/macosx/ButtonGroupToolbarItem.m

    r4082 r4083  
    5757- (NSMenuItem *) menuFormRepresentation
    5858{
    59     NSMenuItem * menuItem = [[NSMenuItem alloc] initWithTitle: [self label] action: NULL keyEquivalent: @""];
    60     NSMenu * menu = [[NSMenu alloc] initWithTitle: [self label]];
    61     [menuItem setSubmenu: menu];
     59    NSMenuItem * menuItem;
     60    if (!fMenuCreated)
     61    {
     62        fMenuCreated = YES;
     63       
     64        menuItem = [[[NSMenuItem alloc] initWithTitle: [self label] action: NULL keyEquivalent: @""] autorelease];
     65        NSMenu * menu = [[NSMenu alloc] initWithTitle: [self label]];
     66        [menuItem setSubmenu: menu];
     67       
     68        [menu setAutoenablesItems: NO];
     69       
     70        NSMenuItem * addItem;
     71        int i;
     72        for (i = 0; i < [(NSSegmentedControl *)[self view] segmentCount]; i++)
     73        {
     74            addItem = [[NSMenuItem alloc] initWithTitle: [fLabels objectAtIndex: i] action: [self action] keyEquivalent: @""];
     75            [addItem setTarget: [self target]];
     76            [addItem setTag: i];
     77           
     78            [menu addItem: addItem];
     79            [addItem release];
     80        }
     81       
     82        [menu release];
     83        [self setMenuFormRepresentation: menuItem];
     84    }
     85    else
     86        menuItem = [super menuFormRepresentation];
    6287   
    63     [menu setAutoenablesItems: NO];
    64    
    65     NSMenuItem * addItem;
    6688    int i;
    6789    for (i = 0; i < [(NSSegmentedControl *)[self view] segmentCount]; i++)
    68     {
    69         addItem = [[NSMenuItem alloc] initWithTitle: [fLabels objectAtIndex: i] action: [self action] keyEquivalent: @""];
    70         [addItem setTarget: [self target]];
    71         [addItem setTag: i];
    72         [addItem setEnabled: [[self target] validateToolbarItem:
     90        [[[menuItem submenu] itemAtIndex: i] setEnabled: [[self target] validateToolbarItem:
    7391            [[[NSToolbarItem alloc] initWithItemIdentifier: [fIdentifiers objectAtIndex: i]] autorelease]]];
    74        
    75         [menu addItem: addItem];
    76         [addItem release];
    77     }
    7892   
    79     [menu release];
    80     return [menuItem autorelease];
     93    return menuItem;
    8194}
    8295
  • trunk/macosx/Controller.h

    r4081 r4083  
    214214- (void) showFilterBar: (BOOL) show animate: (BOOL) animate;
    215215
     216- (void) allToolbarClicked: (id) sender;
    216217- (void) selectedToolbarClicked: (id) sender;
    217218
  • trunk/macosx/Controller.m

    r4082 r4083  
    5656#define TOOLBAR_PAUSE_RESUME_SELECTED   @"Toolbar Pause / Resume Selected"
    5757#define TOOLBAR_FILTER                  @"Toolbar Toggle Filter"
     58
     59typedef enum
     60{
     61    TOOLBAR_PAUSE_TAG = 0,
     62    TOOLBAR_RESUME_TAG = 1
     63} toolbarGroupTag;
    5864
    5965#define SORT_DATE       @"Date"
     
    26932699        [item setAutovalidates: NO];
    26942700    }
    2695     else if ([ident isEqualToString: TOOLBAR_PAUSE_ALL])
    2696     {
    2697         [item setLabel: NSLocalizedString(@"Pause All", "Pause All toolbar item -> label")];
    2698         [item setPaletteLabel: [item label]];
    2699         [item setToolTip: NSLocalizedString(@"Pause all transfers", "Pause All toolbar item -> tooltip")];
    2700         [item setImage: [NSImage imageNamed: @"PauseAll.png"]];
    2701         [item setTarget: self];
    2702         [item setAction: @selector(stopAllTorrents:)];
    2703     }
    2704     else if ([ident isEqualToString: TOOLBAR_RESUME_ALL])
    2705     {
    2706         [item setLabel: NSLocalizedString(@"Resume All", "Resume All toolbar item -> label")];
    2707         [item setPaletteLabel: [item label]];
    2708         [item setToolTip: NSLocalizedString(@"Resume all transfers", "Resume All toolbar item -> tooltip")];
    2709         [item setImage: [NSImage imageNamed: @"ResumeAll.png"]];
    2710         [item setTarget: self];
    2711         [item setAction: @selector(resumeAllTorrents:)];
    2712     }
    27132701    else if ([ident isEqualToString: TOOLBAR_PAUSE_RESUME_ALL])
    27142702    {
     
    27342722                                        NSLocalizedString(@"Resume All", "All toolbar item -> label"), nil]];
    27352723       
    2736         [segmentedControl setImage: [NSImage imageNamed: @"PauseAll.png"] forSegment: 0];
     2724        [segmentedControl setImage: [NSImage imageNamed: @"PauseAll.png"] forSegment: TOOLBAR_PAUSE_TAG];
    27372725        [(NSSegmentedCell *)[segmentedControl cell] setToolTip: NSLocalizedString(@"Pause all transfers",
    2738                                                         "All toolbar item -> tooltip") forSegment: 0];
    2739        
    2740         [segmentedControl setImage: [NSImage imageNamed: @"ResumeAll.png"] forSegment: 1];
     2726                                                        "All toolbar item -> tooltip") forSegment: TOOLBAR_PAUSE_TAG];
     2727       
     2728        [segmentedControl setImage: [NSImage imageNamed: @"ResumeAll.png"] forSegment: TOOLBAR_RESUME_TAG];
    27412729        [(NSSegmentedCell *)[segmentedControl cell] setToolTip: NSLocalizedString(@"Resume all transfers",
    2742                                                         "All toolbar item -> tooltip") forSegment: 1];
     2730                                                        "All toolbar item -> tooltip") forSegment: TOOLBAR_RESUME_TAG];
    27432731       
    27442732        [segmentedControl release];
     
    27692757                                        NSLocalizedString(@"Resume Selected", "Selected toolbar item -> label"), nil]];
    27702758       
    2771         [segmentedControl setImage: [NSImage imageNamed: @"PauseSelected.png"] forSegment: 0];
     2759        [segmentedControl setImage: [NSImage imageNamed: @"PauseSelected.png"] forSegment: TOOLBAR_PAUSE_TAG];
    27722760        [(NSSegmentedCell *)[segmentedControl cell] setToolTip: NSLocalizedString(@"Pause selected transfers",
    2773                                                         "Selected toolbar item -> tooltip") forSegment: 0];
    2774        
    2775         [segmentedControl setImage: [NSImage imageNamed: @"ResumeSelected.png"] forSegment: 1];
     2761                                                        "Selected toolbar item -> tooltip") forSegment: TOOLBAR_PAUSE_TAG];
     2762       
     2763        [segmentedControl setImage: [NSImage imageNamed: @"ResumeSelected.png"] forSegment: TOOLBAR_RESUME_TAG];
    27762764        [(NSSegmentedCell *)[segmentedControl cell] setToolTip: NSLocalizedString(@"Resume selected transfers",
    2777                                                         "Selected toolbar item -> tooltip") forSegment: 1];
     2765                                                        "Selected toolbar item -> tooltip") forSegment: TOOLBAR_RESUME_TAG];
    27782766       
    27792767        [segmentedControl release];
     
    27962784}
    27972785
    2798 #warning use constants
    27992786- (void) allToolbarClicked: (id) sender
    28002787{
    2801     if ([sender tag] == 0)
    2802         [self stopAllTorrents: sender];
    2803     else if ([sender tag] == 1)
    2804         [self resumeAllTorrents: sender];
    2805     else;
    2806 }
    2807 
    2808 #warning use constants
     2788    switch ([sender tag])
     2789    {
     2790        case TOOLBAR_PAUSE_TAG:
     2791            [self stopAllTorrents: sender];
     2792            break;
     2793        case TOOLBAR_RESUME_TAG:
     2794            [self resumeAllTorrents: sender];
     2795            break;
     2796    }
     2797}
     2798
    28092799- (void) selectedToolbarClicked: (id) sender
    28102800{
    2811     if ([sender tag] == 0)
    2812         [self stopSelectedTorrents: sender];
    2813     else if ([sender tag] == 1)
    2814         [self resumeSelectedTorrents: sender];
    2815     else;
     2801    switch ([sender tag])
     2802    {
     2803        case TOOLBAR_PAUSE_TAG:
     2804            [self stopSelectedTorrents: sender];
     2805            break;
     2806        case TOOLBAR_RESUME_TAG:
     2807            [self resumeSelectedTorrents: sender];
     2808            break;
     2809    }
    28162810}
    28172811
Note: See TracChangeset for help on using the changeset viewer.