#import "WrappingDelegate.h"

@implementation WrappingDelegate

- (NSString *) selectedRowURL
{
	NSString *result = nil;
	int row = [oTable selectedRow];
	if (row >= 0)
	{
		result = [[oData objectAtIndex:row] objectForKey:@"url"];
	}
	return result;
}

- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{
	[oURLField setObjectValue:[self selectedRowURL]];
}

- (IBAction)openSelectedRow:(id)sender
{
	NSString *selectedRowURL = [self selectedRowURL];
	if (nil != selectedRowURL)
	{
		[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[self selectedRowURL]]];
	}
}

- (void)awakeFromNib
{
	NSEnumerator *theEnum = [[oTable tableColumns] objectEnumerator];
	NSTableColumn *theCol;
	while (nil != (theCol = [theEnum nextObject]) )
	{
		[[theCol dataCell] setWraps:YES];
	}

	// Permanently make the "description" column display with a small font.
	theCol = [oTable tableColumnWithIdentifier:@"description"];
	[[theCol dataCell] setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];

	[oTable setTarget:self];
	[oTable setDoubleAction:@selector(openSelectedRow:)];

	// Save the column positions in the table
	[oTable setAutosaveName:@"my table"];
	[oTable setAutosaveTableColumns:YES];
}

@end
