Added `-[NSArray validateAsPropertyList]` and `-[NSDictionary validateAsPropertyList...
[adiumx.git] / Source / ESEditStatusGroupWindowController.m
blobfa3ee2f7751e3d27dfb7c66573c66ab2d7254529
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         [button_OK setLocalizedString:AILocalizedString(@"OK", nil)];
76         [button_cancel setLocalizedString:AILocalizedString(@"Cancel", nil)];
78         [super windowDidLoad];
81 /*!
82  * @brief Called before the window is closed
83  *
84  * As our window is closing, we auto-release this window controller instance.  This allows our editor to function
85  * independently without needing a separate object to retain and release it.
86  */
87 - (void)windowWillClose:(id)sender
89         [super windowWillClose:sender];
91         [self autorelease];
94 /*!
95  * Invoked as the sheet closes, dismiss the sheet
96  */
97 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
99     [sheet orderOut:nil];
104  * @brief Okay
106  * Save changes, notify our target of the new configuration, and close the editor.
107  */
108 - (IBAction)okay:(id)sender
110         [statusGroup setTitle:[textField_title stringValue]];
111         [statusGroup setStatusType:[[popUp_groupWith selectedItem] tag]];
113         if (target && [target respondsToSelector:@selector(finishedStatusGroupEdit:)]) {
114                 //Perform on a delay so the sheet can begin closing immediately.
115                 [target performSelector:@selector(finishedStatusGroupEdit:)
116                                    withObject:statusGroup
117                                    afterDelay:0];
118         }
119         
120         [self closeWindow:nil];
124  * @brief Cancel
126  * Close the editor without saving changes.
127  */
128 - (IBAction)cancel:(id)sender
130         [self closeWindow:nil];
133 - (NSMenu *)groupWithStatusMenu
135         NSMenu *menu = [[NSMenu allocWithZone:[NSMenu zone]] init];
136         NSMenuItem *menuItem;
137         
138         menuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[[adium statusController] localizedDescriptionForCoreStatusName:STATUS_NAME_AVAILABLE]
139                                                                                                                                         target:nil
140                                                                                                                                         action:nil
141                                                                                                                          keyEquivalent:@""];
142         [menuItem setTag:AIAvailableStatusType];
143         [menuItem setImage:[AIStatusIcons statusIconForStatusName:nil
144                                                                                                    statusType:AIAvailableStatusType
145                                                                                                          iconType:AIStatusIconMenu
146                                                                                                         direction:AIIconNormal]];
147         [menu addItem:menuItem];
148         [menuItem release];
150         menuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[[adium statusController] localizedDescriptionForCoreStatusName:STATUS_NAME_AWAY]
151                                                                                                                                         target:nil
152                                                                                                                                         action:nil
153                                                                                                                          keyEquivalent:@""];
154         [menuItem setTag:AIAwayStatusType];
155         [menuItem setImage:[AIStatusIcons statusIconForStatusName:nil
156                                                                                                    statusType:AIAwayStatusType
157                                                                                                          iconType:AIStatusIconMenu
158                                                                                                         direction:AIIconNormal]];       
159         [menu addItem:menuItem];
160         [menuItem release];
161         
162         return [menu autorelease];
165 @end