1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-22 06:00:41 +00:00

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]; fDefaults = [NSUserDefaults standardUserDefaults];
#warning move nib names to individual classes fMessageController = [[MessageWindowController alloc] init];
fMessageController = [[MessageWindowController alloc] initWithWindowNibName: @"MessageWindow"]; fInfoController = [[InfoWindowController alloc] init];
fInfoController = [[InfoWindowController alloc] initWithWindowNibName: @"InfoWindow"]; fPrefsController = [[PrefsController alloc] initWithHandle: fLib];
fPrefsController = [[PrefsController alloc] initWithWindowNibName: @"PrefsWindow" handle: fLib];
fBadger = [[Badger alloc] initWithLib: fLib]; fBadger = [[Badger alloc] initWithLib: fLib];

View file

@ -62,12 +62,18 @@ typedef enum
- (void) updateInfoFiles; - (void) updateInfoFiles;
- (void) updateInfoOptions; - (void) updateInfoOptions;
- (NSView *) tabViewForTag: (int) tag;
- (NSArray *) peerSortDescriptors; - (NSArray *) peerSortDescriptors;
@end @end
@implementation InfoWindowController @implementation InfoWindowController
- (id) init
{
return [super initWithWindowNibName: @"InfoWindow"];
}
- (void) awakeFromNib - (void) awakeFromNib
{ {
//get images //get images
@ -76,8 +82,15 @@ typedef enum
//window location and size //window location and size
NSPanel * window = (NSPanel *)[self window]; NSPanel * window = (NSPanel *)[self window];
/*[window setFrameAutosaveName: @"InspectorWindowFrame"]; float windowHeight = [window frame].size.height;
[window setFrameUsingName: @"InspectorWindowFrame"];*/
[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 setBecomesKeyOnlyIfNeeded: YES];
[window setAcceptsMouseMovedEvents: YES]; [window setAcceptsMouseMovedEvents: YES];
@ -146,11 +159,12 @@ typedef enum
- (void) dealloc - (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) if (fCurrentTabTag == TAB_PEERS_TAG || fCurrentTabTag == TAB_FILES_TAG)
{ [[NSUserDefaults standardUserDefaults] setFloat: viewHeight forKey: @"InspectorContentHeight"];
NSView * view = fCurrentTabTag == TAB_PEERS_TAG ? fPeersView : fFilesView;
[[NSUserDefaults standardUserDefaults] setFloat: [view frame].size.height forKey: @"InspectorContentHeight"];
}
[[NSNotificationCenter defaultCenter] removeObserver: self]; [[NSNotificationCenter defaultCenter] removeObserver: self];
@ -811,26 +825,7 @@ typedef enum
return; return;
//get old view //get old view
NSView * oldView; NSView * oldView = [self tabViewForTag: oldTabTag];
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;
}
[oldView setHidden: YES]; [oldView setHidden: YES];
[oldView removeFromSuperview]; [oldView removeFromSuperview];
@ -1007,33 +1002,6 @@ typedef enum
return nil; 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 - (int) outlineView: (NSOutlineView *) outlineView numberOfChildrenOfItem: (id) item
{ {
if (!item) if (!item)
@ -1367,3 +1335,53 @@ typedef enum
} }
@end @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 @implementation MessageWindowController
- (id) initWithWindowNibName: (NSString *) name - (id) init
{ {
if ((self = [super initWithWindowNibName: name])) if ((self = [super initWithWindowNibName: @"MessageWindow"]))
{ {
fMessages = [[NSMutableArray alloc] init]; fMessages = [[NSMutableArray alloc] init];

View file

@ -53,7 +53,7 @@
int fPublicPort, fNatStatus; int fPublicPort, fNatStatus;
} }
- (id) initWithWindowNibName: (NSString *) name handle: (tr_handle *) handle; - (id) initWithHandle: (tr_handle *) handle;
- (void) setUpdater: (SUUpdater *) updater; - (void) setUpdater: (SUUpdater *) updater;
- (void) setPort: (id) sender; - (void) setPort: (id) sender;

View file

@ -49,9 +49,9 @@
@implementation PrefsController @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]; fDefaults = [NSUserDefaults standardUserDefaults];
fHandle = handle; fHandle = handle;