瀏覽代碼

Add copy button to request detail view controller.

Copies the text contents of all the rows (i.e. general, request headers, response headers, query parameters, etc.)
Ryan Olson 11 年之前
父節點
當前提交
f590263d9f
共有 1 個文件被更改,包括 25 次插入0 次删除
  1. 25 0
      Classes/Network/FLEXNetworkTransactionDetailTableViewController.m

+ 25 - 0
Classes/Network/FLEXNetworkTransactionDetailTableViewController.m

@@ -53,6 +53,7 @@ typedef UIViewController *(^FLEXNetworkDetailRowSelectionFuture)(void);
     self = [super initWithStyle:UITableViewStyleGrouped];
     if (self) {
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTransactionUpdatedNotification:) name:kFLEXNetworkRecorderTransactionUpdatedNotification object:nil];
+        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Copy" style:UIBarButtonItemStylePlain target:self action:@selector(copyButtonPressed:)];
     }
     return self;
 }
@@ -117,6 +118,30 @@ typedef UIViewController *(^FLEXNetworkDetailRowSelectionFuture)(void);
     }
 }
 
+- (void)copyButtonPressed:(id)sender
+{
+    NSMutableString *requestDetailString = [NSMutableString string];
+
+    for (FLEXNetworkDetailSection *section in self.sections) {
+        if ([section.rows count] > 0) {
+            if ([section.title length] > 0) {
+                [requestDetailString appendString:section.title];
+                [requestDetailString appendString:@"\n\n"];
+            }
+            for (FLEXNetworkDetailRow *row in section.rows) {
+                NSString *rowDescription = [[[self class] attributedTextForRow:row] string];
+                if ([rowDescription length] > 0) {
+                    [requestDetailString appendString:rowDescription];
+                    [requestDetailString appendString:@"\n"];
+                }
+            }
+            [requestDetailString appendString:@"\n\n"];
+        }
+    }
+
+    [[UIPasteboard generalPasteboard] setString:requestDetailString];
+}
+
 #pragma mark - Table view data source
 
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView