From 302050b2d685bbd9ae160b2df88ec0ed17fe98ed Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sun, 15 Jan 2012 18:07:32 -0500 Subject: [PATCH] Delegate model instantiation to HSGUIController where possible. --HG-- branch : objp --- cocoa/base/DirectoryOutline.h | 2 +- cocoa/base/DirectoryOutline.m | 17 +++++++---------- cocoa/base/DirectoryPanel.m | 2 +- cocoa/base/PrioritizeList.m | 6 ++---- cocoa/base/ResultTable.m | 5 +---- cocoa/base/StatsLabel.m | 7 ++----- 6 files changed, 14 insertions(+), 25 deletions(-) diff --git a/cocoa/base/DirectoryOutline.h b/cocoa/base/DirectoryOutline.h index 05a5e739..572dcd74 100644 --- a/cocoa/base/DirectoryOutline.h +++ b/cocoa/base/DirectoryOutline.h @@ -15,5 +15,5 @@ http://www.hardcoded.net/licenses/bsd_license @interface DirectoryOutline : HSOutline {} - (id)initWithPyRef:(PyObject *)aPyRef outlineView:(HSOutlineView *)aOutlineView; -- (PyDirectoryOutline *)py; +- (PyDirectoryOutline *)model; @end; \ No newline at end of file diff --git a/cocoa/base/DirectoryOutline.m b/cocoa/base/DirectoryOutline.m index caef39c2..342aacef 100644 --- a/cocoa/base/DirectoryOutline.m +++ b/cocoa/base/DirectoryOutline.m @@ -7,22 +7,19 @@ http://www.hardcoded.net/licenses/bsd_license */ #import "DirectoryOutline.h" -#import "Utils.h" @implementation DirectoryOutline - (id)initWithPyRef:(PyObject *)aPyRef outlineView:(HSOutlineView *)aOutlineView { - PyDirectoryOutline *model = [[PyDirectoryOutline alloc] initWithModel:aPyRef]; - self = [super initWithPy:model view:aOutlineView]; - [model bindCallback:createCallback(@"DirectoryOutlineView", self)]; - [model release]; - [outlineView registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]]; + self = [super initWithPyRef:aPyRef wrapperClass:[PyDirectoryOutline class] + callbackClassName:@"DirectoryOutlineView" view:aOutlineView]; + [[self view] registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]]; return self; } -- (PyDirectoryOutline *)py +- (PyDirectoryOutline *)model { - return (PyDirectoryOutline *)py; + return (PyDirectoryOutline *)model; } /* Delegate */ @@ -50,7 +47,7 @@ http://www.hardcoded.net/licenses/bsd_license if (!(sourceDragMask & NSDragOperationLink)) return NO; for (NSString *foldername in foldernames) { - [[self py] addDirectory:foldername]; + [[self model] addDirectory:foldername]; } NSDictionary *userInfo = [NSDictionary dictionaryWithObject:foldernames forKey:@"foldernames"]; [[NSNotificationCenter defaultCenter] postNotificationName:DGAddedFoldersNotification @@ -64,7 +61,7 @@ http://www.hardcoded.net/licenses/bsd_license if ([cell isKindOfClass:[NSTextFieldCell class]]) { NSTextFieldCell *textCell = cell; NSIndexPath *path = item; - BOOL selected = [path isEqualTo:[outlineView selectedPath]]; + BOOL selected = [path isEqualTo:[[self view] selectedPath]]; if (selected) { [textCell setTextColor:[NSColor blackColor]]; return; diff --git a/cocoa/base/DirectoryPanel.m b/cocoa/base/DirectoryPanel.m index 33dc4f4e..1d982c64 100644 --- a/cocoa/base/DirectoryPanel.m +++ b/cocoa/base/DirectoryPanel.m @@ -100,7 +100,7 @@ http://www.hardcoded.net/licenses/bsd_license - (IBAction)removeSelectedDirectory:(id)sender { [[self window] makeKeyAndOrderFront:nil]; - [[outline py] removeSelectedDirectory]; + [[outline model] removeSelectedDirectory]; [self refreshRemoveButtonText]; } diff --git a/cocoa/base/PrioritizeList.m b/cocoa/base/PrioritizeList.m index 47452278..af1f4019 100644 --- a/cocoa/base/PrioritizeList.m +++ b/cocoa/base/PrioritizeList.m @@ -13,10 +13,8 @@ http://www.hardcoded.net/licenses/bsd_license @implementation PrioritizeList - (id)initWithPyRef:(PyObject *)aPyRef tableView:(NSTableView *)aTableView { - PyPrioritizeList *m = [[PyPrioritizeList alloc] initWithModel:aPyRef]; - self = [super initWithModel:m tableView:aTableView]; - [m bindCallback:createCallback(@"PrioritizeListView", self)]; - [m release]; + self = [super initWithPyRef:aPyRef wrapperClass:[PyPrioritizeList class] + callbackClassName:@"PrioritizeListView" view:aTableView]; return self; } diff --git a/cocoa/base/ResultTable.m b/cocoa/base/ResultTable.m index 2c5c1847..00703496 100644 --- a/cocoa/base/ResultTable.m +++ b/cocoa/base/ResultTable.m @@ -20,10 +20,7 @@ http://www.hardcoded.net/licenses/bsd_license @implementation ResultTable - (id)initWithPyRef:(PyObject *)aPyRef view:(NSTableView *)aTableView { - PyResultTable *m = [[PyResultTable alloc] initWithModel:aPyRef]; - self = [super initWithModel:m tableView:aTableView]; - [m bindCallback:createCallback(@"ResultTableView", self)]; - [m release]; + self = [super initWithPyRef:aPyRef wrapperClass:[PyResultTable class] callbackClassName:@"ResultTableView" view:aTableView]; _deltaColumns = [[NSSet setWithArray:[[self model] deltaColumns]] retain]; return self; } diff --git a/cocoa/base/StatsLabel.m b/cocoa/base/StatsLabel.m index 08f94814..834db89a 100644 --- a/cocoa/base/StatsLabel.m +++ b/cocoa/base/StatsLabel.m @@ -12,11 +12,8 @@ http://www.hardcoded.net/licenses/bsd_license @implementation StatsLabel - (id)initWithPyRef:(PyObject *)aPyRef view:(NSTextField *)aLabelView { - PyStatsLabel *m = [[PyStatsLabel alloc] initWithModel:aPyRef]; - self = [self initWithModel:m view:aLabelView]; - [m bindCallback:createCallback(@"StatsLabelView", self)]; - [m release]; - return self; + return [super initWithPyRef:aPyRef wrapperClass:[PyStatsLabel class] + callbackClassName:@"StatsLabelView" view:aLabelView]; } - (PyStatsLabel *)model