Browse files

Make sure new columns are not inserted off-screen

  • Loading branch information...
1 parent 51116aa commit bda36dc35b752250c539e3c652990dc4ee54d784 @p2 committed Feb 22, 2013
Showing with 78 additions and 77 deletions.
  1. +16 −16 CSVDocument/CSVRow.h
  2. +24 −28 CSVDocument/CSVRow.m
  3. +17 −18 CSVWindowController.h
  4. +15 −11 CSVWindowController.m
  5. +1 −1 DataTable/DataTableView.m
  6. +4 −2 Info.plist
  7. +1 −1 MyDocument.m
View
32 CSVDocument/CSVRow.h
@@ -30,22 +30,22 @@
@property (nonatomic, assign) BOOL isHeaderRow;
@property (nonatomic, assign) NSUInteger headerRowPosition;
-+ (id) rowForDocument:(CSVDocument *)forDocument;
-+ (id) rowFromDict:(NSMutableDictionary *)dict forDocument:(CSVDocument *)forDocument;
-
-- (NSArray *) valuesForColumns:(NSArray *)columns;
-- (NSArray *) valuesForColumnKeys:(NSArray *)columnKeys;
-- (NSString *) valuesForColumns:(NSArray *)columns combinedByString:(NSString *)sepString;
-- (NSString *) valueForColumn:(CSVColumn *)column;
-- (NSString *) valueForColumnKey:(NSString *)columnKey;
-- (BOOL) valueForColumnIsEmpty:(CSVColumn *)column;
-- (BOOL) valueForColumnKeyIsEmpty:(NSString *)columnKey;
-- (BOOL) isEmptyRow;
-
-- (void) setValue:(id)value forColumn:(CSVColumn *)column;
-- (void) setValue:(id)value forColumnKey:(NSString *)key;
-
-- (void) changeHeaderRow:(BOOL)isHeader; // changes the header row status without telling the document - only the document should use this!
++ (id)rowForDocument:(CSVDocument *)forDocument;
++ (id)rowFromDict:(NSMutableDictionary *)dict forDocument:(CSVDocument *)forDocument;
+
+- (NSArray *)valuesForColumns:(NSArray *)columns;
+- (NSArray *)valuesForColumnKeys:(NSArray *)columnKeys;
+- (NSString *)valuesForColumns:(NSArray *)columns combinedByString:(NSString *)sepString;
+- (NSString *)valueForColumn:(CSVColumn *)column;
+- (NSString *)valueForColumnKey:(NSString *)columnKey;
+- (BOOL)valueForColumnIsEmpty:(CSVColumn *)column;
+- (BOOL)valueForColumnKeyIsEmpty:(NSString *)columnKey;
+- (BOOL)isEmptyRow;
+
+- (void)setValue:(id)value forColumn:(CSVColumn *)column;
+- (void)setValue:(id)value forColumnKey:(NSString *)key;
+
+- (void)changeHeaderRow:(BOOL)isHeader; // changes the header row status without telling the document - only the document should use this!
@end
View
52 CSVDocument/CSVRow.m
@@ -22,15 +22,15 @@ @implementation CSVRow
@synthesize headerRowPosition;
-+ (id) rowForDocument:(CSVDocument *)forDocument
++ (id)rowForDocument:(CSVDocument *)forDocument
{
CSVRow *row = [[[self alloc] init] autorelease];
row.document = forDocument;
return row;
}
-+ (id) rowFromDict:(NSMutableDictionary *)dict forDocument:(CSVDocument *)forDocument
++ (id)rowFromDict:(NSMutableDictionary *)dict forDocument:(CSVDocument *)forDocument
{
CSVRow *row = [self rowForDocument:forDocument];
@@ -41,7 +41,7 @@ + (id) rowFromDict:(NSMutableDictionary *)dict forDocument:(CSVDocument *)forDoc
return row;
}
-- (id) init
+- (id)init
{
self = [super init];
if (self) {
@@ -52,7 +52,7 @@ - (id) init
return self;
}
-- (id) copyWithZone:(NSZone *)zone
+- (id)copyWithZone:(NSZone *)zone
{
CSVRow *copy = [[[self class] allocWithZone:zone] init];
copy.rowValues = rowValues;
@@ -61,23 +61,22 @@ - (id) copyWithZone:(NSZone *)zone
return copy;
}
-- (void) dealloc
+- (void)dealloc
{
self.document = nil;
self.rowValues = nil;
[super dealloc];
}
-#pragma mark -
-#pragma mark KVC
-- (BOOL) isHeaderRow
+#pragma mark - KVC
+- (BOOL)isHeaderRow
{
return isHeaderRow;
}
-- (void) setIsHeaderRow:(BOOL)isHeader
+- (void)setIsHeaderRow:(BOOL)isHeader
{
if (isHeader != isHeaderRow) {
NSUndoManager *undoManager = [[document document] undoManager];
@@ -89,7 +88,7 @@ - (void) setIsHeaderRow:(BOOL)isHeader
}
}
-- (void) changeHeaderRow:(BOOL)isHeader
+- (void)changeHeaderRow:(BOOL)isHeader
{
// this _silently_ changes the headerRow flag, only use from ourself or self.document!
[self willChangeValueForKey:@"headerRow"];
@@ -104,12 +103,11 @@ - (void) changeHeaderRow:(BOOL)isHeader
self.headerRowPosition = UINT_MAX;
}
}
-#pragma mark -
-#pragma mark Returning Column Values
-- (NSArray *) valuesForColumns:(NSArray *)columns
+#pragma mark - Returning Column Values
+- (NSArray *)valuesForColumns:(NSArray *)columns
{
if ((nil != columns) && (nil != rowValues)) {
NSMutableArray *columnKeys = [NSMutableArray arrayWithCapacity:[columns count]];
@@ -122,7 +120,7 @@ - (NSArray *) valuesForColumns:(NSArray *)columns
return nil;
}
-- (NSArray *) valuesForColumnKeys:(NSArray *)columnKeys
+- (NSArray *)valuesForColumnKeys:(NSArray *)columnKeys
{
if ((nil != columnKeys) && (nil != rowValues)) {
return [rowValues objectsForKeys:columnKeys notFoundMarker:@""];
@@ -131,17 +129,17 @@ - (NSArray *) valuesForColumnKeys:(NSArray *)columnKeys
return nil;
}
-- (NSString *) valuesForColumns:(NSArray *)columns combinedByString:(NSString *)sepString
+- (NSString *)valuesForColumns:(NSArray *)columns combinedByString:(NSString *)sepString
{
return [[self valuesForColumns:columns] componentsJoinedByString:sepString];
}
-- (NSString *) valueForColumn:(CSVColumn *)column
+- (NSString *)valueForColumn:(CSVColumn *)column
{
return [self valueForColumnKey:column.key];
}
-- (NSString *) valueForColumnKey:(NSString *)columnKey
+- (NSString *)valueForColumnKey:(NSString *)columnKey
{
if (nil != columnKey) {
return [rowValues objectForKey:columnKey];
@@ -150,32 +148,31 @@ - (NSString *) valueForColumnKey:(NSString *)columnKey
return nil;
}
-- (BOOL) valueForColumnIsEmpty:(CSVColumn *)column
+- (BOOL)valueForColumnIsEmpty:(CSVColumn *)column
{
return [self valueForColumnKeyIsEmpty:column.key];
}
-- (BOOL) valueForColumnKeyIsEmpty:(NSString *)columnKey
+- (BOOL)valueForColumnKeyIsEmpty:(NSString *)columnKey
{
return [@"" isEqualToString:[self valueForColumnKey:columnKey]];
}
-- (BOOL) isEmptyRow
+- (BOOL)isEmptyRow
{
return ([rowValues count] < 1);
}
-#pragma mark -
-#pragma mark Setting Values
-- (void) setValue:(id)value forColumn:(CSVColumn *)column
+#pragma mark - Setting Values
+- (void)setValue:(id)value forColumn:(CSVColumn *)column
{
[self setValue:value forColumnKey:column.key];
}
-- (void) setValue:(id)value forColumnKey:(NSString *)key
+- (void)setValue:(id)value forColumnKey:(NSString *)key
{
if (nil != key) {
if (document.parseSuccessful) {
@@ -198,7 +195,7 @@ - (void) setValue:(id)value forColumnKey:(NSString *)key
}
}
-- (void) setValue:(id)value forKeyPath:(NSString *)keyPath
+- (void)setValue:(id)value forKeyPath:(NSString *)keyPath
{
// if rowValues get changed, we end up here
if (0 == [keyPath rangeOfString:@"rowValues"].location) {
@@ -220,12 +217,11 @@ - (void) setValue:(id)value forKeyPath:(NSString *)keyPath
[document updateColumnNames];
}
}
-#pragma mark -
-#pragma mark Utilities
-- (NSString *) description
+#pragma mark - Utilities
+- (NSString *)description
{
return [NSString stringWithFormat:@"%@ <%p>; %@", NSStringFromClass([self class]), self, rowValues];
}
View
35 CSVWindowController.h
@@ -58,34 +58,33 @@
// Row/Column control
-- (IBAction) addNewColumn:(id)sender;
-- (IBAction) removeSelectedColumns:(id)sender;
-- (IBAction) addCSVRow:(id)sender;
-- (IBAction) removeCSVRow:(id)sender;
+- (IBAction)addNewColumn:(id)sender;
+- (IBAction)removeSelectedColumns:(id)sender;
+- (IBAction)addCSVRow:(id)sender;
+- (IBAction)removeCSVRow:(id)sender;
// Display options
-- (IBAction) restoreOriginalOrder:(id)sender;
-- (void) didRestoreOriginalOrder;
+- (IBAction)restoreOriginalOrder:(id)sender;
+- (void)didRestoreOriginalOrder;
// TableView delegate
-- (void) redefineTable;
-- (void) addColumn:(CSVColumn *)newColumn toTable:(NSTableView *)aTableView atPosition:(NSUInteger)position withWidth:(CGFloat)width;
-- (void) refreshData;
+- (void)redefineTable;
+- (void)addColumn:(CSVColumn *)newColumn toTable:(NSTableView *)aTableView atPosition:(NSUInteger)position withWidth:(CGFloat)width resizeTable:(BOOL)resize;
+- (void)refreshData;
// Inspector
-- (IBAction) showInspector:(id)sender;
+- (IBAction)showInspector:(id)sender;
// Progress Sheet Actions
-- (void) showProgressSheet;
-- (void) updateProgressSheetProgress:(CGFloat)percentage;
-- (void) setProgressSheetIndeterminate:(NSNumber *)flag;
-- (void) hideProgressSheet;
-- (IBAction) abortImport:(id)sender;
-- (void) didAbortImport:(BOOL)flag;
+- (void)showProgressSheet;
+- (void)updateProgressSheetProgress:(CGFloat)percentage;
+- (void)setProgressSheetIndeterminate:(NSNumber *)flag;
+- (void)hideProgressSheet;
+- (IBAction)abortImport:(id)sender;
+- (void)didAbortImport:(BOOL)flag;
// Export Sheet
-- (IBAction) showExportFormats:(id)sender;
-
+- (IBAction)showExportFormats:(id)sender;
@end
View
26 CSVWindowController.m
@@ -93,22 +93,21 @@ - (void) awakeFromNib
- (void) windowWillClose:(NSNotification *)notification
{
} //*/
-#pragma mark -
-#pragma mark Data Control
-- (IBAction) addNewColumn:(id)sender
+#pragma mark - Data Control
+- (IBAction)addNewColumn:(id)sender
{
[self addColumnWithKey:[document.csvDocument nextAvailableColumnKey] atPosition:UINT_MAX];
// TODO: Tell the CSVInspector when we do crazy stuff like this
}
-- (void) addColumnWithKey:(NSString *)columnKey atPosition:(NSUInteger)position
+- (void)addColumnWithKey:(NSString *)columnKey atPosition:(NSUInteger)position
{
CSVColumn *newColumn = [CSVColumn columnWithKey:columnKey];
if ([document.csvDocument addColumn:newColumn]) {
- [self addColumn:newColumn toTable:mainTable atPosition:position withWidth:0.f];
+ [self addColumn:newColumn toTable:mainTable atPosition:position withWidth:0.f resizeTable:YES];
// allow undo
NSUndoManager *undoManager = [document undoManager];
@@ -118,7 +117,7 @@ - (void) addColumnWithKey:(NSString *)columnKey atPosition:(NSUInteger)position
}
-- (IBAction) removeSelectedColumns:(id)sender
+- (IBAction)removeSelectedColumns:(id)sender
{
NSIndexSet *indexes = [mainTable selectedColumnIndexes];
if ([indexes count] > 0) {
@@ -130,7 +129,7 @@ - (IBAction) removeSelectedColumns:(id)sender
}
}
-- (void) removeColumnWithIdentifier:(NSString *)columnIdentifier
+- (void)removeColumnWithIdentifier:(NSString *)columnIdentifier
{
for (NSTableColumn *tableColumn in [mainTable tableColumns]) {
if ([[tableColumn identifier] isEqualToString:columnIdentifier]) {
@@ -141,7 +140,7 @@ - (void) removeColumnWithIdentifier:(NSString *)columnIdentifier
NSLog(@"Can't remove column with identifier '%@'", columnIdentifier);
}
-- (void) removeColumn:(NSTableColumn *)tableColumn
+- (void)removeColumn:(NSTableColumn *)tableColumn
{
NSUndoManager *undoManager = [document undoManager];
@@ -162,7 +161,7 @@ - (void) removeColumn:(NSTableColumn *)tableColumn
}
}
-- (void) moveColumn:(NSInteger)oldPosition ofTable:(NSTableView *)aTableView to:(NSInteger)newPosition
+- (void)moveColumn:(NSInteger)oldPosition ofTable:(NSTableView *)aTableView to:(NSInteger)newPosition
{
if (oldPosition != newPosition) {
[mainTable moveColumn:oldPosition toColumn:newPosition];
@@ -273,14 +272,14 @@ - (void)redefineTable
// loop columns to add the table columns
for (CSVColumn *column in [document columns]) {
- [self addColumn:column toTable:mainTable atPosition:UINT_MAX withWidth:columnWidth];
+ [self addColumn:column toTable:mainTable atPosition:UINT_MAX withWidth:columnWidth resizeTable:NO];
}
[mainTable sizeLastColumnToFit];
}
}
-- (void)addColumn:(CSVColumn *)newColumn toTable:(NSTableView *)aTableView atPosition:(NSUInteger)position withWidth:(CGFloat)width
+- (void)addColumn:(CSVColumn *)newColumn toTable:(NSTableView *)aTableView atPosition:(NSUInteger)position withWidth:(CGFloat)width resizeTable:(BOOL)resize
{
if (aTableView == mainTable) {
@@ -318,6 +317,11 @@ - (void)addColumn:(CSVColumn *)newColumn toTable:(NSTableView *)aTableView atPos
if (position < lastColumnIndex) {
[mainTable moveColumn:lastColumnIndex toColumn:position];
}
+
+ // resize the table width
+ if (resize) {
+ [mainTable sizeToFit];
+ }
}
}
View
2 DataTable/DataTableView.m
@@ -106,7 +106,7 @@ - (void)columnDidChangeCheckedStatus:(DataTableColumn *)tableColumn
NSInteger colIndex = [self.tableColumns indexOfObject:tableColumn];
if (NSNotFound != colIndex) {
if (tableColumn.active) {
- [self selectColumnIndexes:[NSIndexSet indexSetWithIndex:colIndex] byExtendingSelection:NO];
+ [self selectColumnIndexes:[NSIndexSet indexSetWithIndex:colIndex] byExtendingSelection:YES];
}
else {
[self deselectColumn:colIndex];
View
6 Info.plist
@@ -64,7 +64,7 @@
<key>CFBundleIconFile</key>
<string>CSVManipulatorIcon.icns</string>
<key>CFBundleIdentifier</key>
- <string>ch.iiaprism.unibe.CSVManipulator</string>
+ <string>com.github.p2.CSVManipulator</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
@@ -74,7 +74,9 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
- <string>0.2</string>
+ <string>0.3</string>
+ <key>LSApplicationCategoryType</key>
+ <string>public.app-category.utilities</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
View
2 MyDocument.m
@@ -443,7 +443,7 @@ - (void) performCalculationWithArgs:(NSDictionary *)args // designed to run i
// TODO: This is slow as hell!
NSString *result = [BC performMathOperation:evalString];
if (result) {
- [row setValue:result forColumnKey:targetKey];
+ [row setValue:[result stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]] forColumnKey:targetKey];
}
}

0 comments on commit bda36dc

Please sign in to comment.