diff options
author | Stuart Connolly <stuart02@gmail.com> | 2017-03-28 23:17:40 +0100 |
---|---|---|
committer | Stuart Connolly <stuart02@gmail.com> | 2017-03-28 23:17:40 +0100 |
commit | 93239c06887d54de204e1cf0c559327c00f06ed1 (patch) | |
tree | 2dbc6e66bbbf5ecca2ef8ccf3f062e2ab0a32339 /Source | |
parent | ed23600e2539a858b34c52d585830e153593b2b4 (diff) | |
parent | db424ed281c8cf9c99406b248c195f0c8a4a6c38 (diff) | |
download | sequelpro-93239c06887d54de204e1cf0c559327c00f06ed1.tar.gz sequelpro-93239c06887d54de204e1cf0c559327c00f06ed1.tar.bz2 sequelpro-93239c06887d54de204e1cf0c559327c00f06ed1.zip |
Merge branch 'master' of github.com:sequelpro/sequelpro
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPQueryConsoleDataSource.m | 11 | ||||
-rw-r--r-- | Source/SPQueryController.h | 17 | ||||
-rw-r--r-- | Source/SPQueryController.m | 85 | ||||
-rw-r--r-- | Source/SPQueryControllerInitializer.m | 3 |
4 files changed, 77 insertions, 39 deletions
diff --git a/Source/SPQueryConsoleDataSource.m b/Source/SPQueryConsoleDataSource.m index eaac2151..eb669051 100644 --- a/Source/SPQueryConsoleDataSource.m +++ b/Source/SPQueryConsoleDataSource.m @@ -97,4 +97,15 @@ static NSUInteger SPMessageTruncateCharacterLength = 256; #endif } +- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard +{ + NSString *string = [self sqlStringForRowIndexes:rowIndexes]; + if([string length]) { + [pboard declareTypes:@[NSStringPboardType] owner:self]; + return [pboard setString:string forType:NSStringPboardType]; + } + + return NO; +} + @end diff --git a/Source/SPQueryController.h b/Source/SPQueryController.h index 8d128fe3..12ff6d7b 100644 --- a/Source/SPQueryController.h +++ b/Source/SPQueryController.h @@ -84,6 +84,10 @@ extern NSString *SPTableViewDatabaseColumnID; + (SPQueryController *)sharedQueryController; +/** + * Calls -sqlStringForForRowIndexes: with the current selection and + * puts the output into the general Pasteboard (only if non-empty) + */ - (IBAction)copy:(id)sender; - (IBAction)clearConsole:(id)sender; - (IBAction)saveConsoleAs:(id)sender; @@ -103,4 +107,17 @@ extern NSString *SPTableViewDatabaseColumnID; - (NSUInteger)consoleMessageCount; +/** + * Returns the console messages specified by indexes as a string, each message separated by "\n". + * @param indexes The indexes of rows to be returned. + * Invalid indexes will be skipped silently. + * nil is treated as an empty set. + * + * If no (valid) indexes are given, @"" will be returned. + * The output may include other info like timestamp, host, etc. if shown in the table view, as part of a comment. + * + * THIS METHOD IS NOT THREAD-SAFE! + */ +- (NSString *)sqlStringForRowIndexes:(NSIndexSet *)indexes; + @end diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m index dbdc3d44..41d71154 100644 --- a/Source/SPQueryController.m +++ b/Source/SPQueryController.m @@ -150,49 +150,13 @@ static SPQueryController *sharedQueryController = nil; */ - (void)copy:(id)sender { -#ifndef SP_CODA NSResponder *firstResponder = [[self window] firstResponder]; if ((firstResponder == consoleTableView) && ([consoleTableView numberOfSelectedRows] > 0)) { - - NSMutableString *string = [NSMutableString string]; + NSIndexSet *rows = [consoleTableView selectedRowIndexes]; - BOOL includeTimestamps = ![[consoleTableView tableColumnWithIdentifier:SPTableViewDateColumnID] isHidden]; - BOOL includeConnections = ![[consoleTableView tableColumnWithIdentifier:SPTableViewConnectionColumnID] isHidden]; - BOOL includeDatabases = ![[consoleTableView tableColumnWithIdentifier:SPTableViewDatabaseColumnID] isHidden]; - - [string setString:@""]; - - [rows enumerateIndexesUsingBlock:^(NSUInteger i, BOOL * _Nonnull stop) { - if (i < [messagesVisibleSet count]) { - SPConsoleMessage *message = NSArrayObjectAtIndex(messagesVisibleSet, i); - - if (includeTimestamps || includeConnections || includeDatabases) [string appendString:@"/* "]; - - NSDate *date = [message messageDate]; - if (includeTimestamps && date) { - [string appendString:[dateFormatter stringFromDate:date]]; - [string appendString:@" "]; - } - - NSString *connection = [message messageConnection]; - if (includeConnections && connection) { - [string appendString:connection]; - [string appendString:@" "]; - } - - NSString *database = [message messageDatabase]; - if (includeDatabases && database) { - [string appendString:database]; - [string appendString:@" "]; - } - - if (includeTimestamps || includeConnections || includeDatabases) [string appendString:@"*/ "]; - - [string appendFormat:@"%@\n", [message message]]; - } - }]; + NSString *string = [self sqlStringForRowIndexes:rows]; NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard]; @@ -200,7 +164,50 @@ static SPQueryController *sharedQueryController = nil; [pasteBoard declareTypes:@[NSStringPboardType] owner:nil]; [pasteBoard setString:string forType:NSStringPboardType]; } -#endif +} + +- (NSString *)sqlStringForRowIndexes:(NSIndexSet *)rows +{ + if(![rows count]) return @""; + + NSMutableString *string = [[NSMutableString alloc] init]; + + BOOL includeTimestamps = ![[consoleTableView tableColumnWithIdentifier:SPTableViewDateColumnID] isHidden]; + BOOL includeConnections = ![[consoleTableView tableColumnWithIdentifier:SPTableViewConnectionColumnID] isHidden]; + BOOL includeDatabases = ![[consoleTableView tableColumnWithIdentifier:SPTableViewDatabaseColumnID] isHidden]; + + [rows enumerateIndexesUsingBlock:^(NSUInteger i, BOOL * _Nonnull stop) { + if (i < [messagesVisibleSet count]) { + SPConsoleMessage *message = NSArrayObjectAtIndex(messagesVisibleSet, i); + + if (includeTimestamps || includeConnections || includeDatabases) [string appendString:@"/* "]; + + NSDate *date = [message messageDate]; + if (includeTimestamps && date) { + [string appendString:[dateFormatter stringFromDate:date]]; + [string appendString:@" "]; + } + + NSString *connection = [message messageConnection]; + if (includeConnections && connection) { + [string appendString:connection]; + [string appendString:@" "]; + } + + NSString *database = [message messageDatabase]; + if (includeDatabases && database) { + [string appendString:database]; + [string appendString:@" "]; + } + + if (includeTimestamps || includeConnections || includeDatabases) [string appendString:@"*/ "]; + + [string appendString:[message message]]; + [string appendString:@"\n"]; + } + }]; + + return [string autorelease]; } /** diff --git a/Source/SPQueryControllerInitializer.m b/Source/SPQueryControllerInitializer.m index fc03d107..f8292b37 100644 --- a/Source/SPQueryControllerInitializer.m +++ b/Source/SPQueryControllerInitializer.m @@ -85,6 +85,9 @@ static NSString *SPCompletionTokensSnippetsKey = @"function_argument_snippets"; { [[column dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:monospacedFontSize] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; } + + //allow drag-out copying of selected rows + [consoleTableView setDraggingSourceOperationMask:NSDragOperationCopy forLocal:NO]; #endif } |