adium 4595:4a334783042e: Refactor AINewBookmarkWindowController ...
commits at adium.im
commits at adium.im
Sun Jan 29 15:33:57 UTC 2012
details: http://hg.adium.im/adium/rev/4a334783042e
revision: 4595:4a334783042e
branch: (none)
author: Thijs Alkemade <thijsalkemade at gmail.com>
date: Sun Jan 29 16:33:47 2012 +0100
Refactor AINewBookmarkWindowController to be acceptable to the static analyzer, and fix it leaking after closing the window.
diffs (120 lines):
diff -r adb332029858 -r 4a334783042e Source/AIAddBookmarkPlugin.m
--- a/Source/AIAddBookmarkPlugin.m Sun Jan 29 16:15:42 2012 +0100
+++ b/Source/AIAddBookmarkPlugin.m Sun Jan 29 16:33:47 2012 +0100
@@ -87,9 +87,9 @@
*/
- (void)addBookmark:(id)sender
{
- [AINewBookmarkWindowController promptForNewBookmarkForChat:adium.interfaceController.activeChat
- onWindow:[adium.interfaceController.activeChat.chatContainer.windowController window]
- notifyingTarget:self];
+ AINewBookmarkWindowController *newBookmarkWindowController = [[AINewBookmarkWindowController alloc] initWithChat:adium.interfaceController.activeChat
+ notifyingTarget:self];
+ [newBookmarkWindowController showOnWindow:[adium.interfaceController.activeChat.chatContainer.windowController window]];
}
/*!
@@ -99,9 +99,9 @@
*/
- (void)addBookmarkContext:(id)sender
{
- [AINewBookmarkWindowController promptForNewBookmarkForChat:adium.menuController.currentContextMenuChat
- onWindow:[adium.menuController.currentContextMenuChat.chatContainer.windowController window]
- notifyingTarget:self];
+ AINewBookmarkWindowController *newBookmarkWindowController = [[AINewBookmarkWindowController alloc] initWithChat:adium.menuController.currentContextMenuChat
+ notifyingTarget:self];
+ [newBookmarkWindowController showOnWindow:[adium.menuController.currentContextMenuChat.chatContainer.windowController window]];
}
// @brief: create a bookmark for the given chat with the given name in the given group
diff -r adb332029858 -r 4a334783042e Source/AINewBookmarkWindowController.h
--- a/Source/AINewBookmarkWindowController.h Sun Jan 29 16:15:42 2012 +0100
+++ b/Source/AINewBookmarkWindowController.h Sun Jan 29 16:33:47 2012 +0100
@@ -31,10 +31,8 @@
AIChat *chat;
}
-+ (AINewBookmarkWindowController *)promptForNewBookmarkForChat:(AIChat *)inChat
- onWindow:(NSWindow*)parentWindow
- notifyingTarget:(id)inTarget __attribute__((objc_method_family(new)));
-
+- (id)initWithChat:(AIChat *)inChat notifyingTarget:(id)inTarget;
+- (void)showOnWindow:(id)parentWindow __attribute__((ns_consumes_self));
- (IBAction)add:(id)sender;
- (IBAction)cancel:(id)sender;
diff -r adb332029858 -r 4a334783042e Source/AINewBookmarkWindowController.m
--- a/Source/AINewBookmarkWindowController.m Sun Jan 29 16:15:42 2012 +0100
+++ b/Source/AINewBookmarkWindowController.m Sun Jan 29 16:33:47 2012 +0100
@@ -30,7 +30,7 @@
#define DEFAULT_GROUP_NAME AILocalizedString(@"Contacts",nil)
@interface AINewBookmarkWindowController ()
-- (id)initWithWindowNibName:(NSString *)nibName forChat:(AIChat *)inChat notifyingTarget:(id)inTarget;
+- (id)initWithChat:(AIChat *)inChat notifyingTarget:(id)inTarget;
- (void)buildGroupMenu;
- (void)newGroup:(id)sender;
- (void)newGroupDidEnd:(NSNotification *)inNotification;
@@ -38,38 +38,24 @@
@end
@implementation AINewBookmarkWindowController
-/*!
- * @brief Prompt for a new bookmark.
- *
- * @param inChat The chat to bookmark
- * @param parentWindow Window on which to show as a sheet. Pass nil for a panel prompt.
- * @param inTarget The target to send createBookmarkForChat:withName:inGroup: upon success
- *
- * @result An AINewBookmarkWindowController which will manage its own memory
- */
-+ (AINewBookmarkWindowController *)promptForNewBookmarkForChat:(AIChat *)inChat onWindow:(NSWindow*)parentWindow notifyingTarget:(id)inTarget
+
+- (void)showOnWindow:(NSWindow *)parentWindow
{
- AINewBookmarkWindowController *newBookmarkWindowController = [[self alloc] initWithWindowNibName:ADD_BOOKMARK_NIB
- forChat:inChat
- notifyingTarget:inTarget];
-
if(parentWindow) {
- [NSApp beginSheet:[newBookmarkWindowController window]
+ [NSApp beginSheet:self.window
modalForWindow:parentWindow
- modalDelegate:newBookmarkWindowController
+ modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
} else {
- [newBookmarkWindowController showWindow:nil];
- [[newBookmarkWindowController window] makeKeyAndOrderFront:nil];
+ [self showWindow:nil];
+ [self.window makeKeyAndOrderFront:nil];
}
-
- return newBookmarkWindowController;
}
-- (id)initWithWindowNibName:(NSString *)nibName forChat:(AIChat *)inChat notifyingTarget:(id)inTarget
+- (id)initWithChat:(AIChat *)inChat notifyingTarget:(id)inTarget
{
- if ((self = [super initWithWindowNibName:nibName])) {
+ if ((self = [super initWithWindowNibName:ADD_BOOKMARK_NIB])) {
chat = [inChat retain];
target = [inTarget retain];
}
@@ -91,6 +77,15 @@
-(void)sheetDidEnd:(NSWindow*)sheet returnCode:(NSInteger)returnCode contextInfo:(void*)contextInfo
{
[sheet orderOut:nil];
+
+ [self autorelease];
+}
+
+- (void)windowWillClose:(id)sender
+{
+ [super windowWillClose:sender];
+
+ [self autorelease];
}
/*!
More information about the commits
mailing list