adium 4607:aaba6415e501: Refactor ESPresetManagementController t...

commits at adium.im commits at adium.im
Sun Jan 29 17:38:39 UTC 2012


details:	http://hg.adium.im/adium/rev/aaba6415e501
revision:	4607:aaba6415e501
branch:		(none)
author:		Thijs Alkemade <thijsalkemade at gmail.com>
date:		Sun Jan 29 18:38:31 2012 +0100

Refactor ESPresetManagementController to be acceptable to the static analyzer, and fix it leaking after closing the window.

diffs (149 lines):

diff -r 63cb186eda09 -r aaba6415e501 Frameworks/Adium Framework/Source/ESPresetManagementController.h
--- a/Frameworks/Adium Framework/Source/ESPresetManagementController.h	Sun Jan 29 18:24:44 2012 +0100
+++ b/Frameworks/Adium Framework/Source/ESPresetManagementController.h	Sun Jan 29 18:38:31 2012 +0100
@@ -34,7 +34,8 @@
 	NSDictionary	*tempDragPreset;
 }
 
-+ (void)managePresets:(NSArray *)inPresets namedByKey:(NSString *)inNameKey onWindow:(NSWindow *)parentWindow withDelegate:(id)inDelegate;
+- (id)initWithPresets:(NSArray *)inPresets namedByKey:(NSString *)inNameKey withDelegate:(id)inDelegate;
+- (void)showOnWindow:(NSWindow *)parentWindow __attribute__((ns_consumes_self));
 
 - (IBAction)duplicatePreset:(id)sender;
 - (IBAction)deletePreset:(id)sender;
diff -r 63cb186eda09 -r aaba6415e501 Frameworks/Adium Framework/Source/ESPresetManagementController.m
--- a/Frameworks/Adium Framework/Source/ESPresetManagementController.m	Sun Jan 29 18:24:44 2012 +0100
+++ b/Frameworks/Adium Framework/Source/ESPresetManagementController.m	Sun Jan 29 18:38:31 2012 +0100
@@ -19,7 +19,6 @@
 #define	PRESET_DRAG_TYPE @"Adium:PresetDrag"
 
 @interface ESPresetManagementController ()
-- (id)initWithWindowNibName:(NSString *)windowNibName presets:(NSArray *)inPresets namedByKey:(NSString *)inNameKey withDelegate:(id)inDelegate;
 - (void)configureControlDimming;
 - (void)tableViewSelectionDidChange:(NSNotification *)notification;
 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
@@ -31,45 +30,38 @@
  */
 @implementation ESPresetManagementController
 
+- (void)showOnWindow:(NSWindow *)parentWindow
+{
+	if (parentWindow) {
+		[NSApp beginSheet:self.window
+		   modalForWindow:parentWindow
+			modalDelegate:self
+		   didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
+			  contextInfo:nil];
+
+	} else {
+		[self showWindow:nil];
+		[self.window makeKeyAndOrderFront:nil];
+		[NSApp activateIgnoringOtherApps:YES];
+	}
+}
+
+
 /*!
  * @brief Begin managing presets
  *
  * @param inPresets An array of either NSString or NSDictionary objects.
  * @param inNameKey If inPresets contains NSDictionary objects, the key used to look up the name ot present to the user.
- * @param parentWindow A window on which to show the preset manager as a sheet
  * @param inDelegate The delegate for preset management.  It must implement all methods in the ESPresetManagementControllerDelegate informal protocol.
  */
-+ (void)managePresets:(NSArray *)inPresets namedByKey:(NSString *)inNameKey onWindow:(NSWindow *)parentWindow withDelegate:(id)inDelegate
+- (id)initWithPresets:(NSArray *)inPresets namedByKey:(NSString *)inNameKey withDelegate:(id)inDelegate
 {
-	ESPresetManagementController	*controller;
 	
 	NSParameterAssert([inDelegate respondsToSelector:@selector(renamePreset:toName:inPresets:renamedPreset:)]);
 	NSParameterAssert([inDelegate respondsToSelector:@selector(duplicatePreset:inPresets:createdDuplicate:)]);
 	NSParameterAssert([inDelegate respondsToSelector:@selector(deletePreset:inPresets:)]);
 	
-	//(movePreset:toIndex:referencePresetArray:)
-	controller = [[self alloc] initWithWindowNibName:@"PresetManagement"
-											 presets:inPresets
-										  namedByKey:inNameKey
-										withDelegate:inDelegate];
-	
-	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];
-		[NSApp activateIgnoringOtherApps:YES];
-	}
-}
-
-- (id)initWithWindowNibName:(NSString *)windowNibName presets:(NSArray *)inPresets namedByKey:(NSString *)inNameKey withDelegate:(id)inDelegate
-{
-    if ((self = [super initWithWindowNibName:windowNibName])) {
+    if ((self = [super initWithWindowNibName:@"PresetManagement"])) {
 		presets = [inPresets retain];
 		nameKey = [inNameKey retain];
 		delegate = [inDelegate retain];
@@ -135,6 +127,8 @@
 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
 {	
     [sheet orderOut:nil];
+	
+	[self autorelease];
 }
 
 /*!
diff -r 63cb186eda09 -r aaba6415e501 Source/AIAppearancePreferences.m
--- a/Source/AIAppearancePreferences.m	Sun Jan 29 18:24:44 2012 +0100
+++ b/Source/AIAppearancePreferences.m	Sun Jan 29 18:38:31 2012 +0100
@@ -551,10 +551,10 @@
 - (void)manageListThemes:(id)sender
 {
 	_listThemes = [plugin availableThemeSets];
-	[ESPresetManagementController managePresets:_listThemes
-									 namedByKey:@"name"
-									   onWindow:[[self view] window]
-								   withDelegate:self];
+	ESPresetManagementController *presetManagementController = [[ESPresetManagementController alloc] initWithPresets:_listThemes
+																										  namedByKey:@"name"
+																										withDelegate:self];
+	[presetManagementController showOnWindow:[[self view] window]];
 	
 	[popUp_colorTheme selectItemWithRepresentedObject:[adium.preferenceController preferenceForKey:KEY_LIST_THEME_NAME
 																							   group:PREF_GROUP_APPEARANCE]];		
@@ -624,10 +624,10 @@
 - (void)manageListLayouts:(id)sender
 {
 	_listLayouts = [plugin availableLayoutSets];
-	[ESPresetManagementController managePresets:_listLayouts
-									 namedByKey:@"name"
-									   onWindow:[[self view] window]
-								   withDelegate:self];
+	ESPresetManagementController *presetManagementController = [[ESPresetManagementController alloc] initWithPresets:_listLayouts
+																										  namedByKey:@"name"
+																										withDelegate:self];
+	[presetManagementController showOnWindow:[[self view] window]];
 
 	[popUp_listLayout selectItemWithRepresentedObject:[adium.preferenceController preferenceForKey:KEY_LIST_LAYOUT_NAME
 																							   group:PREF_GROUP_APPEARANCE]];		
diff -r 63cb186eda09 -r aaba6415e501 Source/ESGlobalEventsPreferences.m
--- a/Source/ESGlobalEventsPreferences.m	Sun Jan 29 18:24:44 2012 +0100
+++ b/Source/ESGlobalEventsPreferences.m	Sun Jan 29 18:38:31 2012 +0100
@@ -323,10 +323,10 @@
  */
 - (void)editPresets:(id)sender
 {
-	[ESPresetManagementController managePresets:[plugin storedEventPresetsArray]
-									 namedByKey:@"Name"
-									   onWindow:[[self view] window]
-								   withDelegate:self];
+	ESPresetManagementController *presentManagementController = [[ESPresetManagementController alloc] initWithPresets:[plugin storedEventPresetsArray]
+																										   namedByKey:@"Name"
+																										 withDelegate:self];
+	[presentManagementController showOnWindow:[[self view] window]];
 
 	//Get our event presets menu back to its proper selection
 	[self selectActiveEventInPopUp];




More information about the commits mailing list