Skip to content
Browse files

Many internal changes. Export formats can be changed and shown in a p…

…review window. Fixed PPToolbarButton state display.Next: Change string replacing to be an array of hashes, one for the keys and one for the values.
  • Loading branch information...
1 parent 2abb731 commit 910cbd098e6c9d7f2cb62519ef47ac0c6c94c86b svnuser committed Oct 30, 2009
View
12 CSVDocument/CSVDocument.h
@@ -34,6 +34,7 @@
NSArray *columns; // needs to be an array to preserve column order
NSDictionary *columnDict; // readonly to allow fast access to columns by key
+ NSArray *activeColumns; // readonly to allow fast access to active columns
BOOL parseSuccessful;
BOOL autoDetectSeparator; // if YES will check for other separators (";" and TAB) than the comma
@@ -55,6 +56,7 @@
@property (nonatomic, retain) NSArray *columns;
@property (nonatomic, readonly, retain) NSDictionary *columnDict;
+@property (nonatomic, readonly) NSArray *activeColumns;
@property (nonatomic, assign) BOOL parseSuccessful;
@property (nonatomic, assign) BOOL autoDetectSeparator;
@@ -77,15 +79,9 @@
// column handling
- (void) addColumn:(CSVColumn *) newColumn;
-- (BOOL) isFirstColumnKey:(NSString *)columnKey;
-- (BOOL) hasColumnKey:(NSString *)columnKey;
-- (void) setColumnOrderByKeys:(NSArray *)newOrderKeys;
-
- (CSVColumn *) columnWithKey:(NSString *)columnKey;
-- (NSString *) nameForColumnKey:(NSString *)columnKey;
-- (NSString *) nameForColumnKey:(NSString *)columnKey quoted:(BOOL)quoted;
-- (void) setHeaderName:(NSString *)newName forColumnKey:(NSString *)columnKey;
-- (void) setHeaderActive:(BOOL)active forColumnKey:(NSString *)columnKey;
+- (void) setColumnOrderByKeys:(NSArray *)newOrderKeys;
+- (void) setColumnActive:(BOOL)active forColumnKey:(NSString *)columnKey;
// row handling
- (CSVRow *) rowAtIndex:(NSUInteger)rowIndex;
View
151 CSVDocument/CSVDocument.m
@@ -19,6 +19,7 @@ @interface CSVDocument ()
@property (nonatomic, readwrite, retain) NSDictionary *columnDict;
- (void) setColumnDict:(NSDictionary *)newColumnDict;
+- (void) updateColumnNames;
- (void) notifyDelegateOfParsedRow:(CSVRow *)newRow;
@end
@@ -32,6 +33,7 @@ @implementation CSVDocument
@synthesize rows;
@synthesize numRows;
@synthesize columnDict;
+@dynamic activeColumns;
#ifndef IPHONE
@synthesize rowController;
#endif
@@ -208,12 +210,9 @@ - (BOOL) parseCSVString:(NSString *)string maxRows:(NSUInteger)maxRows error:(NS
else { // This is a column separating separator
NSString *newCellString = [[currentCellString copy] autorelease];
if (isNewColumn) {
- if (nil != newCellString && ![@"" isEqualToString:newCellString]) {
+ if (![newCellString isEqualToString:@""]) {
column.name = newCellString;
columnHasName = YES;
- if (nil == [self columnWithKey:newCellString]) {
- column.key = newCellString;
- }
}
[self addColumn:column];
isNewColumn = NO;
@@ -233,20 +232,17 @@ - (BOOL) parseCSVString:(NSString *)string maxRows:(NSUInteger)maxRows error:(NS
}
}
- // found a newline
- else if ([scanner scanCharactersFromSet:newlineCharacterSet intoString:&tempString]) {
- if (insideQuotes) { // We're inside quotes - add line break to column text
- [currentCellString appendString:tempString];
+ // found a newline or the end of the document
+ else if ([scanner scanCharactersFromSet:newlineCharacterSet intoString:&tempString] || [scanner isAtEnd]) {
+ if (insideQuotes && ![scanner isAtEnd]) { // newline inside double quotes
+ [currentCellString appendString:separator];
}
- else { // End of row
+ else { // a real newline or the end
NSString *newCellString = [[currentCellString copy] autorelease];
if (isNewColumn) {
- if (nil != newCellString && ![@"" isEqualToString:newCellString]) {
+ if (![newCellString isEqualToString:@""]) {
column.name = newCellString;
columnHasName = YES;
- if (nil == [self columnWithKey:newCellString]) {
- column.key = newCellString;
- }
}
[self addColumn:column];
isNewColumn = NO;
@@ -259,29 +255,6 @@ - (BOOL) parseCSVString:(NSString *)string maxRows:(NSUInteger)maxRows error:(NS
finishedRow = YES;
}
}
-
-
- // found the end of the document
- else if ([scanner isAtEnd]) {
- NSString *newCellString = [[currentCellString copy] autorelease];
- if (isNewColumn) {
- if (nil != newCellString && ![@"" isEqualToString:newCellString]) {
- column.name = newCellString;
- columnHasName = YES;
- if (nil == [self columnWithKey:newCellString]) {
- column.key = newCellString;
- }
- }
- [self addColumn:column];
- isNewColumn = NO;
- }
- if (!columnHasName) {
- column.name = newCellString;
- }
-
- [newRow setValue:newCellString forColumn:column];
- finishedRow = YES;
- }
}
@@ -346,20 +319,14 @@ - (BOOL) parseCSVString:(NSString *)string maxRows:(NSUInteger)maxRows error:(NS
#ifdef CSV_STRING_EXPORTING
- (NSString *) stringInFormat:(PPStringFormat *)format withColumns:(NSArray *)columnArray forRowIndexes:(NSIndexSet *)rowIndexes includeHeaders:(BOOL)headerFlag
{
- if ([columnArray count] < 1) {
+ if ([rows count] < 1 || [columnArray count] < 1) {
return @"";
}
if (nil == format) {
format = [PPStringFormat csvFormat];
}
- // extract keys from column objects
- NSMutableArray *columnKeys = [NSMutableArray arrayWithCapacity:[columnArray count]];
- for (CSVColumn *column in columnArray) {
- [columnKeys addObject:column.key];
- }
-
// get desired row indexes if not given
// TODO: Also return header rows if we want the headers!
NSArray *exportRows = nil;
@@ -372,12 +339,20 @@ - (NSString *) stringInFormat:(PPStringFormat *)format withColumns:(NSArray *)co
}
}
if (nil != rowIndexes) {
+ NSUInteger num = [rows count];
+
+ // verify indexes
+ if ([rowIndexes lastIndex] >= num) {
+ NSUInteger start = [rowIndexes firstIndex] >= num ? num - 1 : [rowIndexes firstIndex];
+ NSUInteger length = (num - start) > 0 ? num - start : 1;
+ rowIndexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(start, length)];
+ }
exportRows = [[rowController arrangedObjects] objectsAtIndexes:rowIndexes];
}
// get the string from the formatter
- NSString *string = [format stringForRows:exportRows includeHeaderRows:headerFlag withColumnKeys:columnKeys];
- NSLog(@"--> %@ stringInFormat: is returning string:\n%@", self, string);
+ NSString *string = [format stringForRows:exportRows includeHeaderRows:headerFlag withColumns:columnArray];
+ //NSLog(@"--> %@ stringInFormat: is returning string:\n%@", self, string);
return string;
}
#endif
@@ -408,20 +383,23 @@ - (void) addColumn:(CSVColumn *) newColumn
}
}
-- (BOOL) isFirstColumnKey:(NSString *)columnKey
+- (CSVColumn *) columnWithKey:(NSString *)columnKey
{
- if ((nil != columns) && ([columns count] > 0)) {
- CSVColumn *firstColumn = [columns objectAtIndex:0];
- return [columnKey isEqualToString:firstColumn.name];
- }
-
- return NO;
+ return [columnDict objectForKey:columnKey];
}
-
-- (BOOL) hasColumnKey:(NSString *)columnKey
+- (NSArray *) activeColumns
{
- return (nil != [columnDict objectForKey:columnKey]);
+ NSMutableArray *arr = [NSMutableArray array];
+ if ([columns count] > 0) {
+ for (CSVColumn *column in columns) {
+ if (column.active) {
+ [arr addObject:column];
+ }
+ }
+ }
+
+ return arr;
}
- (void) setColumnOrderByKeys:(NSArray *)newOrderKeys
@@ -435,36 +413,29 @@ - (void) setColumnOrderByKeys:(NSArray *)newOrderKeys
}
self.columns = arr;
- NSLog(@"columns: %@", columns);
}
-
-- (CSVColumn *) columnWithKey:(NSString *)columnKey
-{
- return [columnDict objectForKey:columnKey];
-}
-
-- (NSString *) nameForColumnKey:(NSString *)columnKey
-{
- return [self nameForColumnKey:columnKey quoted:NO];
-}
-
-- (NSString *) nameForColumnKey:(NSString *)columnKey quoted:(BOOL)quoted
-{
- NSString *name = ((CSVColumn *)[columnDict objectForKey:columnKey]).name;
- return quoted ? [NSString stringWithFormat:@"\"%@\"", name] : name;
-}
-
-- (void) setHeaderName:(NSString *)newName forColumnKey:(NSString *)columnKey
+- (void) setColumnActive:(BOOL)active forColumnKey:(NSString *)columnKey
{
CSVColumn *column = [columnDict objectForKey:columnKey];
- column.name = newName;
+ column.active = active;
}
-- (void) setHeaderActive:(BOOL)active forColumnKey:(NSString *)columnKey
+- (void) updateColumnNames
{
- CSVColumn *column = [columnDict objectForKey:columnKey];
- column.active = active;
+ if (numHeaderRows < 1) {
+ for (CSVColumn *column in columns) {
+ column.name = nil;
+ }
+ }
+ else {
+ CSVRow *firstRow = [self rowAtIndex:0];
+ for (CSVColumn *column in columns) {
+ if (![column hasName]) {
+ column.name = [firstRow valueForColumn:column];
+ }
+ }
+ }
}
#pragma mark -
@@ -483,10 +454,10 @@ - (CSVRow *) rowAtIndex:(NSUInteger)rowIndex
- (void) changeNumHeaderRows:(NSUInteger)newNum
{
NSUInteger i;
- NSUInteger max = (newNum > numHeaderRows) ? newNum : numHeaderRows;
+ NSUInteger num = (newNum > numHeaderRows) ? newNum : numHeaderRows;
NSUInteger num_rows = [rows count];
- for (i = 0; i < max; i++) {
+ for (i = 0; i < num; i++) {
if (num_rows > i) {
CSVRow *row = [self rowAtIndex:i];
[row changeHeaderRow:(i < newNum)];
@@ -495,6 +466,7 @@ - (void) changeNumHeaderRows:(NSUInteger)newNum
[self rearrangeRows];
self.numHeaderRows = newNum;
+ [self updateColumnNames];
}
- (void) rearrangeRows
@@ -515,17 +487,24 @@ - (void) setNumRowsWithInt:(NSInteger)num_rows
- (void) row:(CSVRow *)thisRow didBecomeHeaderRow:(BOOL)itDid
{
- if (itDid) {
- numHeaderRows += 1;
- }
- else {
- numHeaderRows -= 1;
+ // keep the number of header rows up to date (maybe strip this counting entirely?)
+ if (nil != thisRow) {
+ if (itDid) {
+ numHeaderRows += 1;
+ }
+ else {
+ numHeaderRows -= 1;
+ }
}
-
+
+ // rearrange
[self rearrangeRows];
if ([delegate respondsToSelector:@selector(csvDocument:didChangeRowOrderToOriginalOrder:)]) {
[delegate csvDocument:self didChangeRowOrderToOriginalOrder:NO];
}
+
+ // update column names
+ [self updateColumnNames];
}
#pragma mark -
View
7 CSVDocument/CSVRow.m
@@ -179,9 +179,16 @@ - (void) setValue:(id)value forColumn:(CSVColumn *)column
- (void) setValue:(id)value forColumnKey:(NSString *)key
{
if (nil != key) {
+ value = (nil != value) ? value : [NSNull null];
[rowValues setObject:value forKey:key];
}
}
+
+- (void) setValue:(id)value forKeyPath:(NSString *)keyPath
+{
+ NSLog(@"%@ -> %@", keyPath, value);
+ [super setValue:value forKeyPath:keyPath];
+}
#pragma mark -
View
6,692 CSVManipulator.xcodeproj/pp.pbxuser
5,683 additions, 1,009 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
112 CSVManipulator.xcodeproj/pp.perspectivev3
@@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>ActivePerspectiveName</key>
- <string>Project</string>
+ <string>Debug</string>
<key>AllowedModules</key>
<array>
<dict>
@@ -280,14 +280,14 @@
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array>
<array>
- <integer>30</integer>
+ <integer>28</integer>
<integer>22</integer>
<integer>1</integer>
<integer>0</integer>
</array>
</array>
<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
- <string>{{0, 71}, {257, 867}}</string>
+ <string>{{0, 0}, {257, 867}}</string>
</dict>
<key>PBXTopSmartGroupGIDs</key>
<array/>
@@ -305,8 +305,6 @@
<string>MainColumn</string>
<real>235</real>
</array>
- <key>RubberWindowFrame</key>
- <string>201 102 1430 926 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>PBXSmartGroupTreeModule</string>
@@ -317,26 +315,24 @@
<key>Dock</key>
<array>
<dict>
- <key>BecomeActive</key>
- <true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>EEF027910D6D8015000532A4</string>
<key>PBXProjectModuleLabel</key>
- <string>PPStringFormatManager.m</string>
+ <string>PPStringFormatEntity.m</string>
<key>PBXSplitModuleInNavigatorKey</key>
<dict>
<key>Split0</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>EEF027920D6D8015000532A4</string>
<key>PBXProjectModuleLabel</key>
- <string>PPStringFormatManager.m</string>
+ <string>PPStringFormatEntity.m</string>
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
- <string>EE137CCB109608FE00D31816</string>
+ <string>EE118BC4109B44F00072804F</string>
<key>history</key>
<array>
<string>EECAA3C10D803E5200AE2D4A</string>
@@ -356,49 +352,51 @@
<string>EE13773B1088A0B700D31816</string>
<string>EE13773C1088A0B700D31816</string>
<string>EE13778E1088A95400D31816</string>
- <string>EE1378DE1088BCD400D31816</string>
<string>EE1379401088C32E00D31816</string>
<string>EE13795A1088C3F300D31816</string>
<string>EE13795B1088C3F300D31816</string>
- <string>EE13797B1088C4F700D31816</string>
<string>EE1379E7108F07B200D31816</string>
<string>EE137A9D10904B7A00D31816</string>
<string>EE137ACA10905AA200D31816</string>
<string>EE137ACB10905AA200D31816</string>
<string>EE137ACC10905AA200D31816</string>
<string>EE137B11109065AF00D31816</string>
- <string>EE137B5010907AA000D31816</string>
<string>EE137B8B10907FA000D31816</string>
<string>EE137B8C10907FA000D31816</string>
- <string>EE137BD71090882C00D31816</string>
- <string>EE137BDD10908C7A00D31816</string>
- <string>EE137BDE10908C7A00D31816</string>
- <string>EE137BF21090B63500D31816</string>
<string>EE137BF51090B63500D31816</string>
- <string>EE137BF61090B63500D31816</string>
- <string>EE137C091090B8BF00D31816</string>
- <string>EE137C0A1090B8BF00D31816</string>
- <string>EE137C361095E81100D31816</string>
- <string>EE137C371095E81100D31816</string>
- <string>EE137C391095E81100D31816</string>
<string>EE137C3A1095E81100D31816</string>
- <string>EE137C451095EA3D00D31816</string>
- <string>EE137C4E1095EDF000D31816</string>
- <string>EE137C6A1096013100D31816</string>
- <string>EE137C701096016900D31816</string>
- <string>EE137C871096037800D31816</string>
- <string>EE137C881096037800D31816</string>
- <string>EE137CA6109606E400D31816</string>
- <string>EE137CA7109606E400D31816</string>
<string>EE137CA9109606E400D31816</string>
- <string>EE137CAA109606E400D31816</string>
- <string>EE137CAB109606E400D31816</string>
<string>EE137CC3109608E900D31816</string>
- <string>EE137CC4109608E900D31816</string>
- <string>EE137CC5109608E900D31816</string>
- <string>EE137CC6109608E900D31816</string>
<string>EE137CC7109608E900D31816</string>
- <string>EE137CC8109608E900D31816</string>
+ <string>EE1188FB1099E0D80072804F</string>
+ <string>EE1189E6109AED000072804F</string>
+ <string>EE1189E8109AED000072804F</string>
+ <string>EE118A4E109AFA990072804F</string>
+ <string>EE118A4F109AFA990072804F</string>
+ <string>EE118A53109AFED80072804F</string>
+ <string>EE118A5A109AFED80072804F</string>
+ <string>EE118A64109B00790072804F</string>
+ <string>EE118A65109B00790072804F</string>
+ <string>EE118ABA109B0ADC0072804F</string>
+ <string>EE118AC5109B0B3F0072804F</string>
+ <string>EE118ACE109B240E0072804F</string>
+ <string>EE118AEE109B29D60072804F</string>
+ <string>EE118B09109B30470072804F</string>
+ <string>EE118B1C109B31E20072804F</string>
+ <string>EE118B44109B34390072804F</string>
+ <string>EE118B62109B3C210072804F</string>
+ <string>EE118B7A109B3E4B0072804F</string>
+ <string>EE118B83109B3F050072804F</string>
+ <string>EE118B84109B3F050072804F</string>
+ <string>EE118B85109B3F050072804F</string>
+ <string>EE118B93109B406C0072804F</string>
+ <string>EE118B9F109B42760072804F</string>
+ <string>EE118BAD109B42D00072804F</string>
+ <string>EE118BB8109B44C10072804F</string>
+ <string>EE118BB9109B44C10072804F</string>
+ <string>EE118BBA109B44C10072804F</string>
+ <string>EE118BBB109B44C10072804F</string>
+ <string>EE118BBC109B44C10072804F</string>
</array>
</dict>
<key>SplitCount</key>
@@ -413,8 +411,6 @@
<dict>
<key>Frame</key>
<string>{{0, 0}, {1151, 880}}</string>
- <key>RubberWindowFrame</key>
- <string>201 102 1430 926 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
@@ -437,7 +433,7 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
- <string>{{10, 27}, {1151, -27}}</string>
+ <string>{{10, 27}, {1151, 237}}</string>
</dict>
<key>Module</key>
<string>XCDetailModule</string>
@@ -492,7 +488,7 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
- <string>{{10, 27}, {1151, -27}}</string>
+ <string>{{0, 0}, {480, 244}}</string>
</dict>
<key>Module</key>
<string>PBXCVSModule</string>
@@ -513,8 +509,6 @@
<dict>
<key>Frame</key>
<string>{{10, 27}, {1151, -27}}</string>
- <key>RubberWindowFrame</key>
- <string>201 102 1430 926 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>PBXBuildResultsModule</string>
@@ -542,11 +536,11 @@
</array>
<key>TableOfContents</key>
<array>
- <string>EE1376741088622D00D31816</string>
+ <string>EE1188B41099DACC0072804F</string>
<string>1CA23ED40692098700951B8B</string>
- <string>EE1376751088622D00D31816</string>
+ <string>EE1188B51099DACC0072804F</string>
<string>EEF027910D6D8015000532A4</string>
- <string>EE1376761088622D00D31816</string>
+ <string>EE1188B61099DACC0072804F</string>
<string>1CA23EDF0692099D00951B8B</string>
<string>1CA23EE00692099D00951B8B</string>
<string>1CA23EE10692099D00951B8B</string>
@@ -598,6 +592,8 @@
<dict>
<key>Frame</key>
<string>{{0, 0}, {1430, 533}}</string>
+ <key>RubberWindowFrame</key>
+ <string>201 102 1430 926 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>PBXDebugCLIModule</string>
@@ -672,7 +668,11 @@
</array>
<key>Frame</key>
<string>{{0, 173}, {716, 174}}</string>
+ <key>RubberWindowFrame</key>
+ <string>201 102 1430 926 0 0 1680 1028 </string>
</dict>
+ <key>RubberWindowFrame</key>
+ <string>201 102 1430 926 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>PBXDebugSessionModule</string>
@@ -695,14 +695,14 @@
</array>
<key>TableOfContents</key>
<array>
- <string>EE1376771088622D00D31816</string>
+ <string>EE1188B71099DACC0072804F</string>
<string>1CCC7628064C1048000F2A68</string>
<string>1CCC7629064C1048000F2A68</string>
- <string>EE1376781088622D00D31816</string>
- <string>EE1376791088622D00D31816</string>
- <string>EE13767A1088622D00D31816</string>
- <string>EE13767B1088622D00D31816</string>
- <string>EE13767C1088622D00D31816</string>
+ <string>EE1188B81099DACC0072804F</string>
+ <string>EE1188B91099DACC0072804F</string>
+ <string>EE1188BA1099DACC0072804F</string>
+ <string>EE1188BB1099DACC0072804F</string>
+ <string>EE1188BC1099DACC0072804F</string>
</array>
<key>ToolbarConfigUserDefaultsMinorVersion</key>
<string>2</string>
@@ -734,10 +734,10 @@
<integer>5</integer>
<key>WindowOrderList</key>
<array>
- <string>EE137CCA109608E900D31816</string>
+ <string>EE118BC5109B44F00072804F</string>
<string>EEF071321086083800C05DE9</string>
- <string>EE13768B1088687A00D31816</string>
- <string>EE13768C1088687A00D31816</string>
+ <string>EE1188C31099DB910072804F</string>
+ <string>EE1188C41099DB910072804F</string>
<string>/Users/pp/Cocoa/CSVManipulator/CSVManipulator.xcodeproj</string>
</array>
<key>WindowString</key>
@@ -1573,7 +1573,7 @@
<key>TableOfContents</key>
<array>
<string>EEF071321086083800C05DE9</string>
- <string>EE1379891088C5EB00D31816</string>
+ <string>EE1189AF1099FDEA0072804F</string>
<string>EEF071311086083800C05DE9</string>
</array>
<key>WindowString</key>
View
12 CSVManipulator.xcodeproj/project.pbxproj
@@ -27,6 +27,7 @@
8D15AC320486D014006FF6A4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A37F4B0FDCFA73011CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D15AC340486D014006FF6A4 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A7FEA54F5311CA2CBB /* Cocoa.framework */; };
EE0D3A2A0D6F02350009A7B2 /* DataTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = EE0D3A290D6F02350009A7B2 /* DataTableView.m */; };
+ EE1189361099E7450072804F /* PPStringFormatsController.m in Sources */ = {isa = PBXBuildFile; fileRef = EE1189351099E7450072804F /* PPStringFormatsController.m */; };
EE137ABC1090568600D31816 /* TB_add_column.tiff in Resources */ = {isa = PBXBuildFile; fileRef = EE137AB71090568600D31816 /* TB_add_column.tiff */; };
EE137ABD1090568600D31816 /* TB_inspector.tiff in Resources */ = {isa = PBXBuildFile; fileRef = EE137AB81090568600D31816 /* TB_inspector.tiff */; };
EE137ABE1090568600D31816 /* TB_remove_column.tiff in Resources */ = {isa = PBXBuildFile; fileRef = EE137AB91090568600D31816 /* TB_remove_column.tiff */; };
@@ -67,7 +68,7 @@
isa = PBXContainerItemProxy;
containerPortal = 2A37F4A9FDCFA73011CA2CEA /* Project object */;
proxyType = 1;
- remoteGlobalIDString = EE1377031088767D00D31816 /* Save IB Files */;
+ remoteGlobalIDString = EE1377031088767D00D31816;
remoteInfo = "Save IB Files";
};
/* End PBXContainerItemProxy section */
@@ -87,6 +88,8 @@
8D15AC370486D014006FF6A4 /* CSVManipulator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CSVManipulator.app; sourceTree = BUILT_PRODUCTS_DIR; };
EE0D3A280D6F02350009A7B2 /* DataTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataTableView.h; sourceTree = "<group>"; };
EE0D3A290D6F02350009A7B2 /* DataTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DataTableView.m; sourceTree = "<group>"; };
+ EE1189341099E7450072804F /* PPStringFormatsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PPStringFormatsController.h; sourceTree = "<group>"; };
+ EE1189351099E7450072804F /* PPStringFormatsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PPStringFormatsController.m; sourceTree = "<group>"; };
EE1377641088A54D00D31816 /* DataTableViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataTableViewDelegate.h; sourceTree = "<group>"; };
EE137AB71090568600D31816 /* TB_add_column.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = TB_add_column.tiff; sourceTree = "<group>"; };
EE137AB81090568600D31816 /* TB_inspector.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = TB_inspector.tiff; sourceTree = "<group>"; };
@@ -95,7 +98,7 @@
EE137ABB1090568600D31816 /* TB_add_row.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = TB_add_row.tiff; sourceTree = "<group>"; };
EE137C291095E68F00D31816 /* PPStringFormatManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PPStringFormatManager.h; sourceTree = "<group>"; };
EE137C2A1095E68F00D31816 /* PPStringFormatManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PPStringFormatManager.m; sourceTree = "<group>"; };
- EE137C321095E80700D31816 /* PPStringFormatManager.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PPStringFormatManager.xib; sourceTree = "<group>"; };
+ EE137C321095E80700D31816 /* PPStringFormatManager.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = PPStringFormatManager.xib; path = ../PPStringFormatManager.xib; sourceTree = "<group>"; };
EE15121C0D7F048D0092C02F /* DataTableColumn.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataTableColumn.h; sourceTree = "<group>"; };
EE15121D0D7F048D0092C02F /* DataTableColumn.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DataTableColumn.m; sourceTree = "<group>"; };
EE15121E0D7F048D0092C02F /* DataTableHeaderCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataTableHeaderCell.h; sourceTree = "<group>"; };
@@ -242,7 +245,6 @@
EE9E1DF31046BE3900554687 /* MainMenu.xib */,
EE9E1DED1046BDC400554687 /* MyDocument.xib */,
EE64B6AD104A8598000DF5D2 /* CSVInspector.xib */,
- EE137C321095E80700D31816 /* PPStringFormatManager.xib */,
8D15AC360486D014006FF6A4 /* Info.plist */,
089C165FFE840EACC02AAC07 /* InfoPlist.strings */,
);
@@ -307,8 +309,11 @@
EE64B6FD104A9761000DF5D2 /* PPStringFormatRow.m */,
EE64B6F7104A9648000DF5D2 /* PPStringFormatEntity.h */,
EE64B6F8104A9648000DF5D2 /* PPStringFormatEntity.m */,
+ EE1189341099E7450072804F /* PPStringFormatsController.h */,
+ EE1189351099E7450072804F /* PPStringFormatsController.m */,
EE137C291095E68F00D31816 /* PPStringFormatManager.h */,
EE137C2A1095E68F00D31816 /* PPStringFormatManager.m */,
+ EE137C321095E80700D31816 /* PPStringFormatManager.xib */,
);
path = FileExport;
sourceTree = "<group>";
@@ -466,6 +471,7 @@
EE219ED5107F849100E28D4D /* DataTableCell.m in Sources */,
EEF072F01086302800C05DE9 /* DataTableHeaderView.m in Sources */,
EE137C2B1095E68F00D31816 /* PPStringFormatManager.m in Sources */,
+ EE1189361099E7450072804F /* PPStringFormatsController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
2 CSVWindowController.m
@@ -204,7 +204,7 @@ - (void) tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *
- (void) tableView:(DataTableView *)tableView didChangeTableColumnState:(DataTableColumn *)tableColumn
{
- [document.csvDocument setHeaderActive:tableColumn.active forColumnKey:[tableColumn identifier]];
+ [document.csvDocument setColumnActive:tableColumn.active forColumnKey:[tableColumn identifier]];
document.documentEdited = YES;
}
View
22 English.lproj/MyDocument.xib
@@ -12,7 +12,7 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="5"/>
+ <integer value="100362"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -940,6 +940,22 @@
</object>
<int key="connectionID">100402</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">enabled: document.csvDocument.rowController.canRemove</string>
+ <reference key="source" ref="279959149"/>
+ <reference key="destination" ref="512844837"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="279959149"/>
+ <reference key="NSDestination" ref="512844837"/>
+ <string key="NSLabel">enabled: document.csvDocument.rowController.canRemove</string>
+ <string key="NSBinding">enabled</string>
+ <string key="NSKeyPath">document.csvDocument.rowController.canRemove</string>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">100407</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -1303,7 +1319,7 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{377, 926}, {616, 0}}</string>
+ <string>{{377, 699}, {616, 227}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -1344,7 +1360,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">100404</int>
+ <int key="maxID">100407</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
View
22 FileExport/PPStringFormat.h
@@ -10,30 +10,34 @@
@class PPStringFormatRow;
-@interface PPStringFormat : NSObject {
+@interface PPStringFormat : NSObject <NSCopying> {
+ BOOL systemFormat; // indicates whether this is a system format or not
NSString *name;
+ NSString *formatDescription;
NSString *prefix; // what to put before the content, e.g. <root>
NSString *suffix; // obviously what to put after, e.g. </root>
- PPStringFormatRow *headerFormat;
- PPStringFormatRow *valueFormat;
+ PPStringFormatRow *headerFormat; // the formatRow that formats rows marked as header
+ PPStringFormatRow *valueFormat; // the formatRow that formats arbitrary rows
}
-@property (copy) NSString *name;
+@property (nonatomic, assign, getter=isSystemFormat) BOOL systemFormat;
+@property (nonatomic, copy) NSString *name;
+@property (nonatomic, copy) NSString *formatDescription;
-@property (copy) NSString *prefix;
-@property (copy) NSString *suffix;
+@property (nonatomic, copy) NSString *prefix;
+@property (nonatomic, copy) NSString *suffix;
-@property (retain) PPStringFormatRow *headerFormat;
-@property (retain) PPStringFormatRow *valueFormat;
+@property (nonatomic, retain) PPStringFormatRow *headerFormat;
+@property (nonatomic, retain) PPStringFormatRow *valueFormat;
+ (PPStringFormat *) csvFormat;
+ (PPStringFormat *) tabFormat;
+ (PPStringFormat *) flatXMLFormat;
-- (NSString *) stringForRows:(NSArray *)csvRows includeHeaderRows:(BOOL)includeHeaderRows withColumnKeys:(NSArray *)keys;
+- (NSString *) stringForRows:(NSArray *)csvRows includeHeaderRows:(BOOL)includeHeaderRows withColumns:(NSArray *)columns;
- (NSString *) headerForColumnKeys:(NSArray *)keys values:(NSArray *)values;
- (NSString *) rowForColumnKeys:(NSArray *)keys values:(NSArray *)values;
View
108 FileExport/PPStringFormat.m
@@ -9,12 +9,15 @@
#import "PPStringFormat.h"
#import "PPStringFormatRow.h"
#import "PPStringFormatEntity.h"
+#import "CSVColumn.h"
#import "CSVRow.h"
@implementation PPStringFormat
+@synthesize systemFormat;
@synthesize name;
+@synthesize formatDescription;
@synthesize prefix;
@synthesize suffix;
@@ -32,9 +35,24 @@ - (id) initWithName:(NSString *)newName
return self;
}
+- (id) copyWithZone:(NSZone *)zone
+{
+ PPStringFormat *copy = [[[self class] allocWithZone:zone] initWithName:self.name];
+ // copies are newer system formats, so don't assign the bool
+ copy.formatDescription = self.formatDescription;
+ copy.prefix = self.prefix;
+ copy.suffix = self.suffix;
+
+ copy.headerFormat = [self.headerFormat copyWithZone:zone];
+ copy.valueFormat = [self.valueFormat copyWithZone:zone];
+
+ return copy;
+}
+
- (void) dealloc
{
self.name = nil;
+ self.formatDescription = nil;
self.prefix = nil;
self.suffix = nil;
@@ -49,21 +67,35 @@ - (void) dealloc
#pragma mark Formatting
-- (NSString *) stringForRows:(NSArray *)csvRows includeHeaderRows:(BOOL)includeHeaderRows withColumnKeys:(NSArray *)keys;
+- (NSString *) stringForRows:(NSArray *)csvRows includeHeaderRows:(BOOL)includeHeaderRows withColumns:(NSArray *)columns;
{
NSMutableString *string = nil;
if (nil != csvRows) {
+
+ // prepend the prefix
string = (nil == prefix) ? [NSMutableString string] : [NSMutableString stringWithString:prefix];
// add rows (if there are any)
if ([csvRows count] > 0) {
NSAutoreleasePool *myPool = [[NSAutoreleasePool alloc] init];
+ // extract the keys (actually: names) from the columns
+ NSMutableArray *keys = [NSMutableArray arrayWithCapacity:[columns count]];
+ for (CSVColumn *column in columns) {
+ NSString *newKey = [column hasName] ? column.name : column.key;
+ [keys addObject:newKey];
+ }
+
+ // loop the rows
NSUInteger i = 0;
for (CSVRow *row in csvRows) {
- if (includeHeaderRows || !row.isHeaderRow) {
- [string appendString:[valueFormat rowForColumnKeys:keys values:[row valuesForColumnKeys:keys]]];
+ if (!row.isHeaderRow) {
+ [string appendString:[valueFormat rowForKeys:keys values:[row valuesForColumns:columns]]]; // value row
+ i++;
+ }
+ else if (includeHeaderRows) {
+ [string appendString:[headerFormat rowForKeys:keys values:[row valuesForColumns:columns]]]; // header row
i++;
}
@@ -76,6 +108,7 @@ - (NSString *) stringForRows:(NSArray *)csvRows includeHeaderRows:(BOOL)includeH
[myPool release];
}
+ // append the suffix
if (nil != suffix) {
[string appendString:suffix];
}
@@ -86,12 +119,12 @@ - (NSString *) stringForRows:(NSArray *)csvRows includeHeaderRows:(BOOL)includeH
- (NSString *) headerForColumnKeys:(NSArray *)keys values:(NSArray *)values;
{
- return [headerFormat rowForColumnKeys:keys values:values];
+ return [headerFormat rowForKeys:keys values:values];
}
- (NSString *) rowForColumnKeys:(NSArray *)keys values:(NSArray *)values;
{
- return [valueFormat rowForColumnKeys:keys values:values];
+ return [valueFormat rowForKeys:keys values:values];
}
#pragma mark -
@@ -101,24 +134,26 @@ - (NSString *) rowForColumnKeys:(NSArray *)keys values:(NSArray *)values;
+ (PPStringFormat *) csvFormat
{
PPStringFormat *myself = [[PPStringFormat alloc] initWithName:@"CSV"];
+ myself.systemFormat = YES;
myself.name = @"CSV";
+ myself.formatDescription = @"Regular CSV format";
// Setup CSV properties
NSArray *escapeFrom = [NSArray arrayWithObject:@"\""];
NSArray *escapeTo = [NSArray arrayWithObject:@"\"\""];
- PPStringFormatEntity *valueEntity = [PPStringFormatEntity entity];
+ PPStringFormatEntity *valueEntity = [PPStringFormatEntity formatEntity];
valueEntity.separator = @",";
- valueEntity.stringformat = @"\"$value\"";
- valueEntity.numberformat = @"$value";
+ valueEntity.stringFormat = @"\"$value\"";
+ valueEntity.numberFormat = @"$value";
valueEntity.stringEscapeFrom = escapeFrom;
valueEntity.stringEscapeTo = escapeTo;
- PPStringFormatRow *header = [PPStringFormatRow row];
+ PPStringFormatRow *header = [PPStringFormatRow formatRow];
header.format = @"@values";
header.valueFormat = valueEntity;
- PPStringFormatRow *row = [PPStringFormatRow row];
+ PPStringFormatRow *row = [PPStringFormatRow formatRow];
row.format = @"@values";
row.valueFormat = valueEntity;
@@ -131,24 +166,26 @@ + (PPStringFormat *) csvFormat
+ (PPStringFormat *) tabFormat
{
PPStringFormat *myself = [[PPStringFormat alloc] initWithName:@"Tab"];
+ myself.systemFormat = YES;
myself.name = @"Tab";
+ myself.formatDescription = @"Regular tab separated values format";
// Setup Tab separated properties
NSArray *escapeFrom = [NSArray arrayWithObject:@"\""];
NSArray *escapeTo = [NSArray arrayWithObject:@"\"\""];
- PPStringFormatEntity *valueEntity = [PPStringFormatEntity entity];
- valueEntity.separator = @",";
- valueEntity.stringformat = @"\"$value\"";
- valueEntity.numberformat = @"$value";
+ PPStringFormatEntity *valueEntity = [PPStringFormatEntity formatEntity];
+ valueEntity.separator = @"\t";
+ valueEntity.stringFormat = @"\"$value\"";
+ valueEntity.numberFormat = @"$value";
valueEntity.stringEscapeFrom = escapeFrom;
valueEntity.stringEscapeTo = escapeTo;
- PPStringFormatRow *header = [PPStringFormatRow row];
+ PPStringFormatRow *header = [PPStringFormatRow formatRow];
header.format = @"@values";
header.valueFormat = valueEntity;
- PPStringFormatRow *row = [PPStringFormatRow row];
+ PPStringFormatRow *row = [PPStringFormatRow formatRow];
row.format = @"@values";
row.valueFormat = valueEntity;
@@ -161,24 +198,35 @@ + (PPStringFormat *) tabFormat
+ (PPStringFormat *) flatXMLFormat
{
PPStringFormat *myself = [[PPStringFormat alloc] initWithName:@"flatXML"];
+ myself.systemFormat = YES;
myself.name = @"XML";
+ myself.formatDescription = @"A format that exports your file to a flat XML structure";
// Setup CSV properties
- NSArray *replaceFrom = [NSArray arrayWithObjects:@"&", @"<", @">", @"\"", nil];
- NSArray *replaceTo = [NSArray arrayWithObjects:@"&amp;", @"&lt;", @"&gt;", @"&quot;", nil];
+ NSArray *replaceValuesFrom = [NSArray arrayWithObjects:@"&", @"<", @">", @"\"", nil];
+ NSArray *replaceValuesTo = [NSArray arrayWithObjects:@"&amp;", @"&lt;", @"&gt;", @"&quot;", nil];
+ NSArray *replaceKeysFrom = [NSArray arrayWithObjects:@"&", @"<", @">", @"\"", @" ", @"\t", @"\n", nil];
+ NSArray *replaceKeysTo = [NSArray arrayWithObjects:@"_", nil];
- PPStringFormatEntity *valueEntity = [PPStringFormatEntity entity];
+ PPStringFormatEntity *valueEntity = [PPStringFormatEntity formatEntity];
valueEntity.separator = @"\n\t";
- valueEntity.stringformat = @"<$key>$value</$key>";
- valueEntity.numberformat = @"<$key>$value</$key>";
- valueEntity.stringEscapeFrom = replaceFrom;
- valueEntity.stringEscapeTo = replaceTo;
-
- PPStringFormatRow *header = [PPStringFormatRow row];
+ valueEntity.stringFormat = @"<$key>$value</$key>";
+ valueEntity.numberFormat = @"<$key>$value</$key>";
+ valueEntity.stringEscapeFrom = replaceValuesFrom;
+ valueEntity.stringEscapeTo = replaceValuesTo;
+
+ PPStringFormatEntity *headerEntity = [PPStringFormatEntity formatEntity];
+ headerEntity.separator = @"\n\t";
+ headerEntity.stringFormat = @"<$key />";
+ headerEntity.numberFormat = @"<$key />";
+ headerEntity.stringEscapeFrom = replaceKeysFrom;
+ headerEntity.stringEscapeTo = replaceKeysTo;
+
+ PPStringFormatRow *header = [PPStringFormatRow formatRow];
header.format = @"<header>\n\t@keys\n</header>";
- header.keyFormat = valueEntity;
+ header.keyFormat = headerEntity;
- PPStringFormatRow *row = [PPStringFormatRow row];
+ PPStringFormatRow *row = [PPStringFormatRow formatRow];
row.format = @"<row>\n\t@values\n</row>";
row.valueFormat = valueEntity;
@@ -191,5 +239,11 @@ + (PPStringFormat *) flatXMLFormat
}
+- (NSString *) description
+{
+ return [NSString stringWithFormat:@"%@ <0x%x> %@ (system: %i)", NSStringFromClass([self class]), self, name, systemFormat];
+}
+
+
@end
View
14 FileExport/PPStringFormatEntity.h
@@ -9,21 +9,21 @@
#import <Cocoa/Cocoa.h>
-@interface PPStringFormatEntity : NSObject {
+@interface PPStringFormatEntity : NSObject <NSCopying> {
NSString *separator; // will be put between each key/value pair
- NSString *stringformat; // e.g. <$key>$value</$key>
- NSString *numberformat;
+ NSString *stringFormat; // e.g. <$key>$value</$key>
+ NSString *numberFormat;
NSArray *stringEscapeFrom; // v should be the same length
- NSArray *stringEscapeTo; // ^ should be the same length
+ NSArray *stringEscapeTo; // ^ should be the same length, if not this will be repeated in order to fit
}
@property (copy) NSString *separator;
-@property (copy) NSString *stringformat;
-@property (copy) NSString *numberformat;
+@property (copy) NSString *stringFormat;
+@property (copy) NSString *numberFormat;
@property (retain) NSArray *stringEscapeFrom;
@property (retain) NSArray *stringEscapeTo;
-+ (PPStringFormatEntity *) entity;
++ (PPStringFormatEntity *) formatEntity;
- (NSString *) stringForKeys:(NSArray *)keys values:(NSArray *)values;
View
35 FileExport/PPStringFormatEntity.m
@@ -12,22 +12,35 @@
@implementation PPStringFormatEntity
@synthesize separator;
-@synthesize stringformat;
-@synthesize numberformat;
+@synthesize stringFormat;
+@synthesize numberFormat;
@synthesize stringEscapeFrom;
@synthesize stringEscapeTo;
-+ (PPStringFormatEntity *) entity
++ (PPStringFormatEntity *) formatEntity
{
return [[[PPStringFormatEntity alloc] init] autorelease];
}
+- (id) copyWithZone:(NSZone *)zone
+{
+ PPStringFormatEntity *copy = [[[self class] allocWithZone:zone] init];
+ copy.separator = self.separator;
+ copy.stringFormat = self.stringFormat;
+ copy.numberFormat = self.numberFormat;
+
+ copy.stringEscapeFrom = [self.stringEscapeFrom copyWithZone:zone];
+ copy.stringEscapeTo = [self.stringEscapeTo copyWithZone:zone];
+
+ return copy;
+}
+
- (void) dealloc
{
self.separator = nil;
- self.stringformat = nil;
- self.numberformat = nil;
+ self.stringFormat = nil;
+ self.numberFormat = nil;
self.stringEscapeFrom = nil;
self.stringEscapeTo = nil;
@@ -51,16 +64,18 @@ - (NSString *) stringForKeys:(NSArray *)keys values:(NSArray *)values
NSMutableString *formatted = [NSMutableString string];
// NSString
- if ([value isKindOfClass:[NSString class]] && (nil != stringformat)) {
- formatted = [stringformat mutableCopy]; // e.g. "<$key>$value</$key>"
+ if ([value isKindOfClass:[NSString class]] && (nil != stringFormat)) {
+ formatted = [stringFormat mutableCopy]; // e.g. "<$key>$value</$key>"
NSString *newValue = value; // this will be 'value' with escaped strings
// escape characters in value
if ([stringEscapeFrom count] > 0) {
newValue = [NSMutableString stringWithString:value];
NSUInteger i = 0;
+ NSUInteger num_to = [stringEscapeTo count];
+ NSLog(@"escaping %@ %@", newValue, stringEscapeFrom);
for (NSString *replaceFrom in stringEscapeFrom) {
- NSString *replaceTo = ([stringEscapeTo count] > i) ? [stringEscapeTo objectAtIndex:i] : nil;
+ NSString *replaceTo = [stringEscapeTo objectAtIndex:(i % num_to)];
[(NSMutableString *)newValue replaceOccurrencesOfString:replaceFrom
withString:replaceTo
@@ -75,8 +90,8 @@ - (NSString *) stringForKeys:(NSArray *)keys values:(NSArray *)values
}
// NS(Decimal)Number
- else if ([value isKindOfClass:[NSNumber class]] && (nil != numberformat)) {
- formatted = [numberformat mutableCopy]; // e.g. '$value'
+ else if ([value isKindOfClass:[NSNumber class]] && (nil != numberFormat)) {
+ formatted = [numberFormat mutableCopy]; // e.g. '$value'
NSString *newValue = [value stringValue];
[formatted replaceOccurrencesOfString:@"$key" withString:key options:0 range:NSMakeRange(0, [formatted length])];
View
34 FileExport/PPStringFormatManager.h
@@ -7,25 +7,51 @@
//
#import <Cocoa/Cocoa.h>
+@class PPStringFormatsController;
+@class PPStringFormat;
@class PPToolbarView;
@interface PPStringFormatManager : NSWindowController {
+ NSMutableArray *formats;
NSArray *systemFormats;
- NSArray *userFormats;
- NSArrayController *formats;
+ IBOutlet PPStringFormatsController *formatController;
+ PPStringFormat *selectedFormat;
+ // main views
+ IBOutlet NSView *detailContainer;
+ IBOutlet NSView *systemFormatDetails;
+ IBOutlet NSView *userFormatDetails;
+
+ // outlets
+ IBOutlet NSTableView *formatTable;
IBOutlet PPToolbarView *formatToolbar;
+
+ // preview
+ IBOutlet NSPanel *previewPanel;
+ IBOutlet NSTextView *previewField;
+ NSDictionary *previewAttributes;
}
+@property (nonatomic, readonly, retain) NSMutableArray *formats;
@property (nonatomic, readonly, retain) NSArray *systemFormats;
-@property (nonatomic, readwrite, retain) NSArray *userFormats;
-@property (nonatomic, readonly, retain) NSArrayController *formats;
+@property (nonatomic, readonly, retain) IBOutlet PPStringFormatsController *formatController;
+@property (nonatomic, readonly) PPStringFormat *selectedFormat;
+@property (nonatomic, retain) IBOutlet NSView *systemFormatDetails;
+@property (nonatomic, retain) IBOutlet NSView *userFormatDetails;
+@property (nonatomic, retain) IBOutlet NSTableView *formatTable;
@property (nonatomic, retain) IBOutlet PPToolbarView *formatToolbar;
+@property (nonatomic, retain) IBOutlet NSPanel *previewPanel;
+@property (nonatomic, retain) IBOutlet NSTextView *previewField;
+
+ (PPStringFormatManager *) sharedManager;
+ (void) show:(id)sender;
+- (IBAction) showPreview:(id)sender;
+- (IBAction) updatePreview:(id)sender;
+- (IBAction) copySelectedFormat:(id)sender;
+
@end
View
146 FileExport/PPStringFormatManager.m
@@ -8,25 +8,39 @@
#import "PPStringFormatManager.h"
#import "PPStringFormat.h"
+#import "PPStringFormatsController.h"
#import "PPToolbarView.h"
+#import "MyDocument.h"
+#import "CSVDocument.h"
@interface PPStringFormatManager ()
+@property (nonatomic, readwrite, retain) NSMutableArray *formats;
@property (nonatomic, readwrite, retain) NSArray *systemFormats;
-@property (nonatomic, readwrite, retain) NSArrayController *formats;
+@property (nonatomic, readwrite, retain) PPStringFormatsController *formatController;
+
+@property (nonatomic, readwrite, retain) NSDictionary *previewAttributes;
@end
@implementation PPStringFormatManager
-@dynamic systemFormats;
-@synthesize userFormats;
@dynamic formats;
+@dynamic systemFormats;
+@synthesize formatController;
+@dynamic selectedFormat;
+@synthesize systemFormatDetails;
+@synthesize userFormatDetails;
+@synthesize formatTable;
@synthesize formatToolbar;
+@synthesize previewPanel;
+@synthesize previewField;
+@synthesize previewAttributes;
+
#pragma mark Singleton Overrides
static PPStringFormatManager *managerInstance = nil;
@@ -97,23 +111,46 @@ - (id) autorelease
- (void) dealloc // will never be called anyway! (Singleton)
{
+ self.systemFormatDetails = nil;
+ self.userFormatDetails = nil;
+ self.formatTable = nil;
self.formatToolbar = nil;
+ self.previewPanel = nil;
+ self.previewField = nil;
+
[super dealloc];
}
#pragma mark -
#pragma mark KVC
+- (NSMutableArray *) formats
+{
+ if (nil == formats) {
+ self.formats = [NSMutableArray arrayWithArray:self.systemFormats];
+ }
+ return formats;
+}
+- (void) setFormats:(NSMutableArray *)newFormats
+{
+ if (newFormats != formats) {
+ [self willChangeValueForKey:@"formats"];
+ [formats release];
+ formats = [newFormats retain];
+ [self didChangeValueForKey:@"formats"];
+ }
+}
+
- (NSArray *) systemFormats
{
if (nil == systemFormats) {
- systemFormats = [NSArray arrayWithObjects:
- [PPStringFormat csvFormat],
- [PPStringFormat tabFormat],
- [PPStringFormat flatXMLFormat],
- nil];
+ self.systemFormats = [NSArray arrayWithObjects:
+ [PPStringFormat csvFormat],
+ [PPStringFormat tabFormat],
+ [PPStringFormat flatXMLFormat],
+ nil];
}
return systemFormats;
}
@@ -125,19 +162,13 @@ - (void) setSystemFormats:(NSArray *)newFormats
}
}
-- (NSArrayController *) formats
+- (PPStringFormat *) selectedFormat
{
- if (nil == formats) {
- self.formats = [[[NSArrayController alloc] initWithContent:self.systemFormats] autorelease];
- }
- return formats;
-}
-- (void) setFormats:(NSArrayController *)newController
-{
- if (newController != formats) {
- [formats release];
- formats = [newController retain];
+ NSArray *selectedObjects = [formatController selectedObjects];
+ if ([selectedObjects count] > 0) {
+ return [selectedObjects objectAtIndex:0];
}
+ return nil;
}
#pragma mark -
@@ -149,6 +180,82 @@ - (void) awakeFromNib
[super awakeFromNib];
formatToolbar.borderWidth = PPBorderWidthMake(1.0, 1.0, 0.0, 0.0);
+
+ NSNotification *myNote = [NSNotification notificationWithName:NSTableViewSelectionDidChangeNotification object:formatTable];
+ [self tableViewSelectionDidChange:myNote];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controlTextDidEndEditing:) name:NSTextDidEndEditingNotification object:nil];
+}
+#pragma mark -
+
+
+
+#pragma mark Table and Text Delegate
+- (void) tableViewSelectionDidChange:(NSNotification *)aNotification
+{
+ // change the subview accordingly
+ if (formatTable == aNotification.object) {
+ if ([self selectedFormat]) {
+ BOOL isSystemFormat = [self selectedFormat].isSystemFormat;
+ [[detailContainer subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
+
+ NSView *newSubview = isSystemFormat ? systemFormatDetails : userFormatDetails;
+ newSubview.frame = NSInsetRect(detailContainer.bounds, 5.0, 5.0);
+ [detailContainer addSubview:newSubview];
+
+ [self updatePreview:nil];
+ }
+ }
+}
+
+- (void) controlTextDidEndEditing:(NSNotification *)aNotification
+{
+ [self updatePreview:nil];
+}
+#pragma mark -
+
+
+
+#pragma mark Actions
+- (IBAction) showPreview:(id)sender
+{
+ [previewPanel orderFront:sender];
+ [previewField setFont:[NSFont fontWithName:@"Monaco" size:12.0]];
+ [self updatePreview:sender];
+}
+
+- (IBAction) updatePreview:(id)sender
+{
+ if (nil != previewPanel && [previewPanel isVisible]) {
+ NSDocumentController *docController = [NSDocumentController sharedDocumentController];
+ MyDocument *frontDoc = [docController currentDocument];
+ CSVDocument *csvDoc = frontDoc.csvDocument;
+ if (nil != csvDoc) {
+
+ // get current format
+ PPStringFormat *frontFormat = [self selectedFormat];
+ if (nil != frontFormat) {
+ NSIndexSet *testSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 8)];
+ NSString *previewString = [csvDoc stringInFormat:frontFormat withColumns:csvDoc.activeColumns forRowIndexes:testSet includeHeaders:YES];
+
+ [previewField setString:previewString];
+ }
+
+ // adjust the panel title
+ [previewPanel setTitle:[NSString stringWithFormat:@"Preview • %@", frontFormat.name]];
+ }
+ }
+}
+
+- (IBAction) copySelectedFormat:(id)sender
+{
+ PPStringFormat *selected = [self selectedFormat];
+ if (nil != selected) {
+ PPStringFormat *copy = [selected copy];
+ copy.name = [NSString stringWithFormat:@"%@ copy", selected.name];
+ [formatController addObject:copy];
+ [copy release];
+ }
}
#pragma mark -
@@ -170,7 +277,6 @@ - (NSString *) windowFrameAutosaveName
{
return @"PPStringFormatManager";
}
-#pragma mark -
@end
View
6 FileExport/PPStringFormatRow.h
@@ -10,7 +10,7 @@
@class PPStringFormatEntity;
-@interface PPStringFormatRow : NSObject {
+@interface PPStringFormatRow : NSObject <NSCopying> {
NSString *format; // e.g. <row>\n\t@values\n</row>
BOOL newline; // if YES adds a newline after the row
@@ -24,9 +24,9 @@
@property (retain) PPStringFormatEntity *keyFormat;
@property (retain) PPStringFormatEntity *valueFormat;
-+ (PPStringFormatRow *) row;
++ (PPStringFormatRow *) formatRow;
-- (NSString *) rowForColumnKeys:(NSArray *)keys values:(NSArray *)values;
+- (NSString *) rowForKeys:(NSArray *)keys values:(NSArray *)values;
@end
View
16 FileExport/PPStringFormatRow.m
@@ -19,7 +19,7 @@ @implementation PPStringFormatRow
@synthesize valueFormat;
-+ (PPStringFormatRow *) row
++ (PPStringFormatRow *) formatRow
{
return [[[PPStringFormatRow alloc] init] autorelease];
}
@@ -33,6 +33,18 @@ - (id) init
return self;
}
+- (id) copyWithZone:(NSZone *)zone
+{
+ PPStringFormatRow *copy = [[[self class] allocWithZone:zone] init];
+ copy.format = self.format;
+ copy.newline = self.newline;
+
+ copy.keyFormat = [self.keyFormat copyWithZone:zone];
+ copy.valueFormat = [self.valueFormat copyWithZone:zone];
+
+ return copy;
+}
+
- (void) dealloc
{
self.format = nil;
@@ -47,7 +59,7 @@ - (void) dealloc
#pragma mark Formatting
-- (NSString *) rowForColumnKeys:(NSArray *)keys values:(NSArray *)values
+- (NSString *) rowForKeys:(NSArray *)keys values:(NSArray *)values
{
NSMutableString *string = nil;
if ((nil != keys) && (nil != format)) {
View
19 FileExport/PPStringFormatsController.h
@@ -0,0 +1,19 @@
+//
+// PPStringFormatsController.h
+// CSVManipulator
+//
+// Created by Pascal Pfiffner on 10/29/09.
+// Copyright 2009 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface PPStringFormatsController : NSArrayController {
+
+}
+
+- (BOOL) canRemoveSelectedObjects;
+
+
+@end
View
69 FileExport/PPStringFormatsController.m
@@ -0,0 +1,69 @@
+//
+// PPStringFormatsController.m
+// CSVManipulator
+//
+// Created by Pascal Pfiffner on 10/29/09.
+// Copyright 2009 __MyCompanyName__. All rights reserved.
+//
+
+#import "PPStringFormatsController.h"
+#import "PPStringFormat.h"
+
+
+@implementation PPStringFormatsController
+
+
+- (void) dealloc
+{
+ [super dealloc];
+}
+#pragma mark -
+
+
+
+#pragma mark Array States
+- (void) addObject:(id)object
+{
+ [self willChangeValueForKey:@"canRemoveSelectedObjects"];
+ [super addObject:object];
+ [self didChangeValueForKey:@"canRemoveSelectedObjects"];
+}
+
+- (BOOL) setSelectionIndexes:(NSIndexSet *)indexes
+{
+ [self willChangeValueForKey:@"canRemoveSelectedObjects"];
+ BOOL flag = [super setSelectionIndexes:indexes];
+ [self didChangeValueForKey:@"canRemoveSelectedObjects"];
+ return flag;
+}
+
+- (BOOL) canRemoveSelectedObjects
+{
+ BOOL flag = [super canRemove];
+ if (flag) {
+ for (PPStringFormat *format in [self selectedObjects]) {
+ if (format.isSystemFormat) {
+ return NO;
+ }
+ }
+ }
+ return flag;
+}
+#pragma mark -
+
+
+
+#pragma mark KVO
+- (Class) objectClass
+{
+ return [PPStringFormat class];
+}
+
+//+ (NSSet *) keyPathsForValuesAffectingCanRemoveSelectedObjects // seems to not work, see; http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg40710.html
+//{
+// return [NSSet setWithObjects:@"contentArray", @"selectionIndex", @"selectionIndexes", nil];
+//}
+
+
+
+@end
View
2 Info.plist
@@ -64,6 +64,6 @@
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>SVNRevision</key>
- <string>1519</string>
+ <string>1520</string>
</dict>
</plist>
View
2 MyDocument.h
@@ -62,8 +62,6 @@
- (void) restoreOriginalOrder;
- (void) abortImport;
-- (void) setColumnOrder:(NSArray *)newOrder; // awaits an array of column keys
-
// Clipboard and Files
- (NSArray *) writablePasteboardTypes;
- (NSArray *) fileSuffixesForFormat:(PPStringFormat *)format;
View
6 MyDocument.m
@@ -332,12 +332,6 @@ - (void) abortImport
csvDocument.mustAbortImport = YES;
}
}
-
-- (void) setColumnOrder:(NSArray *)newOrder
-{
- [csvDocument setColumnOrderByKeys:newOrder];
- self.documentEdited = YES;
-}
#pragma mark -
View
3,714 PPStringFormatManager.xib
3,495 additions, 219 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
4 ViewClasses/PPToolbarButton.h
@@ -13,7 +13,7 @@
@interface PPToolbarButton : NSButton {
NSButtonType buttonType;
- NSArray *borderWidths; // like in CSS: top right bottom left
+ PPBorderWidth borderWidth;
NSColor *borderColor;
NSColor *borderHighlightColor;
@@ -28,7 +28,7 @@
@property (nonatomic, assign) NSButtonType buttonType;
-@property (nonatomic, assign) NSArray *borderWidths;
+@property (nonatomic, assign) PPBorderWidth borderWidth;
@property (nonatomic, assign) NSColor *borderColor;
@property (nonatomic, assign) NSColor *borderHighlightColor;
View
19 ViewClasses/PPToolbarButton.m
@@ -13,7 +13,7 @@
@implementation PPToolbarButton
@dynamic buttonType;
-@dynamic borderWidths;
+@dynamic borderWidth;
@dynamic borderColor, borderHighlightColor, borderActiveColor, borderDisabledColor;
@dynamic baseColor, highlightColor, activeColor, disabledColor;
@@ -36,6 +36,7 @@ - (id) initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self) {
+ buttonType = [self buttonType];
NSButtonCell *oldCell = [self cell];
// we need to throw away the NSButtonCell that IB created and replace it with the right one
@@ -61,9 +62,7 @@ - (id) initWithCoder:(NSCoder *)coder
- (void) setDefaults
{
- NSNumber *default_border_width = [NSNumber numberWithInt:1.0];
- self.borderWidths = [NSArray arrayWithObjects:default_border_width, default_border_width, [NSNull null], default_border_width, nil];
-
+ self.borderWidth = PPBorderWidthMake(1.0, 1.0, 0.0, 1.0);
self.borderColor = self.borderHighlightColor = self.borderActiveColor = self.borderDisabledColor = [NSColor grayColor];
self.baseColor = [NSColor whiteColor];
@@ -87,21 +86,21 @@ - (NSButtonType) buttonType
}
- (void) setButtonType:(NSButtonType)newType
{
- //NSLog(@"set to: %i", buttonType);
+ //NSLog(@"set button type to: %i", buttonType);
if (newType != buttonType) {
[super setButtonType:newType];
buttonType = newType;
}
}
-// Border width array
-- (NSArray *) borderWidths
+// Border width
+- (PPBorderWidth) borderWidth
{
- return [[self cell] borderWidths];
+ return [(PPToolbarButtonCell *)[self cell] borderWidth];
}
-- (void) setBorderWidths:(NSArray *)newWidths
+- (void) setBorderWidth:(PPBorderWidth)newWidths
{
- [[self cell] setBorderWidths:newWidths];
+ [(PPToolbarButtonCell *)[self cell] setBorderWidth:newWidths];
}
// Border colors
View
2 ViewClasses/PPToolbarButtonCell.m
@@ -167,7 +167,7 @@ - (void) drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
BOOL enabled = [self isEnabled];
BOOL high = [self isHighlighted];
- BOOL active = (NSOnState == [self state]);
+ BOOL active = (button.buttonType & (NSPushOnPushOffButton | NSToggleButton | NSSwitchButton | NSOnOffButton) && NSOnState == [self state]);
// Get desired colors
NSArray *color_array;

0 comments on commit 910cbd0

Please sign in to comment.
Something went wrong with that request. Please try again.