William Bowling is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this again1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | //
// ESEditStatusGroupWindowController.m
// Adium
//
// Created by Evan Schoenberg on 11/25/05.
//
#import "ESEditStatusGroupWindowController.h"
#import "AIStatusController.h"
#import <Adium/AIStatusGroup.h>
#import <Adium/AIStatusIcons.h>
#import <AIUtilities/AIMenuAdditions.h>
#import <AIUtilities/AIPopUpButtonAdditions.h>
@interface ESEditStatusGroupWindowController ()
- (NSMenu *)groupWithStatusMenu;
- (id)initWithWindowNibName:(NSString *)windowNibName forStatusGroup:(AIStatusGroup *)inStatusGroup notifyingTarget:(id)inTarget;
@end
@implementation ESEditStatusGroupWindowController
+ (void)editStatusGroup:(AIStatusGroup *)inStatusGroup onWindow:(id)parentWindow notifyingTarget:(id)inTarget
{
ESEditStatusGroupWindowController *controller;
controller = [[self alloc] initWithWindowNibName:@"EditStatusGroup"
forStatusGroup:inStatusGroup
notifyingTarget:inTarget];
if (parentWindow) {
[NSApp beginSheet:[controller window]
modalForWindow:parentWindow
modalDelegate:controller
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
} else {
[controller showWindow:nil];
[[controller window] makeKeyAndOrderFront:nil];
}
}
- (id)initWithWindowNibName:(NSString *)windowNibName forStatusGroup:(AIStatusGroup *)inStatusGroup notifyingTarget:(id)inTarget
{
if ((self = [super initWithWindowNibName:windowNibName])) {
target = inTarget;
statusGroup = (inStatusGroup ? [inStatusGroup retain] : [[AIStatusGroup alloc] init]);
}
return self;
}
- (void)dealloc
{
[statusGroup release];
[super dealloc];
}
- (void)windowDidLoad
{
[popUp_groupWith setMenu:[self groupWithStatusMenu]];
[popUp_groupWith selectItemWithTag:statusGroup.statusType];
NSString *title = [statusGroup title];
[textField_title setStringValue:(title ? title : @"")];
[label_groupWith setAutoresizingMask:NSViewMinXMargin];
[label_title setLocalizedString:AILocalizedString(@"Title:", nil)];
[label_groupWith setAutoresizingMask:NSViewMaxXMargin];
[label_title setAutoresizingMask:NSViewMinXMargin];
[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")];
[label_title setAutoresizingMask:NSViewMaxXMargin];
[button_OK setLocalizedString:AILocalizedString(@"OK", nil)];
[button_cancel setLocalizedString:AILocalizedString(@"Cancel", nil)];
[super windowDidLoad];
}
/*!
* @brief Called before the window is closed
*
* As our window is closing, we auto-release this window controller instance. This allows our editor to function
* independently without needing a separate object to retain and release it.
*/
- (void)windowWillClose:(id)sender
{
[super windowWillClose:sender];
[self autorelease];
}
/*!
* Invoked as the sheet closes, dismiss the sheet
*/
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
[sheet orderOut:nil];
}
/*!
* @brief Okay
*
* Save changes, notify our target of the new configuration, and close the editor.
*/
- (IBAction)okay:(id)sender
{
[statusGroup setTitle:[textField_title stringValue]];
[statusGroup setStatusType:[[popUp_groupWith selectedItem] tag]];
if (target && [target respondsToSelector:@selector(finishedStatusGroupEdit:)]) {
//Perform on a delay so the sheet can begin closing immediately.
[target performSelector:@selector(finishedStatusGroupEdit:)
withObject:statusGroup
afterDelay:0];
}
[self closeWindow:nil];
}
/*!
* @brief Cancel
*
* Close the editor without saving changes.
*/
- (IBAction)cancel:(id)sender
{
[self closeWindow:nil];
}
- (NSMenu *)groupWithStatusMenu
{
NSMenu *menu = [[NSMenu allocWithZone:[NSMenu zone]] init];
NSMenuItem *menuItem;
menuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[adium.statusController localizedDescriptionForCoreStatusName:STATUS_NAME_AVAILABLE]
target:nil
action:nil
keyEquivalent:@""];
[menuItem setTag:AIAvailableStatusType];
[menuItem setImage:[AIStatusIcons statusIconForStatusName:nil
statusType:AIAvailableStatusType
iconType:AIStatusIconMenu
direction:AIIconNormal]];
[menu addItem:menuItem];
[menuItem release];
menuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[adium.statusController localizedDescriptionForCoreStatusName:STATUS_NAME_AWAY]
target:nil
action:nil
keyEquivalent:@""];
[menuItem setTag:AIAwayStatusType];
[menuItem setImage:[AIStatusIcons statusIconForStatusName:nil
statusType:AIAwayStatusType
iconType:AIStatusIconMenu
direction:AIIconNormal]];
[menu addItem:menuItem];
[menuItem release];
return [menu autorelease];
}
@end
|