diff --git a/macosx/ButtonGroupToolbarItem.h b/macosx/ButtonGroupToolbarItem.h index 8d2b08f8a..7b3f481e3 100644 --- a/macosx/ButtonGroupToolbarItem.h +++ b/macosx/ButtonGroupToolbarItem.h @@ -26,12 +26,11 @@ @interface ButtonGroupToolbarItem : NSToolbarItem { - NSArray * fLabels, * fIdentifiers; - - BOOL fMenuCreated; + NSArray * fIdentifiers; } -- (void) setLabels: (NSArray *) labels; - (void) setIdentifiers: (NSArray *) identifiers; +- (void) createMenu: (NSArray *) labels; + @end diff --git a/macosx/ButtonGroupToolbarItem.m b/macosx/ButtonGroupToolbarItem.m index 5c302f13f..a55efbd95 100644 --- a/macosx/ButtonGroupToolbarItem.m +++ b/macosx/ButtonGroupToolbarItem.m @@ -32,12 +32,6 @@ [super dealloc]; } -- (void) setLabels: (NSArray *) labels -{ - [fLabels release]; - fLabels = [labels retain]; -} - - (void) setIdentifiers: (NSArray *) identifiers { [fIdentifiers release]; @@ -54,36 +48,34 @@ [[[NSToolbarItem alloc] initWithItemIdentifier: [fIdentifiers objectAtIndex: i]] autorelease]] forSegment: i]; } +- (void) createMenu: (NSArray *) labels +{ + NSMenuItem * menuItem = [[NSMenuItem alloc] initWithTitle: [self label] action: NULL keyEquivalent: @""]; + NSMenu * menu = [[NSMenu alloc] initWithTitle: [self label]]; + [menuItem setSubmenu: menu]; + + [menu setAutoenablesItems: NO]; + + NSMenuItem * addItem; + int i; + for (i = 0; i < [(NSSegmentedControl *)[self view] segmentCount]; i++) + { + addItem = [[NSMenuItem alloc] initWithTitle: [labels objectAtIndex: i] action: [self action] keyEquivalent: @""]; + [addItem setTarget: [self target]]; + [addItem setTag: i]; + + [menu addItem: addItem]; + [addItem release]; + } + + [menu release]; + [self setMenuFormRepresentation: menuItem]; + [menuItem release]; +} + - (NSMenuItem *) menuFormRepresentation { - NSMenuItem * menuItem; - if (!fMenuCreated) - { - fMenuCreated = YES; - - menuItem = [[[NSMenuItem alloc] initWithTitle: [self label] action: NULL keyEquivalent: @""] autorelease]; - NSMenu * menu = [[NSMenu alloc] initWithTitle: [self label]]; - [menuItem setSubmenu: menu]; - - [menu setAutoenablesItems: NO]; - - NSMenuItem * addItem; - int i; - for (i = 0; i < [(NSSegmentedControl *)[self view] segmentCount]; i++) - { - addItem = [[NSMenuItem alloc] initWithTitle: [fLabels objectAtIndex: i] action: [self action] keyEquivalent: @""]; - [addItem setTarget: [self target]]; - [addItem setTag: i]; - - [menu addItem: addItem]; - [addItem release]; - } - - [menu release]; - [self setMenuFormRepresentation: menuItem]; - } - else - menuItem = [super menuFormRepresentation]; + NSMenuItem * menuItem = [super menuFormRepresentation]; int i; for (i = 0; i < [(NSSegmentedControl *)[self view] segmentCount]; i++) diff --git a/macosx/Controller.m b/macosx/Controller.m index 84c252be6..a60bd6689 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -2718,8 +2718,6 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi [groupItem setAction: @selector(allToolbarClicked:)]; [groupItem setIdentifiers: [NSArray arrayWithObjects: TOOLBAR_PAUSE_ALL, TOOLBAR_RESUME_ALL, nil]]; - [groupItem setLabels: [NSArray arrayWithObjects: NSLocalizedString(@"Pause All", "All toolbar item -> label"), - NSLocalizedString(@"Resume All", "All toolbar item -> label"), nil]]; [segmentedControl setImage: [NSImage imageNamed: @"PauseAll.png"] forSegment: TOOLBAR_PAUSE_TAG]; [(NSSegmentedCell *)[segmentedControl cell] setToolTip: NSLocalizedString(@"Pause all transfers", @@ -2729,6 +2727,9 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi [(NSSegmentedCell *)[segmentedControl cell] setToolTip: NSLocalizedString(@"Resume all transfers", "All toolbar item -> tooltip") forSegment: TOOLBAR_RESUME_TAG]; + [groupItem createMenu: [NSArray arrayWithObjects: NSLocalizedString(@"Pause All", "All toolbar item -> label"), + NSLocalizedString(@"Resume All", "All toolbar item -> label"), nil]]; + [segmentedControl release]; return groupItem; } @@ -2753,8 +2754,6 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi [groupItem setAction: @selector(selectedToolbarClicked:)]; [groupItem setIdentifiers: [NSArray arrayWithObjects: TOOLBAR_PAUSE_SELECTED, TOOLBAR_RESUME_SELECTED, nil]]; - [groupItem setLabels: [NSArray arrayWithObjects: NSLocalizedString(@"Pause Selected", "Selected toolbar item -> label"), - NSLocalizedString(@"Resume Selected", "Selected toolbar item -> label"), nil]]; [segmentedControl setImage: [NSImage imageNamed: @"PauseSelected.png"] forSegment: TOOLBAR_PAUSE_TAG]; [(NSSegmentedCell *)[segmentedControl cell] setToolTip: NSLocalizedString(@"Pause selected transfers", @@ -2764,6 +2763,9 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi [(NSSegmentedCell *)[segmentedControl cell] setToolTip: NSLocalizedString(@"Resume selected transfers", "Selected toolbar item -> tooltip") forSegment: TOOLBAR_RESUME_TAG]; + [groupItem createMenu: [NSArray arrayWithObjects: NSLocalizedString(@"Pause Selected", "Selected toolbar item -> label"), + NSLocalizedString(@"Resume Selected", "Selected toolbar item -> label"), nil]]; + [segmentedControl release]; return groupItem; }