// // MainWindowController.m // SolarSeek // // Created by Marcelo Alves on 2007.08.24. // Copyright 2007 __MyCompanyName__. All rights reserved. // #import "MainWindowController.h" #import "KBGradientOutlineView.h" #import @implementation MainWindowController - (IBAction)searchSomething:(id)sender { NSLog(@"Huh! %@", [quickSearch stringValue]); } -(id) managedObjectContext { return [NSApp valueForKeyPath:@"soulseek.managedObjectContext"]; } -(void) awakeFromNib { NSLog(@"awake from nib called"); [sidebar setDelegate:self]; [sidebar setUsesGradientSelection:YES]; [sidebar deselectAll:sidebar]; // registering with nsApp NSApplication *app = [NSApplication sharedApplication]; // [app setValue:self forKeyPath:@"appController.mainWindowController"]; id menuItem = [[[FScriptMenuItem alloc] init] autorelease]; [[NSApp mainMenu] addItem:menuItem]; [[[menuItem interpreterView] interpreter] setObject:[app valueForKeyPath:@"soulseek"] forIdentifier:@"slsk"]; } #pragma mark OutlinewView delegate - (void)outlineView:(NSOutlineView *)olv willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item { // If the row is selected but isn't being edited and the current drawing isn't being used to create a drag image, // colour the text white; otherwise, colour it black int rowIndex = [olv rowForItem:item]; NSColor *fontColor = ( [[olv selectedRowIndexes] containsIndex:rowIndex] && ([olv editedRow] != rowIndex) && (![[(KBGradientOutlineView *)olv draggedRows] containsIndex:rowIndex]) ) ? [NSColor whiteColor] : [NSColor blackColor]; [cell setTextColor:fontColor]; // setting the shadow for selected items. (Iwan wish) if (item && [olv levelForItem:item] >= 1) { // lines below are bugged, need to fix // if ( [[olv selectedRowIndexes] containsIndex:rowIndex] && ([olv editedRow] != rowIndex) && (![[(KBGradientOutlineView *)olv draggedRows] containsIndex:rowIndex]) ) // [cell setFont:[NSFont boldSystemFontOfSize:11.0f]]; // else // [cell setFont:[NSFont systemFontOfSize:11.0f]]; NSShadow *shadow = [NSShadow new]; NSSize shadowSize; shadowSize.width = 0.0f; shadowSize.height = -1.1f; [shadow setShadowOffset:shadowSize]; NSColor *shadowColor = ( [[olv selectedRowIndexes] containsIndex:rowIndex] && ([olv editedRow] != rowIndex) && (![[(KBGradientOutlineView *)olv draggedRows] containsIndex:rowIndex]) ) ? [NSColor colorWithDeviceRed:0.0f green:0.0f blue:0.0f alpha:0.75f] : [NSColor colorWithDeviceRed:0.0f green:0.0f blue:0.0f alpha:0.0f]; [shadow setShadowColor:shadowColor]; NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObjectsAndKeys: shadow, NSShadowAttributeName, nil]; NSMutableAttributedString *s = [[cell attributedStringValue] mutableCopy]; [s setAttributes:attrsDictionary range:NSMakeRange(0, [s length])]; [cell setAttributedStringValue:s]; } } - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item { BOOL shouldSelect = NO; @try { shouldSelect = [outlineView levelForItem:item] >= 1 ;// ![isTitle boolValue]; } @catch (NSException *exception) { return YES; } return shouldSelect; } #pragma mark Sort Descriptor for sidebar -(NSArray *) sidebarSortDescriptors { if (sidebarSortDescriptors == nil) { id orderDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"order" ascending:YES] autorelease]; id nameDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)] autorelease]; sidebarSortDescriptors = [[NSArray arrayWithObjects:orderDescriptor, nameDescriptor, nil] retain]; } return sidebarSortDescriptors; } @end