Skip to content

Commit 93239c0

Browse files
committed
Merge branch 'master' of github.com:sequelpro/sequelpro
2 parents ed23600 + db424ed commit 93239c0

File tree

4 files changed

+77
-39
lines changed

4 files changed

+77
-39
lines changed

Source/SPQueryConsoleDataSource.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,15 @@ - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColum
9797
#endif
9898
}
9999

100+
- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
101+
{
102+
NSString *string = [self sqlStringForRowIndexes:rowIndexes];
103+
if([string length]) {
104+
[pboard declareTypes:@[NSStringPboardType] owner:self];
105+
return [pboard setString:string forType:NSStringPboardType];
106+
}
107+
108+
return NO;
109+
}
110+
100111
@end

Source/SPQueryController.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ extern NSString *SPTableViewDatabaseColumnID;
8484

8585
+ (SPQueryController *)sharedQueryController;
8686

87+
/**
88+
* Calls -sqlStringForForRowIndexes: with the current selection and
89+
* puts the output into the general Pasteboard (only if non-empty)
90+
*/
8791
- (IBAction)copy:(id)sender;
8892
- (IBAction)clearConsole:(id)sender;
8993
- (IBAction)saveConsoleAs:(id)sender;
@@ -103,4 +107,17 @@ extern NSString *SPTableViewDatabaseColumnID;
103107

104108
- (NSUInteger)consoleMessageCount;
105109

110+
/**
111+
* Returns the console messages specified by indexes as a string, each message separated by "\n".
112+
* @param indexes The indexes of rows to be returned.
113+
* Invalid indexes will be skipped silently.
114+
* nil is treated as an empty set.
115+
*
116+
* If no (valid) indexes are given, @"" will be returned.
117+
* The output may include other info like timestamp, host, etc. if shown in the table view, as part of a comment.
118+
*
119+
* THIS METHOD IS NOT THREAD-SAFE!
120+
*/
121+
- (NSString *)sqlStringForRowIndexes:(NSIndexSet *)indexes;
122+
106123
@end

Source/SPQueryController.m

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -150,57 +150,64 @@ - (oneway void)release { }
150150
*/
151151
- (void)copy:(id)sender
152152
{
153-
#ifndef SP_CODA
154153
NSResponder *firstResponder = [[self window] firstResponder];
155154

156155
if ((firstResponder == consoleTableView) && ([consoleTableView numberOfSelectedRows] > 0)) {
157-
158-
NSMutableString *string = [NSMutableString string];
156+
159157
NSIndexSet *rows = [consoleTableView selectedRowIndexes];
160158

161-
BOOL includeTimestamps = ![[consoleTableView tableColumnWithIdentifier:SPTableViewDateColumnID] isHidden];
162-
BOOL includeConnections = ![[consoleTableView tableColumnWithIdentifier:SPTableViewConnectionColumnID] isHidden];
163-
BOOL includeDatabases = ![[consoleTableView tableColumnWithIdentifier:SPTableViewDatabaseColumnID] isHidden];
164-
165-
[string setString:@""];
166-
167-
[rows enumerateIndexesUsingBlock:^(NSUInteger i, BOOL * _Nonnull stop) {
168-
if (i < [messagesVisibleSet count]) {
169-
SPConsoleMessage *message = NSArrayObjectAtIndex(messagesVisibleSet, i);
170-
171-
if (includeTimestamps || includeConnections || includeDatabases) [string appendString:@"/* "];
172-
173-
NSDate *date = [message messageDate];
174-
if (includeTimestamps && date) {
175-
[string appendString:[dateFormatter stringFromDate:date]];
176-
[string appendString:@" "];
177-
}
178-
179-
NSString *connection = [message messageConnection];
180-
if (includeConnections && connection) {
181-
[string appendString:connection];
182-
[string appendString:@" "];
183-
}
184-
185-
NSString *database = [message messageDatabase];
186-
if (includeDatabases && database) {
187-
[string appendString:database];
188-
[string appendString:@" "];
189-
}
190-
191-
if (includeTimestamps || includeConnections || includeDatabases) [string appendString:@"*/ "];
192-
193-
[string appendFormat:@"%@\n", [message message]];
194-
}
195-
}];
159+
NSString *string = [self sqlStringForRowIndexes:rows];
196160

197161
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
198162

199163
// Copy the string to the pasteboard
200164
[pasteBoard declareTypes:@[NSStringPboardType] owner:nil];
201165
[pasteBoard setString:string forType:NSStringPboardType];
202166
}
203-
#endif
167+
}
168+
169+
- (NSString *)sqlStringForRowIndexes:(NSIndexSet *)rows
170+
{
171+
if(![rows count]) return @"";
172+
173+
NSMutableString *string = [[NSMutableString alloc] init];
174+
175+
BOOL includeTimestamps = ![[consoleTableView tableColumnWithIdentifier:SPTableViewDateColumnID] isHidden];
176+
BOOL includeConnections = ![[consoleTableView tableColumnWithIdentifier:SPTableViewConnectionColumnID] isHidden];
177+
BOOL includeDatabases = ![[consoleTableView tableColumnWithIdentifier:SPTableViewDatabaseColumnID] isHidden];
178+
179+
[rows enumerateIndexesUsingBlock:^(NSUInteger i, BOOL * _Nonnull stop) {
180+
if (i < [messagesVisibleSet count]) {
181+
SPConsoleMessage *message = NSArrayObjectAtIndex(messagesVisibleSet, i);
182+
183+
if (includeTimestamps || includeConnections || includeDatabases) [string appendString:@"/* "];
184+
185+
NSDate *date = [message messageDate];
186+
if (includeTimestamps && date) {
187+
[string appendString:[dateFormatter stringFromDate:date]];
188+
[string appendString:@" "];
189+
}
190+
191+
NSString *connection = [message messageConnection];
192+
if (includeConnections && connection) {
193+
[string appendString:connection];
194+
[string appendString:@" "];
195+
}
196+
197+
NSString *database = [message messageDatabase];
198+
if (includeDatabases && database) {
199+
[string appendString:database];
200+
[string appendString:@" "];
201+
}
202+
203+
if (includeTimestamps || includeConnections || includeDatabases) [string appendString:@"*/ "];
204+
205+
[string appendString:[message message]];
206+
[string appendString:@"\n"];
207+
}
208+
}];
209+
210+
return [string autorelease];
204211
}
205212

206213
/**

Source/SPQueryControllerInitializer.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ - (void)awakeFromNib
8585
{
8686
[[column dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:monospacedFontSize] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
8787
}
88+
89+
//allow drag-out copying of selected rows
90+
[consoleTableView setDraggingSourceOperationMask:NSDragOperationCopy forLocal:NO];
8891
#endif
8992
}
9093

0 commit comments

Comments
 (0)