Permalink
Browse files

added possibility to remove Folder/Context from Task

  • Loading branch information...
1 parent f0c9a3a commit 9a93b2d62451bd6448cde474b5cfffbc2e481d9f @myell0w committed Jan 18, 2010
@@ -30,6 +30,9 @@ typedef enum _TaskControllerMode {
TaskControllerMode mode;
// footer view
UIView *footerView;
+
+ Folder *oldFolder;
+ Context *oldContext;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -51,13 +51,17 @@ - (void)viewDidLoad {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
self.tempData = dict;
+
self.navigationItem.leftBarButtonItem = cancel;
self.navigationItem.rightBarButtonItem = save;
[save release];
[cancel release];
[dict release];
+ oldFolder = (Folder *)[self.task.folder retain];
+ oldContext = (Context *)[self.task.context retain];
+
[super viewDidLoad];
}
@@ -74,12 +78,18 @@ - (void)viewDidUnload {
self.task = nil;
self.tempData = nil;
self.textFieldBeingEdited = nil;
+ [oldFolder release];
+ oldFolder = nil;
+ [oldContext release];
+ oldContext = nil;
}
- (void)dealloc {
[task release];
[tempData release];
[textFieldBeingEdited release];
+ [oldFolder release];
+ [oldContext release];
[super dealloc];
}
@@ -544,6 +554,9 @@ -(void)actionSheet:(UIActionSheet*)actionSheet didDismissWithButtonIndex:(NSInte
if ([actionSheet.title isEqualToString:@"Really Cancel?"]) {
// if the user really wants to abort, delete the modal view and show the parent view again
if (buttonIndex != [actionSheet cancelButtonIndex]) {
+ self.task.folder = oldFolder;
+ self.task.context = oldContext;
+
if (self.mode == TaskControllerAddMode) {
Less2DoAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
delegate.currentEditedTask = nil;
@@ -37,8 +37,11 @@ - (void)viewWillAppear:(BOOL)animated {
// pre-check row if task has context set
if (self.task.context != nil) {
NSUInteger idx = [contexts indexOfObject:self.task.context];
- lastIndexPath = [NSIndexPath indexPathForRow:idx inSection:0];
+ lastIndexPath = [NSIndexPath indexPathForRow:idx inSection:1];
+ } else {
+ lastIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
}
+
[super viewWillAppear:animated];
}
@@ -84,62 +87,98 @@ - (void)dealloc {
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
+ return 2;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+ if (section == 0)
+ return 1;
+
return [contexts count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID = @"ContextCellInTaskEdit";
- int row = [indexPath row];
-
- UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellID];
+ static NSString *cellIDNoContext = @"ContextCellInTaskEditNoContext";
+
+ UITableViewCell *cell = nil;
+
+ if (indexPath.section == 0) {
+ cell = [aTableView dequeueReusableCellWithIdentifier:cellIDNoContext];
+ } else {
+ cell = [aTableView dequeueReusableCellWithIdentifier:cellID];
+ }
+
+
if (cell == nil) {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID] autorelease];
+ if (indexPath.section == 0) {
+ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIDNoContext] autorelease];
+ } else {
+ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID] autorelease];
+ }
+
cell.textLabel.font = [UIFont boldSystemFontOfSize:FONT_SIZE];
}
// Set up the cell...
- Context *context = (Context *)[contexts objectAtIndex:row];
- cell.textLabel.text = context.name;
- cell.imageView.image = [context hasGps] ? [UIImage imageNamed:@"context_gps.png"] : [UIImage imageNamed:@"context_no_gps.png"];
- cell.accessoryType = [indexPath isEqual:lastIndexPath] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
+ if (indexPath.section == 0) {
+ cell.textLabel.text = @"No Context";
+ cell.imageView.image = [UIImage imageNamed:@"no_context.png"];
+ cell.accessoryType = [indexPath isEqual:lastIndexPath] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
+ } else {
+ Context *context = (Context *)[contexts objectAtIndex:indexPath.row];
+ cell.textLabel.text = context.name;
+ cell.imageView.image = [context hasGps] ? [UIImage imageNamed:@"context_gps.png"] : [UIImage imageNamed:@"context_no_gps.png"];
+ cell.accessoryType = [indexPath isEqual:lastIndexPath] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
+ }
return cell;
}
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- int row = [indexPath row];
- Context *c = (Context *)[contexts objectAtIndex:row];
-
- [addContextControl resignFirstResponder];
-
- if (![indexPath isEqual:lastIndexPath]) {
- UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
- newCell.accessoryType = UITableViewCellAccessoryCheckmark;
-
- UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];
- oldCell.accessoryType = UITableViewCellAccessoryNone;
+ if (indexPath.section == 0) {
+ [addContextControl resignFirstResponder];
- lastIndexPath = indexPath;
- self.task.context = c;
-
- if(c.tasks == nil) {
- ALog ("Init new Set for Context-Task");
- [c addTasks:[NSSet setWithObject:self.task]];
+ if (![indexPath isEqual:lastIndexPath]) {
+ UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
+ newCell.accessoryType = UITableViewCellAccessoryCheckmark;
+
+ UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];
+ oldCell.accessoryType = UITableViewCellAccessoryNone;
+
+ lastIndexPath = indexPath;
+ self.task.context = nil;
}
- else {
- ALog ("Set exists, added Task");
- [c addTasksObject:self.task];
+ } else {
+ Context *c = (Context *)[contexts objectAtIndex:indexPath.row];
+
+ [addContextControl resignFirstResponder];
+
+ if (![indexPath isEqual:lastIndexPath]) {
+ UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
+ newCell.accessoryType = UITableViewCellAccessoryCheckmark;
+
+ UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];
+ oldCell.accessoryType = UITableViewCellAccessoryNone;
+
+ lastIndexPath = indexPath;
+ self.task.context = c;
+
+ if(c.tasks == nil) {
+ ALog ("Init new Set for Context-Task");
+ [c addTasks:[NSSet setWithObject:self.task]];
+ }
+ else {
+ ALog ("Set exists, added Task");
+ [c addTasksObject:self.task];
+ }
}
- }
+ }
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@@ -168,7 +207,7 @@ - (IBAction)addContext:(id)sender {
NSUInteger idx = [contexts indexOfObject:context];
- lastIndexPath = [NSIndexPath indexPathForRow:idx inSection:0];
+ lastIndexPath = [NSIndexPath indexPathForRow:idx inSection:1];
self.addContextControl.text = @"";
[self.tableView reloadData];
@@ -38,8 +38,11 @@ - (void)viewWillAppear:(BOOL)animated {
// pre-check row if task has folder set
if (self.task.folder != nil) {
NSUInteger idx = [folders indexOfObject:self.task.folder];
- lastIndexPath = [NSIndexPath indexPathForRow:idx inSection:0];
+ lastIndexPath = [NSIndexPath indexPathForRow:idx inSection:1];
+ } else {
+ lastIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
}
+
[super viewWillAppear:animated];
}
@@ -85,69 +88,106 @@ - (void)dealloc {
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
+ return 2;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+ if (section == 0)
+ return 1;
+
return [folders count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID = @"FolderCellInTaskEdit";
- int row = [indexPath row];
- Folder *folder = [folders objectAtIndex:row];
+ static NSString *cellIDNoFolder = @"FolderCellInTaskEditNoFolder";
+
+ Folder *folder = nil;
+ UITableViewCell *cell = nil;
- UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellID];
+ if (indexPath.section == 0) {
+ cell = [aTableView dequeueReusableCellWithIdentifier:cellIDNoFolder];
+ } else {
+ cell = [aTableView dequeueReusableCellWithIdentifier:cellID];
+ folder = [folders objectAtIndex:indexPath.row];
+ }
+
// create new cell
if (cell == nil) {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID] autorelease];
-
- UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(12,12,22,22)];
- imageView.image = [UIImage imageNamed:@"smallWhiteBoarderedButton.png"];
- imageView.tag = TAG_COLOR;
- [cell.contentView addSubview:imageView];
- [imageView release];
-
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(46,10,235,27)];
- label.tag = TAG_FOLDER;
- label.font = [UIFont boldSystemFontOfSize:FONT_SIZE];
- [cell.contentView addSubview:label];
- [label release];
+ if (indexPath.section == 0) {
+ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIDNoFolder] autorelease];
+ } else {
+ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID] autorelease];
+
+ UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(12,12,22,22)];
+ imageView.image = [UIImage imageNamed:@"smallWhiteBoarderedButton.png"];
+ imageView.tag = TAG_COLOR;
+ [cell.contentView addSubview:imageView];
+ [imageView release];
+
+ UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(46,10,235,27)];
+ label.tag = TAG_FOLDER;
+ label.font = [UIFont boldSystemFontOfSize:FONT_SIZE];
+ [cell.contentView addSubview:label];
+ [label release];
+ }
}
// Set up the cell...
- UIView *colorView = [cell.contentView viewWithTag:TAG_COLOR];
- colorView.backgroundColor = [folder color];
-
- UILabel *textLabel = (UILabel *)[cell.contentView viewWithTag:TAG_FOLDER];
- textLabel.text = folder.name;
- cell.accessoryType = [indexPath isEqual:lastIndexPath] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
+ if (indexPath.section == 0) {
+ cell.textLabel.text = @"No Folder";
+ cell.imageView.image = [UIImage imageNamed:@"no_folder.png"];
+ cell.accessoryType = [indexPath isEqual:lastIndexPath] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
+ } else {
+ UIView *colorView = [cell.contentView viewWithTag:TAG_COLOR];
+ colorView.backgroundColor = [folder color];
+
+ UILabel *textLabel = (UILabel *)[cell.contentView viewWithTag:TAG_FOLDER];
+ textLabel.text = folder.name;
+ cell.accessoryType = [indexPath isEqual:lastIndexPath] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
+ }
return cell;
}
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- int row = [indexPath row];
- Folder *f = (Folder *)[folders objectAtIndex:row];
-
- ALog("Selected Folder: %@", f);
- [addFolderControl resignFirstResponder];
-
- if (![indexPath isEqual:lastIndexPath]) {
- UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
- newCell.accessoryType = UITableViewCellAccessoryCheckmark;
-
- UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];
- oldCell.accessoryType = UITableViewCellAccessoryNone;
+ if (indexPath.section == 0) {
+ [addFolderControl resignFirstResponder];
- lastIndexPath = indexPath;
- self.task.folder = f;
- }
+ if (![indexPath isEqual:lastIndexPath]) {
+ UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
+ newCell.accessoryType = UITableViewCellAccessoryCheckmark;
+
+ UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];
+ oldCell.accessoryType = UITableViewCellAccessoryNone;
+
+ lastIndexPath = indexPath;
+ self.task.folder = nil;
+ }
+
+ } else {
+ int row = [indexPath row];
+ Folder *f = (Folder *)[folders objectAtIndex:row];
+
+ ALog("Selected Folder: %@", f);
+ [addFolderControl resignFirstResponder];
+
+ if (![indexPath isEqual:lastIndexPath]) {
+ UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
+ newCell.accessoryType = UITableViewCellAccessoryCheckmark;
+
+ UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];
+ oldCell.accessoryType = UITableViewCellAccessoryNone;
+
+ lastIndexPath = indexPath;
+ self.task.folder = f;
+ }
+ }
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@@ -174,7 +214,7 @@ - (IBAction)addFolder:(id)sender {
self.task.folder = folder;
NSUInteger idx = [folders indexOfObject:folder];
- lastIndexPath = [NSIndexPath indexPathForRow:idx inSection:0];
+ lastIndexPath = [NSIndexPath indexPathForRow:idx inSection:1];
self.addFolderControl.text = @"";
[self.tableView reloadData];

0 comments on commit 9a93b2d

Please sign in to comment.