aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPConstants.h1
-rw-r--r--Source/SPConstants.m1
-rw-r--r--Source/SPFieldMapperController.m13
-rw-r--r--Source/TableDocument.h1
-rw-r--r--Source/TableDocument.m18
-rw-r--r--Source/TableDump.h7
-rw-r--r--Source/TableDump.m136
7 files changed, 159 insertions, 18 deletions
diff --git a/Source/SPConstants.h b/Source/SPConstants.h
index b7241136..e6574f31 100644
--- a/Source/SPConstants.h
+++ b/Source/SPConstants.h
@@ -230,6 +230,7 @@ extern NSString *SPCSVImportFieldEnclosedBy;
extern NSString *SPCSVImportFieldEscapeCharacter;
extern NSString *SPCSVImportFirstLineIsHeader;
extern NSString *SPCSVFieldImportMappingAlignment;
+extern NSString *SPImportClipboardTempFileNamePrefix;
// Misc
extern NSString *SPContentFilters;
diff --git a/Source/SPConstants.m b/Source/SPConstants.m
index 8a2729e8..f0d12e51 100644
--- a/Source/SPConstants.m
+++ b/Source/SPConstants.m
@@ -144,6 +144,7 @@ NSString *SPCSVImportFieldTerminator = @"CSVImportFieldTerminator";
NSString *SPCSVImportFirstLineIsHeader = @"CSVImportFirstLineIsHeader";
NSString *SPCSVImportLineTerminator = @"CSVImportLineTerminator";
NSString *SPCSVFieldImportMappingAlignment = @"CSVFieldImportMappingAlignment";
+NSString *SPImportClipboardTempFileNamePrefix = @"/tmp/_SP_ClipBoard_Import_File_";
// Misc
NSString *SPContentFilters = @"ContentFilters";
diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m
index ae935b44..a3d17f1c 100644
--- a/Source/SPFieldMapperController.m
+++ b/Source/SPFieldMapperController.m
@@ -82,8 +82,13 @@
{
// Set source path
- [fileSourcePath setURL:[NSURL fileURLWithPath:sourcePath]];
+ if([sourcePath hasPrefix:SPImportClipboardTempFileNamePrefix]) {
+ [fileSourcePath setURL:[NSURL fileURLWithPath:NSLocalizedString(@"Clipboard", @"Clipboard")]];
+ } else {
+ [fileSourcePath setURL:[NSURL fileURLWithPath:sourcePath]];
+ }
[fileSourcePath setDoubleAction:@selector(goBackToFileChooser:)];
+
[onupdateTextView setDelegate:theDelegate];
windowMinWidth = [[self window] minSize].width;
windowMinHeigth = [[self window] minSize].height;
@@ -541,7 +546,11 @@
- (IBAction)goBackToFileChooser:(id)sender
{
[NSApp endSheet:[self window] returnCode:[sender tag]];
- [theDelegate importFile];
+ if([sourcePath hasPrefix:SPImportClipboardTempFileNamePrefix]) {
+ [theDelegate importFromClipboard];
+ } else {
+ [theDelegate importFile];
+ }
}
#pragma mark -
diff --git a/Source/TableDocument.h b/Source/TableDocument.h
index 5f173f9d..e3598c18 100644
--- a/Source/TableDocument.h
+++ b/Source/TableDocument.h
@@ -275,6 +275,7 @@
- (BOOL)validateMenuItem:(NSMenuItem *)anItem;
- (IBAction)saveConnectionSheet:(id)sender;
- (IBAction)import:(id)sender;
+- (IBAction)importFromClipboard:(id)sender;
- (IBAction)export:(id)sender;
- (IBAction)exportTable:(id)sender;
- (IBAction)exportMultipleTables:(id)sender;
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index ab8a7ac5..3e442d6e 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -1684,7 +1684,7 @@
}
[createTableSyntaxTextField setStringValue:[NSString stringWithFormat:@"Create syntax for %@ '%@'", typeString, [self table]]];
-
+
[createTableSyntaxTextView setEditable:YES];
[createTableSyntaxTextView setString:@""];
[createTableSyntaxTextView insertText:([tablesListInstance tableType] == SPTableTypeView) ? [[tableSyntax createViewSyntaxPrettifier] stringByAppendingString:@";"] : [tableSyntax stringByAppendingString:@";"]];
@@ -3025,6 +3025,14 @@
/**
* Passes the request to the tableDump object
*/
+- (IBAction)importFromClipboard:(id)sender
+{
+ [tableDumpInstance importFromClipboard];
+}
+
+/**
+ * Passes the request to the tableDump object
+ */
- (IBAction)export:(id)sender
{
if ([sender tag] == -1) {
@@ -3086,7 +3094,13 @@
{
return ([self database] != nil);
}
-
+
+ if ([menuItem action] == @selector(importFromClipboard:))
+ {
+ return ([[NSPasteboard generalPasteboard] availableTypeFromArray:[NSArray arrayWithObjects:NSStringPboardType, nil]]) ? YES : NO;
+
+ }
+
// Change "Save Query/Queries" menu item title dynamically
// and disable it if no query in the editor
if ([menuItem action] == @selector(saveConnectionSheet:) && [menuItem tag] == 0) {
diff --git a/Source/TableDump.h b/Source/TableDump.h
index 6a6a34b0..af621f68 100644
--- a/Source/TableDump.h
+++ b/Source/TableDump.h
@@ -74,6 +74,10 @@
IBOutlet id importLinesTerminatedField;
IBOutlet id importFieldMapperSheetWindow;
+ IBOutlet id importFromClipboardSheet;
+ IBOutlet NSTextView *importFromClipboardTextView;
+ IBOutlet id importFromClipboardAccessoryView;
+
IBOutlet id addDropTableSwitch;
IBOutlet id addCreateTableSwitch;
IBOutlet id addTableContentSwitch;
@@ -133,11 +137,12 @@
// Import methods
- (void)importFile;
+- (void)importFromClipboard;
- (void)importSQLFile:(NSString *)filename;
- (void)startSQLImportProcessWithFile:(NSString *)filename;
- (void)importCSVFile:(NSString *)filename;
- (IBAction)changeFormat:(id)sender;
-- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo;
+- (void)openPanelDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo;
- (BOOL) buildFieldMappingArrayWithData:(NSArray *)importData isPreview:(BOOL)dataIsPreviewData ofSoureFile:(NSString*)filename;
- (NSString *) mappedValueStringForRowArray:(NSArray *)csvRowArray;
- (NSString *) mappedUpdateSetStatementStringForRowArray:(NSArray *)csvRowArray;
diff --git a/Source/TableDump.m b/Source/TableDump.m
index a7a1f31d..3021f3c4 100644
--- a/Source/TableDump.m
+++ b/Source/TableDump.m
@@ -473,6 +473,51 @@
#pragma mark -
#pragma mark Import methods
+- (void)importFromClipboard
+/*
+ invoked when user clicks on an ImportFromClipboard menuItem
+ */
+{
+ // Load accessory nib each time
+ if(![NSBundle loadNibNamed:@"ImportAccessory" owner:self]) {
+ NSBeep();
+ NSLog(@"ImportAccessory accessory dialog could not be loaded.");
+ return;
+ }
+
+ // clipboard textview with no wrapping
+ const CGFloat LargeNumberForText = 1.0e7;
+ [[importFromClipboardTextView textContainer] setContainerSize:NSMakeSize(LargeNumberForText, LargeNumberForText)];
+ [[importFromClipboardTextView textContainer] setWidthTracksTextView:NO];
+ [[importFromClipboardTextView textContainer] setHeightTracksTextView:NO];
+ [importFromClipboardTextView setAutoresizingMask:NSViewNotSizable];
+ [importFromClipboardTextView setMaxSize:NSMakeSize(LargeNumberForText, LargeNumberForText)];
+ [importFromClipboardTextView setHorizontallyResizable:YES];
+ [importFromClipboardTextView setVerticallyResizable:YES];
+ [importFromClipboardTextView setFont:[NSFont fontWithName:@"Monaco" size:11.0f]];
+
+ if([[[NSPasteboard generalPasteboard] stringForType:NSStringPboardType] length] > 4000)
+ [importFromClipboardTextView setString:[[[[NSPasteboard generalPasteboard] stringForType:NSStringPboardType] substringToIndex:4000] stringByAppendingString:@"\n…"]];
+ else
+ [importFromClipboardTextView setString:[[NSPasteboard generalPasteboard] stringForType:NSStringPboardType]];
+
+ // Preset the accessory view with prefs defaults
+ [importFieldsTerminatedField setStringValue:[prefs objectForKey:SPCSVImportFieldTerminator]];
+ [importLinesTerminatedField setStringValue:[prefs objectForKey:SPCSVImportLineTerminator]];
+ [importFieldsEscapedField setStringValue:[prefs objectForKey:SPCSVImportFieldEscapeCharacter]];
+ [importFieldsEnclosedField setStringValue:[prefs objectForKey:SPCSVImportFieldEnclosedBy]];
+ [importFieldNamesSwitch setState:[[prefs objectForKey:SPCSVImportFirstLineIsHeader] boolValue]];
+ [importFromClipboardAccessoryView addSubview:importCSVView];
+
+ [NSApp beginSheet:importFromClipboardSheet
+ modalForWindow:tableWindow
+ modalDelegate:self
+ didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
+ contextInfo:@"importFromClipboard"];
+
+ // NSString );
+}
+
- (void)importFile
/*
invoked when user clicks on an import menuItem
@@ -563,6 +608,8 @@
NSLocalizedString(@"OK button label", @"OK button"),
nil, nil, tableWindow, self, nil, nil, nil,
NSLocalizedString(@"SQL file open error", @"The SQL file you selected could not be found or read."));
+ if([filename hasPrefix:SPImportClipboardTempFileNamePrefix])
+ [[NSFileManager defaultManager] removeItemAtPath:filename error:nil];
return;
}
@@ -608,6 +655,8 @@
[sqlDataBuffer release];
[importPool drain];
[tableDocumentInstance setQueryMode:SPInterfaceQueryMode];
+ if([filename hasPrefix:SPImportClipboardTempFileNamePrefix])
+ [[NSFileManager defaultManager] removeItemAtPath:filename error:nil];
return;
}
@@ -656,6 +705,8 @@
[sqlDataBuffer release];
[importPool drain];
[tableDocumentInstance setQueryMode:SPInterfaceQueryMode];
+ if([filename hasPrefix:SPImportClipboardTempFileNamePrefix])
+ [[NSFileManager defaultManager] removeItemAtPath:filename error:nil];
return;
}
}
@@ -679,7 +730,11 @@
}
// Before entering the following loop, check that we actually have a connection. If not, bail.
- if (![mySQLConnection isConnected]) return;
+ if (![mySQLConnection isConnected]) {
+ if([filename hasPrefix:SPImportClipboardTempFileNamePrefix])
+ [[NSFileManager defaultManager] removeItemAtPath:filename error:nil];
+ return;
+ }
// Extract and process any complete SQL queries that can be found in the strings parsed so far
while (query = [sqlParser trimAndReturnStringToCharacter:';' trimmingInclusively:YES returningInclusively:NO]) {
@@ -791,7 +846,9 @@
NSInteger i;
BOOL allDataRead = NO;
BOOL insertBaseStringHasEntries;
+
NSStringEncoding csvEncoding = [MCPConnection encodingForMySQLEncoding:[[tableDocumentInstance connectionEncoding] UTF8String]];
+
fieldMappingArray = nil;
fieldMappingGlobalValueArray = nil;
@@ -805,6 +862,8 @@
NSLocalizedString(@"OK button label", @"OK button"),
nil, nil, tableWindow, self, nil, nil, nil,
NSLocalizedString(@"CSV file open error", @"The CSV file you selected could not be found or read."));
+ if([filename hasPrefix:SPImportClipboardTempFileNamePrefix])
+ [[NSFileManager defaultManager] removeItemAtPath:filename error:nil];
return;
}
@@ -876,6 +935,8 @@
if(fieldMapperOperator) [fieldMapperOperator release], fieldMapperOperator = nil;
[importPool drain];
[tableDocumentInstance setQueryMode:SPInterfaceQueryMode];
+ if([filename hasPrefix:SPImportClipboardTempFileNamePrefix])
+ [[NSFileManager defaultManager] removeItemAtPath:filename error:nil];
return;
}
@@ -923,6 +984,8 @@
if(fieldMapperOperator) [fieldMapperOperator release], fieldMapperOperator = nil;
[importPool drain];
[tableDocumentInstance setQueryMode:SPInterfaceQueryMode];
+ if([filename hasPrefix:SPImportClipboardTempFileNamePrefix])
+ [[NSFileManager defaultManager] removeItemAtPath:filename error:nil];
return;
}
@@ -974,6 +1037,8 @@
if(fieldMapperOperator) [fieldMapperOperator release], fieldMapperOperator = nil;
[importPool drain];
[tableDocumentInstance setQueryMode:SPInterfaceQueryMode];
+ if([filename hasPrefix:SPImportClipboardTempFileNamePrefix])
+ [[NSFileManager defaultManager] removeItemAtPath:filename error:nil];
return;
}
@@ -1024,6 +1089,8 @@
if(fieldMapperOperator) [fieldMapperOperator release], fieldMapperOperator = nil;
[importPool drain];
[tableDocumentInstance setQueryMode:SPInterfaceQueryMode];
+ if([filename hasPrefix:SPImportClipboardTempFileNamePrefix])
+ [[NSFileManager defaultManager] removeItemAtPath:filename error:nil];
return;
}
@@ -1169,6 +1236,8 @@
if(fieldMapperOperator) [fieldMapperOperator release], fieldMapperOperator = nil;
[importPool drain];
[tableDocumentInstance setQueryMode:SPInterfaceQueryMode];
+ if([filename hasPrefix:SPImportClipboardTempFileNamePrefix])
+ [[NSFileManager defaultManager] removeItemAtPath:filename error:nil];
// Close progress sheet
[self closeAndStopProgressSheet];
@@ -1178,8 +1247,8 @@
[self showErrorSheetWithMessage:errors];
}
- // Import finished Growl notification
- [[SPGrowlController sharedGrowlController] notifyWithTitle:@"Import Finished"
+ // Import finished Growl notification
+ [[SPGrowlController sharedGrowlController] notifyWithTitle:@"Import Finished"
description:[NSString stringWithFormat:NSLocalizedString(@"Finished importing %@",@"description for finished importing growl notification"), [filename lastPathComponent]]
window:tableWindow
notificationName:@"Import Finished"];
@@ -1195,30 +1264,71 @@
}
}
-- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo
+- (void)openPanelDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo
{
+
+ // if contextInfo == nil NSOpenPanel else importFromClipboardPanel
+
// save values to preferences
- [prefs setObject:[sheet directory] forKey:@"openPath"];
+ if(contextInfo == nil)
+ [prefs setObject:[(NSOpenPanel*)sheet directory] forKey:@"openPath"];
+ else
+ [importFromClipboardTextView setString:@""];
+
[prefs setObject:[[importFormatPopup selectedItem] title] forKey:@"importFormatPopupValue"];
- // close sheet, and check if user canceled
- [sheet orderOut:self];
+ // close NSOpenPanel sheet
+ if(contextInfo == nil)
+ [sheet orderOut:self];
+
+ // check if user canceled
if (returnCode != NSOKButton)
return;
// Reset progress cancelled from any previous runs
progressCancelled = NO;
- if(lastFilename) [lastFilename release]; lastFilename = nil;
- lastFilename = [[NSString stringWithString:[sheet filename]] retain];
+ NSString *importFileName;
- if(lastFilename == nil || ![lastFilename length]) {
- NSBeep();
- return;
+ // File path from NSOpenPanel
+ if(contextInfo == nil)
+ {
+ if(lastFilename) [lastFilename release]; lastFilename = nil;
+ lastFilename = [[NSString stringWithString:[(NSOpenPanel*)sheet filename]] retain];
+ importFileName = [NSString stringWithString:lastFilename];
+ if(lastFilename == nil || ![lastFilename length]) {
+ NSBeep();
+ return;
+ }
+ }
+
+ // Import from Clipboard
+ else
+ {
+ importFileName = [NSString stringWithFormat:@"%@%@", SPImportClipboardTempFileNamePrefix,
+ [[NSDate date] descriptionWithCalendarFormat:@"%H%M%S"
+ timeZone:nil
+ locale:[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]]];
+
+ // Write clipboard content to temp file using the connection encoding
+
+ NSStringEncoding encoding;
+ if ([[[importFormatPopup selectedItem] title] isEqualToString:@"SQL"])
+ encoding = NSUTF8StringEncoding;
+ else
+ encoding = [MCPConnection encodingForMySQLEncoding:[[tableDocumentInstance connectionEncoding] UTF8String]];
+
+ if(![[[NSPasteboard generalPasteboard] stringForType:NSStringPboardType] writeToFile:importFileName atomically:NO encoding:encoding error:nil]) {
+ NSBeep();
+ NSLog(@"Couldn't write clipboard content to temporary file.");
+ return;
+ }
}
+ if(importFileName == nil) return;
+
// begin import process
- [NSThread detachNewThreadSelector:@selector(importBackgroundProcess:) toTarget:self withObject:lastFilename];
+ [NSThread detachNewThreadSelector:@selector(importBackgroundProcess:) toTarget:self withObject:importFileName];
}
- (void)startSQLImportProcessWithFile:(NSString *)filename