add table view data source

master
Jordan Orelli 8 years ago
parent cc1256d99c
commit 1515a0d950

@ -1,5 +1,5 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import "EventListener.h" #import "EventListener.h"
@interface MainViewController : NSViewController <EventListener> @interface MainViewController : NSViewController <EventListener, NSTableViewDataSource>
@end @end

@ -2,6 +2,7 @@
#import "MainViewController.h" #import "MainViewController.h"
#import "MainView.h" #import "MainView.h"
#import "EventBridge.h" #import "EventBridge.h"
#import "RequestHistory.h"
@interface MainViewController () @interface MainViewController ()
@ -10,6 +11,7 @@
@property (nonatomic, strong) NSTextField *selectedDirectoryText; @property (nonatomic, strong) NSTextField *selectedDirectoryText;
@property (nonatomic, strong) NSScrollView *historyContainer; @property (nonatomic, strong) NSScrollView *historyContainer;
@property (nonatomic, strong) NSTableView *historyTable; @property (nonatomic, strong) NSTableView *historyTable;
@property (nonatomic, strong) RequestHistory *history;
@end @end
@ -58,6 +60,7 @@
} }
- (void) createHistoryTable { - (void) createHistoryTable {
[self setHistory:[RequestHistory new]];
NSScrollView *tableContainer = [[NSScrollView alloc] init]; NSScrollView *tableContainer = [[NSScrollView alloc] init];
[tableContainer setTranslatesAutoresizingMaskIntoConstraints:NO]; [tableContainer setTranslatesAutoresizingMaskIntoConstraints:NO];
[tableContainer setHasVerticalScroller:YES]; [tableContainer setHasVerticalScroller:YES];
@ -68,6 +71,7 @@
[tableView setTranslatesAutoresizingMaskIntoConstraints:NO]; [tableView setTranslatesAutoresizingMaskIntoConstraints:NO];
[tableView setFocusRingType:NSFocusRingTypeNone]; [tableView setFocusRingType:NSFocusRingTypeNone];
[tableView setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone]; [tableView setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];
[tableView setDataSource:self.history];
NSTableColumn *idColumn = [[NSTableColumn alloc] initWithIdentifier:@"id"]; NSTableColumn *idColumn = [[NSTableColumn alloc] initWithIdentifier:@"id"];
[idColumn setTitle:@"id"]; [idColumn setTitle:@"id"];
@ -140,10 +144,14 @@
- (void) serverDidReceiveRequest:(RequestMeta *)meta { - (void) serverDidReceiveRequest:(RequestMeta *)meta {
NSLog(@"[MainViewController] request start: {%d %s}", meta->seq, meta->path); NSLog(@"[MainViewController] request start: {%d %s}", meta->seq, meta->path);
[[self history] addRequestItem:meta];
[[self historyTable] reloadData];
} }
- (void) serverDidWriteResponse:(ResponseMeta *)meta { - (void) serverDidWriteResponse:(ResponseMeta *)meta {
NSLog(@"[MainViewController] request finish: {%d %d %d}", meta->seq, meta->status, meta->bytes); NSLog(@"[MainViewController] request finish: {%d %d %d}", meta->seq, meta->status, meta->bytes);
[[self history] addResponseItem:meta];
[[self historyTable] reloadData];
} }
@end @end

@ -0,0 +1,7 @@
#import <Cocoa/Cocoa.h>
#import "ui_darwin.h"
@interface RequestHistory : NSObject <NSTableViewDataSource>
- (void) addRequestItem:(RequestMeta *)meta;
- (void) addResponseItem:(ResponseMeta *)meta;
@end

@ -0,0 +1,35 @@
#import "RequestHistory.h"
@interface RequestHistory ()
@property (strong) NSMutableArray *items;
@end
@implementation RequestHistory
- (instancetype) init {
self = [super init];
if (self) {
[self setItems:[[NSMutableArray alloc] initWithCapacity:1000]];
}
return self;
}
- (NSInteger) numberOfRowsInTableView:(NSTableView *)view {
return [[self items] count];
}
- (id) tableView:(NSTableView *)view objectValueForTableColumn:(NSTableColumn *)column row:(NSInteger) row {
NSLog(@"[RequestHistory] objectValueForTableColumn: %@ row: %zd", column, row);
return [[self items] objectAtIndex:row];
}
- (void) addRequestItem:(RequestMeta *)meta {
NSLog(@"[RequestHistory] add request item");
[[self items] addObject:[NSValue valueWithBytes:meta objCType:@encode(RequestMeta)]];
}
- (void) addResponseItem:(ResponseMeta *)meta {
NSLog(@"[RequestHistory] add response item");
}
@end
Loading…
Cancel
Save