Core/Source/GrowlPreferencePane.m
changeset 4189 30c4b669cad3
parent 4188 71e205ca6b20
child 4190 e0dba26e13a1
     1.1 --- a/Core/Source/GrowlPreferencePane.m	Tue Apr 07 11:34:52 2009 -0700
     1.2 +++ b/Core/Source/GrowlPreferencePane.m	Tue Apr 14 18:04:03 2009 -0700
     1.3 @@ -38,6 +38,12 @@
     1.4  
     1.5  @end
     1.6  
     1.7 +@interface GrowlPreferencePane (PRIVATE)
     1.8 +
     1.9 +- (void) populateDisplaysPopUpButton:(NSPopUpButton *)popUp nameOfSelectedDisplay:(NSString *)nameOfSelectedDisplay includeDefaultMenuItem:(BOOL)includeDefault;
    1.10 +
    1.11 +@end
    1.12 +
    1.13  @implementation GrowlPreferencePane
    1.14  
    1.15  - (id) initWithBundle:(NSBundle *)bundle {
    1.16 @@ -192,16 +198,6 @@
    1.17  												 selector:@selector(translateSeparatorsInMenu:)
    1.18  													 name:NSPopUpButtonWillPopUpNotification
    1.19  												    object:soundMenuButton];
    1.20 -
    1.21 -		[[NSNotificationCenter defaultCenter] addObserver:self
    1.22 -												 selector:@selector(translateSeparatorsInMenu:)
    1.23 -													 name:NSPopUpButtonWillPopUpNotification
    1.24 -												    object:displayMenuButton];
    1.25 -
    1.26 -		[[NSNotificationCenter defaultCenter] addObserver:self
    1.27 -												 selector:@selector(translateSeparatorsInMenu:)
    1.28 -													 name:NSPopUpButtonWillPopUpNotification
    1.29 -												    object:notificationDisplayMenuButton];
    1.30  	}
    1.31  }
    1.32  
    1.33 @@ -759,6 +755,27 @@
    1.34  		[[NSSound soundNamed:[[sender selectedItem] title]] play];
    1.35  }
    1.36  
    1.37 +- (IBAction) showApplicationConfigurationTab:(id)sender {
    1.38 +	if ([ticketsArrayController selectionIndex] != NSNotFound) {
    1.39 +		[self populateDisplaysPopUpButton:displayMenuButton nameOfSelectedDisplay:[[ticketsArrayController selection] valueForKey:@"displayPluginName"] includeDefaultMenuItem:YES];
    1.40 +		[self populateDisplaysPopUpButton:notificationDisplayMenuButton nameOfSelectedDisplay:[[notificationsArrayController selection] valueForKey:@"displayPluginName"] includeDefaultMenuItem:YES];
    1.41 +
    1.42 +		[applicationsTab selectLastTabViewItem:sender];
    1.43 +		[configurationTab selectFirstTabViewItem:sender];
    1.44 +	}
    1.45 +}
    1.46 +
    1.47 +- (IBAction) changeNameOfDisplayForApplication:(id)sender {
    1.48 +	NSString *newDisplayPluginName = [[sender selectedItem] representedObject];
    1.49 +	[[ticketsArrayController selectedObjects] setValue:newDisplayPluginName forKey:@"displayPluginName"];
    1.50 +	[self showPreview:sender];
    1.51 +}
    1.52 +- (IBAction) changeNameOfDisplayForNotification:(id)sender {
    1.53 +	NSString *newDisplayPluginName = [[sender selectedItem] representedObject];
    1.54 +	[[notificationsArrayController selectedObjects] setValue:newDisplayPluginName forKey:@"displayPluginName"];
    1.55 +	[self showPreview:sender];
    1.56 +}
    1.57 +
    1.58  #pragma mark "Display" tab pane
    1.59  
    1.60  - (IBAction) showDisabledDisplays:(id)sender {
    1.61 @@ -789,13 +806,22 @@
    1.62  		return;
    1.63  	
    1.64  	NSDictionary *pluginToUse = currentPlugin;
    1.65 -	
    1.66 +	NSString *pluginName = nil;
    1.67 +	
    1.68 +	if ([sender isKindOfClass:[NSPopUpButton class]]) {
    1.69 +		NSPopUpButton *popUp = (NSPopUpButton *)sender;
    1.70 +		if (sender == displayMenuButton || sender == notificationDisplayMenuButton)
    1.71 +			pluginName = [[popUp selectedItem] representedObject];
    1.72 +		else
    1.73  #warning This does not work if the popup button is not using the exact same order as displayPluginsArrayController - a default or separator item breaks it
    1.74 -	if([sender isKindOfClass:[NSPopUpButton class]]) 
    1.75 -		pluginToUse = [[displayPluginsArrayController content] objectAtIndex:[(NSPopUpButton *)sender indexOfSelectedItem]];
    1.76 +			pluginToUse = [[displayPluginsArrayController content] objectAtIndex:[popUp indexOfSelectedItem]];
    1.77 +	}
    1.78 +
    1.79 +	if (!pluginName)
    1.80 +		pluginName = [pluginToUse objectForKey:GrowlPluginInfoKeyName];
    1.81  			
    1.82  	[[NSDistributedNotificationCenter defaultCenter] postNotificationName:GrowlPreview
    1.83 -																   object:[pluginToUse objectForKey:GrowlPluginInfoKeyName]];
    1.84 +																   object:pluginName];
    1.85  }
    1.86  
    1.87  - (void) loadViewForDisplay:(NSString *)displayName {
    1.88 @@ -918,10 +944,7 @@
    1.89  }
    1.90  
    1.91  - (IBAction) tableViewDoubleClick:(id)sender {
    1.92 -	if ([ticketsArrayController selectionIndex] != NSNotFound) {
    1.93 -		[applicationsTab selectLastTabViewItem:sender];
    1.94 -		[configurationTab selectFirstTabViewItem:sender];
    1.95 -	}
    1.96 +	[self showApplicationConfigurationTab:sender];
    1.97  }
    1.98  
    1.99  #pragma mark NSNetServiceBrowser Delegate Methods
   1.100 @@ -1035,6 +1058,43 @@
   1.101  	}
   1.102  }
   1.103  
   1.104 +#pragma mark Display pop-up menus
   1.105 +
   1.106 +//Empties the pop-up menu and fills it out with a menu item for each display, optionally including a special menu item for the default display, selecting the menu item whose name is nameOfSelectedDisplay.
   1.107 +- (void) populateDisplaysPopUpButton:(NSPopUpButton *)popUp nameOfSelectedDisplay:(NSString *)nameOfSelectedDisplay includeDefaultMenuItem:(BOOL)includeDefault {
   1.108 +	NSMenu *menu = [popUp menu];
   1.109 +	NSString *nameOfDisplay = nil;
   1.110 +
   1.111 +	NSMenuItem *selectedItem = nil;
   1.112 +
   1.113 +	[popUp removeAllItems];
   1.114 +
   1.115 +	if (includeDefault) {
   1.116 +		NSMenuItem *item = [menu addItemWithTitle:NSLocalizedStringFromTableInBundle(@"Default", nil, [NSBundle bundleForClass:[self class]], /*comment*/ @"Title of menu item for default display")
   1.117 +										   action:NULL
   1.118 +									keyEquivalent:@""];
   1.119 +		[item setRepresentedObject:nil];
   1.120 +
   1.121 +		if (!nameOfSelectedDisplay)
   1.122 +			selectedItem = item;
   1.123 +
   1.124 +		[menu addItem:[NSMenuItem separatorItem]];
   1.125 +	}
   1.126 +
   1.127 +	NSEnumerator *displaysEnum = [[plugins sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectEnumerator];
   1.128 +	while ((nameOfDisplay = [displaysEnum nextObject])) {
   1.129 +		NSMenuItem *item = [menu addItemWithTitle:nameOfDisplay
   1.130 +										   action:NULL
   1.131 +									keyEquivalent:@""];
   1.132 +		[item setRepresentedObject:nameOfDisplay];
   1.133 +
   1.134 +		if (nameOfSelectedDisplay && [nameOfSelectedDisplay respondsToSelector:@selector(isEqualToString:)] && [nameOfSelectedDisplay isEqualToString:nameOfDisplay])
   1.135 +			selectedItem = item;
   1.136 +	}
   1.137 +
   1.138 +	[popUp selectItem:selectedItem];
   1.139 +}
   1.140 +
   1.141  #pragma mark -
   1.142  
   1.143  /*!