aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPDatabaseDocument.m4
-rw-r--r--Source/SPNavigatorController.m15
-rw-r--r--Source/SPTablesList.m41
3 files changed, 55 insertions, 5 deletions
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index 45615c9f..3a0e029d 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -4191,6 +4191,8 @@
return isSaved;
}
+ [[SPNavigatorController sharedNavigatorController] performSelectorOnMainThread:@selector(removeConnection:) withObject:[self connectionID] waitUntilDone:YES];
+
// Return YES by default
return YES;
}
@@ -4212,8 +4214,6 @@
object:nil];
- [[SPNavigatorController sharedNavigatorController] performSelectorOnMainThread:@selector(removeConnection:) withObject:[self connectionID] waitUntilDone:YES];
-
[mySQLConnection setDelegate:nil];
if (_isConnected) [self closeConnection];
else [connectionController cancelConnection];
diff --git a/Source/SPNavigatorController.m b/Source/SPNavigatorController.m
index 191e7043..3ce8a090 100644
--- a/Source/SPNavigatorController.m
+++ b/Source/SPNavigatorController.m
@@ -37,6 +37,7 @@
static SPNavigatorController *sharedNavigatorController = nil;
#define DragFromNavigatorPboardType @"SPDragFromNavigatorPboardType"
+#define DragTableDataFromNavigatorPboardType @"SPDragTableDataFromNavigatorPboardType"
@implementation SPNavigatorController
@@ -131,7 +132,7 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte
prefs = [NSUserDefaults standardUserDefaults];
[self setWindowFrameAutosaveName:@"SPNavigator"];
- [outlineSchema2 registerForDraggedTypes:[NSArray arrayWithObjects:DragFromNavigatorPboardType, NSStringPboardType, nil]];
+ [outlineSchema2 registerForDraggedTypes:[NSArray arrayWithObjects:DragTableDataFromNavigatorPboardType, DragFromNavigatorPboardType, NSStringPboardType, nil]];
[outlineSchema2 setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];
[outlineSchema2 setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];
@@ -1082,7 +1083,7 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte
- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
{
// Provide data for our custom type, and simple NSStrings.
- [pboard declareTypes:[NSArray arrayWithObjects:DragFromNavigatorPboardType, NSStringPboardType, nil] owner:self];
+ [pboard declareTypes:[NSArray arrayWithObjects:DragTableDataFromNavigatorPboardType, DragFromNavigatorPboardType, NSStringPboardType, nil] owner:self];
// Collect the actual schema paths without leading connection ID
NSMutableArray *draggedItems = [NSMutableArray array];
@@ -1101,6 +1102,16 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte
[archiver finishEncoding];
[pboard setData:arraydata forType:DragFromNavigatorPboardType];
+ if([draggedItems count] == 1) {
+ NSArray *pathComponents = [[draggedItems objectAtIndex:0] componentsSeparatedByString:SPUniqueSchemaDelimiter];
+ // Is a table?
+ if([pathComponents count] == 2) {
+ [pboard setString:[NSString stringWithFormat:@"CREATE TABLE IF NOT EXISTS %@ SELECT * FROM %@",
+ [[pathComponents lastObject] backtickQuotedString],
+ [pathComponents componentsJoinedByPeriodAndBacktickQuoted]
+ ] forType:DragTableDataFromNavigatorPboardType];
+ }
+ }
// For external destinations provide a comma separated string
NSMutableString *dragString = [NSMutableString string];
for(id item in draggedItems) {
diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m
index 9e74e9d2..60961e98 100644
--- a/Source/SPTablesList.m
+++ b/Source/SPTablesList.m
@@ -1555,7 +1555,7 @@
[(ImageAndTextCell*)aCell setIndentationLevel:0];
} else {
[(ImageAndTextCell*)aCell setIndentationLevel:1];
- [(ImageAndTextCell*)aCell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+ [(ImageAndTextCell*)aCell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
}
} else {
[(ImageAndTextCell*)aCell setImage:nil];
@@ -1571,6 +1571,40 @@
return (row == 0) ? 25 : 17;
}
+- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
+{
+ NSPasteboard *pboard = [info draggingPasteboard];
+
+ // tables were dropped coming from the Navigator
+ if ( [[pboard types] containsObject:@"SPDragTableDataFromNavigatorPboardType"] ) {
+ NSString *query = [pboard stringForType:@"SPDragTableDataFromNavigatorPboardType"];
+ if(!query) return NO;
+
+ [mySQLConnection queryString:query];
+ if ([mySQLConnection queryErrored]) {
+ NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error while importing table", @"rror while importing table message")
+ defaultButton:NSLocalizedString(@"OK", @"OK button")
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to import a table via: \n%@\n\n\nMySQL said: %@", @"error importing table informative message"),
+ query, [mySQLConnection getLastErrorMessage]]];
+
+ [alert setAlertStyle:NSCriticalAlertStyle];
+ [alert beginSheetModalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"truncateTableError"];
+ return NO;
+ }
+ [self updateTables:nil];
+ return YES;
+ }
+
+ return NO;
+}
+
+- (NSDragOperation)tableView:(NSTableView *)aTableView validateDrop:(id < NSDraggingInfo >)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation
+{
+ return NSDragOperationCopy;
+}
+
#pragma mark -
#pragma mark TabView delegate methods
@@ -1892,6 +1926,11 @@
selector:@selector(endDocumentTaskForTab:)
name:SPDocumentTaskEndNotification
object:tableDocumentInstance];
+
+
+ [tablesListView registerForDraggedTypes:[NSArray arrayWithObjects:@"SPDragTableDataFromNavigatorPboardType", nil]];
+ [tablesListView setDropRow:-1 dropOperation:NSTableViewDropOn];
+
}
/**