-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTableModel.m
59 lines (44 loc) · 1.4 KB
/
TableModel.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// TableModel.m
// Nodobo Replay
//
// Created by Alisdair McDiarmid on 22/09/2010.
// Copyright 2010 University of Strathclyde. All rights reserved.
//
#import "TableModel.h"
@implementation TableModel
@synthesize tableView;
@synthesize current;
- (void) setSession: (Session *) s
{
[session autorelease];
session = [s retain];
[tableView reloadData];
}
- (void) setCurrent: (Interaction *) i
{
[current autorelease];
current = [i retain];
NSUInteger index = [session.interactions indexOfObject: i];
if (index == NSNotFound)
return;
NSIndexSet * indexSet = [NSIndexSet indexSetWithIndex: index];
[tableView selectRowIndexes: indexSet byExtendingSelection: NO];
int rowsVisible = [tableView rowsInRect: [tableView visibleRect]].length;
[tableView scrollRowToVisible: [tableView selectedRow] - rowsVisible / 2];
[tableView scrollRowToVisible: [tableView selectedRow] + rowsVisible / 2];
}
- (id) tableView: (NSTableView *) tv objectValueForTableColumn: (NSTableColumn *) tc row: (int) ri
{
if (session == nil)
return nil;
Interaction * interaction = [session.interactions objectAtIndex: ri];
return [interaction performSelector: NSSelectorFromString([tc identifier])];
}
- (int) numberOfRowsInTableView: (NSTableView *) tv
{
if (session == nil)
return 0;
return [session.interactions count];
}
@end