2 // ESEditStatusGroupWindowController.m
5 // Created by Evan Schoenberg on 11/25/05.
8 #import "ESEditStatusGroupWindowController.h"
9 #import "AIStatusController.h"
10 #import <Adium/AIStatusGroup.h>
11 #import <Adium/AIStatusIcons.h>
12 #import <AIUtilities/AIMenuAdditions.h>
13 #import <AIUtilities/AIPopUpButtonAdditions.h>
15 @interface ESEditStatusGroupWindowController (PRIVATE)
16 - (NSMenu *)groupWithStatusMenu;
17 - (id)initWithWindowNibName:(NSString *)windowNibName forStatusGroup:(AIStatusGroup *)inStatusGroup notifyingTarget:(id)inTarget;
20 @implementation ESEditStatusGroupWindowController
22 + (void)editStatusGroup:(AIStatusGroup *)inStatusGroup onWindow:(id)parentWindow notifyingTarget:(id)inTarget
24 ESEditStatusGroupWindowController *controller;
26 controller = [[self alloc] initWithWindowNibName:@"EditStatusGroup"
27 forStatusGroup:inStatusGroup
28 notifyingTarget:inTarget];
31 [NSApp beginSheet:[controller window]
32 modalForWindow:parentWindow
33 modalDelegate:controller
34 didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
37 [controller showWindow:nil];
38 [[controller window] makeKeyAndOrderFront:nil];
42 - (id)initWithWindowNibName:(NSString *)windowNibName forStatusGroup:(AIStatusGroup *)inStatusGroup notifyingTarget:(id)inTarget
44 if ((self = [super initWithWindowNibName:windowNibName])) {
46 statusGroup = (inStatusGroup ? [inStatusGroup retain] : [[AIStatusGroup alloc] init]);
54 [statusGroup release];
61 [popUp_groupWith setMenu:[self groupWithStatusMenu]];
62 [popUp_groupWith compatibleSelectItemWithTag:[statusGroup statusType]];
64 NSString *title = [statusGroup title];
65 [textField_title setStringValue:(title ? title : @"")];
67 [label_groupWith setAutoresizingMask:NSViewMinXMargin];
68 [label_title setLocalizedString:AILocalizedString(@"Title:", nil)];
69 [label_groupWith setAutoresizingMask:NSViewMaxXMargin];
71 [label_title setAutoresizingMask:NSViewMinXMargin];
72 [label_groupWith setLocalizedString:AILocalizedString(@"Group with:", "The popup button after this lists status types; it will determine the status type with which a status group will be listed in status menus")];
73 [label_title setAutoresizingMask:NSViewMaxXMargin];
75 [super windowDidLoad];
79 * @brief Called before the window is closed
81 * As our window is closing, we auto-release this window controller instance. This allows our editor to function
82 * independently without needing a separate object to retain and release it.
84 - (void)windowWillClose:(id)sender
86 [super windowWillClose:sender];
92 * Invoked as the sheet closes, dismiss the sheet
94 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
103 * Save changes, notify our target of the new configuration, and close the editor.
105 - (IBAction)okay:(id)sender
107 [statusGroup setTitle:[textField_title stringValue]];
108 [statusGroup setStatusType:[[popUp_groupWith selectedItem] tag]];
110 if (target && [target respondsToSelector:@selector(finishedSatusGroupEdit:)]) {
111 //Perform on a delay so the sheet can begin closing immediately.
112 [target performSelector:@selector(finishedSatusGroupEdit:)
113 withObject:statusGroup
117 [self closeWindow:nil];
123 * Close the editor without saving changes.
125 - (IBAction)cancel:(id)sender
127 [self closeWindow:nil];
130 - (NSMenu *)groupWithStatusMenu
132 NSMenu *menu = [[NSMenu allocWithZone:[NSMenu zone]] init];
133 NSMenuItem *menuItem;
135 menuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[[adium statusController] localizedDescriptionForCoreStatusName:STATUS_NAME_AVAILABLE]
139 [menuItem setTag:AIAvailableStatusType];
140 [menuItem setImage:[AIStatusIcons statusIconForStatusName:nil
141 statusType:AIAvailableStatusType
142 iconType:AIStatusIconMenu
143 direction:AIIconNormal]];
144 [menu addItem:menuItem];
147 menuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[[adium statusController] localizedDescriptionForCoreStatusName:STATUS_NAME_AWAY]
151 [menuItem setTag:AIAwayStatusType];
152 [menuItem setImage:[AIStatusIcons statusIconForStatusName:nil
153 statusType:AIAwayStatusType
154 iconType:AIStatusIconMenu
155 direction:AIIconNormal]];
156 [menu addItem:menuItem];
159 return [menu autorelease];