adium 4610:fe11c44e0c28: Refactor SHLinkEditorWindowController a...

commits at adium.im commits at adium.im
Sun Jan 29 18:29:06 UTC 2012


details:	http://hg.adium.im/adium/rev/fe11c44e0c28
revision:	4610:fe11c44e0c28
branch:		(none)
author:		Thijs Alkemade <thijsalkemade at gmail.com>
date:		Sun Jan 29 19:28:56 2012 +0100

Refactor SHLinkEditorWindowController and ESPresetNameSheetController to be accepted by the static analyzer, and fix leaking when closing.

diffs (206 lines):

diff -r b5fc58d16917 -r fe11c44e0c28 Frameworks/Adium Framework/Source/ESPresetNameSheetController.h
--- a/Frameworks/Adium Framework/Source/ESPresetNameSheetController.h	Sun Jan 29 19:03:22 2012 +0100
+++ b/Frameworks/Adium Framework/Source/ESPresetNameSheetController.h	Sun Jan 29 19:28:56 2012 +0100
@@ -35,12 +35,8 @@
 	id			target;
 	id			userInfo;
 }
-
-+ (void)showPresetNameSheetWithDefaultName:(NSString *)inDefaultName
-						   explanatoryText:(NSString *)inExplanatoryText
-								  onWindow:(NSWindow *)parentWindow
-						   notifyingTarget:(id)inTarget
-								  userInfo:(id)inUserInfo;
+- (id)initWithDefaultName:(NSString *)inDefaultName explanatoryText:(NSString *)inExplanatoryText notifyingTarget:(id)inTarget userInfo:(id)inUserInfo;
+- (void)showOnWindow:(NSWindow *)parentWindow __attribute__((ns_consumes_self));
 - (IBAction)okay:(id)sender;
 - (IBAction)cancel:(id)sender;
 
diff -r b5fc58d16917 -r fe11c44e0c28 Frameworks/Adium Framework/Source/ESPresetNameSheetController.m
--- a/Frameworks/Adium Framework/Source/ESPresetNameSheetController.m	Sun Jan 29 19:03:22 2012 +0100
+++ b/Frameworks/Adium Framework/Source/ESPresetNameSheetController.m	Sun Jan 29 19:28:56 2012 +0100
@@ -19,40 +19,30 @@
 #define	PRESET_NAME_SHEET	@"PresetNameSheet"
 
 @interface ESPresetNameSheetController ()
-- (id)initWithWindowNibName:(NSString *)windowNibName defaultName:(NSString *)inDefaultName explanatoryText:(NSString *)inExplanatoryText notifyingTarget:(id)inTarget userInfo:(id)inUserInfo;
 - (void)configureExplanatoryTextWithString:(NSString *)inExplanatoryText;
 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
 @end
 
 @implementation ESPresetNameSheetController
 
-+ (void)showPresetNameSheetWithDefaultName:(NSString *)inDefaultName
-						   explanatoryText:(NSString *)inExplanatoryText
-								  onWindow:(NSWindow *)parentWindow
-						   notifyingTarget:(id)inTarget
-								  userInfo:(id)inUserInfo
+- (void)showOnWindow:(NSWindow *)parentWindow
 {
-	ESPresetNameSheetController	*controller = [[self alloc] initWithWindowNibName:PRESET_NAME_SHEET
-																	  defaultName:inDefaultName
-																explanatoryText:inExplanatoryText
-																notifyingTarget:inTarget
-																	   userInfo:inUserInfo];
 	//Must be called on a window
 	NSParameterAssert(parentWindow != nil);
 	
-	//Target must respond to the ending selector
-	NSParameterAssert([inTarget respondsToSelector:@selector(presetNameSheetControllerDidEnd:returnCode:newName:userInfo:)]);
-	
-	[NSApp beginSheet:[controller window]
+	[NSApp beginSheet:self.window
 	   modalForWindow:parentWindow
-		modalDelegate:controller
+		modalDelegate:self
 	   didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
 		  contextInfo:nil];
 }
 
-- (id)initWithWindowNibName:(NSString *)windowNibName defaultName:(NSString *)inDefaultName explanatoryText:(NSString *)inExplanatoryText notifyingTarget:(id)inTarget userInfo:(id)inUserInfo
+- (id)initWithDefaultName:(NSString *)inDefaultName explanatoryText:(NSString *)inExplanatoryText notifyingTarget:(id)inTarget userInfo:(id)inUserInfo
 {
-	if ((self = [super initWithWindowNibName:windowNibName])) {
+	//Target must respond to the ending selector
+	NSParameterAssert([inTarget respondsToSelector:@selector(presetNameSheetControllerDidEnd:returnCode:newName:userInfo:)]);
+	
+	if ((self = [super initWithWindowNibName:PRESET_NAME_SHEET])) {
 		defaultName = [inDefaultName retain];
 		explanatoryText = [inExplanatoryText retain];
 		target = [inTarget retain];
@@ -68,6 +58,8 @@
 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
 {	
     [sheet orderOut:nil];
+	
+	[self autorelease];
 }
 
 /*!
diff -r b5fc58d16917 -r fe11c44e0c28 Plugins/Link Management/SHLinkEditorWindowController.h
--- a/Plugins/Link Management/SHLinkEditorWindowController.h	Sun Jan 29 19:03:22 2012 +0100
+++ b/Plugins/Link Management/SHLinkEditorWindowController.h	Sun Jan 29 19:28:56 2012 +0100
@@ -42,7 +42,8 @@
     id 									target;
 }
 
-+ (void)showLinkEditorForTextView:(NSTextView *)inTextView onWindow:(NSWindow *)parentWindow notifyingTarget:(id)inTarget;
+- (id)initWithTextView:(NSTextView *)inTextView notifyingTarget:(id)inTarget;
+- (void)showOnWindow:(NSWindow *)parentWindow __attribute__((ns_consumes_self));
 
 - (IBAction)cancel:(id)sender;
 - (IBAction)acceptURL:(id)sender;
diff -r b5fc58d16917 -r fe11c44e0c28 Plugins/Link Management/SHLinkEditorWindowController.m
--- a/Plugins/Link Management/SHLinkEditorWindowController.m	Sun Jan 29 19:03:22 2012 +0100
+++ b/Plugins/Link Management/SHLinkEditorWindowController.m	Sun Jan 29 19:28:56 2012 +0100
@@ -25,7 +25,6 @@
 
 @interface SHLinkEditorWindowController ()
 
-- (id)initWithWindowNibName:(NSString *)windowNibName forTextView:(NSTextView *)inTextView notifyingTarget:(id)inTarget;
 - (void)insertLinkTo:(NSURL *)urlString withText:(NSString *)linkString inView:(NSTextView *)inView;
 - (void)informTargetOfLink;
 
@@ -43,27 +42,23 @@
 
 #pragma mark Init methods
 
-+ (void)showLinkEditorForTextView:(NSTextView *)inTextView onWindow:(NSWindow *)parentWindow notifyingTarget:(id)inTarget
+- (void)showOnWindow:(NSWindow *)parentWindow
 {
-	SHLinkEditorWindowController	*editorWindow = [[self alloc] initWithWindowNibName:LINK_EDITOR_NIB_NAME
-																			forTextView:inTextView
-																		notifyingTarget:inTarget];
-	
 	if (parentWindow) {
-		[NSApp beginSheet:[editorWindow window]
+		[NSApp beginSheet:self.window
 		   modalForWindow:parentWindow
-			modalDelegate:editorWindow
+			modalDelegate:self
 		   didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
 			  contextInfo:nil];
 	} else {
-		[editorWindow showWindow:nil];
+		[self showWindow:nil];
 	}
 }
 
-- (id)initWithWindowNibName:(NSString *)windowNibName forTextView:(NSTextView *)inTextView notifyingTarget:(id)inTarget
+- (id)initWithTextView:(NSTextView *)inTextView notifyingTarget:(id)inTarget
 
 {
-    if ((self = [super initWithWindowNibName:windowNibName])) {
+    if ((self = [super initWithWindowNibName:LINK_EDITOR_NIB_NAME])) {
 		textView = [inTextView retain];
 		target = [inTarget retain];
 	}
@@ -179,6 +174,7 @@
 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
 {
     [sheet orderOut:nil];
+	[self autorelease];
 }
 
 // Cancel
diff -r b5fc58d16917 -r fe11c44e0c28 Plugins/Link Management/SHLinkManagementPlugin.m
--- a/Plugins/Link Management/SHLinkManagementPlugin.m	Sun Jan 29 19:03:22 2012 +0100
+++ b/Plugins/Link Management/SHLinkManagementPlugin.m	Sun Jan 29 19:28:56 2012 +0100
@@ -91,9 +91,9 @@
 
     if (earliestTextView &&
 		![[keyWin windowController] isKindOfClass:[SHLinkEditorWindowController class]]) {
-		[SHLinkEditorWindowController showLinkEditorForTextView:earliestTextView
-													   onWindow:keyWin
-												notifyingTarget:nil];
+		SHLinkEditorWindowController *linkEditorWindowController = [[SHLinkEditorWindowController alloc] initWithTextView:earliestTextView
+																										  notifyingTarget:nil];
+		[linkEditorWindowController showOnWindow:keyWin];
     }
 }
 
diff -r b5fc58d16917 -r fe11c44e0c28 Source/ESGlobalEventsPreferences.m
--- a/Source/ESGlobalEventsPreferences.m	Sun Jan 29 19:03:22 2012 +0100
+++ b/Source/ESGlobalEventsPreferences.m	Sun Jan 29 19:28:56 2012 +0100
@@ -306,11 +306,11 @@
 		COPY_IN_PARENTHESIS];
 	explanatoryText = AILocalizedString(@"Enter a unique name for this new event set.",nil);
 
-	[ESPresetNameSheetController showPresetNameSheetWithDefaultName:defaultName
-													explanatoryText:explanatoryText
-														   onWindow:[[self view] window]
-													notifyingTarget:self
-														   userInfo:nil];
+	ESPresetNameSheetController *presetNameSheetController = [[ESPresetNameSheetController alloc] initWithDefaultName:defaultName
+																									  explanatoryText:explanatoryText
+																									  notifyingTarget:self
+																											 userInfo:nil];
+	[presetNameSheetController showOnWindow:[[self view] window]];
 
 	//Get our event presets menu back to its proper selection
 	[self selectActiveEventInPopUp];
@@ -655,11 +655,11 @@
 	defaultName = [NSString stringWithFormat:@"%@ %@", originalPresetName, COPY_IN_PARENTHESIS];
 	explanatoryText = AILocalizedString(@"You are editing a default event set.  Please enter a unique name for your modified set.",nil);
 	
-	[ESPresetNameSheetController showPresetNameSheetWithDefaultName:defaultName
+	ESPresetNameSheetController *presetNameSheetController = [[ESPresetNameSheetController alloc] initWithDefaultName:defaultName
 													explanatoryText:explanatoryText
-														   onWindow:[[self view] window]
 													notifyingTarget:self
 														   userInfo:nil];
+	[presetNameSheetController showOnWindow:[[self view] window]];
 }
 
 - (BOOL)presetNameSheetController:(ESPresetNameSheetController *)controller
diff -r b5fc58d16917 -r fe11c44e0c28 Source/ESProxyPasswordPromptController.m
--- a/Source/ESProxyPasswordPromptController.m	Sun Jan 29 19:03:22 2012 +0100
+++ b/Source/ESProxyPasswordPromptController.m	Sun Jan 29 19:28:56 2012 +0100
@@ -53,6 +53,7 @@
 													  context:inContext])) {
 			[proxyPasswordPromptControllerDict setObject:controller
 												  forKey:identifier];
+			[controller autorelease];
 		}
 	}
 	




More information about the commits mailing list