Skip to content

Commit

Permalink
Issue #113: Changing save request menus and behavior to match standar…
Browse files Browse the repository at this point in the history
…d Save and Save As behavior.
  • Loading branch information
mmattozzi committed Dec 21, 2016
1 parent 5fab5c9 commit fcb6a98
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
9 changes: 4 additions & 5 deletions English.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,14 @@
<action selector="reloadLastRequest:" target="494" id="913"/>
</connections>
</menuItem>
<menuItem title="Save Request" keyEquivalent="s" id="717">
<menuItem title="Save" keyEquivalent="s" id="717">
<connections>
<action selector="saveRequest:" target="494" id="730"/>
<action selector="overwriteRequest:" target="494" id="6Xy-bG-JIn"/>
</connections>
</menuItem>
<menuItem title="Overwrite Request" keyEquivalent="s" id="936">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<menuItem title="Save As..." keyEquivalent="S" id="936">
<connections>
<action selector="overwriteRequest:" target="494" id="937"/>
<action selector="saveRequest:" target="494" id="FEY-rg-7rd"/>
</connections>
</menuItem>
<menuItem title="Delete Request" id="719">
Expand Down
27 changes: 21 additions & 6 deletions core/CocoaRestClientAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,7 @@ - (IBAction) deleteSavedRequest:(id) sender {
}

// Save an HTTP request into the request drawer
// This is the Save As menu option because the user will always have a chance to name the request.
- (IBAction) saveRequest:(id) sender {
lastSelectedSavedOutlineViewItem = [savedOutlineView itemAtRow:[savedOutlineView selectedRow]];
[savedOutlineView deselectAll:nil];
Expand Down Expand Up @@ -1227,23 +1228,37 @@ + (NSString *) nameForRequest:(id)object {
}

//
// Save menu option
// Overwrite the selected request with the settings currently in the Application window, using the
// same name as the selected request.
// same name as the selected request. Presents a confirmation. If no request is selected or if a
// folder is selected, default to Save As behavior.
//
- (IBAction) overwriteRequest:(id)sender {
NSLog(@"Overwriting request");
int row = [savedOutlineView selectedRow];
if (row > -1) {
CRCRequest * request = [CRCRequest requestWithApplication:self];

id selectedSavedOutlineViewItem = [savedOutlineView itemAtRow:[savedOutlineView selectedRow]];
if ([selectedSavedOutlineViewItem isKindOfClass:[CRCSavedRequestFolder class]]) {
// TODO: doesn't make sense to overwrite a folder
return [self saveRequest:sender];
} else {
[((CRCRequest *) selectedSavedOutlineViewItem) overwriteContentsWith:request];
[savedOutlineView reloadItem:nil reloadChildren:YES];
[self saveDataToDisk];
NSString *nameOfRequest = [selectedSavedOutlineViewItem name];

NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"Cancel"];
[alert addButtonWithTitle:@"Replace"];
[alert setMessageText:@"Overwrite request?"];
[alert setInformativeText:[NSString stringWithFormat:@"Would you like to overwrite the request '%@'?", nameOfRequest]];
[alert setAlertStyle:NSWarningAlertStyle];

if ([alert runModal] == NSAlertSecondButtonReturn) {
[((CRCRequest *) selectedSavedOutlineViewItem) overwriteContentsWith:request];
[savedOutlineView reloadItem:nil reloadChildren:YES];
[self saveDataToDisk];
}
}
} else {
return [self saveRequest:sender];
}
}

Expand Down

0 comments on commit fcb6a98

Please sign in to comment.