-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBCTableViewExtensions.m
138 lines (81 loc) · 4.15 KB
/
BCTableViewExtensions.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//
// BCTableViewExtensions.m
// Xynk
//
// Created by Tom Houpt on 14/7/25.
//
//
#import "BCTableViewExtensions.h"
@implementation NSTableView (ExportExtensions)
-(NSString *)tableAsTabDelimitedString; {
NSIndexSet *allColumns = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [self numberOfColumns])];
return [self columnsAsTabDelimitedString:allColumns];
}
-(NSString *)rowsAsTabDelimitedString:(NSIndexSet *)indexOfRows; {
NSMutableString *buffer = [NSMutableString string];
// add headers to buffer based on tableColumn titles
// add table cells to buffer, row by row
NSInteger rowIndex;
NSInteger numRows = [self numberOfRows];
BOOL firstPass;
for (rowIndex=0;rowIndex<numRows;rowIndex++) {
if ([indexOfRows containsIndex:rowIndex]) {
firstPass = YES;
// add cells to row, column by column
for (NSTableColumn *aTableColumn in [self tableColumns]) {
if (!firstPass) {[buffer appendString: @"\t"]; }
else { firstPass = NO; }
NSString *objectValue = [[self dataSource] tableView:self objectValueForTableColumn:aTableColumn row:rowIndex];
if (objectValue) { [buffer appendString:objectValue]; }
else {
// if blank column, leave table cell blank
if ([[[aTableColumn headerCell] stringValue] isEqualToString:[NSString string]]){
[buffer appendString:kBlankTabCellText];
}
else { [buffer appendString:kNoDataTabCellText]; }
}
} // next column
[buffer appendString: @"\n"];
} // row is in index
} // next row
return buffer;
}
-(NSString *)columnsAsTabDelimitedString:(NSIndexSet *)indexOfColumns; {
NSMutableString *buffer = [NSMutableString string];
// add headers to buffer based on tableColumn titles
BOOL firstPass = YES;
for (NSTableColumn *aTableColumn in [self tableColumns]) {
if ([indexOfColumns containsIndex:[[self tableColumns] indexOfObject:aTableColumn ]]) {
if (!firstPass) {[buffer appendString: @"\t"]; }
else { firstPass = NO; }
[buffer appendString:[[aTableColumn headerCell] stringValue]];
}
}
[buffer appendString: @"\n"];
// add headers to buffer based on tableColumn titles
// add table cells to buffer, row by row
NSInteger rowIndex;
NSInteger numRows = [self numberOfRows];
for (rowIndex=0;rowIndex<numRows;rowIndex++) {
firstPass = YES;
// add cells to row, column by column
for (NSTableColumn *aTableColumn in [self tableColumns]) {
if ([indexOfColumns containsIndex:[[self tableColumns] indexOfObject:aTableColumn ]]) {
if (!firstPass) {[buffer appendString: @"\t"]; }
else { firstPass = NO; }
NSString *objectValue = [[self dataSource] tableView:self objectValueForTableColumn:aTableColumn row:rowIndex];
if (objectValue) { [buffer appendString:objectValue]; }
else {
// if blank column, leave table cell blank
if ([[[aTableColumn headerCell] stringValue] isEqualToString:[NSString string]]){
[buffer appendString:kBlankTabCellText];
}
else { [buffer appendString:kNoDataTabCellText]; }
}
} // column is in index
} // next column
[buffer appendString: @"\n"];
} // next row
return buffer;
}
@end