aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorbamse16 <marius@marius.me.uk>2009-05-05 12:24:43 +0000
committerbamse16 <marius@marius.me.uk>2009-05-05 12:24:43 +0000
commit2a4bbd2e425fbbf0ffd20a9c36921778b92963ae (patch)
tree2e3030c66bc4171066a37b0516eda38a1ec8a947 /Source
parent4be832e7173836d78c91a8724c9dbfa14bd4b09f (diff)
downloadsequelpro-2a4bbd2e425fbbf0ffd20a9c36921778b92963ae.tar.gz
sequelpro-2a4bbd2e425fbbf0ffd20a9c36921778b92963ae.tar.bz2
sequelpro-2a4bbd2e425fbbf0ffd20a9c36921778b92963ae.zip
Issue 233: Option to copy field headings from result panels
Also replaced some NSLog with DLog/ALog
Diffstat (limited to 'Source')
-rw-r--r--Source/TableDocument.h2
-rw-r--r--Source/TableDocument.m49
-rw-r--r--Source/TableDump.m21
-rw-r--r--Source/TablesList.m21
4 files changed, 60 insertions, 33 deletions
diff --git a/Source/TableDocument.h b/Source/TableDocument.h
index 94e95047..17440f68 100644
--- a/Source/TableDocument.h
+++ b/Source/TableDocument.h
@@ -150,6 +150,8 @@
//table methods
- (IBAction)showCreateTableSyntax:(id)sender;
- (IBAction)copyCreateTableSyntax:(id)sender;
+- (IBAction)copyColumnNames:(id)sender;
+- (NSArray *)columnNames;
- (IBAction)checkTable:(id)sender;
- (IBAction)analyzeTable:(id)sender;
- (IBAction)optimizeTable:(id)sender;
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index ecbe6d86..fcb3340e 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -160,11 +160,10 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
[connection setValue:versionForPrint forKey:@"version"];
NSArray *columns, *rows;
- columns = rows = [[NSArray alloc] init];
+ columns = rows = nil;
+ columns = [self columnNames];
if ( [tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 0 ){
- if([[tableSourceInstance tableStructureForPrint] count] > 0)
- columns = [[NSArray alloc] initWithArray:[[tableSourceInstance tableStructureForPrint] objectAtIndex:0] copyItems:YES];
if([[tableSourceInstance tableStructureForPrint] count] > 1)
rows = [[NSArray alloc] initWithArray:
[[tableSourceInstance tableStructureForPrint] objectsAtIndexes:
@@ -173,8 +172,6 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
];
}
else if ( [tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 1 ){
- if([[tableContentInstance currentResult] count] > 0)
- columns = [[NSArray alloc] initWithArray:[[tableContentInstance currentResult] objectAtIndex:0] copyItems:YES];
if([[tableContentInstance currentResult] count] > 1)
rows = [[NSArray alloc] initWithArray:
[[tableContentInstance currentResult] objectsAtIndexes:
@@ -184,8 +181,6 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
[connection setValue:[tableContentInstance usedQuery] forKey:@"query"];
}
else if ( [tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 2 ){
- if([[customQueryInstance currentResult] count] > 0)
- columns = [[NSArray alloc] initWithArray:[[customQueryInstance currentResult] objectAtIndex:0] copyItems:YES];
if([[customQueryInstance currentResult] count] > 1)
rows = [[NSArray alloc] initWithArray:
[[customQueryInstance currentResult] objectsAtIndexes:
@@ -982,6 +977,45 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
notificationName:@"Table Syntax Copied"];
}
+- (IBAction)copyColumnNames:(id)sender
+{
+ //NSArray *columns;
+ NSString *columnNames;
+ //columns = ;
+ if ([self columnNames]) {
+ columnNames = [NSString stringWithFormat:@"`%@`", [[self columnNames] componentsJoinedByString:@"`, `"]];
+ }
+
+ if([columnNames length]){
+ NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
+ // Copy the string to the pasteboard
+ [pasteBoard declareTypes:[NSArray arrayWithObjects:NSStringPboardType, nil] owner:nil];
+ [pasteBoard setString:columnNames forType:NSStringPboardType];
+ }
+}
+
+- (NSArray *)columnNames
+{
+ NSArray *columns = nil;
+ if ( [tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 0
+ && [[tableSourceInstance tableStructureForPrint] count] > 0 ){
+ columns = [[NSArray alloc] initWithArray:[[tableSourceInstance tableStructureForPrint] objectAtIndex:0] copyItems:YES];
+ }
+ else if ( [tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 1
+ && [[tableContentInstance currentResult] count] > 0 ){
+ columns = [[NSArray alloc] initWithArray:[[tableContentInstance currentResult] objectAtIndex:0] copyItems:YES];
+ }
+ else if ( [tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 2
+ && [[customQueryInstance currentResult] count] > 0 ){
+ columns = [[NSArray alloc] initWithArray:[[customQueryInstance currentResult] objectAtIndex:0] copyItems:YES];
+ }
+
+ if(columns) {
+ [columns autorelease];
+ }
+ return columns;
+}
+
/**
* Performs a MySQL check table on the selected table and presents the result to the user via an alert sheet.
*/
@@ -1473,6 +1507,7 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
// table menu items
if ([menuItem action] == @selector(showCreateTableSyntax:) ||
[menuItem action] == @selector(copyCreateTableSyntax:) ||
+ [menuItem action] == @selector(copyColumnNames:) ||
[menuItem action] == @selector(checkTable:) ||
[menuItem action] == @selector(analyzeTable:) ||
[menuItem action] == @selector(optimizeTable:) ||
diff --git a/Source/TableDump.m b/Source/TableDump.m
index e44e01ae..23db6cf5 100644
--- a/Source/TableDump.m
+++ b/Source/TableDump.m
@@ -193,7 +193,7 @@
contextInfo = @"exportMultipleTablesAsXML";
break;
default:
- NSLog(@"ERROR: unknown export item with tag %d", tag);
+ ALog(@"ERROR: unknown export item with tag %d", tag);
return;
break;
}
@@ -312,7 +312,7 @@
// Unknown operation
} else {
- NSLog(@"Unknown export operation: %@", [contextInfo description]);
+ ALog(@"Unknown export operation: %@", [contextInfo description]);
return;
}
@@ -391,7 +391,7 @@
// Load file into string. For SQL imports, try UTF8 file encoding before the current encoding.
if ([fileType isEqualToString:@"SQL"]) {
- NSLog(@"Attempting to read as utf8");
+ DLog(@"Attempting to read as utf8");
dumpFile = [SPSQLParser stringWithContentsOfFile:filename
encoding:NSUTF8StringEncoding
error:&errorStr];
@@ -407,7 +407,7 @@
// If the SQL-as-UTF8 read failed, and for CSVs, use the current connection encoding.
if (!importSQLAsUTF8 || [fileType isEqualToString:@"CSV"]) {
- NSLog(@"Reading using connection encoding");
+ DLog(@"Reading using connection encoding");
dumpFile = [SPSQLParser stringWithContentsOfFile:filename
encoding:[CMMCPConnection encodingForMySQLEncoding:[[tableDocumentInstance connectionEncoding] UTF8String]]
error:&errorStr];
@@ -505,8 +505,6 @@
////////////////
} else if ( [fileType isEqualToString:@"CSV"] ) {
- //NSLog(@"CSV Import...");
- //import csv file
int code;
NSPopUpButtonCell *buttonCell = [[NSPopUpButtonCell alloc] init];
@@ -1309,10 +1307,7 @@
/*
loads a csv string into an array
*/
-{
-
- //NSLog(@"In arrayForCSV...");
-
+{
NSMutableString *tempTerminated, *tempLineEnds;
NSMutableArray *tempArray = [NSMutableArray array];
NSMutableArray *tempRowArray = [NSMutableArray array];
@@ -1444,7 +1439,6 @@
}
//add row to tempArray
[tempArray addObject:[NSArray arrayWithArray:tempRowArray]];
- //NSLog(@"tempArray count: %d", [tempArray count]);
}
return [NSArray arrayWithArray:tempArray];
@@ -1871,7 +1865,6 @@
}
} else {
//add object to array
- //NSLog([string substringWithRange:NSMakeRange(start,(i-start))]);
[tempArray addObject:[string substringWithRange:NSMakeRange(start,(i-start))]];
start = i + 1;
}
@@ -2042,9 +2035,7 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn
}
- (void)dealloc
-{
- // NSLog(@"TableDump dealloc");
-
+{
[tables release];
[importArray release];
[fieldMappingButtonOptions release];
diff --git a/Source/TablesList.m b/Source/TablesList.m
index df22bb92..beeef5a1 100644
--- a/Source/TablesList.m
+++ b/Source/TablesList.m
@@ -707,7 +707,6 @@
*/
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{
-
if ( [tablesListView numberOfSelectedRows] == 1 && [[self tableName] length] ) {
// Reset the table information caches
@@ -750,24 +749,24 @@
// Change mainMenu > Table > ... according to table type
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:0] setTitle:NSLocalizedString(@"Copy Create View Syntax", @"copy create view syntax menu item")];
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:1] setTitle:NSLocalizedString(@"Show Create View Syntax", @"show create view syntax menu item")];
- [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:3] setTitle:NSLocalizedString(@"Check View", @"check view menu item")];
- [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:4] setHidden:YES]; // repair
- [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:6] setHidden:YES]; // analyse
- [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:7] setHidden:YES]; // optimize
- [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:8] setTitle:NSLocalizedString(@"Flush View", @"flush view menu item")];
- [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:9] setHidden:YES]; // checksum
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:5] setTitle:NSLocalizedString(@"Check View", @"check view menu item")];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:6] setHidden:YES]; // repair
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:8] setHidden:YES]; // analyse
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:9] setHidden:YES]; // optimize
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:10] setTitle:NSLocalizedString(@"Flush View", @"flush view menu item")];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:11] setHidden:YES]; // checksum
[removeTableMenuItem setTitle:NSLocalizedString(@"Remove view", @"remove view menu title")];
[duplicateTableMenuItem setTitle:NSLocalizedString(@"Duplicate view", @"duplicate view menu title")];
} else {
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:0] setTitle:NSLocalizedString(@"Copy Create Table Syntax", @"copy create table syntax menu item")];
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:1] setTitle:NSLocalizedString(@"Show Create Table Syntax", @"show create table syntax menu item")];
- [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:3] setTitle:NSLocalizedString(@"Check Table", @"check table menu item")];
- [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:4] setHidden:NO];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:5] setTitle:NSLocalizedString(@"Check Table", @"check table menu item")];
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:6] setHidden:NO];
- [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:7] setHidden:NO];
- [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:8] setTitle:NSLocalizedString(@"Flush Table", @"flush table menu item")];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:8] setHidden:NO];
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:9] setHidden:NO];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:10] setTitle:NSLocalizedString(@"Flush Table", @"flush table menu item")];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:11] setHidden:NO];
[removeTableMenuItem setTitle:NSLocalizedString(@"Remove table", @"remove table menu title")];
[duplicateTableMenuItem setTitle:NSLocalizedString(@"Duplicate table", @"duplicate table menu title")];