Skip to content

Commit

Permalink
Second part of URL Params Table update; updates to the params table c…
Browse files Browse the repository at this point in the history
…hange the URL in the URL box
  • Loading branch information
mmattozzi committed Jul 9, 2017
1 parent e54dd2c commit 8b23792
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion core/MainWindowController.m
Expand Up @@ -416,10 +416,30 @@ - (IBAction) plusUrlParamsRow:(id)sender {
- (IBAction) minusUrlParamsRow:(id)sender {
if (self.urlParamsTable.lastObject) {
[self.urlParamsTable removeObjectAtIndex:[self.urlParametersTableView selectedRow]];
[self updateUrlFromParamsTable];
}
[self.urlParametersTableView reloadData];
}

- (void) updateUrlFromParamsTable {
NSString *urlEscaped = [[self.urlBox stringValue] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlEscaped];

NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:url
resolvingAgainstBaseURL:NO];

NSMutableArray *queryItems = [[NSMutableArray alloc] init];

for (NSMutableDictionary *dict in self.urlParamsTable) {
NSURLQueryItem *queryItem = [[NSURLQueryItem alloc] initWithName:[dict objectForKey:@"key"] value:[dict objectForKey:@"value"]];
[queryItems addObject:queryItem];
}

urlComponents.queryItems = queryItems;

[self.urlBox setStringValue:[[urlComponents URL] absoluteString]];
}

- (BOOL) updateParamsTableFromUrl {
NSString *urlEscaped = [[self.urlBox stringValue] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlEscaped];
Expand All @@ -444,7 +464,6 @@ - (BOOL) updateParamsTableFromUrl {
- (void) urlBoxTextEdited:(NSNotification *)notification {
NSTextView *object = [notification object];
if ([[object superview] superview] == self.urlBox) {
NSLog(@"Updating params table from url box");
[self.urlParamsTable removeAllObjects];
if ([self updateParamsTableFromUrl]) {
[self.urlParametersTableView reloadData];
Expand Down Expand Up @@ -1102,6 +1121,7 @@ - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
}
[row setObject:anObject forKey:[aTableColumn identifier]];
[self.urlParamsTable replaceObjectAtIndex:rowIndex withObject:row];
[self updateUrlFromParamsTable];
}
}

Expand Down

0 comments on commit 8b23792

Please sign in to comment.