Skip to content

Commit

Permalink
Make mark as done actions use edits instead of special flagging notes
Browse files Browse the repository at this point in the history
  • Loading branch information
richard committed Oct 12, 2009
1 parent 85eaca3 commit b34ea84
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 23 deletions.
6 changes: 1 addition & 5 deletions Classes/Capture/NoteListController.m
Expand Up @@ -198,11 +198,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
NSString *createdAtStr = [formatter stringFromDate:[note createdAt]];
[formatter release];

if (note.flagAction && [note.flagAction length] > 0) {
cell.detailTextLabel.text = [NSString stringWithFormat:@"F(%@) %@", note.flagAction, createdAtStr];
} else {
cell.detailTextLabel.text = [NSString stringWithFormat:@"F() %@", createdAtStr];
}
cell.detailTextLabel.text = createdAtStr;

cell.accessoryType = UIButtonTypeDetailDisclosure;

Expand Down
1 change: 1 addition & 0 deletions Classes/DataModel/Node.h
Expand Up @@ -65,6 +65,7 @@
- (void)collectLinks:(NSMutableArray*)links;
- (NSString*)htmlForDocumentViewLevel:(int)level;
- (NSString*)ownerFile;
- (NSString*)bestDoneState;

@end

Expand Down
26 changes: 26 additions & 0 deletions Classes/DataModel/Node.m
Expand Up @@ -536,4 +536,30 @@ - (NSString*)ownerFile {
return nil;
}

- (NSString*)bestDoneState {
NSString *ret = @"DONE";

// Default to the first DONE entry in the first todo state group
NSArray *todoStateGroup = [[[Settings instance] todoStateGroups] objectAtIndex:0];
if (todoStateGroup && [todoStateGroup count] > 1) {
if ([[todoStateGroup objectAtIndex:1] count] > 0) {
ret = [[todoStateGroup objectAtIndex:1] objectAtIndex:0];
}
}

// But prefer to use the first DONE entry in the todo state group that owns the current todostate
for (NSArray *todoStateGroup in [[Settings instance] todoStateGroups]) {
if ([todoStateGroup count] > 1) {
if ([[todoStateGroup objectAtIndex:0] containsObject:self.todoState] || [[todoStateGroup objectAtIndex:1] containsObject:self.todoState]) {
if ([[todoStateGroup objectAtIndex:1] count] > 0) {
ret = [[todoStateGroup objectAtIndex:1] objectAtIndex:0];
break;
}
}
}
}

return ret;
}

@end
1 change: 0 additions & 1 deletion Classes/DataModel/Note.h
Expand Up @@ -31,7 +31,6 @@
@property (nonatomic, retain) NSString * text;
@property (nonatomic, retain) NSDate * createdAt;
@property (nonatomic, retain) NSString * nodeId;
@property (nonatomic, retain) NSString * flagAction;
@property (nonatomic, retain) NSString * noteId;
@property (nonatomic, retain) NSNumber * locallyModified;
@property (nonatomic, retain) NSNumber * deleted;
Expand Down
3 changes: 1 addition & 2 deletions Classes/DataModel/Note.m
Expand Up @@ -29,7 +29,6 @@ @implementation Note
@dynamic text;
@dynamic createdAt;
@dynamic nodeId;
@dynamic flagAction;
@dynamic noteId;
@dynamic locallyModified;
@dynamic deleted;
Expand All @@ -38,7 +37,7 @@ - (NSString*)heading {
// If it is a flag entry, the flag part is the title, the rest is the body
if ([self isFlagEntry]) {
Node *node = ResolveNode(self.nodeId);
return [NSString stringWithFormat:@"F(%@) [[%@][%@]]", self.flagAction, self.nodeId, [node headingForDisplay]];
return [NSString stringWithFormat:@"F() [[%@][%@]]", self.nodeId, [node headingForDisplay]];
}

if (!self.text || [self.text length] == 0) {
Expand Down
21 changes: 18 additions & 3 deletions Classes/Outline/ActionMenuController.m
Expand Up @@ -28,6 +28,7 @@
#import "Note.h"
#import "NoteListController.h"
#import "OutlineViewController.h"
#import "LocalEditAction.h"

@implementation ActionMenuController

Expand All @@ -48,7 +49,6 @@ - (void)addFlag:(NSString*)action andEdit:(bool)edit {
Note *note = (Note*)[NSEntityDescription insertNewObjectForEntityForName:@"Note" inManagedObjectContext:[node managedObjectContext]];
note.nodeId = [node bestId];
note.createdAt = [NSDate date];
note.flagAction = action;
note.noteId = UUID();
note.locallyModified = [NSNumber numberWithBool:true];

Expand All @@ -62,13 +62,28 @@ - (void)addFlag:(NSString*)action andEdit:(bool)edit {
}
}

- (void)setTodoState:(NSString*)newState {
bool created;
LocalEditAction *action = FindOrCreateLocalEditActionForNode(@"edit:todo", node, &created);
if (created) {
action.oldValue = [node todoState];
}

action.newValue = newState;
action.nodeId = [node bestId];

node.todoState = newState;

Save();
}

- (void)onDone {
[self addFlag:@"d" andEdit:false];
[self setTodoState:[node bestDoneState]];
[self close];
}

- (void)onDoneAndArchive {
[self addFlag:@"d-a" andEdit:false];
[self setTodoState:@"DONEARCHIVE"];
[self close];
}

Expand Down
2 changes: 0 additions & 2 deletions Classes/Parsing/EditEntity.h
Expand Up @@ -30,7 +30,6 @@
NSString *newValue;
NSString *heading;
NSString *noteId;
NSString *flagAction;
NSDate *createdAt;
Node *node;
}
Expand All @@ -40,7 +39,6 @@
@property (nonatomic, copy) NSString *newValue;
@property (nonatomic, copy) NSString *heading;
@property (nonatomic, copy) NSString *noteId;
@property (nonatomic, copy) NSString *flagAction;
@property (nonatomic, copy) NSDate *createdAt;
@property (nonatomic, retain) Node *node;

Expand Down
2 changes: 0 additions & 2 deletions Classes/Parsing/EditEntity.m
Expand Up @@ -28,7 +28,6 @@ @implementation EditEntity
@synthesize oldValue, newValue;
@synthesize heading;
@synthesize noteId;
@synthesize flagAction;
@synthesize createdAt;
@synthesize node;

Expand All @@ -38,7 +37,6 @@ - (void)dealloc {
[newValue release];
[heading release];
[noteId release];
[flagAction release];
[createdAt release];
[node release];
[super dealloc];
Expand Down
7 changes: 0 additions & 7 deletions Classes/Parsing/EditsFileParser.m
Expand Up @@ -144,12 +144,6 @@ - (void)parse {
}
}

NSString *flagAction = @"";
NSArray *flagActionCaptures = [line captureComponentsMatchedByRegex:@"F\\((.*)\\) .+"];
if ([flagActionCaptures count] > 0) {
flagAction = [flagActionCaptures objectAtIndex:1];
}

// This means we are in a note or otherwise non-edit section of the outline
// In this case, we want to make a simple edit entry with no actionType, and
// get ready to accept the body
Expand All @@ -158,7 +152,6 @@ - (void)parse {
EditEntity *entity = [[EditEntity alloc] init];
[entity setEditAction:@""];
[entity setHeading:[line substringFromIndex:2]];
[entity setFlagAction:flagAction];
[editEntities addObject:entity];
[entity release];

Expand Down
9 changes: 9 additions & 0 deletions Classes/Parsing/OrgFileParser.m
Expand Up @@ -83,6 +83,7 @@ - (void)parse {
Node *lastNode = nil;
int sequenceIndex = 1;
bool readOnlyFile = false;
bool addedDefaultTodoStates = false;

lines = [entireFile componentsSeparatedByString:@"\n"];

Expand Down Expand Up @@ -287,6 +288,14 @@ - (void)parse {
// Handle headings
if (numStars > 0) {

if (isIndex && !addedDefaultTodoStates) {
NSMutableArray *todoStateGroup = [NSMutableArray arrayWithCapacity:2];
[todoStateGroup addObject:[NSMutableArray arrayWithCapacity:0]];
[todoStateGroup addObject:[NSMutableArray arrayWithObject:@"DONEARCHIVE"]];
[[Settings instance] addTodoStateGroup:todoStateGroup];
addedDefaultTodoStates = true;
}

// The title is * THIS PART
NSString *title = [[line substringFromIndex:(numStars+1)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

Expand Down
1 change: 0 additions & 1 deletion Classes/Sync/SyncManager.m
Expand Up @@ -620,7 +620,6 @@ - (void)doneParsingEditsForApplication {
[newNote setCreatedAt:entity.createdAt];
[newNote setNoteId:entity.noteId];
[newNote setLocallyModified:[NSNumber numberWithBool:false]];
[newNote setFlagAction:entity.flagAction];
NSString *text = @"";
if (entity.newValue && [entity.newValue length] > 0) {
text = [NSString stringWithFormat:@"%@\n%@", entity.heading, entity.newValue];
Expand Down
Binary file modified MobileOrg.xcdatamodel/elements
Binary file not shown.
Binary file modified MobileOrg.xcdatamodel/layout
Binary file not shown.

0 comments on commit b34ea84

Please sign in to comment.