Skip to content

Commit

Permalink
## LEWorkViewController
Browse files Browse the repository at this point in the history
* Add API for cancel and reply
* When the user edits the text:
  * The UI switches between `cancel` and `back` depending on whether the body text is blank.
  * If the `reply` button is showing, it will be replaced with the `save` button.
* If the text has been changed, and is not blank, going back simply saves the talk and adds it to the table if necessary—but not to the server.
  * Here the new talk should have a marking indicating that it is unsaved. Maybe it could be caution striped, or use a special avatar. (Refs #34)
* Implement cancel / revert behavior, refs #36

### Cancel / Revert

You only get the cancel button if the text has all been deleted.

This is the default state for new items, which are deleted on cancel.

If you delete all the text from an item, it will also show cancel.

Here, hitting cancel reverts that items to the server version, discarding all changes.

Here, hitting save would delete the item from the table and the server.

The button doesn’t say `revert` because there’s no system item for that and it’s nerdy.

What probably needs to happen is deleting all the text from something, the blank screen is replaced with a detailed delete and revert API.

The app should react like: Holy crap, why did you do that? What are you trying to do? It seems dangerous, so let’s be explicit here.
  • Loading branch information
ElDragonRojo committed Aug 1, 2013
1 parent 5a8c13d commit 60aceb8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Lemacs/LEWorkViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
@property (nonatomic, weak) IBOutlet UISegmentedControl *segmentedControl;
@property (strong, nonatomic) id <LETalk> talk;

- (IBAction)cancel;
- (IBAction)reply;
- (IBAction)save;
- (IBAction)togglePreview:(UISegmentedControl *)segmentedControl;

Expand Down
56 changes: 47 additions & 9 deletions Lemacs/LEWorkViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ - (void)textViewDidChange:(UITextView *)textView;
GHManagedObject *editedObject = (GHManagedObject *)self.talk;
assert([editedObject isKindOfClass:[GHManagedObject class]]);

if (!self.talk.plainBody.length && textView.text.length)
self.navigationItem.leftBarButtonItem = nil;
else if (!textView.text.length && self.talk.plainBody.length)
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel)];

[editedObject setChangeValue:textView.text forPropertyNamed:kLETalkBodyKey];
}

Expand All @@ -94,10 +99,18 @@ - (void)setEditing:(BOOL)editing;
self.textView.editable = editing;
self.textView.font = [UIFont markdownParagraphFont]; // To clear style

if (editing)
if (editing) {
self.textView.text = self.talk.plainBody;
else
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save)];
if (!self.talk.hasChanges || (!self.talk.plainBody.length && !self.textView.text.length))
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel)];
else
self.navigationItem.leftBarButtonItem = nil;
} else {
self.textView.attributedText = self.talk.styledBody;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(reply)];
self.navigationItem.leftBarButtonItem = nil;
}

super.editing = editing;
[self.textView becomeFirstResponder];
Expand All @@ -113,6 +126,37 @@ - (void)setTalk:(id <LETalk>)talk;
[self configureView];
}


#pragma mark Actions

- (IBAction)cancel;
{
NSLog(@"%@", NSStringFromSelector(_cmd));

self.textView.text = NSLocalizedString(@"I'm sorry Dave. I can't let you do that.", @"Placeholder for text that is about to be deleted.");

BOOL isNew = IsEmpty([(id)self.talk valueForKey:kLETalkBodyKey]);
BOOL isEmpty = IsEmpty(self.talk.plainBody);
BOOL delete = isEmpty && isNew;
BOOL revert = isEmpty && !isNew;

if (delete) { // Otherwise, you have to kill it from the list.
// In the future, we can
GHManagedObject *doomedObject = (GHManagedObject *)self.talk;
assert([doomedObject isKindOfClass:[GHManagedObject class]]);
self.talk = nil;
[doomedObject die];
}

if (revert) {
GHManagedObject *revertedObject = (GHManagedObject *)self.talk;
assert([revertedObject isKindOfClass:[GHManagedObject class]]);
revertedObject.changes = nil;
}

[self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)reply;
{
GHIssue *issue;
Expand Down Expand Up @@ -147,13 +191,7 @@ - (void)configureView;

// Default to editing mode if this is an uncommited talk
self.editing = IsEmpty([(NSObject *)self.talk valueForKey:kLETalkBodyKey]) || self.talk.hasChanges;
if (self.editing) {
self.segmentedControl.selectedSegmentIndex = 1;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save)];
} else {
self.segmentedControl.selectedSegmentIndex = 0;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(reply)];
}
self.segmentedControl.selectedSegmentIndex = self.editing ? 1 : 0;
}

@end

0 comments on commit 60aceb8

Please sign in to comment.