merged [21403]: Fixed an exception thrown when clearing all complete file transfers...
[adiumx.git] / Source / ESEditStatusGroupWindowController.m
blob42d2085dfba0eb432c10802a84d189a69cdc9394
1 //
2 //  ESEditStatusGroupWindowController.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 11/25/05.
6 //
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;
18 @end
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];
30         if (parentWindow) {
31                 [NSApp beginSheet:[controller window]
32                    modalForWindow:parentWindow
33                         modalDelegate:controller
34                    didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
35                           contextInfo:nil];
36         } else {
37                 [controller showWindow:nil];
38                 [[controller window] makeKeyAndOrderFront:nil];
39         }
42 - (id)initWithWindowNibName:(NSString *)windowNibName forStatusGroup:(AIStatusGroup *)inStatusGroup notifyingTarget:(id)inTarget
44     if ((self = [super initWithWindowNibName:windowNibName])) {
45                 target = inTarget;
46                 statusGroup = (inStatusGroup ? [inStatusGroup retain] : [[AIStatusGroup alloc] init]);
47         }       
48         
49         return self;
52 - (void)dealloc
54         [statusGroup release];
55         
56         [super dealloc];
59 - (void)windowDidLoad
61         [popUp_groupWith setMenu:[self groupWithStatusMenu]];
62         [popUp_groupWith compatibleSelectItemWithTag:[statusGroup statusType]];
63         
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];
78 /*!
79  * @brief Called before the window is closed
80  *
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.
83  */
84 - (void)windowWillClose:(id)sender
86         [super windowWillClose:sender];
88         [self autorelease];
91 /*!
92  * Invoked as the sheet closes, dismiss the sheet
93  */
94 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
96     [sheet orderOut:nil];
101  * @brief Okay
103  * Save changes, notify our target of the new configuration, and close the editor.
104  */
105 - (IBAction)okay:(id)sender
107         [statusGroup setTitle:[textField_title stringValue]];
108         [statusGroup setStatusType:[[popUp_groupWith selectedItem] tag]];
110         if (target && [target respondsToSelector:@selector(finishedStatusGroupEdit:)]) {
111                 //Perform on a delay so the sheet can begin closing immediately.
112                 [target performSelector:@selector(finishedStatusGroupEdit:)
113                                    withObject:statusGroup
114                                    afterDelay:0];
115         }
116         
117         [self closeWindow:nil];
121  * @brief Cancel
123  * Close the editor without saving changes.
124  */
125 - (IBAction)cancel:(id)sender
127         [self closeWindow:nil];
130 - (NSMenu *)groupWithStatusMenu
132         NSMenu *menu = [[NSMenu allocWithZone:[NSMenu zone]] init];
133         NSMenuItem *menuItem;
134         
135         menuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[[adium statusController] localizedDescriptionForCoreStatusName:STATUS_NAME_AVAILABLE]
136                                                                                                                                         target:nil
137                                                                                                                                         action:nil
138                                                                                                                          keyEquivalent:@""];
139         [menuItem setTag:AIAvailableStatusType];
140         [menuItem setImage:[AIStatusIcons statusIconForStatusName:nil
141                                                                                                    statusType:AIAvailableStatusType
142                                                                                                          iconType:AIStatusIconMenu
143                                                                                                         direction:AIIconNormal]];
144         [menu addItem:menuItem];
145         [menuItem release];
147         menuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[[adium statusController] localizedDescriptionForCoreStatusName:STATUS_NAME_AWAY]
148                                                                                                                                         target:nil
149                                                                                                                                         action:nil
150                                                                                                                          keyEquivalent:@""];
151         [menuItem setTag:AIAwayStatusType];
152         [menuItem setImage:[AIStatusIcons statusIconForStatusName:nil
153                                                                                                    statusType:AIAwayStatusType
154                                                                                                          iconType:AIStatusIconMenu
155                                                                                                         direction:AIIconNormal]];       
156         [menu addItem:menuItem];
157         [menuItem release];
158         
159         return [menu autorelease];
162 @end