Implemented Add/Save for TableView

This commit is contained in:
Armando Rivera 2021-08-03 00:37:15 -04:00
parent f4a06bf928
commit 27ebd03c48
2 changed files with 19 additions and 1 deletions

View File

@ -4,4 +4,6 @@ import NSFunctions
proc newTableview*(parent: ID, left, top, width, height: cint): ID {.cdecl, importc: "createTableView".}
proc addColumn*(parent: ID, name: cstring) {.cdecl, importc: "newTableColumn".}
proc addRow*(parent: ID, person: cstring) {.cdecl, importc: "addRow".}
proc addRow*(parent: ID, person: cstring) {.cdecl, importc: "addRow".}
proc saveTableView*(tview: ID, path: cstring) {.cdecl, importc: "tableviewSaveToFile".}
proc loadTableView*(tview: ID, path: cstring) {.cdecl, importc: "tableviewLoadFromFile".}

View File

@ -23,6 +23,7 @@
tbl = [[NSTableView alloc] initWithFrame: NSMakeRect(5,40,335,185)];
[tbl setGridStyleMask: NSTableViewGridNone];
[tbl setUsesAlternatingRowBackgroundColors: YES];
[tbl setAllowsColumnSelection: YES];
[tbl setAllowsColumnReordering: YES];
[tbl setAllowsEmptySelection: NO];
@ -112,4 +113,19 @@ void newTableColumn(id parent, const char *name) {
[tCol setTitle: title];
[[parent tbl] addTableColumn: tCol];
}
void tableviewSaveToFile(id tview, const char *path) {
[[tview db] writeToFile: NSSTR(path) atomically:YES];
}
void tableviewLoadFromFile(id tview, const char *path) {
NSArray *fileArrary = [NSArray arrayWithContentsOfFile: NSSTR(path)];
[[tview db] removeAllObjects];
for (NSMutableDictionary *x in fileArrary) {
[[tview db] addObject: x];
}
[[tview tbl] reloadData];
}