aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPFieldMapperController.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/SPFieldMapperController.m')
-rw-r--r--Source/SPFieldMapperController.m72
1 files changed, 57 insertions, 15 deletions
diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m
index f6633172..d42916a1 100644
--- a/Source/SPFieldMapperController.m
+++ b/Source/SPFieldMapperController.m
@@ -4,7 +4,7 @@
// SPFieldMapperController.m
// sequel-pro
//
-// Created by Hans-Jörg Bibiko on February 01, 2010
+// Created by Hans-Jörg Bibiko on February 01, 2010
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -82,23 +82,26 @@ static NSString *SPTableViewSqlColumnID = @"sql";
doImport = [NSNumber numberWithInteger:0];
doNotImport = [NSNumber numberWithInteger:1];
isEqual = [NSNumber numberWithInteger:2];
- doImportString = @"―";
+ doImportString = @"―";
doNotImportString = @" ";
isEqualString = @"=";
newTableMode = NO;
addGlobalSheetIsOpen = NO;
toBeEditedRowIndexes = [[NSMutableIndexSet alloc] init];
+#ifndef SP_REFACTOR /* init ivars */
prefs = [NSUserDefaults standardUserDefaults];
+#endif
tablesListInstance = [theDelegate valueForKeyPath:@"tablesListInstance"];
databaseDataInstance = [tablesListInstance valueForKeyPath:@"databaseDataInstance"];
+#ifndef SP_REFACTOR /* init ivars */
if(![prefs objectForKey:SPLastImportIntoNewTableType])
[prefs setObject:@"Default" forKey:SPLastImportIntoNewTableType];
if(![prefs objectForKey:SPLastImportIntoNewTableEncoding])
[prefs setObject:@"Default" forKey:SPLastImportIntoNewTableEncoding];
-
+#endif
}
return self;
@@ -253,8 +256,8 @@ static NSString *SPTableViewSqlColumnID = @"sql";
NSInteger i;
for(i=0; i<numberOfImportColumns; i++) {
- [fieldMappingGlobalValues addObject:@"…"];
- [fieldMappingGlobalValuesSQLMarked addObject:@"…"];
+ [fieldMappingGlobalValues addObject:@"…"];
+ [fieldMappingGlobalValuesSQLMarked addObject:@"…"];
}
}
@@ -387,8 +390,10 @@ static NSString *SPTableViewSqlColumnID = @"sql";
{
// Only save selection if the user selected 'OK'
if ([sender tag]) {
+#ifndef SP_REFACTOR
[prefs setObject:[newTableInfoEnginePopup titleOfSelectedItem] forKey:SPLastImportIntoNewTableType];
[prefs setObject:[newTableInfoEncodingPopup titleOfSelectedItem] forKey:SPLastImportIntoNewTableEncoding];
+#endif
}
[NSApp endSheet:[sender window] returnCode:[sender tag]];
@@ -453,13 +458,15 @@ static NSString *SPTableViewSqlColumnID = @"sql";
}
[createString appendString:@")"];
+#ifndef SP_REFACTOR
if(![[prefs objectForKey:SPLastImportIntoNewTableType] isEqualToString:@"Default"])
[createString appendFormat:@" ENGINE=%@", [prefs objectForKey:SPLastImportIntoNewTableType]];
if(![[prefs objectForKey:SPLastImportIntoNewTableEncoding] isEqualToString:@"Default"]) {
NSString *encodingName = [[prefs objectForKey:SPLastImportIntoNewTableEncoding] stringByMatching:@"\\((.*)\\)" capture:1L];
if (!encodingName) encodingName = @"utf8";
- [createString appendFormat:[NSString stringWithFormat:@" DEFAULT CHARACTER SET %@", [encodingName backtickQuotedString]]];
+ [createString appendString:[NSString stringWithFormat:@" DEFAULT CHARACTER SET %@", [encodingName backtickQuotedString]]];
}
+#endif
[mySQLConnection queryString:createString];
@@ -551,7 +558,7 @@ static NSString *SPTableViewSqlColumnID = @"sql";
if([column objectForKey:@"length"])
[type appendFormat:@"(%@)", [column objectForKey:@"length"]];
if([column objectForKey:@"values"])
- [type appendFormat:@"(%@)", [[column objectForKey:@"values"] componentsJoinedByString:@"¦"]];
+ [type appendFormat:@"(%@)", [[column objectForKey:@"values"] componentsJoinedByString:@"¦"]];
if([column objectForKey:@"isprimarykey"]) {
[type appendFormat:@",%@",@"PRIMARY"];
@@ -728,9 +735,11 @@ static NSString *SPTableViewSqlColumnID = @"sql";
}
[fieldMapperTableView reloadData];
+#ifndef SP_REFACTOR
// Remember last field alignment if not "custom order"
if([[alignByPopup selectedItem] tag] != 3)
[prefs setInteger:[[alignByPopup selectedItem] tag] forKey:SPCSVFieldImportMappingAlignment];
+#endif
}
/*
@@ -834,8 +843,8 @@ static NSString *SPTableViewSqlColumnID = @"sql";
columnCounter = 0;
for(id col in row) {
if(col && col != [NSNull null]) {
- if([col isKindOfClass:[NSString class]] && maxLengthOfSourceColumns[columnCounter] < (NSInteger)[col length]) {
- maxLengthOfSourceColumns[columnCounter] = [col length];
+ if([col isKindOfClass:[NSString class]] && maxLengthOfSourceColumns[columnCounter] < (NSInteger)[(NSString*)col length]) {
+ maxLengthOfSourceColumns[columnCounter] = [(NSString*)col length];
}
if(typeOfSourceColumns[columnCounter] == 1) {
if(![[[NSNumber numberWithLongLong:[col longLongValue]] stringValue] isEqualToString:col])
@@ -1034,7 +1043,9 @@ static NSString *SPTableViewSqlColumnID = @"sql";
[newTableInfoEnginePopup addItemWithTitle:[engine objectForKey:@"Engine"]];
}
+#ifndef SP_REFACTOR
[newTableInfoEnginePopup selectItemWithTitle:[prefs objectForKey:SPLastImportIntoNewTableType]];
+#endif
// Populate the table encoding popup button with a default menu item
[newTableInfoEncodingPopup removeAllItems];
@@ -1065,7 +1076,9 @@ static NSString *SPTableViewSqlColumnID = @"sql";
[newTableInfoEncodingPopup insertItemWithTitle:utf8MenuItemTitle atIndex:2];
}
+#ifndef SP_REFACTOR
[newTableInfoEncodingPopup selectItemWithTitle:[prefs objectForKey:SPLastImportIntoNewTableEncoding]];
+#endif
}
[NSApp beginSheet:newTableInfoWindow
@@ -1092,10 +1105,12 @@ static NSString *SPTableViewSqlColumnID = @"sql";
while([insertPullDownButton numberOfItems] > (([[self selectedImportMethod] isEqualToString:@"UPDATE"]) ? 6 : 5))
[insertPullDownButton removeItemAtIndex:[insertPullDownButton numberOfItems]-1];
+#ifndef SP_REFACTOR
// Add recent global value menu
if([prefs objectForKey:SPGlobalValueHistory] && [[prefs objectForKey:SPGlobalValueHistory] isKindOfClass:[NSArray class]] && [[prefs objectForKey:SPGlobalValueHistory] count])
for(id item in [prefs objectForKey:SPGlobalValueHistory])
[recentGlobalValueMenu addItemWithTitle:item action:@selector(insertRecentGlobalValue:) keyEquivalent:@""];
+#endif
// Add column placeholder
NSInteger i = 0;
@@ -1103,11 +1118,17 @@ static NSString *SPTableViewSqlColumnID = @"sql";
for(id item in [fieldMappingImportArray objectAtIndex:0]) {
i++;
if ([item isNSNull]) {
- [insertPullDownButton addItemWithTitle:[NSString stringWithFormat:@"%i. <%@>", i, [prefs objectForKey:SPNullValue]]];
+ [insertPullDownButton addItemWithTitle:[NSString stringWithFormat:@"%i. <%@>", i,
+#ifndef SP_REFACTOR
+ [prefs objectForKey:SPNullValue]
+#else
+ @"NULL"
+#endif
+ ]];
} else if ([item isSPNotLoaded]) {
[insertPullDownButton addItemWithTitle:[NSString stringWithFormat:@"%i. <%@>", i, @"DEFAULT"]];
} else {
- if([item length] > 20)
+ if([(NSString*)item length] > 20)
[insertPullDownButton addItemWithTitle:[NSString stringWithFormat:@"%i. %@…", i, [item substringToIndex:20]]];
else
[insertPullDownButton addItemWithTitle:[NSString stringWithFormat:@"%i. %@", i, item]];
@@ -1309,6 +1330,7 @@ static NSString *SPTableViewSqlColumnID = @"sql";
- (void)resizeWindowByHeightDelta:(NSInteger)delta
{
+#ifndef SP_REFACTOR /* resizeWindowByHeightDelta: */
NSUInteger tableMask = [fieldMapperTableScrollView autoresizingMask];
NSUInteger headerSwitchMask = [importFieldNamesHeaderSwitch autoresizingMask];
NSUInteger alignPopupMask = [alignByPopup autoresizingMask];
@@ -1362,7 +1384,7 @@ static NSString *SPTableViewSqlColumnID = @"sql";
[advancedUpdateView setAutoresizingMask:updateViewMask];
[advancedInsertView setAutoresizingMask:insertViewMask];
[advancedBox setAutoresizingMask:NSViewNotSizable|NSViewWidthSizable|NSViewMaxYMargin|NSViewMaxXMargin|NSViewMinXMargin];
-
+#endif
}
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
@@ -1495,7 +1517,13 @@ static NSString *SPTableViewSqlColumnID = @"sql";
[fieldMappingButtonOptions setArray:[fieldMappingImportArray objectAtIndex:fieldMappingCurrentRow]];
for (i = 0; i < [fieldMappingButtonOptions count]; i++) {
if ([[fieldMappingButtonOptions objectAtIndex:i] isNSNull])
- [fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. <%@>", i+1, [prefs objectForKey:SPNullValue]]];
+ [fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. <%@>", i+1,
+#ifndef SP_REFACTOR
+ [prefs objectForKey:SPNullValue]
+#else
+ @"NULL"
+#endif
+ ]];
else if ([[fieldMappingButtonOptions objectAtIndex:i] isSPNotLoaded])
[fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. <%@>", i+1, @"DEFAULT"]];
else
@@ -1506,7 +1534,13 @@ static NSString *SPTableViewSqlColumnID = @"sql";
if((NSInteger)[fieldMappingGlobalValues count]>numberOfImportColumns)
for( ; i < [fieldMappingGlobalValues count]; i++) {
if ([NSArrayObjectAtIndex(fieldMappingGlobalValues, i) isNSNull])
- [fieldMappingButtonOptions addObject:[NSString stringWithFormat:@"%i. <%@>", i+1, [prefs objectForKey:SPNullValue]]];
+ [fieldMappingButtonOptions addObject:[NSString stringWithFormat:@"%i. <%@>", i+1,
+#ifndef SP_REFACTOR
+ [prefs objectForKey:SPNullValue]
+#else
+ @"NULL"
+#endif
+ ]];
else
[fieldMappingButtonOptions addObject:[NSString stringWithFormat:@"%i. %@", i+1, NSArrayObjectAtIndex(fieldMappingGlobalValues, i)]];
}
@@ -1535,11 +1569,13 @@ static NSString *SPTableViewSqlColumnID = @"sql";
NSInteger alignment = 0;
+#ifndef SP_REFACTOR
if([prefs integerForKey:SPCSVFieldImportMappingAlignment]
&& [prefs integerForKey:SPCSVFieldImportMappingAlignment] >= 0
&& [prefs integerForKey:SPCSVFieldImportMappingAlignment] < 4) {
alignment = [prefs integerForKey:SPCSVFieldImportMappingAlignment];
}
+#endif
// Set matching names only if csv file has an header
if(importFieldNamesHeader && alignment == 2)
@@ -1642,7 +1678,9 @@ static NSString *SPTableViewSqlColumnID = @"sql";
- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
+#ifndef SP_REFACTOR
[aCell setFont:([prefs boolForKey:SPUseMonospacedFonts]) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+#endif
}
- (void)tableView:(NSTableView*)aTableView didClickTableColumn:(NSTableColumn *)aTableColumn
@@ -1785,7 +1823,7 @@ static NSString *SPTableViewSqlColumnID = @"sql";
if([[self selectedImportMethod] isEqualToString:@"UPDATE"])
[c addItemWithTitle:NSLocalizedString(@"Match Field", @"match field menu item")];
[m addItem:[NSMenuItem separatorItem]];
- NSMenuItem *menuItem = [m addItemWithTitle:NSLocalizedString(@"Add Value or Expression…", @"add global value or expression menu item") action:@selector(addGlobalSourceVariable:) keyEquivalent:@"g"];
+ NSMenuItem *menuItem = [m addItemWithTitle:NSLocalizedString(@"Add Value or Expression…", @"add global value or expression menu item") action:@selector(addGlobalSourceVariable:) keyEquivalent:@"g"];
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
[c addItemWithTitle:[NSString stringWithFormat:@"DEFAULT: %@", [fieldMappingTableDefaultValues objectAtIndex:rowIndex]]];
[[m itemAtIndex:[c numberOfItems]-1] setEnabled:NO];
@@ -1940,15 +1978,19 @@ static NSString *SPTableViewSqlColumnID = @"sql";
// Store anObject as recent global value if it's new
NSMutableArray *recents = [NSMutableArray array];
+#ifndef SP_REFACTOR
if([prefs objectForKey:SPGlobalValueHistory] && [[prefs objectForKey:SPGlobalValueHistory] isKindOfClass:[NSArray class]] && [[prefs objectForKey:SPGlobalValueHistory] count])
[recents setArray:[prefs objectForKey:SPGlobalValueHistory]];
+#endif
if([recents containsObject:anObject])
[recents removeObject:anObject];
[recents insertObject:anObject atIndex:0];
while([recents count] > 20)
[recents removeObjectAtIndex:[recents count]-1];
+#ifndef SP_REFACTOR
if([recents count])
[prefs setObject:recents forKey:SPGlobalValueHistory];
+#endif
// Re-init recent menu
[recentGlobalValueMenu compatibleRemoveAllItems];