Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Lots of fixes. Prepared to update calculation inspector.

  • Loading branch information...
commit 13380bee8dba67af0f2eada6236cc88bac4654f5 1 parent 6a8b664
svnuser authored
View
1  CSVDocument/CSVColumn.h
@@ -29,6 +29,7 @@
+ (id) columnWithKey:(NSString *)newKey;
- (BOOL) hasName;
+- (NSString *) fullName;
@end
View
14 CSVDocument/CSVColumn.m
@@ -71,6 +71,20 @@ - (BOOL) hasName
#pragma mark Utilities
+- (NSString *) fullName
+{
+ NSString *fullName = nil;
+
+ if ([name length] > 0) {
+ fullName = [NSString stringWithFormat:@"%@ (%@)", self.name, self.key];
+ }
+ else {
+ fullName = self.key;
+ }
+
+ return fullName;
+}
+
- (NSString *) description
{
return [NSString stringWithFormat:@"%@ <0x%X>; %@ -> %@, active: %i", NSStringFromClass([self class]), self, key, name, active];
View
7 CSVDocument/CSVDocument.h
@@ -39,9 +39,9 @@
NSMutableArray *columns; // needs to be an array to preserve column order
NSMutableDictionary *columnDict; // readonly to allow fast access to columns by key
+ NSUInteger parseNumHeaderRows; // if set before parsing, the first x rows will be header rows
BOOL parseSuccessful;
BOOL autoDetectSeparator; // if YES will check for other separators (";" and TAB) than the comma
- NSUInteger numHeaderRows; // first x rows contain header data
BOOL mustAbortImport;
BOOL didAbortImport;
@@ -64,7 +64,7 @@
@property (nonatomic, assign) BOOL parseSuccessful;
@property (nonatomic, assign) BOOL autoDetectSeparator;
-@property (nonatomic, assign) NSUInteger numHeaderRows;
+@property (nonatomic, assign) NSUInteger parseNumHeaderRows;
@property (assign) BOOL mustAbortImport;
@property (nonatomic, assign) BOOL didAbortImport;
@@ -91,12 +91,15 @@
- (CSVColumn *) columnWithKey:(NSString *)columnKey;
- (void) setColumnOrderByKeys:(NSArray *)newOrderKeys;
- (void) setColumnActive:(BOOL)active forColumnKey:(NSString *)columnKey;
+- (void) updateColumnNames;
// row handling
- (CSVRow *) rowAtIndex:(NSUInteger)rowIndex;
+- (NSUInteger) numHeaderRows;
- (void) changeNumHeaderRows:(NSUInteger)newNum;
- (void) rearrangeRows;
- (void) row:(CSVRow *)thisRow didBecomeHeaderRow:(BOOL)itDid;
+- (void) removeRow:(CSVRow *)row;
// utils
- (NSString *) nextAvailableColumnKey;
View
97 CSVDocument/CSVDocument.m
@@ -18,7 +18,6 @@ @interface CSVDocument ()
@property (nonatomic, readwrite, retain) NSMutableDictionary *columnDict;
-- (void) updateColumnNames;
- (void) notifyDelegateOfParsedRow:(CSVRow *)newRow;
@end
@@ -43,7 +42,7 @@ @implementation CSVDocument
@synthesize didAbortImport;
@synthesize reportEveryRowParsed;
@synthesize columns;
-@synthesize numHeaderRows;
+@synthesize parseNumHeaderRows;
- (id) init
@@ -105,7 +104,7 @@ - (BOOL) parseCSVString:(NSString *)string maxRows:(NSUInteger)maxRows error:(NS
{
NSUInteger num_rows = 0;
BOOL success = YES;
-
+ parseNumHeaderRows = 1;
// this thing is thread safe
[string retain];
NSAutoreleasePool *outerPool = [[NSAutoreleasePool alloc] init];
@@ -150,7 +149,6 @@ - (BOOL) parseCSVString:(NSString *)string maxRows:(NSUInteger)maxRows error:(NS
BOOL finishedRow = NO; // used for the inner while loop
BOOL skipWhitespace = (NSNotFound == [separator rangeOfCharacterFromSet:whiteSpaceChars].location);
BOOL isNewColumn = NO; // will be YES when a new column is created
- BOOL columnHasName = NO; // we use a BOOL here to avoid calling [column hasName] all too often
NSMutableString *currentCellString = [[NSMutableString alloc] init];
NSUInteger colIndex = 0;
CSVColumn *column;
@@ -183,13 +181,11 @@ - (BOOL) parseCSVString:(NSString *)string maxRows:(NSUInteger)maxRows error:(NS
// get the current column or create a new one, if needed
if ([columns count] > colIndex) {
column = [columns objectAtIndex:colIndex];
- columnHasName = [column hasName];
}
else {
column = [CSVColumn columnWithKey:[NSString stringWithFormat:kColumnKeyMask, colIndex]];
column.active = YES;
isNewColumn = YES;
- columnHasName = NO;
}
// Scan characters into our string
@@ -217,16 +213,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 (![newCellString isEqualToString:@""]) {
- column.name = newCellString;
- columnHasName = YES;
- }
[self addColumn:column];
isNewColumn = NO;
}
- if (!columnHasName) {
- column.name = newCellString;
- }
[newRow setValue:newCellString forColumn:column];
@@ -247,16 +236,9 @@ - (BOOL) parseCSVString:(NSString *)string maxRows:(NSUInteger)maxRows error:(NS
else { // a real newline or the end
NSString *newCellString = [[currentCellString copy] autorelease];
if (isNewColumn) {
- if (![newCellString isEqualToString:@""]) {
- column.name = newCellString;
- columnHasName = YES;
- }
[self addColumn:column];
isNewColumn = NO;
}
- if (!columnHasName) {
- column.name = newCellString;
- }
[newRow setValue:newCellString forColumn:column];
finishedRow = YES;
@@ -268,7 +250,7 @@ - (BOOL) parseCSVString:(NSString *)string maxRows:(NSUInteger)maxRows error:(NS
// one row scanned - add to our array, save the columns and report to delegate if desired
[rows addObject:newRow];
- if (num_rows >= numHeaderRows) {
+ if (num_rows >= parseNumHeaderRows) {
if (sendRowUpdateToDelegate) {
[self performSelectorOnMainThread:@selector(notifyDelegateOfParsedRow:) withObject:newRow waitUntilDone:NO];
}
@@ -306,6 +288,9 @@ - (BOOL) parseCSVString:(NSString *)string maxRows:(NSUInteger)maxRows error:(NS
success = NO;
}
+ // header rows?
+ [self changeNumHeaderRows:parseNumHeaderRows];
+
// clean the outer pool
[outerPool release];
[string release];
@@ -392,6 +377,11 @@ - (BOOL) addColumn:(CSVColumn *)newColumn
[columns addObject:newColumn];
[columnDict setObject:newColumn forKey:newColumn.key];
+ // inform delegate
+ if ([delegate respondsToSelector:@selector(csvDocumentDidChangeNumColumns:)]) {
+ [delegate csvDocumentDidChangeNumColumns:self];
+ }
+
return YES;
}
return NO;
@@ -406,6 +396,12 @@ - (BOOL) removeColumn:(CSVColumn *)oldColumn
// TODO: Remove values from rows??
[columns removeObjectAtIndex:i];
[columnDict removeObjectForKey:column.key];
+
+ // inform delegate
+ if ([delegate respondsToSelector:@selector(csvDocumentDidChangeNumColumns:)]) {
+ [delegate csvDocumentDidChangeNumColumns:self];
+ }
+
return YES;
}
i++;
@@ -455,7 +451,8 @@ - (void) setColumnActive:(BOOL)active forColumnKey:(NSString *)columnKey
- (void) updateColumnNames
{
- if (numHeaderRows < 1) {
+ NSUInteger nHeaderRows = [self numHeaderRows];
+ if (nHeaderRows < 1) {
for (CSVColumn *column in columns) {
column.name = nil;
}
@@ -463,11 +460,16 @@ - (void) updateColumnNames
else {
CSVRow *firstRow = [self rowAtIndex:0];
for (CSVColumn *column in columns) {
- if (![column hasName]) {
+ if ((1 == nHeaderRows) || ![column hasName]) {
column.name = [firstRow valueForColumn:column];
}
}
}
+
+ // inform delegate
+ if ([delegate respondsToSelector:@selector(csvDocumentDidChangeColumnNames:)]) {
+ [delegate csvDocumentDidChangeColumnNames:self];
+ }
}
#pragma mark -
@@ -483,21 +485,37 @@ - (CSVRow *) rowAtIndex:(NSUInteger)rowIndex
#endif
}
+- (NSUInteger) numHeaderRows
+{
+ NSUInteger num = 0;
+#ifdef IPHONE
+ for (CSVRow *row in rows)
+#else
+ for (CSVRow *row in [rowController arrangedObjects])
+#endif
+ {
+ if (row.isHeaderRow) {
+ num++;
+ }
+ else {
+ break; // we can break here since header rows are sorted first
+ }
+ }
+ return num;
+}
+
- (void) changeNumHeaderRows:(NSUInteger)newNum
{
NSUInteger i;
- NSUInteger num = (newNum > numHeaderRows) ? newNum : numHeaderRows;
NSUInteger num_rows = [rows count];
+ NSUInteger num = MIN(MAX([self numHeaderRows], newNum), num_rows);
for (i = 0; i < num; i++) {
- if (num_rows > i) {
- CSVRow *row = [self rowAtIndex:i];
- [row changeHeaderRow:(i < newNum)];
- }
+ CSVRow *row = [self rowAtIndex:i];
+ [row changeHeaderRow:(i < newNum)];
}
[self rearrangeRows];
- self.numHeaderRows = newNum;
[self updateColumnNames];
}
@@ -519,16 +537,6 @@ - (void) setNumRowsWithInt:(NSInteger)num_rows
- (void) row:(CSVRow *)thisRow didBecomeHeaderRow:(BOOL)itDid
{
- // 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:)]) {
@@ -538,6 +546,17 @@ - (void) row:(CSVRow *)thisRow didBecomeHeaderRow:(BOOL)itDid
// update column names
[self updateColumnNames];
}
+
+- (void) removeRow:(CSVRow *)row
+{
+ if (nil != row) {
+#ifdef IPHONE
+ [rows removeObject:row];
+#else
+ [rowController removeObject:row];
+#endif
+ }
+}
#pragma mark -
View
3  CSVDocument/CSVDocumentDelegate.h
@@ -25,5 +25,8 @@
- (void) csvDocument:(CSVDocument *)document didParseRow:(CSVRow *)row;
- (void) csvDocument:(CSVDocument *)document didChangeRowOrderToOriginalOrder:(BOOL)isOriginalOrder;
+- (void) csvDocumentDidChangeColumnNames:(CSVDocument *)document;
+- (void) csvDocumentDidChangeNumColumns:(CSVDocument *)document;
+
@end
View
14 CSVDocument/CSVRow.m
@@ -82,7 +82,7 @@ - (void) setIsHeaderRow:(BOOL)isHeader
if (isHeader != isHeaderRow) {
NSUndoManager *undoManager = [[document document] undoManager];
[[undoManager prepareWithInvocationTarget:self] setIsHeaderRow:isHeaderRow];
- //[undoManager setActionName:NSLocalizedString(@"Set Header Row", @"")];
+ [undoManager setActionName:NSLocalizedString(@"Header Row", nil)];
[self changeHeaderRow:isHeader];
[document row:self didBecomeHeaderRow:isHeaderRow];
@@ -178,10 +178,7 @@ - (void) setValue:(id)value forColumn:(CSVColumn *)column
- (void) setValue:(id)value forColumnKey:(NSString *)key
{
if (nil != key) {
- NSUndoManager *undoManager = [[document document] undoManager];
- [[undoManager prepareWithInvocationTarget:self] setValue:[self valueForColumnKey:key] forColumnKey:key];
- //[undoManager setActionName:NSLocalizedString(@"Set Value", nil)];
-
+ // this is currently only used when parsing CSV, so no need for the undo manager here
value = (nil != value) ? value : [NSNull null];
[rowValues setObject:value forKey:key];
}
@@ -193,7 +190,7 @@ - (void) setValue:(id)value forKeyPath:(NSString *)keyPath
if (0 == [keyPath rangeOfString:@"rowValues"].location) {
NSUndoManager *undoManager = [[document document] undoManager];
[[undoManager prepareWithInvocationTarget:self] setValue:[self valueForKeyPath:keyPath] forKeyPath:keyPath];
- //[undoManager setActionName:NSLocalizedString(@"Set Value", nil)];
+ [undoManager setActionName:NSLocalizedString(@"Value Change", nil)];
// if we were editing the cell, an undo operation would not be visible, so circumvent this manually
if ([undoManager isUndoing]) {
@@ -203,6 +200,11 @@ - (void) setValue:(id)value forKeyPath:(NSString *)keyPath
}
[super setValue:value forKeyPath:keyPath];
+
+ // if we are a header row, maybe the column name changed
+ if (isHeaderRow) {
+ [document updateColumnNames];
+ }
}
#pragma mark -
View
4 CSVDocument/CSVRowController.m
@@ -85,7 +85,7 @@ - (void) addObject:(id)object
{
NSUndoManager *undoManager = [[document document] undoManager];
[undoManager registerUndoWithTarget:self selector:@selector(removeObject:) object:object];
- //[undoManager setActionName:NSLocalizedString(@"Add Row", nil)];
+ [undoManager setActionName:NSLocalizedString([undoManager isUndoing] ? @"Delete Row" : @"Add Row", nil)];
[super addObject:object];
}
@@ -100,7 +100,7 @@ - (void) removeObject:(id)object
{
NSUndoManager *undoManager = [[document document] undoManager];
[undoManager registerUndoWithTarget:self selector:@selector(addObject:) object:object];
- //[undoManager setActionName:NSLocalizedString(@"Remove Row", nil)];
+ [undoManager setActionName:NSLocalizedString([undoManager isUndoing] ? @"Add Row" : @"Delete Row", nil)];
[super removeObject:object];
}
View
11 CSVInspector.h
@@ -7,9 +7,13 @@
//
#import <Cocoa/Cocoa.h>
+@class MyDocument;
@interface CSVInspector : NSWindowController {
+ MyDocument *currentDocument;
+ NSArrayController *documentColumns;
+
IBOutlet NSPopUpButton *calculationSourcePopup; // the popup to choose the source column
IBOutlet NSPopUpButton *calculationTargetPopup; // the popup to choose the target column
IBOutlet NSTextField *calculationSourceRegExp; // the text field to define the source RegExp
@@ -20,9 +24,16 @@
BOOL calculationIsRunning;
}
+@property (nonatomic, assign) MyDocument *currentDocument;
+
+ (CSVInspector *) sharedInspector;
+ (void) show:(id)sender;
+- (void) documentBecameActiveNotification:(NSNotification *)notification;
+- (void) documentBecameInactiveNotification:(NSNotification *)notification;
+- (void) documentDidChangeColumns:(NSNotification *)notification;
+
+
- (IBAction) performCalculation:(id)sender;
- (void) updateCalculationStatus:(NSNumber *)alreadyDone;
View
102 CSVInspector.m
@@ -8,10 +8,23 @@
#import "CSVInspector.h"
#import "RegexKitLite.h"
+#import "MyDocument.h"
+#import "CSVDocument.h"
+#import "CSVColumn.h"
+
+
+@interface CSVInspector ()
+
+@property (nonatomic, readwrite, retain) NSArrayController *documentColumns;
+
+@end
@implementation CSVInspector
+@dynamic currentDocument;
+@dynamic documentColumns;
+
#pragma mark Singleton Overrides
static CSVInspector *inspectorInstance = nil;
@@ -21,6 +34,23 @@ + (CSVInspector *) sharedInspector
@synchronized (self) {
if (nil == inspectorInstance ) {
[[self alloc] init];
+
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+
+ [center addObserver:inspectorInstance
+ selector:@selector(documentBecameActiveNotification:)
+ name:kDocumentDidBecomeActive
+ object:nil];
+
+ [center addObserver:inspectorInstance
+ selector:@selector(documentBecameInactiveNotification:)
+ name:kDocumentDidBecomeInactive
+ object:nil];
+
+ [center addObserver:inspectorInstance
+ selector:@selector(documentDidChangeColumns:)
+ name:kDocumentDidChangeColumns
+ object:nil];
}
}
@@ -79,24 +109,61 @@ - (id) autorelease
return self;
}
-- (void) dealloc // will never be called anyway! (Singleton)
+- (void) dealloc // will never be called! (Singleton)
{
+ self.currentDocument = nil;
+ self.documentColumns = nil;
+
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:nil];
[super dealloc];
}
#pragma mark -
+#pragma mark KVC
+- (MyDocument *) currentDocument
+{
+ return currentDocument;
+}
+- (void) setCurrentDocument:(MyDocument *)newDocument
+{
+ if (newDocument != currentDocument) {
+ currentDocument = newDocument;
+
+ [self willChangeValueForKey:@"documentColumns"];
+ self.documentColumns.content = currentDocument.csvDocument.columns;
+ [self didChangeValueForKey:@"documentColumns"];
+ }
+}
+
+- (NSArrayController *) documentColumns
+{
+ if (nil == documentColumns) {
+ self.documentColumns = [[[NSArrayController alloc] init] autorelease];
+ }
+ return documentColumns;
+}
+- (void) setDocumentColumns:(NSArrayController *)newColumns
+{
+ if (newColumns != documentColumns) {
+ [self willChangeValueForKey:@"documentColumns"];
+ [documentColumns release];
+ documentColumns = [newColumns retain];
+ [self didChangeValueForKey:@"documentColumns"];
+ }
+}
+#pragma mark -
+
+
+
#pragma mark GUI
+ (void) show:(id)sender
{
CSVInspector *i = [CSVInspector sharedInspector];
- while (nil == [i window]) {
- usleep(50);
- }
-
- [[i window] makeKeyAndOrderFront:sender];
+ i.currentDocument = [[NSDocumentController sharedDocumentController] currentDocument];
+ [i showWindow:sender];
}
- (void) awakeFromNib
@@ -114,11 +181,32 @@ - (NSString *) windowFrameAutosaveName
+#pragma mark Notifications
+- (void) documentBecameActiveNotification:(NSNotification *)notification
+{
+ MyDocument *document = [notification object];
+ self.currentDocument = document;
+}
+
+- (void) documentBecameInactiveNotification:(NSNotification *)notification
+{
+ self.currentDocument = nil;
+}
+
+- (void) documentDidChangeColumns:(NSNotification *)notification
+{
+ [self willChangeValueForKey:@"documentColumns"];
+ [self didChangeValueForKey:@"documentColumns"];
+}
+#pragma mark -
+
+
+
#pragma mark Calculations
- (IBAction) performCalculation:(id)sender
{
// should cancel
- if(calculationIsRunning) {
+ if (calculationIsRunning) {
// [document setCalculationShouldTerminate:YES];
return;
}
View
3,819 CSVManipulator.xcodeproj/pp.pbxuser
3,460 additions, 359 deletions not shown
View
113 CSVManipulator.xcodeproj/pp.perspectivev3
@@ -272,22 +272,24 @@
<string>EE64B59F1049D9C5000DF5D2</string>
<string>EE9E220D1047FF7100554687</string>
<string>EE1512230D7F04910092C02F</string>
+ <string>2A37F4AFFDCFA73011CA2CEA</string>
<string>EE137AB21090565D00D31816</string>
<string>EE137AB31090566500D31816</string>
<string>2A37F4B8FDCFA73011CA2CEA</string>
+ <string>EE64B6AD104A8598000DF5D2</string>
<string>2A37F4C3FDCFA73011CA2CEA</string>
</array>
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array>
<array>
- <integer>17</integer>
+ <integer>15</integer>
<integer>12</integer>
<integer>1</integer>
<integer>0</integer>
</array>
</array>
<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
- <string>{{0, 21}, {298, 867}}</string>
+ <string>{{0, 0}, {298, 867}}</string>
</dict>
<key>PBXTopSmartGroupGIDs</key>
<array/>
@@ -324,7 +326,7 @@
<key>PBXProjectModuleGUID</key>
<string>EEF027910D6D8015000532A4</string>
<key>PBXProjectModuleLabel</key>
- <string>CSVRow.m</string>
+ <string>CSVWindowController.m</string>
<key>PBXSplitModuleInNavigatorKey</key>
<dict>
<key>Split0</key>
@@ -332,17 +334,16 @@
<key>PBXProjectModuleGUID</key>
<string>EEF027920D6D8015000532A4</string>
<key>PBXProjectModuleLabel</key>
- <string>CSVRow.m</string>
+ <string>CSVWindowController.m</string>
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
- <string>EE714AD911383F1100418030</string>
+ <string>EE6C8B24113E9CCC001C7A92</string>
<key>history</key>
<array>
<string>EECAA3C10D803E5200AE2D4A</string>
<string>EE2EE7510DFDA3C6005764C0</string>
<string>EEE8F3680F13A00F0081E83D</string>
- <string>EEE8F3740F13A00F0081E83D</string>
<string>EEE8F5260F13DBE80081E83D</string>
<string>EE9E112F1042D26300554687</string>
<string>EE9E11301042D26300554687</string>
@@ -352,35 +353,28 @@
<string>EEF072F4108630B900C05DE9</string>
<string>EEF07453108781AD00C05DE9</string>
<string>EE13773B1088A0B700D31816</string>
- <string>EE13778E1088A95400D31816</string>
<string>EE1379E7108F07B200D31816</string>
<string>EE137A9D10904B7A00D31816</string>
<string>EE137B11109065AF00D31816</string>
- <string>EE137B8B10907FA000D31816</string>
<string>EE137B8C10907FA000D31816</string>
- <string>EE137C3A1095E81100D31816</string>
<string>EE137CC3109608E900D31816</string>
<string>EE1188FB1099E0D80072804F</string>
<string>EE118A4E109AFA990072804F</string>
<string>EE118A4F109AFA990072804F</string>
- <string>EE118DBE10A1D5320072804F</string>
<string>EE118EF210A1F78A0072804F</string>
<string>EE1A5DA310BAF0F10041C5BF</string>
<string>EE1A5DD910BAF46D0041C5BF</string>
<string>EE7144E9113538C800418030</string>
<string>EE7144EA113538C800418030</string>
- <string>EE7144FD11353C9E00418030</string>
<string>EE71466611356A4600418030</string>
<string>EE71466711356A4600418030</string>
<string>EE71466911356A4600418030</string>
- <string>EE71466A11356A4600418030</string>
<string>EE71467C113582F400418030</string>
<string>EE71469B11367CB000418030</string>
<string>EE71469C11367CB000418030</string>
<string>EE7146A911367CE300418030</string>
<string>EE7146AF11367D7D00418030</string>
<string>EE7146FC11369A2800418030</string>
- <string>EE7146FE11369A2800418030</string>
<string>EE7146FF11369A2800418030</string>
<string>EE7147231136A57900418030</string>
<string>EE7147241136A57900418030</string>
@@ -399,15 +393,23 @@
<string>EE7149201137D7C900418030</string>
<string>EE7149DE1138129E00418030</string>
<string>EE7149F2113814AD00418030</string>
- <string>EE714AA7113839C900418030</string>
- <string>EE714AAE11383A9700418030</string>
- <string>EE714AAF11383A9700418030</string>
- <string>EE714AB011383A9700418030</string>
<string>EE714AC011383B1E00418030</string>
- <string>EE714ACA11383DDF00418030</string>
- <string>EE714ACE11383ECE00418030</string>
- <string>EE714ACF11383ECE00418030</string>
- <string>EE714AD711383EF200418030</string>
+ <string>EE6C88D3113D733A001C7A92</string>
+ <string>EE6C88D4113D733A001C7A92</string>
+ <string>EE6C8A4D113E8929001C7A92</string>
+ <string>EE6C8A4F113E8929001C7A92</string>
+ <string>EE6C8A81113E8A97001C7A92</string>
+ <string>EE6C8A82113E8A97001C7A92</string>
+ <string>EE6C8A8F113E8B1E001C7A92</string>
+ <string>EE6C8A9A113E8C74001C7A92</string>
+ <string>EE6C8AD2113E9130001C7A92</string>
+ <string>EE6C8AEF113E94DE001C7A92</string>
+ <string>EE6C8AF0113E94DE001C7A92</string>
+ <string>EE6C8AFE113E956C001C7A92</string>
+ <string>EE6C8AFF113E956C001C7A92</string>
+ <string>EE6C8B1D113E969D001C7A92</string>
+ <string>EE6C8B1E113E969D001C7A92</string>
+ <string>EE6C8B1F113E969D001C7A92</string>
</array>
</dict>
<key>SplitCount</key>
@@ -421,14 +423,14 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
- <string>{{0, 0}, {1110, 880}}</string>
+ <string>{{0, 0}, {1110, 881}}</string>
<key>RubberWindowFrame</key>
<string>193 102 1430 926 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
<key>Proportion</key>
- <string>880pt</string>
+ <string>881pt</string>
</dict>
<dict>
<key>Proportion</key>
@@ -551,11 +553,11 @@
</array>
<key>TableOfContents</key>
<array>
- <string>EE7149D51138050F00418030</string>
+ <string>EE6C88AE113D6F0D001C7A92</string>
<string>1CA23ED40692098700951B8B</string>
- <string>EE7149D61138050F00418030</string>
+ <string>EE6C88AF113D6F0D001C7A92</string>
<string>EEF027910D6D8015000532A4</string>
- <string>EE7149D71138050F00418030</string>
+ <string>EE6C88B0113D6F0D001C7A92</string>
<string>1CA23EDF0692099D00951B8B</string>
<string>1CA23EE00692099D00951B8B</string>
<string>1CA23EE10692099D00951B8B</string>
@@ -606,12 +608,12 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
- <string>{{0, 0}, {1430, 501}}</string>
+ <string>{{0, 0}, {1430, 492}}</string>
</dict>
<key>Module</key>
<string>PBXDebugCLIModule</string>
<key>Proportion</key>
- <string>501pt</string>
+ <string>492pt</string>
</dict>
<dict>
<key>ContentConfiguration</key>
@@ -630,8 +632,8 @@
<string>yes</string>
<key>sizes</key>
<array>
- <string>{{0, 0}, {462, 183}}</string>
- <string>{{0, 183}, {462, 196}}</string>
+ <string>{{0, 0}, {463, 188}}</string>
+ <string>{{0, 188}, {463, 200}}</string>
</array>
</dict>
<key>VerticalSplitView</key>
@@ -646,8 +648,8 @@
<string>yes</string>
<key>sizes</key>
<array>
- <string>{{0, 0}, {462, 379}}</string>
- <string>{{462, 0}, {968, 379}}</string>
+ <string>{{0, 0}, {463, 388}}</string>
+ <string>{{463, 0}, {967, 388}}</string>
</array>
</dict>
</dict>
@@ -667,7 +669,7 @@
<key>DebugSTDIOWindowFrame</key>
<string>{{200, 200}, {500, 300}}</string>
<key>Frame</key>
- <string>{{0, 506}, {1430, 379}}</string>
+ <string>{{0, 497}, {1430, 388}}</string>
<key>PBXDebugSessionStackFrameViewKey</key>
<dict>
<key>DebugVariablesTableConfiguration</key>
@@ -677,16 +679,16 @@
<string>Value</string>
<real>85</real>
<string>Summary</string>
- <real>232</real>
+ <real>233</real>
</array>
<key>Frame</key>
- <string>{{0, 183}, {462, 196}}</string>
+ <string>{{0, 188}, {463, 200}}</string>
</dict>
</dict>
<key>Module</key>
<string>PBXDebugSessionModule</string>
<key>Proportion</key>
- <string>379pt</string>
+ <string>388pt</string>
</dict>
</array>
<key>Name</key>
@@ -704,13 +706,13 @@
</array>
<key>TableOfContents</key>
<array>
- <string>EE7149E8113812A100418030</string>
+ <string>EE6C88B1113D6F0D001C7A92</string>
<string>1CCC7628064C1048000F2A68</string>
<string>1CCC7629064C1048000F2A68</string>
- <string>EE7149E9113812A100418030</string>
- <string>EE7149EA113812A100418030</string>
- <string>EE7149EB113812A100418030</string>
- <string>EE7149EC113812A100418030</string>
+ <string>EE6C88B2113D6F0D001C7A92</string>
+ <string>EE6C88B3113D6F0D001C7A92</string>
+ <string>EE6C88B4113D6F0D001C7A92</string>
+ <string>EE6C88B5113D6F0D001C7A92</string>
<string>EEF027910D6D8015000532A4</string>
</array>
<key>ToolbarConfigUserDefaultsMinorVersion</key>
@@ -743,9 +745,8 @@
<integer>5</integer>
<key>WindowOrderList</key>
<array>
- <string>EE7149EF113812A100418030</string>
- <string>EE7149F0113812A100418030</string>
- <string>EEF071321086083800C05DE9</string>
+ <string>EE6C88B7113D6F0D001C7A92</string>
+ <string>EE6C88B8113D6F0D001C7A92</string>
<string>/Users/pp/Cocoa/CSVManipulator/CSVManipulator.xcodeproj</string>
</array>
<key>WindowString</key>
@@ -1075,16 +1076,18 @@
<string>Yes</string>
</dict>
<dict>
+ <key>FirstTimeWindowDisplayed</key>
+ <false/>
<key>Identifier</key>
<string>windowTool.debuggerConsole</string>
+ <key>IsVertical</key>
+ <true/>
<key>Layout</key>
<array>
<dict>
<key>Dock</key>
<array>
<dict>
- <key>BecomeActive</key>
- <integer>1</integer>
<key>ContentConfiguration</key>
<dict>
<key>PBXProjectModuleGUID</key>
@@ -1095,18 +1098,18 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
- <string>{{0, 0}, {700, 358}}</string>
+ <string>{{0, 0}, {440, 359}}</string>
<key>RubberWindowFrame</key>
- <string>149 87 700 400 0 0 1440 878 </string>
+ <string>214 605 440 400 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>PBXDebugCLIModule</string>
<key>Proportion</key>
- <string>358pt</string>
+ <string>359pt</string>
</dict>
</array>
<key>Proportion</key>
- <string>358pt</string>
+ <string>359pt</string>
</dict>
</array>
<key>Name</key>
@@ -1116,21 +1119,21 @@
<string>PBXDebugCLIModule</string>
</array>
<key>StatusbarIsVisible</key>
- <integer>1</integer>
+ <true/>
<key>TableOfContents</key>
<array>
<string>1C530D5B069F1CE1000CFCEE</string>
- <string>1C530D5C069F1CE1000CFCEE</string>
+ <string>EE2E4965113D6ED00000A733</string>
<string>1C78EAAC065D492600B07095</string>
</array>
<key>ToolbarConfiguration</key>
<string>xcode.toolbar.config.consoleV3</string>
<key>WindowString</key>
- <string>149 87 440 400 0 0 1440 878 </string>
+ <string>214 605 440 400 0 0 1680 1028 </string>
<key>WindowToolGUID</key>
<string>1C530D5B069F1CE1000CFCEE</string>
<key>WindowToolIsVisible</key>
- <integer>0</integer>
+ <false/>
</dict>
<dict>
<key>Identifier</key>
@@ -1581,7 +1584,7 @@
<key>TableOfContents</key>
<array>
<string>EEF071321086083800C05DE9</string>
- <string>EE7149ED113812A100418030</string>
+ <string>EE2E490D113D6AA70000A733</string>
<string>EEF071311086083800C05DE9</string>
</array>
<key>WindowString</key>
View
10 CSVManipulator.xcodeproj/project.pbxproj
@@ -588,7 +588,10 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "./**";
- OTHER_CFLAGS = "-DCSV_STRING_EXPORTING";
+ OTHER_CFLAGS = (
+ "-DCSV_STRING_EXPORTING",
+ "-DDEBUG",
+ );
PREBINDING = NO;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
};
@@ -638,7 +641,10 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "./**";
- OTHER_CFLAGS = "-DCSV_STRING_EXPORTING";
+ OTHER_CFLAGS = (
+ "-DCSV_STRING_EXPORTING",
+ "-DDEBUG",
+ );
PREBINDING = NO;
RUN_CLANG_STATIC_ANALYZER = YES;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
View
8 CSVManipulator_Prefix.pch
@@ -5,3 +5,11 @@
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif
+
+// DLog only displays if -DDEBUG is set, ALog always displays output regardless of the DEBUG setting
+#ifdef DEBUG
+# define DLog(fmt, ...) NSLog((@"%s (line %d) " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
+#else
+# define DLog(...)
+#endif
+#define ALog(fmt, ...) NSLog((@"%s (line %d) " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
View
2  CSVWindowController.h
@@ -69,7 +69,7 @@
// TableView delegate
- (void) redefineTable;
-- (void) addColumn:(CSVColumn *)newColumn toTable:(NSTableView *)aTableView withWidth:(CGFloat)width;
+- (void) addColumn:(CSVColumn *)newColumn toTable:(NSTableView *)aTableView atPosition:(NSUInteger)position withWidth:(CGFloat)width;
- (void) refreshData;
// Inspector
View
172 CSVWindowController.m
@@ -20,12 +20,15 @@
#import "PPToolbarView.h"
#define COLUMN_MIN_WIDTH 40
+#define kHeaderColumnIdentifier @"_theHeaderRowColumn"
@interface CSVWindowController ()
-- (void) addColumnWithKey:(NSString *)columnKey;
+- (void) addColumnWithKey:(NSString *)columnKey atPosition:(NSUInteger)position;
- (void) removeColumn:(NSTableColumn *)tableColumn;
+- (void) moveColumn:(NSInteger)oldPosition ofTable:(NSTableView *)aTableView to:(NSInteger)newPosition;
+- (void) didMoveColumn:(NSInteger)oldPosition ofTable:(NSTableView *)aTableView to:(NSInteger)newPosition;
@end
@@ -70,6 +73,12 @@ - (void) awakeFromNib
{
mainToolbar.borderWidth = PPBorderWidthMake(1.f, 0.f, 0.f, 0.f);
+ // the following enables prevention of moving a column before the first column
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(tableViewColumnDidMove:)
+ name:NSTableViewColumnDidMoveNotification
+ object:mainTable];
+
// document is still loading
if (!document.documentLoaded) {
[self performSelector:@selector(showProgressSheet) withObject:nil afterDelay:0.01f];
@@ -91,19 +100,20 @@ - (void) windowWillClose:(NSNotification *)notification
#pragma mark Data Control
- (IBAction) addNewColumn:(id)sender
{
- [self addColumnWithKey:[document.csvDocument nextAvailableColumnKey]];
+ [self addColumnWithKey:[document.csvDocument nextAvailableColumnKey] atPosition:UINT_MAX];
+ // TODO: Tell the CSVInspector when we do crazy stuff like this
}
-- (void) addColumnWithKey:(NSString *)columnKey
+- (void) addColumnWithKey:(NSString *)columnKey atPosition:(NSUInteger)position
{
CSVColumn *newColumn = [CSVColumn columnWithKey:columnKey];
if ([document.csvDocument addColumn:newColumn]) {
- [self addColumn:newColumn toTable:mainTable withWidth:0.f];
+ [self addColumn:newColumn toTable:mainTable atPosition:position withWidth:0.f];
// allow undo
NSUndoManager *undoManager = [document undoManager];
[undoManager registerUndoWithTarget:self selector:@selector(removeColumnWithIdentifier:) object:columnKey];
- //[undoManager setActionName:NSLocalizedString(@"Add Column", nil)];
+ [undoManager setActionName:NSLocalizedString([undoManager isUndoing] ? @"Remove Column" : @"Add Column", nil)];
}
}
@@ -128,26 +138,60 @@ - (void) removeColumnWithIdentifier:(NSString *)columnIdentifier
return;
}
}
- NSLog(@"Could not remove column with identifier '%@'", columnIdentifier);
+ NSLog(@"Can't remove column with identifier '%@'", columnIdentifier);
}
- (void) removeColumn:(NSTableColumn *)tableColumn
{
NSUndoManager *undoManager = [document undoManager];
- // TODO: Make undo insert the column at the original spot
- [undoManager registerUndoWithTarget:self selector:@selector(addColumnWithKey:) object:[tableColumn identifier]];
- //[undoManager setActionName:NSLocalizedString(@"Remove Column", nil)];
+
+ id columnIdentifier = [tableColumn identifier];
+ NSUInteger columnIndex = [mainTable columnWithIdentifier:columnIdentifier];
+
+ [[undoManager prepareWithInvocationTarget:self] addColumnWithKey:columnIdentifier atPosition:columnIndex];
+ [undoManager setActionName:NSLocalizedString([undoManager isUndoing] ? @"Add Column" : @"Remove Column", nil)];
// remove
- CSVColumn *csvColumn = [document.csvDocument columnWithKey:[tableColumn identifier]];
+ CSVColumn *csvColumn = [document.csvDocument columnWithKey:columnIdentifier];
if ([document.csvDocument removeColumn:csvColumn]) {
[mainTable removeTableColumn:tableColumn];
[mainTable sizeLastColumnToFit];
}
else {
- NSLog(@"Can't remove column %@ as it is not a valid column", csvColumn.key);
+ NSLog(@"Can't remove column %@ as it is not a valid column", columnIdentifier);
+ }
+}
+
+- (void) moveColumn:(NSInteger)oldPosition ofTable:(NSTableView *)aTableView to:(NSInteger)newPosition
+{
+ if (oldPosition != newPosition) {
+ [mainTable moveColumn:oldPosition toColumn:newPosition];
+ [self didMoveColumn:oldPosition ofTable:aTableView to:newPosition];
+ }
+}
+
+- (void) didMoveColumn:(NSInteger)oldPosition ofTable:(NSTableView *)aTableView to:(NSInteger)newPosition
+{
+ if (oldPosition != newPosition) {
+ NSUndoManager *undoManager = [document undoManager];
+ [[undoManager prepareWithInvocationTarget:self] moveColumn:newPosition ofTable:aTableView to:oldPosition];
+ [undoManager setActionName:NSLocalizedString(@"Column Order", nil)];
+
+ // collect column keys
+ NSArray *allColumns = [aTableView tableColumns];
+ NSMutableArray *arr = [NSMutableArray arrayWithCapacity:[allColumns count]];
+ for (DataTableColumn *col in allColumns) {
+ if (![kHeaderColumnIdentifier isEqualToString:[col identifier]]) {
+ [arr addObject:[col identifier]];
+ }
+ }
+
+ // propagate changes to CSVDocument
+ [document.csvDocument setColumnOrderByKeys:arr];
+ document.documentEdited = YES;
}
}
+
- (IBAction) addCSVRow:(id)sender
{
@@ -161,6 +205,18 @@ - (IBAction) removeCSVRow:(id)sender
document.documentEdited = YES;
}
+- (void) removeSelectedRows:(id)sender
+{
+ NSIndexSet *indexes = [mainTable selectedRowIndexes];
+ if ([indexes count] > 0) {
+ NSArray *exRows = [document.csvDocument.rows objectsAtIndexes:indexes];
+
+ for (CSVRow *row in exRows) {
+ [document.csvDocument removeRow:row];
+ }
+ }
+}
+
- (IBAction) restoreOriginalOrder:(id)sender;
{
[document restoreOriginalOrder];
@@ -196,7 +252,7 @@ - (void) redefineTable
[firstDataCell setTitle:@""];
DataTableColumn *firstTableColumn = [DataTableColumn column];
- [firstTableColumn setIdentifier:@"_theHeaderRowColumn"];
+ [firstTableColumn setIdentifier:kHeaderColumnIdentifier];
[firstTableColumn setDataCell:firstDataCell];
[firstTableColumn setWidth:firstColumnWidth];
firstTableColumn.resizingMask = NSTableColumnNoResizing;
@@ -221,18 +277,18 @@ - (void) redefineTable
// loop columns to add the table columns
for (CSVColumn *column in [document columns]) {
- [self addColumn:column toTable:mainTable withWidth:columnWidth];
+ [self addColumn:column toTable:mainTable atPosition:UINT_MAX withWidth:columnWidth];
}
[mainTable sizeLastColumnToFit];
}
}
-- (void) addColumn:(CSVColumn *)newColumn toTable:(NSTableView *)aTableView withWidth:(CGFloat)width
+- (void) addColumn:(CSVColumn *)newColumn toTable:(NSTableView *)aTableView atPosition:(NSUInteger)position withWidth:(CGFloat)width
{
if (aTableView == mainTable) {
- // add the table column
+ // create the table column
DataTableColumn *tableColumn = [DataTableColumn column];
[tableColumn setIdentifier:newColumn.key];
[tableColumn setDataCell:[DataTableCell cell]];
@@ -243,8 +299,6 @@ - (void) addColumn:(CSVColumn *)newColumn toTable:(NSTableView *)aTableView with
[[tableColumn headerCell] setEditable:YES];
[[tableColumn headerCell] setChecked:newColumn.active];
- [mainTable addTableColumn:tableColumn];
-
// bind the column row values
[tableColumn bind:@"value"
toObject:document.csvDocument.rowController
@@ -261,6 +315,13 @@ - (void) addColumn:(CSVColumn *)newColumn toTable:(NSTableView *)aTableView with
toObject:document.csvDocument.columnDict
withKeyPath:[NSString stringWithFormat:@"%@.type", newColumn.key]
options:nil];
+
+ // add the column
+ [mainTable addTableColumn:tableColumn];
+ NSUInteger lastColumnIndex = [[mainTable tableColumns] count] - 1;
+ if (position < lastColumnIndex) {
+ [mainTable moveColumn:lastColumnIndex toColumn:position];
+ }
}
}
@@ -295,22 +356,62 @@ - (void) tableView:(DataTableView *)tableView didChangeTableColumnState:(DataTab
}
+- (void) tableView:(NSTableView*)aTableView mouseDownInHeaderOfTableColumn:(NSTableColumn*)tableColumn
+{
+ if (0 == [[aTableView tableColumns] indexOfObject:tableColumn]) {
+ [aTableView setAllowsColumnReordering:NO];
+ }
+ else {
+ [aTableView setAllowsColumnReordering:YES];
+ }
+}
+
- (void) tableView:(NSTableView *)tableView didDragTableColumn:(NSTableColumn *)tableColumn
{
if (mainTable == tableView) {
- NSMutableArray *arr = document.csvDocument.columns;
-
- // propagate changes to CSVDocument
- for (DataTableColumn *col in [tableView tableColumns]) {
- CSVColumn *csvCol = [document.csvDocument.columnDict objectForKey:[col identifier]];
- if (nil != csvCol) {
- [arr addObject:csvCol];
+ if (![kHeaderColumnIdentifier isEqualToString:[tableColumn identifier]]) {
+ NSInteger newPos = [[tableView tableColumns] indexOfObject:tableColumn];
+
+ // a move only happened when newPos is >= 0
+ if (newPos >= 0) {
+
+ // determine old position for the undo operation
+ NSInteger oldPos = 0;
+ for (CSVColumn *column in document.csvDocument.columns) {
+ if ([column.key isEqualToString:[tableColumn identifier]]) {
+ break;
+ }
+ oldPos++;
+ }
+ oldPos++; // compensating for the first column, which is not a column of csvDocument
+
+ [self didMoveColumn:oldPos ofTable:mainTable to:newPos];
}
}
-
- document.documentEdited = YES;
}
}
+
+- (void) tableViewColumnDidMove:(NSNotification*)aNotification
+{
+ NSDictionary* userInfo = [aNotification userInfo];
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+
+ // temporarily stop listening to column moves to prevent recursion
+ [center removeObserver:self name:NSTableViewColumnDidMoveNotification object:nil];
+
+ // if the user tries to move the first column out, move it back (should not be possible since we disable moving the first column)
+ if (0 == [[userInfo objectForKey:@"NSOldColumn"] intValue]) {
+ [mainTable moveColumn:[[userInfo objectForKey:@"NSNewColumn"] intValue] toColumn:0];
+ }
+
+ // if the user tries to move a column in front of the first column, move it back
+ else if (0 == [[userInfo objectForKey:@"NSNewColumn"] intValue]) {
+ [mainTable moveColumn:0 toColumn:[[userInfo objectForKey:@"NSOldColumn"] intValue]];
+ }
+
+ // listen again for column moves
+ [center addObserver:self selector:@selector(tableViewColumnDidMove:) name:NSTableViewColumnDidMoveNotification object:mainTable];
+}
#pragma mark -
@@ -430,6 +531,25 @@ - (IBAction) showExportFormats:(id)sender
{
[PPStringFormatManager show:sender];
}
+#pragma mark -
+
+
+
+#pragma mark Notifications
+- (void) windowDidBecomeMain:(NSNotification *)notification
+{
+ [document windowDidBecomeMain:notification];
+}
+
+- (void) windowDidResignMain:(NSNotification *)notification
+{
+ [document windowDidResignMain:notification];
+}
+
+- (void) windowWillClose:(NSNotification *)notification
+{
+ [document windowDidResignMain:notification];
+}
@end
View
29 DataTable/DataTableView.m
@@ -107,6 +107,35 @@ - (void) columnDidChangeCheckedStatus:(DataTableColumn *)tableColumn
+#pragma mark TEST
+- (void) keyDown:(NSEvent *)event
+{
+ unichar u = [[event charactersIgnoringModifiers] characterAtIndex:0];
+
+ if (u == NSDeleteCharacter || u == NSDeleteFunctionKey) {
+ [self interpretKeyEvents:[NSArray arrayWithObject:event]];
+ }
+ else {
+ [super keyDown:event];
+ }
+}
+
+- (void) deleteForward:(id)sender
+{
+ [self deleteBackward:sender];
+}
+
+- (void) deleteBackward:(id)sender
+{
+ id dataSource = [self dataSource];
+ if ([dataSource respondsToSelector:@selector(removeSelectedRows:)]) {
+ [dataSource performSelector:@selector(removeSelectedRows:) withObject:nil];
+ }
+}
+#pragma mark -
+
+
+
#pragma mark Drawing
- (void) drawRow:(NSInteger)rowIndex clipRect:(NSRect)clipRect
{
View
106 English.lproj/CSVInspector.xib
@@ -2,17 +2,16 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
<data>
<int key="IBDocument.SystemTarget">1050</int>
- <string key="IBDocument.SystemVersion">10B504</string>
- <string key="IBDocument.InterfaceBuilderVersion">732</string>
- <string key="IBDocument.AppKitVersion">1038.2</string>
- <string key="IBDocument.HIToolboxVersion">437.00</string>
+ <string key="IBDocument.SystemVersion">10C540</string>
+ <string key="IBDocument.InterfaceBuilderVersion">761</string>
+ <string key="IBDocument.AppKitVersion">1038.25</string>
+ <string key="IBDocument.HIToolboxVersion">458.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string key="NS.object.0">732</string>
+ <string key="NS.object.0">761</string>
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="31"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -43,7 +42,7 @@
<int key="NSWindowBacking">2</int>
<string key="NSWindowRect">{{196, 280}, {250, 230}}</string>
<int key="NSWTFlags">-469762048</int>
- <string key="NSWindowTitle">Window</string>
+ <string key="NSWindowTitle">Calculations</string>
<string key="NSWindowClass">NSPanel</string>
<nil key="NSViewClass"/>
<string key="NSWindowContentMaxSize">{1.79769e+308, 1.79769e+308}</string>
@@ -66,8 +65,9 @@
<object class="NSPopUpButton" id="855641149">
<reference key="NSNextResponder" ref="344408959"/>
<int key="NSvFlags">267</int>
- <string key="NSFrame">{{110, 154}, {113, 26}}</string>
+ <string key="NSFrame">{{77, 154}, {146, 26}}</string>
<reference key="NSSuperview" ref="344408959"/>
+ <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSPopUpButtonCell" key="NSCell" id="656371158">
<int key="NSCellFlags">-2076049856</int>
@@ -141,8 +141,9 @@
<object class="NSPopUpButton" id="438122764">
<reference key="NSNextResponder" ref="344408959"/>
<int key="NSvFlags">267</int>
- <string key="NSFrame">{{110, 78}, {113, 26}}</string>
+ <string key="NSFrame">{{77, 78}, {146, 26}}</string>
<reference key="NSSuperview" ref="344408959"/>
+ <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSPopUpButtonCell" key="NSCell" id="163707557">
<int key="NSCellFlags">-2076049856</int>
@@ -208,6 +209,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{15, 160}, {60, 17}}</string>
<reference key="NSSuperview" ref="344408959"/>
+ <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="865326272">
<int key="NSCellFlags">68288064</int>
@@ -240,6 +242,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{15, 84}, {60, 17}}</string>
<reference key="NSSuperview" ref="344408959"/>
+ <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="873210291">
<int key="NSCellFlags">68288064</int>
@@ -256,6 +259,7 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{15, 138}, {208, 14}}</string>
<reference key="NSSuperview" ref="344408959"/>
+ <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="471513666">
<int key="NSCellFlags">68288064</int>
@@ -276,6 +280,7 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{15, 115}, {205, 22}}</string>
<reference key="NSSuperview" ref="344408959"/>
+ <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="600078507">
<int key="NSCellFlags">-1804468671</int>
@@ -306,6 +311,7 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{15, 62}, {208, 14}}</string>
<reference key="NSSuperview" ref="344408959"/>
+ <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="815921625">
<int key="NSCellFlags">68288064</int>
@@ -322,6 +328,7 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{15, 39}, {205, 22}}</string>
<reference key="NSSuperview" ref="344408959"/>
+ <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="381977831">
<int key="NSCellFlags">-1804468671</int>
@@ -339,6 +346,7 @@
<int key="NSvFlags">265</int>
<string key="NSFrame">{{144, 3}, {82, 32}}</string>
<reference key="NSSuperview" ref="344408959"/>
+ <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="125987407">
<int key="NSCellFlags">67239424</int>
@@ -361,16 +369,19 @@
<object class="NSPSMatrix" key="NSDrawMatrix"/>
<string key="NSFrame">{{14, 14}, {113, 12}}</string>
<reference key="NSSuperview" ref="344408959"/>
+ <reference key="NSWindow"/>
<int key="NSpiFlags">24840</int>
<double key="NSMaxValue">100</double>
</object>
</object>
<string key="NSFrame">{{1, 1}, {238, 188}}</string>
<reference key="NSSuperview" ref="7885019"/>
+ <reference key="NSWindow"/>
</object>
</object>
<string key="NSFrame">{{4, 19}, {240, 204}}</string>
<reference key="NSSuperview" ref="339864959"/>
+ <reference key="NSWindow"/>
<string key="NSOffsets">{0, 0}</string>
<object class="NSTextFieldCell" key="NSTitleCell">
<int key="NSCellFlags">67239424</int>
@@ -393,12 +404,16 @@
</object>
<string key="NSFrameSize">{250, 230}</string>
<reference key="NSSuperview"/>
+ <reference key="NSWindow"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1440, 878}}</string>
<string key="NSMinSize">{250, 246}</string>
<string key="NSMaxSize">{1.79769e+308, 1.79769e+308}</string>
<string key="NSFrameAutosaveName"/>
</object>
+ <object class="NSUserDefaultsController" id="467889110">
+ <bool key="NSSharedInstance">YES</bool>
+ </object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
<object class="NSMutableArray" key="connectionRecords">
@@ -467,6 +482,38 @@
</object>
<int key="connectionID">40</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">contentValues: documentColumns.arrangedObjects.fullName</string>
+ <reference key="source" ref="855641149"/>
+ <reference key="destination" ref="1001"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="855641149"/>
+ <reference key="NSDestination" ref="1001"/>
+ <string key="NSLabel">contentValues: documentColumns.arrangedObjects.fullName</string>
+ <string key="NSBinding">contentValues</string>
+ <string key="NSKeyPath">documentColumns.arrangedObjects.fullName</string>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">47</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">contentValues: documentColumns.arrangedObjects.fullName</string>
+ <reference key="source" ref="438122764"/>
+ <reference key="destination" ref="1001"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="438122764"/>
+ <reference key="NSDestination" ref="1001"/>
+ <string key="NSLabel">contentValues: documentColumns.arrangedObjects.fullName</string>
+ <string key="NSBinding">contentValues</string>
+ <string key="NSKeyPath">documentColumns.arrangedObjects.fullName</string>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">50</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -722,6 +769,11 @@
<reference key="object" ref="865326272"/>
<reference key="parent" ref="57377784"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">41</int>
+ <reference key="object" ref="467889110"/>
+ <reference key="parent" ref="0"/>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -790,9 +842,9 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{578, 531}, {250, 230}}</string>
+ <string>{{1025, 586}, {250, 230}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{578, 531}, {250, 230}}</string>
+ <string>{{1025, 586}, {250, 230}}</string>
<boolean value="YES"/>
<boolean value="YES"/>
<string>{250, 230}</string>
@@ -821,7 +873,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">40</int>
+ <int key="maxID">50</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -954,6 +1006,14 @@
</object>
</object>
<object class="IBPartialClassDescription">
+ <string key="className">NSController</string>
+ <string key="superclassName">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">AppKit.framework/Headers/NSController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
<string key="className">NSFormatter</string>
<string key="superclassName">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
@@ -1293,6 +1353,14 @@
</object>
</object>
<object class="IBPartialClassDescription">
+ <string key="className">NSUserDefaultsController</string>
+ <string key="superclassName">NSController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">AppKit.framework/Headers/NSUserDefaultsController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
<string key="className">NSView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
@@ -1352,6 +1420,7 @@
</object>
</object>
<int key="IBDocument.localizationMode">0</int>
+ <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencies">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string>
<integer value="1050" key="NS.object.0"/>
@@ -1367,5 +1436,18 @@
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<string key="IBDocument.LastKnownRelativeProjectPath">../CSVManipulator.xcodeproj</string>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
+ <object class="NSMutableDictionary" key="IBDocument.LastKnownImageSizes">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>NSMenuCheckmark</string>
+ <string>NSMenuMixedState</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>{9, 8}</string>
+ <string>{7, 2}</string>
+ </object>
+ </object>
</data>
</archive>
View
2  Info.plist
@@ -80,6 +80,6 @@
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>SVNRevision</key>
- <string>2526</string>
+ <string>2527</string>
</dict>
</plist>
View
8 MyDocument.h
@@ -15,6 +15,9 @@
@class PPStringFormat;
@class DataTableView;
+#define kDocumentDidBecomeActive @"CSVManip_DocumentDidBecomeActive"
+#define kDocumentDidBecomeInactive @"CSVManip_DocumentDidBecomeInactive"
+#define kDocumentDidChangeColumns @"CSVManip_DocumentDidChangeColumns"
@interface MyDocument : NSDocument <CSVDocumentDelegate>
@@ -73,5 +76,10 @@
// calculations
- (void) performCalculationWithArgs:(NSDictionary *)args;
+// window notifications
+- (void) windowDidBecomeMain:(NSNotification *)notification;
+- (void) windowDidResignMain:(NSNotification *)notification;
+- (void) windowWillClose:(NSNotification *)notification;
+
@end
View
34 MyDocument.m
@@ -85,6 +85,7 @@ - (void) dealloc
#pragma mark KVC
- (BOOL) isDocumentEdited
{
+ // TODO: Rewrite using NSUndoManager info
return documentEdited || !dataIsAtOriginalOrder;
}
- (void) setDocumentEdited:(BOOL)flag
@@ -243,6 +244,18 @@ - (void) csvDocument:(CSVDocument *)document didChangeRowOrderToOriginalOrder:(B
[mainWindowController didRestoreOriginalOrder];
}
}
+
+- (void) csvDocumentDidChangeColumnNames:(CSVDocument *)document
+{
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+ [center postNotificationName:kDocumentDidChangeColumns object:self];
+}
+
+- (void) csvDocumentDidChangeNumColumns:(CSVDocument *)document
+{
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+ [center postNotificationName:kDocumentDidChangeColumns object:self];
+}
#pragma mark -
@@ -614,7 +627,26 @@ - (BOOL) hasUndoManager
-#pragma mark Document Based Musts
+#pragma mark Document Windows
+- (void) windowDidBecomeMain:(NSNotification *)notification
+{
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+ [center postNotificationName:kDocumentDidBecomeActive object:self];
+}
+
+- (void) windowDidResignMain:(NSNotification *)notification
+{
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+ [center postNotificationName:kDocumentDidBecomeInactive object:self];
+}
+
+- (void) windowWillClose:(NSNotification *)notification
+{
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+ [center postNotificationName:kDocumentDidBecomeInactive object:self];
+}
+
+
- (NSString *) windowNibName
{
return @"MyDocument";
Please sign in to comment.
Something went wrong with that request. Please try again.