From b3c35b036c9bc36d340f6f8433cb8e32f5e88198 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sun, 7 Oct 2007 12:24:26 +0000 Subject: [PATCH] change some initializers so that they are aware of their own nib's name --- macosx/Controller.m | 7 +- macosx/InfoWindowController.m | 124 ++++++++++++++++++------------- macosx/MessageWindowController.m | 4 +- macosx/PrefsController.h | 2 +- macosx/PrefsController.m | 4 +- 5 files changed, 79 insertions(+), 62 deletions(-) diff --git a/macosx/Controller.m b/macosx/Controller.m index 56507e4bf..ca57695eb 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -166,10 +166,9 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi fDefaults = [NSUserDefaults standardUserDefaults]; - #warning move nib names to individual classes - fMessageController = [[MessageWindowController alloc] initWithWindowNibName: @"MessageWindow"]; - fInfoController = [[InfoWindowController alloc] initWithWindowNibName: @"InfoWindow"]; - fPrefsController = [[PrefsController alloc] initWithWindowNibName: @"PrefsWindow" handle: fLib]; + fMessageController = [[MessageWindowController alloc] init]; + fInfoController = [[InfoWindowController alloc] init]; + fPrefsController = [[PrefsController alloc] initWithHandle: fLib]; fBadger = [[Badger alloc] initWithLib: fLib]; diff --git a/macosx/InfoWindowController.m b/macosx/InfoWindowController.m index c13a13ceb..30e58f77c 100644 --- a/macosx/InfoWindowController.m +++ b/macosx/InfoWindowController.m @@ -62,12 +62,18 @@ typedef enum - (void) updateInfoFiles; - (void) updateInfoOptions; +- (NSView *) tabViewForTag: (int) tag; - (NSArray *) peerSortDescriptors; @end @implementation InfoWindowController +- (id) init +{ + return [super initWithWindowNibName: @"InfoWindow"]; +} + - (void) awakeFromNib { //get images @@ -76,8 +82,15 @@ typedef enum //window location and size NSPanel * window = (NSPanel *)[self window]; - /*[window setFrameAutosaveName: @"InspectorWindowFrame"]; - [window setFrameUsingName: @"InspectorWindowFrame"];*/ + float windowHeight = [window frame].size.height; + + [window setFrameAutosaveName: @"InspectorWindow"]; + [window setFrameUsingName: @"InspectorWindow"]; + + NSRect windowRect = [window frame]; + windowRect.origin.y -= windowHeight - windowRect.size.height; + windowRect.size.height = windowHeight; + [window setFrame: windowRect display: NO]; [window setBecomesKeyOnlyIfNeeded: YES]; [window setAcceptsMouseMovedEvents: YES]; @@ -146,11 +159,12 @@ typedef enum - (void) dealloc { + #warning not called? + float viewHeight = [[self tabViewForTag: fCurrentTabTag] frame].size.height; + + //save resizeable view height if (fCurrentTabTag == TAB_PEERS_TAG || fCurrentTabTag == TAB_FILES_TAG) - { - NSView * view = fCurrentTabTag == TAB_PEERS_TAG ? fPeersView : fFilesView; - [[NSUserDefaults standardUserDefaults] setFloat: [view frame].size.height forKey: @"InspectorContentHeight"]; - } + [[NSUserDefaults standardUserDefaults] setFloat: viewHeight forKey: @"InspectorContentHeight"]; [[NSNotificationCenter defaultCenter] removeObserver: self]; @@ -811,26 +825,7 @@ typedef enum return; //get old view - NSView * oldView; - switch (oldTabTag) - { - case TAB_INFO_TAG: - oldView = fInfoView; - break; - case TAB_ACTIVITY_TAG: - oldView = fActivityView; - break; - case TAB_PEERS_TAG: - oldView = fPeersView; - break; - case TAB_FILES_TAG: - oldView = fFilesView; - break; - case TAB_OPTIONS_TAG: - oldView = fOptionsView; - break; - } - + NSView * oldView = [self tabViewForTag: oldTabTag]; [oldView setHidden: YES]; [oldView removeFromSuperview]; @@ -1007,33 +1002,6 @@ typedef enum return nil; } -- (NSArray *) peerSortDescriptors -{ - NSMutableArray * descriptors = [NSMutableArray arrayWithCapacity: 2]; - - NSArray * oldDescriptors = [fPeerTable sortDescriptors]; - BOOL useSecond = YES, asc = YES; - if ([oldDescriptors count] > 0) - { - NSSortDescriptor * descriptor = [oldDescriptors objectAtIndex: 0]; - [descriptors addObject: descriptor]; - - if ((useSecond = ![[descriptor key] isEqualToString: @"IP"])) - asc = [descriptor ascending]; - } - - //sort by IP after primary sort - if (useSecond) - { - NSSortDescriptor * secondDescriptor = [[NSSortDescriptor alloc] initWithKey: @"IP" ascending: asc - selector: @selector(compareIP:)]; - [descriptors addObject: secondDescriptor]; - [secondDescriptor release]; - } - - return descriptors; -} - - (int) outlineView: (NSOutlineView *) outlineView numberOfChildrenOfItem: (id) item { if (!item) @@ -1367,3 +1335,53 @@ typedef enum } @end + +@implementation InfoWindowController (Private) + +- (NSView *) tabViewForTag: (int) tag +{ + switch (tag) + { + case TAB_INFO_TAG: + return fInfoView; + case TAB_ACTIVITY_TAG: + return fActivityView; + case TAB_PEERS_TAG: + return fPeersView; + case TAB_FILES_TAG: + return fFilesView; + case TAB_OPTIONS_TAG: + return fOptionsView; + default: + return nil; + } +} + +- (NSArray *) peerSortDescriptors +{ + NSMutableArray * descriptors = [NSMutableArray arrayWithCapacity: 2]; + + NSArray * oldDescriptors = [fPeerTable sortDescriptors]; + BOOL useSecond = YES, asc = YES; + if ([oldDescriptors count] > 0) + { + NSSortDescriptor * descriptor = [oldDescriptors objectAtIndex: 0]; + [descriptors addObject: descriptor]; + + if ((useSecond = ![[descriptor key] isEqualToString: @"IP"])) + asc = [descriptor ascending]; + } + + //sort by IP after primary sort + if (useSecond) + { + NSSortDescriptor * secondDescriptor = [[NSSortDescriptor alloc] initWithKey: @"IP" ascending: asc + selector: @selector(compareIP:)]; + [descriptors addObject: secondDescriptor]; + [secondDescriptor release]; + } + + return descriptors; +} + +@end diff --git a/macosx/MessageWindowController.m b/macosx/MessageWindowController.m index 6e1c80009..1a082a464 100644 --- a/macosx/MessageWindowController.m +++ b/macosx/MessageWindowController.m @@ -41,9 +41,9 @@ @implementation MessageWindowController -- (id) initWithWindowNibName: (NSString *) name +- (id) init { - if ((self = [super initWithWindowNibName: name])) + if ((self = [super initWithWindowNibName: @"MessageWindow"])) { fMessages = [[NSMutableArray alloc] init]; diff --git a/macosx/PrefsController.h b/macosx/PrefsController.h index 754ec3b34..899ab25ac 100644 --- a/macosx/PrefsController.h +++ b/macosx/PrefsController.h @@ -53,7 +53,7 @@ int fPublicPort, fNatStatus; } -- (id) initWithWindowNibName: (NSString *) name handle: (tr_handle *) handle; +- (id) initWithHandle: (tr_handle *) handle; - (void) setUpdater: (SUUpdater *) updater; - (void) setPort: (id) sender; diff --git a/macosx/PrefsController.m b/macosx/PrefsController.m index a82437de4..a3dabc84f 100644 --- a/macosx/PrefsController.m +++ b/macosx/PrefsController.m @@ -49,9 +49,9 @@ @implementation PrefsController -- (id) initWithWindowNibName: (NSString *) name handle: (tr_handle *) handle +- (id) initWithHandle: (tr_handle *) handle { - if ((self = [self initWithWindowNibName: name])) + if ((self = [super initWithWindowNibName: @"PrefsWindow"])) { fDefaults = [NSUserDefaults standardUserDefaults]; fHandle = handle;