@@ -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/* *
0 commit comments