#import "SimpleSource.h"

@implementation SimpleSource

// ----------------------------------------------------------------------------------------
// Display
// ----------------------------------------------------------------------------------------

// This needs to be pretty fast, since it's called frequently.  Cache things if you can.

- (int)numberOfRowsInTableView:(NSTableView *)inTableView
{
	return [oData count];
}

- (id)tableView:(NSTableView *)inTableView
	objectValueForTableColumn:(NSTableColumn *)inTableColumn
	row:(int)inRowIndex
{
	NSDictionary *dict = [oData objectAtIndex:inRowIndex];
	return [dict objectForKey:[inTableColumn identifier]];
}

// ----------------------------------------------------------------------------------------
// Editing
// ----------------------------------------------------------------------------------------

- (void)tableView:(NSTableView *)inTableView
	  setObjectValue:(id)inObject
	  forTableColumn:(NSTableColumn *)inTableColumn
	  row:(int)inRowIndex
{
	NSMutableDictionary *dict = [oData objectAtIndex:inRowIndex];
	[dict setObject:inObject forKey:[inTableColumn identifier]];
}

// ----------------------------------------------------------------------------------------
// Deleting
// ----------------------------------------------------------------------------------------

- (void) deleteSelectedRowsInTableView:(NSTableView *)inTableView
{
	int row = [inTableView selectedRow];

	if (row >= 0)
	{
		NSEnumerator *theEnum = [inTableView selectedRowEnumerator];
		id theRowNumber;
		while (nil != (theRowNumber = [theEnum nextObject]) )
		{
			int row = [theRowNumber intValue];
			[oData replaceObjectAtIndex:row withObject:[NSNull null]];
		}

		// Now, remove the NSNull placeholders
		[oData removeObjectIdenticalTo:[NSNull null]];
		[inTableView deselectAll:nil];
		[inTableView reloadData];
	}
}





@end
