change some initializers so that they are aware of their own nib's name

This commit is contained in:
Mitchell Livingston 2007-10-07 12:24:26 +00:00
parent 02e45340f4
commit b3c35b036c
5 changed files with 79 additions and 62 deletions

View File

@ -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];

View File

@ -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

View File

@ -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];

View File

@ -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;

View File

@ -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;