Просмотр исходного кода

Support copying log messages on cell long-presses.

Ryan Olson лет назад: 11
Родитель
Сommit
d989001073
1 измененных файлов с 27 добавлено и 0 удалено
  1. 27 0
      Classes/Global State Explorers/System Log/FLEXSystemLogTableViewController.m

+ 27 - 0
Classes/Global State Explorers/System Log/FLEXSystemLogTableViewController.m

@@ -141,6 +141,33 @@
     return [FLEXSystemLogTableViewCell preferredHeightForLogMessage:logMessage inWidth:self.tableView.bounds.size.width];
     return [FLEXSystemLogTableViewCell preferredHeightForLogMessage:logMessage inWidth:self.tableView.bounds.size.width];
 }
 }
 
 
+#pragma mark - Copy on long press
+
+- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    return YES;
+}
+
+- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
+{
+    return action == @selector(copy:);
+}
+
+- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
+{
+    if (action == @selector(copy:)) {
+        FLEXSystemLogMessage *logMessage = nil;
+        if (tableView == self.tableView) {
+            logMessage = [self.logMessages objectAtIndex:indexPath.row];
+        } else if (tableView == self.searchDisplayController.searchResultsTableView) {
+            logMessage = [self.filteredLogMessages objectAtIndex:indexPath.row];
+        }
+
+        NSString *stringToCopy = [FLEXSystemLogTableViewCell displayedTextForLogMessage:logMessage] ?: @"";
+        [[UIPasteboard generalPasteboard] setString:stringToCopy];
+    }
+}
+
 #pragma mark - Search display delegate
 #pragma mark - Search display delegate
 
 
 - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
 - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString