diff --git a/redo/table_darwin.go b/redo/table_darwin.go index bccaf1b..904600d 100644 --- a/redo/table_darwin.go +++ b/redo/table_darwin.go @@ -18,6 +18,7 @@ type table struct { scroller *scroller images []C.id + selected *event } func finishNewTable(b *tablebase, ty reflect.Type) Table { @@ -26,7 +27,9 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table { _id: id, scroller: newScroller(id, true), // border on Table tablebase: b, + selected: newEvent(), } + // also sets the delegate C.tableMakeDataSource(t._id, unsafe.Pointer(t)) for i := 0; i < ty.NumField(); i++ { cname := C.CString(ty.Field(i).Name) @@ -74,6 +77,10 @@ func (t *table) Select(index int) { C.tableSelect(t._id, C.intptr_t(index)) } +func (t *table) OnSelected(f func()) { + t.selected.set(f) +} + //export goTableDataSource_getValue func goTableDataSource_getValue(data unsafe.Pointer, row C.intptr_t, col C.intptr_t, outtype *C.int) unsafe.Pointer { t := (*table)(data) @@ -119,6 +126,12 @@ func goTableDataSource_toggled(data unsafe.Pointer, row C.intptr_t, col C.intptr datum.SetBool(fromBOOL(checked)) } +//export tableSelectionChanged +func tableSelectionChanged(data unsafe.Pointer) { + t := (*table)(data) + t.selected.fire() +} + func (t *table) id() C.id { return t._id } diff --git a/redo/table_darwin.m b/redo/table_darwin.m index 5fdac83..a8c85be 100644 --- a/redo/table_darwin.m +++ b/redo/table_darwin.m @@ -17,7 +17,7 @@ @implementation goTableColumn @end -@interface goTableDataSource : NSObject { +@interface goTableDataSource : NSObject { @public void *gotable; } @@ -63,6 +63,11 @@ goTableDataSource_toggled(self->gotable, (intptr_t) row, colnum, [value boolValue]); } +- (void)tableViewSelectionDidChange:(NSNotification *)note +{ + tableSelectionChanged(self->gotable); +} + @end id newTable(void) @@ -134,6 +139,7 @@ void tableUpdate(id t) [toNSTableView(t) reloadData]; } +// also sets the delegate void tableMakeDataSource(id table, void *gotable) { goTableDataSource *model; @@ -141,6 +147,7 @@ void tableMakeDataSource(id table, void *gotable) model = [goTableDataSource new]; model->gotable = gotable; [toNSTableView(table) setDataSource:model]; + [toNSTableView(table) setDelegate:model]; } // -[NSTableView sizeToFit] does not actually size to fit