diff --git a/ui/MainViewController.h b/ui/MainViewController.h index 11079f2..0297d16 100644 --- a/ui/MainViewController.h +++ b/ui/MainViewController.h @@ -1,5 +1,5 @@ #import #import "EventListener.h" -@interface MainViewController : NSViewController +@interface MainViewController : NSViewController @end diff --git a/ui/MainViewController.m b/ui/MainViewController.m index 2a3a682..5b48e55 100644 --- a/ui/MainViewController.m +++ b/ui/MainViewController.m @@ -2,6 +2,7 @@ #import "MainViewController.h" #import "MainView.h" #import "EventBridge.h" +#import "RequestHistory.h" @interface MainViewController () @@ -10,6 +11,7 @@ @property (nonatomic, strong) NSTextField *selectedDirectoryText; @property (nonatomic, strong) NSScrollView *historyContainer; @property (nonatomic, strong) NSTableView *historyTable; +@property (nonatomic, strong) RequestHistory *history; @end @@ -58,6 +60,7 @@ } - (void) createHistoryTable { + [self setHistory:[RequestHistory new]]; NSScrollView *tableContainer = [[NSScrollView alloc] init]; [tableContainer setTranslatesAutoresizingMaskIntoConstraints:NO]; [tableContainer setHasVerticalScroller:YES]; @@ -68,6 +71,7 @@ [tableView setTranslatesAutoresizingMaskIntoConstraints:NO]; [tableView setFocusRingType:NSFocusRingTypeNone]; [tableView setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone]; + [tableView setDataSource:self.history]; NSTableColumn *idColumn = [[NSTableColumn alloc] initWithIdentifier:@"id"]; [idColumn setTitle:@"id"]; @@ -140,10 +144,14 @@ - (void) serverDidReceiveRequest:(RequestMeta *)meta { NSLog(@"[MainViewController] request start: {%d %s}", meta->seq, meta->path); + [[self history] addRequestItem:meta]; + [[self historyTable] reloadData]; } - (void) serverDidWriteResponse:(ResponseMeta *)meta { NSLog(@"[MainViewController] request finish: {%d %d %d}", meta->seq, meta->status, meta->bytes); + [[self history] addResponseItem:meta]; + [[self historyTable] reloadData]; } @end diff --git a/ui/RequestHistory.h b/ui/RequestHistory.h new file mode 100644 index 0000000..f4f2cfa --- /dev/null +++ b/ui/RequestHistory.h @@ -0,0 +1,7 @@ +#import +#import "ui_darwin.h" + +@interface RequestHistory : NSObject +- (void) addRequestItem:(RequestMeta *)meta; +- (void) addResponseItem:(ResponseMeta *)meta; +@end diff --git a/ui/RequestHistory.m b/ui/RequestHistory.m new file mode 100644 index 0000000..5f163c6 --- /dev/null +++ b/ui/RequestHistory.m @@ -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