From ead90b8ef2b5f91b7936b43187764f93c38550df Mon Sep 17 00:00:00 2001 From: Jackie Meggesto Date: Sat, 27 Jun 2015 12:41:18 -0400 Subject: [PATCH 01/43] first commit --- TodoList/TodoList/main.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 187be40..c3d3987 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -11,7 +11,7 @@ int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... - NSLog(@"Hello, World!"); + NSLog(@"whimmy wam wam wozzle"); } return 0; } From 7f145a56601cb1d3a090442c4179a7075b27b4b2 Mon Sep 17 00:00:00 2001 From: elberdev Date: Sat, 27 Jun 2015 12:48:55 -0400 Subject: [PATCH 02/43] re-wrote item class --- TodoList/TodoList/main.m | 47 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index c3d3987..6b048ac 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -8,10 +8,53 @@ #import +@interface listItem : NSObject +@end + +@implementation listItem { + NSString *_itemDescription; + int _priority; + BOOL _doneStatus; +} + +-(id)init { + if(self = [super init]) { + _priority = 1; + _doneStatus = NO; + } + return self; +} + +-(void)setItemDescription:(NSString *)itemDescription { + _itemDescription = itemDescription; +} + +-(NSString *)itemDescription { + return _itemDescription; +} + +-(void)setPriority:(int)priority { + _priority = priority; +} + +-(int)priority { + return _priority; +} + +-(void)setDoneStatus:(BOOL)doneStatus { + _doneStatus = doneStatus; +} + +-(BOOL)doneStatus { + return _doneStatus; +} + +@end + int main(int argc, const char * argv[]) { @autoreleasepool { - // insert code here... - NSLog(@"whimmy wam wam wozzle"); + + } return 0; } From ce81807e49abdd67fa025a8226a3355ad484c272 Mon Sep 17 00:00:00 2001 From: elberdev Date: Sat, 27 Jun 2015 12:51:48 -0400 Subject: [PATCH 03/43] added methods to interface --- TodoList/TodoList/main.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 6b048ac..d4c7385 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -9,6 +9,14 @@ #import @interface listItem : NSObject + +-(void)setItemDescription:(NSString *)itemDescription; +-(NSString *)itemDescription; +-(void)setPriority:(int)priority; +-(int)priority; +-(void)setDoneStatus:(BOOL)doneStatus; +-(BOOL)doneStatus; + @end @implementation listItem { From 3dc6ec7c8ac932f378304e13139ab2e955baa15f Mon Sep 17 00:00:00 2001 From: Jackie Meggesto Date: Sat, 27 Jun 2015 12:53:35 -0400 Subject: [PATCH 04/43] testing user input --- TodoList/TodoList/main.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index c3d3987..d590c00 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -11,7 +11,10 @@ int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... - NSLog(@"whimmy wam wam wozzle"); + char string[256]; + scanf("%255s", &string); + NSString *firstName = [NSString stringWithCString:string encoding:1]; + NSLog(@"%@", firstName); } return 0; } From 5c8b0ae8ef17a9d024d611cf10aaa8fe247ec68d Mon Sep 17 00:00:00 2001 From: elberdev Date: Sat, 27 Jun 2015 14:54:56 -0400 Subject: [PATCH 05/43] implemented List class --- TodoList/TodoList/main.m | 100 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 94 insertions(+), 6 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 8284494..0451ab4 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -8,7 +8,9 @@ #import -@interface listItem : NSObject + +//*************************** listItem class *********************************// +@interface ListItem : NSObject -(void)setItemDescription:(NSString *)itemDescription; -(NSString *)itemDescription; @@ -19,7 +21,7 @@ -(BOOL)doneStatus; @end -@implementation listItem { +@implementation ListItem { NSString *_itemDescription; int _priority; BOOL _doneStatus; @@ -58,15 +60,101 @@ -(BOOL)doneStatus { } @end +//**************************** end listItem class ****************************// + + +//******************************** List class ********************************// +@interface List : NSObject + +-(void)addListItem:(ListItem *)listItem; +-(NSMutableArray *)listArray; +-(void)removeListItem:(int)index; +-(void)editListItem:(int)index withString:(NSString *)string; + +@end + +@implementation List { + NSMutableArray *_listArray; +} + +-(void)addListItem:(ListItem *)listItem { + if (_listArray == nil) { + _listArray = [[NSMutableArray alloc] init]; + } + [_listArray addObject:listItem]; +} + +-(void)removeListItem:(int)index { + if (_listArray == nil) { + _listArray = [[NSMutableArray alloc] init]; + } + + if (index < [_listArray count]) { + [_listArray removeObjectAtIndex:index]; + } else { + NSLog(@"The list item you input does not exist"); + } +} + +-(void)editListItem:(int)index withString:(NSString *)string { + if (_listArray == nil) { + _listArray = [[NSMutableArray alloc] init]; + } + + if (index < [_listArray count]) { + [[_listArray objectAtIndex:index] setItemDescription:string]; + + } else { + NSLog(@"The list item you input does not exist"); + } +} + +-(NSMutableArray *)listArray { + return _listArray; +} + +@end +//****************************** end List class ******************************// + int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... - char string[256]; - scanf("%255s", &string); - NSString *firstName = [NSString stringWithCString:string encoding:1]; - NSLog(@"%@", firstName); +// char string[256]; +// scanf("%255s", &string); +// NSString *firstName = [NSString stringWithCString:string encoding:1]; +// NSLog(@"%@", firstName); + + ListItem *item1 = [[ListItem alloc] init]; + [item1 setItemDescription:@"do laundry"]; + ListItem *item2 = [[ListItem alloc] init]; + [item2 setItemDescription:@"kill bad guys"]; + ListItem *item3 = [[ListItem alloc] init]; + [item3 setItemDescription:@"call Robin"]; + + List *list = [[List alloc] init]; + [list addListItem:item1]; + [list addListItem:item2]; + [list addListItem:item3]; + + NSMutableArray *arrayList = [list listArray]; + + for(int i = 0; i < [arrayList count]; i++) { + NSLog(@"%@", [arrayList[i] itemDescription]); + } + + [list removeListItem:2]; + + for(int i = 0; i < [arrayList count]; i++) { + NSLog(@"%@", [arrayList[i] itemDescription]); + } + + [list editListItem:0 withString:@"elect Bernie Sanders president"]; + + for(int i = 0; i < [arrayList count]; i++) { + NSLog(@"%@", [arrayList[i] itemDescription]); + } } return 0; From 7916ad46f223164629ef5d244ad46a32b5f43dc3 Mon Sep 17 00:00:00 2001 From: Jackie Meggesto Date: Sat, 27 Jun 2015 14:56:00 -0400 Subject: [PATCH 06/43] minor changes --- TodoList/TodoList/main.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 8284494..9076211 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -34,7 +34,10 @@ -(id)init { } -(void)setItemDescription:(NSString *)itemDescription { +// char string[256]; +// itemDescription = [NSString stringWithCString:string encoding:1]; _itemDescription = itemDescription; + } -(NSString *)itemDescription { @@ -63,11 +66,8 @@ int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... - char string[256]; - scanf("%255s", &string); - NSString *firstName = [NSString stringWithCString:string encoding:1]; - NSLog(@"%@", firstName); - + listItem *myItem = [[listItem alloc]init]; + } return 0; } From 59faecac44db9470f7d59fbad1f683e906191250 Mon Sep 17 00:00:00 2001 From: Jackie Meggesto Date: Sat, 27 Jun 2015 15:43:09 -0400 Subject: [PATCH 07/43] added ability to name lists, created base framework for list manager --- TodoList/TodoList/main.m | 48 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 0451ab4..00332f3 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -10,6 +10,42 @@ //*************************** listItem class *********************************// +@interface ListManager : NSObject +-(void)run; +@end + +@implementation ListManager + +-(void)run { + BOOL programIsRunning = YES; + while (programIsRunning) { + printf("Welcome to the Elbo-Yucatan To-Do List Manager. Please select an option. \n 0) Exit program \n 1) Show my active to-do lists \n 2) Create a new to-do list \n 3) Edit a to-do list"); + int input; + scanf("%d%*c", &input); + switch (input) { + case 0: + programIsRunning = NO; + break; + case 1: + // show your lists + break; + case 2: + //create to-do list + break; + case 3: + //edit to-do list + break; + default: + printf("You have selected an invalid option."); + break; + + } + } +} + +@end + + @interface ListItem : NSObject -(void)setItemDescription:(NSString *)itemDescription; @@ -70,13 +106,21 @@ -(void)addListItem:(ListItem *)listItem; -(NSMutableArray *)listArray; -(void)removeListItem:(int)index; -(void)editListItem:(int)index withString:(NSString *)string; +-(void)setName:(NSString*)name; +-(NSString*)name; @end @implementation List { + NSString *_name; NSMutableArray *_listArray; } - +-(void)setName:(NSString*)name { + _name = name; +} +-(NSString*)name { + return _name; +} -(void)addListItem:(ListItem *)listItem { if (_listArray == nil) { _listArray = [[NSMutableArray alloc] init]; @@ -155,6 +199,8 @@ int main(int argc, const char * argv[]) { for(int i = 0; i < [arrayList count]; i++) { NSLog(@"%@", [arrayList[i] itemDescription]); } + ListManager *myListManager = [[ListManager alloc]init]; + [myListManager run]; } return 0; From 1cc80cb5748de3147c7e186a387196d343f146bf Mon Sep 17 00:00:00 2001 From: elberdev Date: Sat, 27 Jun 2015 16:45:10 -0400 Subject: [PATCH 08/43] implemented addList method and showLists method --- TodoList/TodoList/main.m | 156 ++++++++++++++++++++++++++++++--------- 1 file changed, 120 insertions(+), 36 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 00332f3..488c0e3 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -10,42 +10,6 @@ //*************************** listItem class *********************************// -@interface ListManager : NSObject --(void)run; -@end - -@implementation ListManager - --(void)run { - BOOL programIsRunning = YES; - while (programIsRunning) { - printf("Welcome to the Elbo-Yucatan To-Do List Manager. Please select an option. \n 0) Exit program \n 1) Show my active to-do lists \n 2) Create a new to-do list \n 3) Edit a to-do list"); - int input; - scanf("%d%*c", &input); - switch (input) { - case 0: - programIsRunning = NO; - break; - case 1: - // show your lists - break; - case 2: - //create to-do list - break; - case 3: - //edit to-do list - break; - default: - printf("You have selected an invalid option."); - break; - - } - } -} - -@end - - @interface ListItem : NSObject -(void)setItemDescription:(NSString *)itemDescription; @@ -115,12 +79,15 @@ @implementation List { NSString *_name; NSMutableArray *_listArray; } + -(void)setName:(NSString*)name { _name = name; } + -(NSString*)name { return _name; } + -(void)addListItem:(ListItem *)listItem { if (_listArray == nil) { _listArray = [[NSMutableArray alloc] init]; @@ -153,6 +120,13 @@ -(void)editListItem:(int)index withString:(NSString *)string { } } +-(NSUInteger)showNumberOfItems { + if (_listArray == nil) { + _listArray = [[NSMutableArray alloc] init]; + } + return [_listArray count]; +} + -(NSMutableArray *)listArray { return _listArray; } @@ -161,6 +135,100 @@ -(NSMutableArray *)listArray { //****************************** end List class ******************************// +//*************************** ListManager class *******************************// +@interface ListManager : NSObject + +-(void)run; +-(void)showLists; +-(void)addList:(List *)list; +-(void)removeList:(NSString *)name; + +@end + +@implementation ListManager { + NSMutableArray *_listDatabase; +} + +-(void)addList:(List *)list { + if (_listDatabase == nil) { + _listDatabase = [[NSMutableArray alloc] init]; + } + + [_listDatabase addObject:list]; +} + +-(void)removeList:(NSString *)name { + if (_listDatabase == nil) { + _listDatabase = [[NSMutableArray alloc] init]; + } + + BOOL found = NO; + + for (int i = 0; i < [_listDatabase count]; i++) { + if ([_listDatabase[i] name] == name) { + [_listDatabase removeObjectAtIndex:i]; + found = YES; + } + } + + if (found == NO) { + printf("\nThere are no lists matching that name"); + } + +} + +-(void)showLists { + for (int i = 0; i < [_listDatabase count]; i++) { + printf("%s: %lu items\n", [[_listDatabase[i] name] UTF8String], + (unsigned long)[_listDatabase[i] showNumberOfItems]); + } +} + +-(void)createList { + List *list = [[List alloc] init]; + + printf("\n Please enter a name for your list: "); + char nameC[256]; + scanf("%255s[^\n]%*c", nameC); + fpurge(stdin); + NSString *name = [NSString stringWithCString:nameC + encoding:NSUTF8StringEncoding]; + + [list setName:name]; + [self addList: list]; + +} + +-(void)run { + BOOL programIsRunning = YES; + while (programIsRunning) { + printf("Welcome to the Elbo-Yucatan To-Do List Manager. Please select an option. \n 0) Exit program \n 1) Show my active to-do lists \n 2) Create a new to-do list \n 3) Edit a to-do list"); + int input; + scanf("\n%d%*c", &input); + switch (input) { + case 0: + programIsRunning = NO; + break; + case 1: + [self showLists]; + break; + case 2: + [self createList]; + break; + case 3: + //edit to-do list + break; + default: + printf("You have selected an invalid option."); + break; + } + } +} + +@end +//************************** end ListManager class ***************************// + + int main(int argc, const char * argv[]) { @autoreleasepool { @@ -176,11 +244,24 @@ int main(int argc, const char * argv[]) { [item2 setItemDescription:@"kill bad guys"]; ListItem *item3 = [[ListItem alloc] init]; [item3 setItemDescription:@"call Robin"]; + ListItem *item4 = [[ListItem alloc] init]; + [item1 setItemDescription:@"polish bat-mobile"]; + ListItem *item5 = [[ListItem alloc] init]; + [item2 setItemDescription:@"grab a beer with Joker"]; + ListItem *item6 = [[ListItem alloc] init]; + [item3 setItemDescription:@"look mysterious"]; List *list = [[List alloc] init]; [list addListItem:item1]; [list addListItem:item2]; [list addListItem:item3]; + [list setName:@"urgent"]; + + List *list2 = [[List alloc] init]; + [list2 addListItem:item4]; + [list2 addListItem:item5]; + [list2 addListItem:item6]; + [list2 setName:@"monty python"]; NSMutableArray *arrayList = [list listArray]; @@ -200,6 +281,9 @@ int main(int argc, const char * argv[]) { NSLog(@"%@", [arrayList[i] itemDescription]); } ListManager *myListManager = [[ListManager alloc]init]; + [myListManager addList:list]; + [myListManager addList:list2]; + //[myListManager showLists]; [myListManager run]; } From a23e9153e581ae43cdf57cde183ac4dc36c1e5ce Mon Sep 17 00:00:00 2001 From: Jackie Meggesto Date: Sat, 27 Jun 2015 17:31:49 -0400 Subject: [PATCH 09/43] added some functionality for List Manager, editing list names --- TodoList/TodoList/main.m | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 488c0e3..fe3b23c 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -138,9 +138,11 @@ -(NSMutableArray *)listArray { //*************************** ListManager class *******************************// @interface ListManager : NSObject +-(void)editList; -(void)run; -(void)showLists; -(void)addList:(List *)list; +-(List*)getListByName:(NSString*)listname; -(void)removeList:(NSString *)name; @end @@ -149,6 +151,36 @@ @implementation ListManager { NSMutableArray *_listDatabase; } +-(void)editList { + printf("Name of list to edit:"); + char nameC[256]; + scanf("%255s[^\n]%*c", nameC); + fpurge(stdin); + NSString *name = [NSString stringWithCString:nameC + encoding:NSUTF8StringEncoding]; + int input; + List *tempList = [[List alloc]init]; + + printf("What would you like to do? \n 1) Edit list name \n 2) Delete list \n 3) Add an item to list \n 4) Delete an item from list"); + scanf("%d", &input); + switch (input) { + + case 1: + tempList = [self getListByName:name]; + if (tempList != nil) { + [tempList setName:@"hello"]; + } + break; + + default: + printf("placeholder"); + + + + } + +} + -(void)addList:(List *)list { if (_listDatabase == nil) { _listDatabase = [[NSMutableArray alloc] init]; @@ -176,6 +208,15 @@ -(void)removeList:(NSString *)name { } } +-(List*)getListByName:(NSString*)listname { + for (int i = 0; i < [_listDatabase count]; i++) { + if ([listname isEqualToString:[_listDatabase[i] name]]) { + return _listDatabase[i]; + } + } + printf("There are no lists by that name."); + return nil; +} -(void)showLists { for (int i = 0; i < [_listDatabase count]; i++) { From b9410bbd3e3cba245f14a0e5e1ed4228f92c5859 Mon Sep 17 00:00:00 2001 From: elberdev Date: Sun, 28 Jun 2015 11:10:45 -0400 Subject: [PATCH 10/43] stuff --- TodoList/TodoList/main.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 488c0e3..9a62c23 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -192,7 +192,7 @@ -(void)createList { scanf("%255s[^\n]%*c", nameC); fpurge(stdin); NSString *name = [NSString stringWithCString:nameC - encoding:NSUTF8StringEncoding]; + encoding:NSUTF8StringEncoding]; [list setName:name]; [self addList: list]; From cea487a30a6183225976ba72ee265ebfa19b7df4 Mon Sep 17 00:00:00 2001 From: Jackie Meggesto Date: Sun, 28 Jun 2015 11:32:03 -0400 Subject: [PATCH 11/43] added natural language parsing --- TodoList/TodoList/main.m | 98 ++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 25 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index fe3b23c..2c6a666 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -239,33 +239,81 @@ -(void)createList { [self addList: list]; } - --(void)run { - BOOL programIsRunning = YES; - while (programIsRunning) { - printf("Welcome to the Elbo-Yucatan To-Do List Manager. Please select an option. \n 0) Exit program \n 1) Show my active to-do lists \n 2) Create a new to-do list \n 3) Edit a to-do list"); - int input; - scanf("\n%d%*c", &input); - switch (input) { - case 0: - programIsRunning = NO; - break; - case 1: - [self showLists]; - break; - case 2: - [self createList]; - break; - case 3: - //edit to-do list - break; - default: - printf("You have selected an invalid option."); - break; - } +-(void)newItem:(NSString *)listName { + printf("\n\n CREATING NEW ITEM IN LIST %s\n", [listName UTF8String]); + printf("\n Input to do item description: \n"); + NSString *description = [self parse]; + printf("\n Input item priority from 1 (most pressing) to 4 (least pressing)\n"); + NSString *priority = [self parse]; + printf("\n to do item created successfully\n\n"); + [self commandTree:[self parse]]; +} +-(NSString *)snip:(NSString *)toDelete fromCommand:(NSString *)command { + command = [command stringByReplacingOccurrencesOfString:toDelete + withString:@""]; + + return command; +} +-(void)newList:(NSString *)listName { + printf("\n\n A NEW LIST HAS BEEN CREATED:\n"); + printf("\n %s\n\n", [listName UTF8String]); + [self commandTree:[self parse]]; +} +-(void)commandTree:(NSString *)command { + if ([command isEqualToString:@"help"]) { + [self help]; + } else if ([command containsString:@"new list "]) { + [self newList:[self snip:@"new list " fromCommand:command]]; + } else if ([command containsString:@"new item in "]) { + [self newItem:[self snip:@"new item in " fromCommand:command]]; + } else if ([command isEqualToString:@"exit"]) { + exit(0); + } else { + printf("\n NOT A RECOGNIZED COMMAND\n"); + printf(" Type 'help' for available commands"); + [self commandTree:[self parse]]; } } - +-(NSString *)parse { + + printf("\n "); + + /* Allocate memory and check if okay. */ + char *commandC = malloc (256); + if (commandC == NULL) { + printf ("No memory\n"); + } + + // fgets is a function analogous to scanf but with better protection against + // buffer overflow + fgets (commandC, 256, stdin); + + /* Remove trailing newline, if there. */ + if ((strlen(commandC) > 0) && (commandC[strlen (commandC) - 1] == '\n')) { + commandC[strlen(commandC) - 1] = '\0'; + } + + // change C string to NSString + NSString *command = [NSString stringWithCString:commandC + encoding:NSUTF8StringEncoding]; + + return command; +} +-(void)help { + printf("\n\n AVAILABLE COMMANDS:\n"); + printf("\n new list \n"); + printf("\n new item in \n"); + printf("\n delete list \n"); + printf("\n edit list \n"); + printf("\n display list \n\n"); + printf("\n exit \n\n"); + [self commandTree:[self parse]]; +} +-(void)run { + printf("\n Welcome to the Elbo-Yucatan To-Do List Management System. \n"); + printf("\n Type a command (or type 'help' for instructions)\n\n"); + [self commandTree:[self parse]]; +} @end //************************** end ListManager class ***************************// From df195e2506d898a95a1e5d92e7e2f23233eefe6b Mon Sep 17 00:00:00 2001 From: Jackie Meggesto Date: Sun, 28 Jun 2015 11:41:54 -0400 Subject: [PATCH 12/43] trying to give Elber the code --- TodoList/TodoList/main.m | 1 + 1 file changed, 1 insertion(+) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 2c6a666..cc683f2 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -374,6 +374,7 @@ int main(int argc, const char * argv[]) { [myListManager addList:list2]; //[myListManager showLists]; [myListManager run]; + /// yo yo yo } return 0; From b95bd3e2a115262f50f26ac6a4c7275d53bca2eb Mon Sep 17 00:00:00 2001 From: elberdev Date: Sun, 28 Jun 2015 12:48:08 -0400 Subject: [PATCH 13/43] implemented some commands fo realz --- TodoList/TodoList/main.m | 146 ++++++++++++++++++++++++--------------- 1 file changed, 91 insertions(+), 55 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 5e2d894..b2f411b 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -140,7 +140,6 @@ @interface ListManager : NSObject -(void)editList; -(void)run; --(void)showLists; -(void)addList:(List *)list; -(List*)getListByName:(NSString*)listname; -(void)removeList:(NSString *)name; @@ -151,36 +150,6 @@ @implementation ListManager { NSMutableArray *_listDatabase; } --(void)editList { - printf("Name of list to edit:"); - char nameC[256]; - scanf("%255s[^\n]%*c", nameC); - fpurge(stdin); - NSString *name = [NSString stringWithCString:nameC - encoding:NSUTF8StringEncoding]; - int input; - List *tempList = [[List alloc]init]; - - printf("What would you like to do? \n 1) Edit list name \n 2) Delete list \n 3) Add an item to list \n 4) Delete an item from list"); - scanf("%d", &input); - switch (input) { - - case 1: - tempList = [self getListByName:name]; - if (tempList != nil) { - [tempList setName:@"hello"]; - } - break; - - default: - printf("placeholder"); - - - - } - -} - -(void)addList:(List *)list { if (_listDatabase == nil) { _listDatabase = [[NSMutableArray alloc] init]; @@ -208,6 +177,7 @@ -(void)removeList:(NSString *)name { } } + -(List*)getListByName:(NSString*)listname { for (int i = 0; i < [_listDatabase count]; i++) { if ([listname isEqualToString:[_listDatabase[i] name]]) { @@ -218,13 +188,6 @@ -(List*)getListByName:(NSString*)listname { return nil; } --(void)showLists { - for (int i = 0; i < [_listDatabase count]; i++) { - printf("%s: %lu items\n", [[_listDatabase[i] name] UTF8String], - (unsigned long)[_listDatabase[i] showNumberOfItems]); - } -} - -(void)createList { List *list = [[List alloc] init]; @@ -239,6 +202,14 @@ -(void)createList { [self addList: list]; } +/************************************************************************************/ + +-(void)newList:(NSString *)listName { + printf("\n\n A NEW LIST HAS BEEN CREATED:\n"); + printf("\n %s\n\n", [listName UTF8String]); + [self commandTree:[self parse]]; +} + -(void)newItem:(NSString *)listName { printf("\n\n CREATING NEW ITEM IN LIST %s\n", [listName UTF8String]); printf("\n Input to do item description: \n"); @@ -248,24 +219,84 @@ -(void)newItem:(NSString *)listName { printf("\n to do item created successfully\n\n"); [self commandTree:[self parse]]; } + +-(void)deleteList:(NSString *)listName { + + NSString *confirm; + + while (true) { + printf("\n\n ARE YOU SURE YOU WANT TO DELETE LIST %s?\n", + [listName UTF8String]); + printf("\n RE-ENTER THE LIST NAME TO CONFIRM or type 'cancel' to abort\n"); + confirm = [self parse]; + if ([confirm isEqualToString:listName]) { + printf("\n LIST %s HAS BEEN DELETED.\n", [listName UTF8String]); + break; + } else if ([confirm isEqualToString:@"cancel"]) { + printf("\n ABORTING DELETION.\n"); + break; + } else { + printf("\n list name mismatch.\n"); + } + } + + [self commandTree:[self parse]]; + +} + +-(void)renameList:(NSString *)listName { + printf("\n\n PLEASE ENTER NEW NAME FOR LIST %s\n", [listName UTF8String]); + NSString *newName = [self parse]; + printf("\n List %s has been renamed %s\n", [listName UTF8String], + [newName UTF8String]); + [self commandTree:[self parse]]; +} + +-(void)displayList:(NSString *)listName { + + if ([listName isEqualToString:@"all"]) { + printf("\n\n DISPLAYING ALL TO-DO LISTS\n"); + for (int i = 0; i < [_listDatabase count]; i++) { + printf("\n %s: %lu items\n", [[_listDatabase[i] name] UTF8String], + (unsigned long)[_listDatabase[i] showNumberOfItems]); + } + } else { + printf("\n\n DISPLAYING LIST %s\n", [listName UTF8String]); + } + + [self commandTree:[self parse]]; +} + +-(void)displayItems:(NSString *)listName { + List *list = [self getListByName:listName]; + NSArray *array = [list listArray]; + for (int i = 0; i < [array count]; i++) { + printf("\n %d) %s\n", i, [[array[i] itemDescription] UTF8String]); + } +} + -(NSString *)snip:(NSString *)toDelete fromCommand:(NSString *)command { command = [command stringByReplacingOccurrencesOfString:toDelete withString:@""]; return command; } --(void)newList:(NSString *)listName { - printf("\n\n A NEW LIST HAS BEEN CREATED:\n"); - printf("\n %s\n\n", [listName UTF8String]); - [self commandTree:[self parse]]; -} + -(void)commandTree:(NSString *)command { if ([command isEqualToString:@"help"]) { [self help]; } else if ([command containsString:@"new list "]) { [self newList:[self snip:@"new list " fromCommand:command]]; + } else if ([command containsString:@"delete list "]) { + [self deleteList:[self snip:@"delete list " fromCommand:command]]; + } else if ([command containsString:@"rename list "]) { + [self renameList:[self snip:@"rename list " fromCommand:command]]; + } else if ([command containsString:@"display list "]) { + [self displayList:[self snip:@"display list " fromCommand:command]]; } else if ([command containsString:@"new item in "]) { [self newItem:[self snip:@"new item in " fromCommand:command]]; + } else if ([command containsString:@"display items in "]) { + [self displayItems:[self snip:@"display items in " fromCommand:command]]; } else if ([command isEqualToString:@"exit"]) { exit(0); } else { @@ -274,6 +305,7 @@ -(void)commandTree:(NSString *)command { [self commandTree:[self parse]]; } } + -(NSString *)parse { printf("\n "); @@ -299,16 +331,19 @@ -(NSString *)parse { return command; } + -(void)help { printf("\n\n AVAILABLE COMMANDS:\n"); printf("\n new list \n"); - printf("\n new item in \n"); printf("\n delete list \n"); - printf("\n edit list \n"); - printf("\n display list \n\n"); + printf("\n rename list \n"); + printf("\n display list \n"); + printf("\n new item in \n"); + printf("\n display items in \n"); printf("\n exit \n\n"); [self commandTree:[self parse]]; } + -(void)run { printf("\n Welcome to the Elbo-Yucatan To-Do List Management System. \n"); printf("\n Type a command (or type 'help' for instructions)\n\n"); @@ -354,21 +389,22 @@ int main(int argc, const char * argv[]) { NSMutableArray *arrayList = [list listArray]; - for(int i = 0; i < [arrayList count]; i++) { - NSLog(@"%@", [arrayList[i] itemDescription]); - } +// for(int i = 0; i < [arrayList count]; i++) { +// NSLog(@"%@", [arrayList[i] itemDescription]); +// } [list removeListItem:2]; - for(int i = 0; i < [arrayList count]; i++) { - NSLog(@"%@", [arrayList[i] itemDescription]); - } +// for(int i = 0; i < [arrayList count]; i++) { +// NSLog(@"%@", [arrayList[i] itemDescription]); +// } [list editListItem:0 withString:@"elect Bernie Sanders president"]; - for(int i = 0; i < [arrayList count]; i++) { - NSLog(@"%@", [arrayList[i] itemDescription]); - } +// for(int i = 0; i < [arrayList count]; i++) { +// NSLog(@"%@", [arrayList[i] itemDescription]); +// } + ListManager *myListManager = [[ListManager alloc]init]; [myListManager addList:list]; [myListManager addList:list2]; From 0217d8e39547d8c429049125bd4f1c2276e1f0bf Mon Sep 17 00:00:00 2001 From: Jackie Meggesto Date: Sun, 28 Jun 2015 15:07:41 -0400 Subject: [PATCH 14/43] added additional command functionality, began work on deleting items from lists --- TodoList/TodoList/main.m | 56 +++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index b2f411b..1de1a81 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -138,7 +138,7 @@ -(NSMutableArray *)listArray { //*************************** ListManager class *******************************// @interface ListManager : NSObject --(void)editList; + -(void)run; -(void)addList:(List *)list; -(List*)getListByName:(NSString*)listname; @@ -166,7 +166,7 @@ -(void)removeList:(NSString *)name { BOOL found = NO; for (int i = 0; i < [_listDatabase count]; i++) { - if ([_listDatabase[i] name] == name) { + if ([[_listDatabase[i] name] isEqualToString:name]) { [_listDatabase removeObjectAtIndex:i]; found = YES; } @@ -184,7 +184,8 @@ -(List*)getListByName:(NSString*)listname { return _listDatabase[i]; } } - printf("There are no lists by that name."); + printf("There are no lists by that name.\n"); + [self commandTree:[self parse]]; return nil; } @@ -204,23 +205,41 @@ -(void)createList { } /************************************************************************************/ --(void)newList:(NSString *)listName { +-(void)newList:(NSString *)newListName { + List *list = [[List alloc] init]; + + [list setName:newListName]; + [self addList: list]; printf("\n\n A NEW LIST HAS BEEN CREATED:\n"); - printf("\n %s\n\n", [listName UTF8String]); + printf("\n %s\n\n", [newListName UTF8String]); + [self commandTree:[self parse]]; } -(void)newItem:(NSString *)listName { + [self getListByName:listName]; + ListItem *newItem = [[ListItem alloc]init]; + printf("\n\n CREATING NEW ITEM IN LIST %s\n", [listName UTF8String]); printf("\n Input to do item description: \n"); NSString *description = [self parse]; + [newItem setItemDescription:description]; printf("\n Input item priority from 1 (most pressing) to 4 (least pressing)\n"); - NSString *priority = [self parse]; + // NSString *priority = [self parse]; + int priority; + scanf("%d%*c", &priority); + fpurge(stdin); + [newItem setPriority:priority]; + [[[self getListByName:listName] listArray] addObject:newItem]; + + printf("\n to do item created successfully\n\n"); [self commandTree:[self parse]]; } -(void)deleteList:(NSString *)listName { + [self getListByName:listName]; + NSString *confirm; @@ -230,6 +249,7 @@ -(void)deleteList:(NSString *)listName { printf("\n RE-ENTER THE LIST NAME TO CONFIRM or type 'cancel' to abort\n"); confirm = [self parse]; if ([confirm isEqualToString:listName]) { + [self removeList:listName]; printf("\n LIST %s HAS BEEN DELETED.\n", [listName UTF8String]); break; } else if ([confirm isEqualToString:@"cancel"]) { @@ -245,8 +265,11 @@ -(void)deleteList:(NSString *)listName { } -(void)renameList:(NSString *)listName { + + [self getListByName:listName]; printf("\n\n PLEASE ENTER NEW NAME FOR LIST %s\n", [listName UTF8String]); NSString *newName = [self parse]; + [[self getListByName:listName] setName:newName]; printf("\n List %s has been renamed %s\n", [listName UTF8String], [newName UTF8String]); [self commandTree:[self parse]]; @@ -273,8 +296,19 @@ -(void)displayItems:(NSString *)listName { for (int i = 0; i < [array count]; i++) { printf("\n %d) %s\n", i, [[array[i] itemDescription] UTF8String]); } + [self commandTree:[self parse]]; +} +-(void)deleteItems:(NSString *)listName { + [self displayList:listName]; + while (true) { + printf("Please select an item to be deleted:\n"); + int input; + scanf("%d%*c", &input); + fpurge(stdin); + + + } } - -(NSString *)snip:(NSString *)toDelete fromCommand:(NSString *)command { command = [command stringByReplacingOccurrencesOfString:toDelete withString:@""]; @@ -297,6 +331,8 @@ -(void)commandTree:(NSString *)command { [self newItem:[self snip:@"new item in " fromCommand:command]]; } else if ([command containsString:@"display items in "]) { [self displayItems:[self snip:@"display items in " fromCommand:command]]; + } else if ([command containsString:@"delete items in "]) { + [self deleteItems:[self snip:@"delete items in " fromCommand:command]]; } else if ([command isEqualToString:@"exit"]) { exit(0); } else { @@ -369,11 +405,11 @@ int main(int argc, const char * argv[]) { ListItem *item3 = [[ListItem alloc] init]; [item3 setItemDescription:@"call Robin"]; ListItem *item4 = [[ListItem alloc] init]; - [item1 setItemDescription:@"polish bat-mobile"]; + [item4 setItemDescription:@"polish bat-mobile"]; ListItem *item5 = [[ListItem alloc] init]; - [item2 setItemDescription:@"grab a beer with Joker"]; + [item5 setItemDescription:@"grab a beer with Joker"]; ListItem *item6 = [[ListItem alloc] init]; - [item3 setItemDescription:@"look mysterious"]; + [item6 setItemDescription:@"look mysterious"]; List *list = [[List alloc] init]; [list addListItem:item1]; From 8e669832935b422fd2e8fb1b0051c765c2add281 Mon Sep 17 00:00:00 2001 From: Jackie Meggesto Date: Sun, 28 Jun 2015 15:31:31 -0400 Subject: [PATCH 15/43] almost all lisst functionality implemented --- TodoList/TodoList/main.m | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 1de1a81..459fea8 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -103,7 +103,7 @@ -(void)removeListItem:(int)index { if (index < [_listArray count]) { [_listArray removeObjectAtIndex:index]; } else { - NSLog(@"The list item you input does not exist"); + printf("The list item you input does not exist\n"); } } @@ -290,24 +290,39 @@ -(void)displayList:(NSString *)listName { [self commandTree:[self parse]]; } --(void)displayItems:(NSString *)listName { +-(void)displayItems:(NSString *)listName withPrompt:(BOOL)prompt{ List *list = [self getListByName:listName]; NSArray *array = [list listArray]; for (int i = 0; i < [array count]; i++) { printf("\n %d) %s\n", i, [[array[i] itemDescription] UTF8String]); } - [self commandTree:[self parse]]; + if (prompt == YES) { + [self commandTree:[self parse]]; + } + } -(void)deleteItems:(NSString *)listName { - [self displayList:listName]; + [self getListByName:listName]; while (true) { + [self displayItems:listName withPrompt:NO]; printf("Please select an item to be deleted:\n"); int input; scanf("%d%*c", &input); fpurge(stdin); + [[self getListByName:listName] removeListItem:input]; + printf("Do you want to continue item deletion? y/n"); + NSString *deletion = [self parse]; + if ([deletion isEqualToString:@"y"]) { + continue; + } else if ([deletion isEqualToString:@"n"]) { + break; + } else { + printf("Invalid command."); + } } + [self commandTree:[self parse]]; } -(NSString *)snip:(NSString *)toDelete fromCommand:(NSString *)command { command = [command stringByReplacingOccurrencesOfString:toDelete @@ -330,7 +345,7 @@ -(void)commandTree:(NSString *)command { } else if ([command containsString:@"new item in "]) { [self newItem:[self snip:@"new item in " fromCommand:command]]; } else if ([command containsString:@"display items in "]) { - [self displayItems:[self snip:@"display items in " fromCommand:command]]; + [self displayItems:[self snip:@"display items in " fromCommand:command] withPrompt:YES]; } else if ([command containsString:@"delete items in "]) { [self deleteItems:[self snip:@"delete items in " fromCommand:command]]; } else if ([command isEqualToString:@"exit"]) { From 7463dde97ee11c27b9e862d263ff758a0a587895 Mon Sep 17 00:00:00 2001 From: elberdev Date: Sun, 28 Jun 2015 16:00:42 -0400 Subject: [PATCH 16/43] broke everything --- TodoList/TodoList/main.m | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 459fea8..4984a13 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -225,7 +225,6 @@ -(void)newItem:(NSString *)listName { NSString *description = [self parse]; [newItem setItemDescription:description]; printf("\n Input item priority from 1 (most pressing) to 4 (least pressing)\n"); - // NSString *priority = [self parse]; int priority; scanf("%d%*c", &priority); fpurge(stdin); @@ -290,21 +289,22 @@ -(void)displayList:(NSString *)listName { [self commandTree:[self parse]]; } --(void)displayItems:(NSString *)listName withPrompt:(BOOL)prompt{ +-(void)displayItems:(NSString *)listName {//withPrompt:(BOOL)prompt{ List *list = [self getListByName:listName]; - NSArray *array = [list listArray]; + NSMutableArray *array = [list listArray]; for (int i = 0; i < [array count]; i++) { printf("\n %d) %s\n", i, [[array[i] itemDescription] UTF8String]); } - if (prompt == YES) { + printf("\n"); + //if (prompt == YES) { [self commandTree:[self parse]]; - } + //} } -(void)deleteItems:(NSString *)listName { [self getListByName:listName]; while (true) { - [self displayItems:listName withPrompt:NO]; + [self displayItems:listName];// withPrompt:NO]; printf("Please select an item to be deleted:\n"); int input; scanf("%d%*c", &input); @@ -345,14 +345,14 @@ -(void)commandTree:(NSString *)command { } else if ([command containsString:@"new item in "]) { [self newItem:[self snip:@"new item in " fromCommand:command]]; } else if ([command containsString:@"display items in "]) { - [self displayItems:[self snip:@"display items in " fromCommand:command] withPrompt:YES]; + [self displayItems:[self snip:@"display items in " fromCommand:command]]; //withPrompt:YES]; } else if ([command containsString:@"delete items in "]) { [self deleteItems:[self snip:@"delete items in " fromCommand:command]]; } else if ([command isEqualToString:@"exit"]) { exit(0); } else { printf("\n NOT A RECOGNIZED COMMAND\n"); - printf(" Type 'help' for available commands"); + printf("\n Type 'help' for available commands\n"); [self commandTree:[self parse]]; } } @@ -438,8 +438,6 @@ int main(int argc, const char * argv[]) { [list2 addListItem:item6]; [list2 setName:@"monty python"]; - NSMutableArray *arrayList = [list listArray]; - // for(int i = 0; i < [arrayList count]; i++) { // NSLog(@"%@", [arrayList[i] itemDescription]); // } From 9b4cea31094ce99c6dc6320504f885afc5350f2c Mon Sep 17 00:00:00 2001 From: elberdev Date: Sun, 28 Jun 2015 16:46:00 -0400 Subject: [PATCH 17/43] unbroke by magic --- TodoList/TodoList/main.m | 57 +++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 4984a13..67138aa 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -209,33 +209,13 @@ -(void)newList:(NSString *)newListName { List *list = [[List alloc] init]; [list setName:newListName]; - [self addList: list]; + [self addList:list]; printf("\n\n A NEW LIST HAS BEEN CREATED:\n"); printf("\n %s\n\n", [newListName UTF8String]); [self commandTree:[self parse]]; } --(void)newItem:(NSString *)listName { - [self getListByName:listName]; - ListItem *newItem = [[ListItem alloc]init]; - - printf("\n\n CREATING NEW ITEM IN LIST %s\n", [listName UTF8String]); - printf("\n Input to do item description: \n"); - NSString *description = [self parse]; - [newItem setItemDescription:description]; - printf("\n Input item priority from 1 (most pressing) to 4 (least pressing)\n"); - int priority; - scanf("%d%*c", &priority); - fpurge(stdin); - [newItem setPriority:priority]; - [[[self getListByName:listName] listArray] addObject:newItem]; - - - printf("\n to do item created successfully\n\n"); - [self commandTree:[self parse]]; -} - -(void)deleteList:(NSString *)listName { [self getListByName:listName]; @@ -289,22 +269,42 @@ -(void)displayList:(NSString *)listName { [self commandTree:[self parse]]; } --(void)displayItems:(NSString *)listName {//withPrompt:(BOOL)prompt{ +-(void)newItem:(NSString *)listName { + [self getListByName:listName]; + ListItem *newItem = [[ListItem alloc]init]; + + printf("\n\n CREATING NEW ITEM IN LIST %s\n", [listName UTF8String]); + printf("\n Input to do item description: \n"); + NSString *description = [self parse]; + [newItem setItemDescription:description]; + printf("\n Input item priority from 1 (most pressing) to 4 (least pressing)\n"); + int priority; + scanf(" %d%*c", &priority); + fpurge(stdin); + [newItem setPriority:priority]; + [[[self getListByName:listName] listArray] addObject:newItem]; + + printf("\n to do item created successfully\n\n"); + [self commandTree:[self parse]]; +} + +-(void)displayItems:(NSString *)listName withPrompt:(BOOL)prompt{ List *list = [self getListByName:listName]; NSMutableArray *array = [list listArray]; for (int i = 0; i < [array count]; i++) { printf("\n %d) %s\n", i, [[array[i] itemDescription] UTF8String]); } printf("\n"); - //if (prompt == YES) { + if (prompt == YES) { [self commandTree:[self parse]]; - //} + } } + -(void)deleteItems:(NSString *)listName { [self getListByName:listName]; while (true) { - [self displayItems:listName];// withPrompt:NO]; + [self displayItems:listName withPrompt:NO]; printf("Please select an item to be deleted:\n"); int input; scanf("%d%*c", &input); @@ -324,6 +324,7 @@ -(void)deleteItems:(NSString *)listName { } [self commandTree:[self parse]]; } + -(NSString *)snip:(NSString *)toDelete fromCommand:(NSString *)command { command = [command stringByReplacingOccurrencesOfString:toDelete withString:@""]; @@ -345,7 +346,8 @@ -(void)commandTree:(NSString *)command { } else if ([command containsString:@"new item in "]) { [self newItem:[self snip:@"new item in " fromCommand:command]]; } else if ([command containsString:@"display items in "]) { - [self displayItems:[self snip:@"display items in " fromCommand:command]]; //withPrompt:YES]; + [self displayItems:[self snip:@"display items in " fromCommand:command] + withPrompt:YES]; } else if ([command containsString:@"delete items in "]) { [self deleteItems:[self snip:@"delete items in " fromCommand:command]]; } else if ([command isEqualToString:@"exit"]) { @@ -386,11 +388,12 @@ -(NSString *)parse { -(void)help { printf("\n\n AVAILABLE COMMANDS:\n"); printf("\n new list \n"); - printf("\n delete list \n"); + printf("\n delete list \n"); printf("\n rename list \n"); printf("\n display list \n"); printf("\n new item in \n"); printf("\n display items in \n"); + printf("\n delete items in \n"); printf("\n exit \n\n"); [self commandTree:[self parse]]; } From 970ed6ee6a03179cc865232fd42c3f17ad33a354 Mon Sep 17 00:00:00 2001 From: Jackie Meggesto Date: Sun, 28 Jun 2015 17:04:55 -0400 Subject: [PATCH 18/43] finally fucking fixed the new item bug --- TodoList/TodoList/main.m | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 67138aa..59ecb7a 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -89,31 +89,31 @@ -(NSString*)name { } -(void)addListItem:(ListItem *)listItem { - if (_listArray == nil) { - _listArray = [[NSMutableArray alloc] init]; - } - [_listArray addObject:listItem]; +// if (_listArray == nil) { +// _listArray = [[NSMutableArray alloc] init]; +// } + [self.listArray addObject:listItem]; } -(void)removeListItem:(int)index { - if (_listArray == nil) { - _listArray = [[NSMutableArray alloc] init]; - } +// if (_listArray == nil) { +// _listArray = [[NSMutableArray alloc] init]; +// } - if (index < [_listArray count]) { - [_listArray removeObjectAtIndex:index]; + if (index < [self.listArray count]) { + [self.listArray removeObjectAtIndex:index]; } else { printf("The list item you input does not exist\n"); } } -(void)editListItem:(int)index withString:(NSString *)string { - if (_listArray == nil) { - _listArray = [[NSMutableArray alloc] init]; - } +// if (_listArray == nil) { +// _listArray = [[NSMutableArray alloc] init]; +// } - if (index < [_listArray count]) { - [[_listArray objectAtIndex:index] setItemDescription:string]; + if (index < [self.listArray count]) { + [[self.listArray objectAtIndex:index] setItemDescription:string]; } else { NSLog(@"The list item you input does not exist"); @@ -121,13 +121,16 @@ -(void)editListItem:(int)index withString:(NSString *)string { } -(NSUInteger)showNumberOfItems { - if (_listArray == nil) { - _listArray = [[NSMutableArray alloc] init]; - } - return [_listArray count]; +// if (_listArray == nil) { +// _listArray = [[NSMutableArray alloc] init]; +// } + return [self.listArray count]; } -(NSMutableArray *)listArray { + if (_listArray == nil) { + _listArray = [[NSMutableArray alloc] init]; + } return _listArray; } From ae9bd48adf975ade134dbfa304ef6552c70e8862 Mon Sep 17 00:00:00 2001 From: elberdev Date: Sun, 28 Jun 2015 17:49:08 -0400 Subject: [PATCH 19/43] started adding skeleton code to sort to do items --- TodoList/TodoList/main.m | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 59ecb7a..b7d7274 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -25,6 +25,7 @@ @implementation ListItem { NSString *_itemDescription; int _priority; BOOL _doneStatus; + NSDate *_dueDate; } -(id)init { @@ -89,16 +90,10 @@ -(NSString*)name { } -(void)addListItem:(ListItem *)listItem { -// if (_listArray == nil) { -// _listArray = [[NSMutableArray alloc] init]; -// } [self.listArray addObject:listItem]; } -(void)removeListItem:(int)index { -// if (_listArray == nil) { -// _listArray = [[NSMutableArray alloc] init]; -// } if (index < [self.listArray count]) { [self.listArray removeObjectAtIndex:index]; @@ -108,9 +103,6 @@ -(void)removeListItem:(int)index { } -(void)editListItem:(int)index withString:(NSString *)string { -// if (_listArray == nil) { -// _listArray = [[NSMutableArray alloc] init]; -// } if (index < [self.listArray count]) { [[self.listArray objectAtIndex:index] setItemDescription:string]; @@ -121,9 +113,7 @@ -(void)editListItem:(int)index withString:(NSString *)string { } -(NSUInteger)showNumberOfItems { -// if (_listArray == nil) { -// _listArray = [[NSMutableArray alloc] init]; -// } + return [self.listArray count]; } @@ -328,6 +318,25 @@ -(void)deleteItems:(NSString *)listName { [self commandTree:[self parse]]; } +-(void)displayAllItems:(NSString *)order { + + NSMutableArray *combinedList = [[NSMutableArray alloc] init]; + for (int i = 0; i < [_listDatabase count]; i++) { + for (int j = 0; j < [_listDatabase[i] count]; j++) { + [combinedList addObject:[_listDatabase[i] objectAtIndex:j]]; + } + } + + if([order isEqualTo:@"urgent first"]) { + for (int i = 1; i <= 4; i++) { + for (int j = 0; j < [combinedList count]; j++) { + + } + } + } + +} + -(NSString *)snip:(NSString *)toDelete fromCommand:(NSString *)command { command = [command stringByReplacingOccurrencesOfString:toDelete withString:@""]; @@ -353,6 +362,8 @@ -(void)commandTree:(NSString *)command { withPrompt:YES]; } else if ([command containsString:@"delete items in "]) { [self deleteItems:[self snip:@"delete items in " fromCommand:command]]; + } else if ([command containsString:@"display all items "]) { + [self displayAllItems:[self snip:@"display all items " fromCommand:command]]; } else if ([command isEqualToString:@"exit"]) { exit(0); } else { @@ -397,6 +408,10 @@ -(void)help { printf("\n new item in \n"); printf("\n display items in \n"); printf("\n delete items in \n"); + printf("\n display all items urgent first"); + printf("\n display all items urgent last"); + printf("\n display all items closest date first"); + printf("\n display all items closest date last"); printf("\n exit \n\n"); [self commandTree:[self parse]]; } From f216c8e9704b19347a7e15d7b1c0e04c834d5afd Mon Sep 17 00:00:00 2001 From: elberdev Date: Mon, 29 Jun 2015 06:01:19 -0400 Subject: [PATCH 20/43] changed some display spacing, fixed some lingering weird method behavior --- TodoList/TodoList/main.m | 52 +++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index b7d7274..fd90242 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -86,6 +86,9 @@ -(void)setName:(NSString*)name { } -(NSString*)name { + if (_name == nil) { + _name = [[NSString alloc] init]; + } return _name; } @@ -143,18 +146,25 @@ @implementation ListManager { NSMutableArray *_listDatabase; } --(void)addList:(List *)list { - if (_listDatabase == nil) { +-(id)init { + if (self = [super init]) { _listDatabase = [[NSMutableArray alloc] init]; } + return self; +} + +-(void)addList:(List *)list { +// if (_listDatabase == nil) { +// _listDatabase = [[NSMutableArray alloc] init]; +// } [_listDatabase addObject:list]; } -(void)removeList:(NSString *)name { - if (_listDatabase == nil) { - _listDatabase = [[NSMutableArray alloc] init]; - } +// if (_listDatabase == nil) { +// _listDatabase = [[NSMutableArray alloc] init]; +// } BOOL found = NO; @@ -172,12 +182,16 @@ -(void)removeList:(NSString *)name { } -(List*)getListByName:(NSString*)listname { +// if (_listDatabase == nil) { +// _listDatabase = [[NSMutableArray alloc] init]; +// } + for (int i = 0; i < [_listDatabase count]; i++) { if ([listname isEqualToString:[_listDatabase[i] name]]) { return _listDatabase[i]; } } - printf("There are no lists by that name.\n"); + printf("\n There are no lists by that name.\n\n"); [self commandTree:[self parse]]; return nil; } @@ -196,7 +210,6 @@ -(void)createList { [self addList: list]; } -/************************************************************************************/ -(void)newList:(NSString *)newListName { List *list = [[List alloc] init]; @@ -212,7 +225,6 @@ -(void)newList:(NSString *)newListName { -(void)deleteList:(NSString *)listName { [self getListByName:listName]; - NSString *confirm; while (true) { @@ -231,7 +243,8 @@ -(void)deleteList:(NSString *)listName { printf("\n list name mismatch.\n"); } } - + printf("\n"); + [self commandTree:[self parse]]; } @@ -239,10 +252,10 @@ -(void)deleteList:(NSString *)listName { -(void)renameList:(NSString *)listName { [self getListByName:listName]; - printf("\n\n PLEASE ENTER NEW NAME FOR LIST %s\n", [listName UTF8String]); + printf("\n\n PLEASE ENTER NEW NAME FOR LIST %s\n", [listName UTF8String]); NSString *newName = [self parse]; [[self getListByName:listName] setName:newName]; - printf("\n List %s has been renamed %s\n", [listName UTF8String], + printf("\n List %s has been renamed %s\n\n", [listName UTF8String], [newName UTF8String]); [self commandTree:[self parse]]; } @@ -258,7 +271,8 @@ -(void)displayList:(NSString *)listName { } else { printf("\n\n DISPLAYING LIST %s\n", [listName UTF8String]); } - + printf("\n"); + [self commandTree:[self parse]]; } @@ -270,9 +284,9 @@ -(void)newItem:(NSString *)listName { printf("\n Input to do item description: \n"); NSString *description = [self parse]; [newItem setItemDescription:description]; - printf("\n Input item priority from 1 (most pressing) to 4 (least pressing)\n"); + printf("\n Input item priority from 1 (most pressing) to 4 (least pressing)\n\n "); int priority; - scanf(" %d%*c", &priority); + scanf("%d%*c", &priority); fpurge(stdin); [newItem setPriority:priority]; [[[self getListByName:listName] listArray] addObject:newItem]; @@ -368,7 +382,7 @@ -(void)commandTree:(NSString *)command { exit(0); } else { printf("\n NOT A RECOGNIZED COMMAND\n"); - printf("\n Type 'help' for available commands\n"); + printf("\n Type 'help' for available commands\n\n"); [self commandTree:[self parse]]; } } @@ -408,10 +422,10 @@ -(void)help { printf("\n new item in \n"); printf("\n display items in \n"); printf("\n delete items in \n"); - printf("\n display all items urgent first"); - printf("\n display all items urgent last"); - printf("\n display all items closest date first"); - printf("\n display all items closest date last"); + printf("\n display all items high priority first\n"); + printf("\n display all items low priority first\n"); + printf("\n display all items closest due date first\n"); + printf("\n display all items farthest due date first\n"); printf("\n exit \n\n"); [self commandTree:[self parse]]; } From 0ea5add70acd1889c325c27e3ba9fae3f51089f7 Mon Sep 17 00:00:00 2001 From: elberdev Date: Mon, 29 Jun 2015 06:28:19 -0400 Subject: [PATCH 21/43] fixed minor display inconsistencies and made display list do the same thing that display items in does (since before it was doing nothing). We can always just keep one of the commands later if thats what we want. Right now both commands do the same exact thing. --- TodoList/TodoList/main.m | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index fd90242..defe318 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -111,7 +111,7 @@ -(void)editListItem:(int)index withString:(NSString *)string { [[self.listArray objectAtIndex:index] setItemDescription:string]; } else { - NSLog(@"The list item you input does not exist"); + NSLog(@"\n The list item you input does not exist"); } } @@ -154,17 +154,17 @@ -(id)init { } -(void)addList:(List *)list { -// if (_listDatabase == nil) { -// _listDatabase = [[NSMutableArray alloc] init]; -// } + if (_listDatabase == nil) { + _listDatabase = [[NSMutableArray alloc] init]; + } [_listDatabase addObject:list]; } -(void)removeList:(NSString *)name { -// if (_listDatabase == nil) { -// _listDatabase = [[NSMutableArray alloc] init]; -// } + if (_listDatabase == nil) { + _listDatabase = [[NSMutableArray alloc] init]; + } BOOL found = NO; @@ -182,9 +182,9 @@ -(void)removeList:(NSString *)name { } -(List*)getListByName:(NSString*)listname { -// if (_listDatabase == nil) { -// _listDatabase = [[NSMutableArray alloc] init]; -// } + if (_listDatabase == nil) { + _listDatabase = [[NSMutableArray alloc] init]; + } for (int i = 0; i < [_listDatabase count]; i++) { if ([listname isEqualToString:[_listDatabase[i] name]]) { @@ -270,6 +270,7 @@ -(void)displayList:(NSString *)listName { } } else { printf("\n\n DISPLAYING LIST %s\n", [listName UTF8String]); + [self displayItems:listName withPrompt:NO]; } printf("\n"); @@ -312,12 +313,12 @@ -(void)deleteItems:(NSString *)listName { [self getListByName:listName]; while (true) { [self displayItems:listName withPrompt:NO]; - printf("Please select an item to be deleted:\n"); + printf(" Please select an item to be deleted:\n\n "); int input; scanf("%d%*c", &input); fpurge(stdin); [[self getListByName:listName] removeListItem:input]; - printf("Do you want to continue item deletion? y/n"); + printf("\n Do you want to continue item deletion? y/n\n"); NSString *deletion = [self parse]; if ([deletion isEqualToString:@"y"]) { continue; @@ -372,8 +373,7 @@ -(void)commandTree:(NSString *)command { } else if ([command containsString:@"new item in "]) { [self newItem:[self snip:@"new item in " fromCommand:command]]; } else if ([command containsString:@"display items in "]) { - [self displayItems:[self snip:@"display items in " fromCommand:command] - withPrompt:YES]; + [self displayList:[self snip:@"display items in " fromCommand:command]]; } else if ([command containsString:@"delete items in "]) { [self deleteItems:[self snip:@"delete items in " fromCommand:command]]; } else if ([command containsString:@"display all items "]) { From c8a9d97f5618947a12fbcecdd2ce435dc2754936 Mon Sep 17 00:00:00 2001 From: elberdev Date: Mon, 29 Jun 2015 06:36:13 -0400 Subject: [PATCH 22/43] minor visual fixes --- TodoList/TodoList/main.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index defe318..fa8fb01 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -312,13 +312,15 @@ -(void)displayItems:(NSString *)listName withPrompt:(BOOL)prompt{ -(void)deleteItems:(NSString *)listName { [self getListByName:listName]; while (true) { + printf("\n\n DELETING ITEMS IN LIST %s\n", [listName UTF8String]); [self displayItems:listName withPrompt:NO]; printf(" Please select an item to be deleted:\n\n "); int input; scanf("%d%*c", &input); fpurge(stdin); [[self getListByName:listName] removeListItem:input]; - printf("\n Do you want to continue item deletion? y/n\n"); + printf("\n Item has been deleted.\n"); + printf("\n Do you want to delete more items? y/n\n"); NSString *deletion = [self parse]; if ([deletion isEqualToString:@"y"]) { continue; From 13d3c23ab3ed9413c0c7429bef2fe8d7221fb324 Mon Sep 17 00:00:00 2001 From: elberdev Date: Mon, 29 Jun 2015 06:51:26 -0400 Subject: [PATCH 23/43] minor visual tweaks --- TodoList/TodoList/main.m | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index fa8fb01..933aeed 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -297,6 +297,10 @@ -(void)newItem:(NSString *)listName { } -(void)displayItems:(NSString *)listName withPrompt:(BOOL)prompt{ + if (prompt == YES) { + printf("\n\n DISPLAYING ITEMS IN LIST %s\n", [listName UTF8String]); + } + List *list = [self getListByName:listName]; NSMutableArray *array = [list listArray]; for (int i = 0; i < [array count]; i++) { @@ -314,20 +318,21 @@ -(void)deleteItems:(NSString *)listName { while (true) { printf("\n\n DELETING ITEMS IN LIST %s\n", [listName UTF8String]); [self displayItems:listName withPrompt:NO]; - printf(" Please select an item to be deleted:\n\n "); + printf(" Please select an item to be deleted:\n\n "); int input; scanf("%d%*c", &input); fpurge(stdin); [[self getListByName:listName] removeListItem:input]; - printf("\n Item has been deleted.\n"); - printf("\n Do you want to delete more items? y/n\n"); + printf("\n Item has been deleted.\n"); + printf("\n Do you want to delete more items? y/n\n"); NSString *deletion = [self parse]; if ([deletion isEqualToString:@"y"]) { + printf("\n\n RETURNING TO NORMAL PROMPT\n"); continue; } else if ([deletion isEqualToString:@"n"]) { break; } else { - printf("Invalid command."); + printf("\n Invalid command.\n"); } @@ -375,7 +380,8 @@ -(void)commandTree:(NSString *)command { } else if ([command containsString:@"new item in "]) { [self newItem:[self snip:@"new item in " fromCommand:command]]; } else if ([command containsString:@"display items in "]) { - [self displayList:[self snip:@"display items in " fromCommand:command]]; + [self displayItems:[self snip:@"display items in " fromCommand:command] + withPrompt:YES]; } else if ([command containsString:@"delete items in "]) { [self deleteItems:[self snip:@"delete items in " fromCommand:command]]; } else if ([command containsString:@"display all items "]) { From 8619410b7fddd927be8dec11b2d58fc6bbedf94a Mon Sep 17 00:00:00 2001 From: elberdev Date: Mon, 29 Jun 2015 07:09:38 -0400 Subject: [PATCH 24/43] added priority and done status to list item displays --- TodoList/TodoList/main.m | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 933aeed..59b5884 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -15,7 +15,7 @@ @interface ListItem : NSObject -(void)setItemDescription:(NSString *)itemDescription; -(NSString *)itemDescription; -(void)setPriority:(int)priority; --(int)priority; +-(int)getPriority; -(void)setDoneStatus:(BOOL)doneStatus; -(BOOL)doneStatus; @@ -48,7 +48,7 @@ -(void)setPriority:(int)priority { _priority = priority; } --(int)priority { +-(int)getPriority { return _priority; } @@ -304,7 +304,10 @@ -(void)displayItems:(NSString *)listName withPrompt:(BOOL)prompt{ List *list = [self getListByName:listName]; NSMutableArray *array = [list listArray]; for (int i = 0; i < [array count]; i++) { - printf("\n %d) %s\n", i, [[array[i] itemDescription] UTF8String]); + printf("\n %d) %-40s %d %s\n", i, + [[array[i] itemDescription] UTF8String], + (int)[array[i] getPriority], + [[array[i] doneStatus] ? @"Y" : @"N" UTF8String]); } printf("\n"); if (prompt == YES) { From a3e7a67ebf8cd4ae54c8cb1aa0faef97f4b8ff86 Mon Sep 17 00:00:00 2001 From: elberdev Date: Mon, 29 Jun 2015 07:31:35 -0400 Subject: [PATCH 25/43] weird behavior started happening again even with camerons code so i added an init method in listmanager and list which seems to have fixed it. also tweaked item display --- TodoList/TodoList/main.m | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 59b5884..0366815 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -81,6 +81,13 @@ @implementation List { NSMutableArray *_listArray; } +-(id)init { + if (self = [super init]) { + _listArray = [[NSMutableArray alloc] init]; + } + return self; +} + -(void)setName:(NSString*)name { _name = name; } @@ -134,11 +141,7 @@ -(NSMutableArray *)listArray { //*************************** ListManager class *******************************// @interface ListManager : NSObject - -(void)run; --(void)addList:(List *)list; --(List*)getListByName:(NSString*)listname; --(void)removeList:(NSString *)name; @end @@ -298,13 +301,15 @@ -(void)newItem:(NSString *)listName { -(void)displayItems:(NSString *)listName withPrompt:(BOOL)prompt{ if (prompt == YES) { - printf("\n\n DISPLAYING ITEMS IN LIST %s\n", [listName UTF8String]); + printf("\n\n DISPLAYING ITEMS IN LIST %s\n\n", [listName UTF8String]); } List *list = [self getListByName:listName]; NSMutableArray *array = [list listArray]; + printf("\n | %-35s priority completed\n", + [[NSString stringWithFormat:@"description"] UTF8String]); for (int i = 0; i < [array count]; i++) { - printf("\n %d) %-40s %d %s\n", i, + printf(" |\n | %d) %-35s %d %s \n", i, [[array[i] itemDescription] UTF8String], (int)[array[i] getPriority], [[array[i] doneStatus] ? @"Y" : @"N" UTF8String]); From 9b18c8e54a5abab62fa32de628faed57298f96ad Mon Sep 17 00:00:00 2001 From: elberdev Date: Mon, 29 Jun 2015 09:19:06 -0400 Subject: [PATCH 26/43] added display all items functionality, made item display more pretty --- TodoList/TodoList/main.m | 115 ++++++++++++++++++++++++++++++--------- 1 file changed, 88 insertions(+), 27 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 0366815..999234c 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -306,19 +306,47 @@ -(void)displayItems:(NSString *)listName withPrompt:(BOOL)prompt{ List *list = [self getListByName:listName]; NSMutableArray *array = [list listArray]; - printf("\n | %-35s priority completed\n", + + [self formatItems:array]; + + if (prompt == YES) { + [self commandTree:[self parse]]; + } + +} + +-(void)formatItems:(NSMutableArray *)array { + + // figure out if i have to add any padding before any of the numbers by + // seeing how long the array is + int biggestNumPadding = 0; + NSString *arrayCount = [NSString stringWithFormat:@"%lu", [array count]]; + biggestNumPadding = (int) [arrayCount length]; + NSString* num = [[NSString alloc] init]; + + // figure out which item description is the longest so you can use its + // length as the standard for formatting + int longestLength = 0; + for (int i = 0; i < [array count]; i++) { + if ([[array[i] itemDescription] length] > longestLength) { + longestLength = (int) [[array[i] itemDescription] length]; + } + } + + // crazy c formatting I have to use to make everything pretty + printf("\n | %*s %-*s priority completed\n", biggestNumPadding, + [[NSString stringWithFormat:@" "] UTF8String], longestLength, [[NSString stringWithFormat:@"description"] UTF8String]); + for (int i = 0; i < [array count]; i++) { - printf(" |\n | %d) %-35s %d %s \n", i, - [[array[i] itemDescription] UTF8String], + printf(" |\n | %*s) %-*s %d %s \n", + biggestNumPadding, + [(num = [NSString stringWithFormat:@"%d", i]) UTF8String], + longestLength, [[array[i] itemDescription] UTF8String], (int)[array[i] getPriority], [[array[i] doneStatus] ? @"Y" : @"N" UTF8String]); } printf("\n"); - if (prompt == YES) { - [self commandTree:[self parse]]; - } - } -(void)deleteItems:(NSString *)listName { @@ -345,25 +373,29 @@ -(void)deleteItems:(NSString *)listName { } - [self commandTree:[self parse]]; + [self commandTree:[self parse]]; } -(void)displayAllItems:(NSString *)order { NSMutableArray *combinedList = [[NSMutableArray alloc] init]; for (int i = 0; i < [_listDatabase count]; i++) { - for (int j = 0; j < [_listDatabase[i] count]; j++) { - [combinedList addObject:[_listDatabase[i] objectAtIndex:j]]; + for (int j = 0; j < [[_listDatabase[i] listArray] count]; j++) { + [combinedList addObject:[[_listDatabase[i] listArray] objectAtIndex:j]]; } } - if([order isEqualTo:@"urgent first"]) { - for (int i = 1; i <= 4; i++) { - for (int j = 0; j < [combinedList count]; j++) { - - } - } - } + [self formatItems:combinedList]; + +// if([order isEqualTo:@"urgent first"]) { +// for (int i = 1; i <= 4; i++) { +// for (int j = 0; j < [combinedList count]; j++) { +// +// } +// } +// } + + [self commandTree:[self parse]]; } @@ -438,10 +470,14 @@ -(void)help { printf("\n new item in \n"); printf("\n display items in \n"); printf("\n delete items in \n"); - printf("\n display all items high priority first\n"); - printf("\n display all items low priority first\n"); - printf("\n display all items closest due date first\n"); - printf("\n display all items farthest due date first\n"); + printf("\n display all items first\n"); + printf("\n sort selectors:\n\n"); + printf(" high priority\n"); + printf(" low priority\n"); + printf(" closest due date\n"); + printf(" farthest due date\n"); + printf(" completed\n"); + printf(" not completed\n"); printf("\n exit \n\n"); [self commandTree:[self parse]]; } @@ -466,40 +502,65 @@ int main(int argc, const char * argv[]) { ListItem *item1 = [[ListItem alloc] init]; [item1 setItemDescription:@"do laundry"]; + [item1 setPriority:3]; ListItem *item2 = [[ListItem alloc] init]; [item2 setItemDescription:@"kill bad guys"]; + [item2 setPriority:2]; ListItem *item3 = [[ListItem alloc] init]; [item3 setItemDescription:@"call Robin"]; + [item3 setPriority:4]; ListItem *item4 = [[ListItem alloc] init]; [item4 setItemDescription:@"polish bat-mobile"]; ListItem *item5 = [[ListItem alloc] init]; [item5 setItemDescription:@"grab a beer with Joker"]; + [item5 setPriority:3]; ListItem *item6 = [[ListItem alloc] init]; [item6 setItemDescription:@"look mysterious"]; + ListItem *item7 = [[ListItem alloc] init]; + [item7 setItemDescription:@"get haircut"]; + [item7 setPriority:1]; + ListItem *item8 = [[ListItem alloc] init]; + [item8 setItemDescription:@"buy flowers for catwoman"]; + [item8 setPriority:3]; + ListItem *item9 = [[ListItem alloc] init]; + [item9 setItemDescription:@"fire alfred"]; + [item9 setPriority:2]; + ListItem *item10 = [[ListItem alloc] init]; + [item10 setItemDescription:@"march at pride"]; + [item10 setPriority:4]; + ListItem *item11 = [[ListItem alloc] init]; + [item11 setItemDescription:@"get wonder woman to teach me how to use a lasso"]; + [item11 setPriority:2]; List *list = [[List alloc] init]; [list addListItem:item1]; [list addListItem:item2]; [list addListItem:item3]; + [list addListItem:item4]; + [list addListItem:item5]; + [list addListItem:item6]; [list setName:@"urgent"]; List *list2 = [[List alloc] init]; - [list2 addListItem:item4]; - [list2 addListItem:item5]; - [list2 addListItem:item6]; - [list2 setName:@"monty python"]; + [list2 addListItem:item7]; + [list2 addListItem:item8]; + [list2 addListItem:item9]; + [list2 addListItem:item9]; + [list2 addListItem:item10]; + [list2 addListItem:item11]; + [list2 setName:@"more urgentest"]; // for(int i = 0; i < [arrayList count]; i++) { // NSLog(@"%@", [arrayList[i] itemDescription]); // } - [list removeListItem:2]; +// [list removeListItem:2]; // for(int i = 0; i < [arrayList count]; i++) { // NSLog(@"%@", [arrayList[i] itemDescription]); // } - [list editListItem:0 withString:@"elect Bernie Sanders president"]; + [list editListItem:0 withString:@"hit Bernie Sanders with a batarang"]; // for(int i = 0; i < [arrayList count]; i++) { // NSLog(@"%@", [arrayList[i] itemDescription]); From 5f3c10a1a2516dab481447f415e4d7c4c03b7d89 Mon Sep 17 00:00:00 2001 From: elberdev Date: Mon, 29 Jun 2015 10:05:29 -0400 Subject: [PATCH 27/43] fixed some minor display issues --- TodoList/TodoList/main.m | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 999234c..5bb82c8 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -2,8 +2,8 @@ // main.m // TodoList // -// Created by Michael Kavouras on 6/25/15. -// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// Created by Elber Carneiro and Jackie Meggesto on 6/25/15. +// Copyright (c) 2015 Jackie Meggesto and Elber Carneiro. All rights reserved. // #import @@ -265,7 +265,9 @@ -(void)renameList:(NSString *)listName { -(void)displayList:(NSString *)listName { - if ([listName isEqualToString:@"all"]) { + if ([_listDatabase count] == 0) { + printf("\n\n NO TO-DO LISTS TO DISPLAY\n"); + } else if ([listName isEqualToString:@"all"]) { printf("\n\n DISPLAYING ALL TO-DO LISTS\n"); for (int i = 0; i < [_listDatabase count]; i++) { printf("\n %s: %lu items\n", [[_listDatabase[i] name] UTF8String], @@ -317,6 +319,11 @@ -(void)displayItems:(NSString *)listName withPrompt:(BOOL)prompt{ -(void)formatItems:(NSMutableArray *)array { + if ([array count] == 0) { + printf("\n No items to display\n\n"); + return; + } + // figure out if i have to add any padding before any of the numbers by // seeing how long the array is int biggestNumPadding = 0; @@ -326,7 +333,8 @@ -(void)formatItems:(NSMutableArray *)array { // figure out which item description is the longest so you can use its // length as the standard for formatting - int longestLength = 0; + NSString *description = [NSString stringWithFormat:@"description"]; + int longestLength = (int) [description length]; for (int i = 0; i < [array count]; i++) { if ([[array[i] itemDescription] length] > longestLength) { longestLength = (int) [[array[i] itemDescription] length]; @@ -336,7 +344,7 @@ -(void)formatItems:(NSMutableArray *)array { // crazy c formatting I have to use to make everything pretty printf("\n | %*s %-*s priority completed\n", biggestNumPadding, [[NSString stringWithFormat:@" "] UTF8String], longestLength, - [[NSString stringWithFormat:@"description"] UTF8String]); + [description UTF8String]); for (int i = 0; i < [array count]; i++) { printf(" |\n | %*s) %-*s %d %s \n", @@ -550,26 +558,12 @@ int main(int argc, const char * argv[]) { [list2 addListItem:item11]; [list2 setName:@"more urgentest"]; -// for(int i = 0; i < [arrayList count]; i++) { -// NSLog(@"%@", [arrayList[i] itemDescription]); -// } - -// [list removeListItem:2]; - -// for(int i = 0; i < [arrayList count]; i++) { -// NSLog(@"%@", [arrayList[i] itemDescription]); -// } - [list editListItem:0 withString:@"hit Bernie Sanders with a batarang"]; -// for(int i = 0; i < [arrayList count]; i++) { -// NSLog(@"%@", [arrayList[i] itemDescription]); -// } - ListManager *myListManager = [[ListManager alloc]init]; [myListManager addList:list]; [myListManager addList:list2]; - //[myListManager showLists]; + [myListManager run]; /// yo yo yo From 72fd41315a4bd33ba5358b2ee2b3981e5e19a361 Mon Sep 17 00:00:00 2001 From: elberdev Date: Mon, 29 Jun 2015 21:16:37 -0400 Subject: [PATCH 28/43] built sortItems method to sort by item properties. still has to be implemented into other methods --- TodoList/TodoList/main.m | 61 +++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 5bb82c8..aa6fce0 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -14,8 +14,8 @@ @interface ListItem : NSObject -(void)setItemDescription:(NSString *)itemDescription; -(NSString *)itemDescription; --(void)setPriority:(int)priority; --(int)getPriority; +-(void)setItemPriority:(int)itemPriority; +-(int)itemPriority; -(void)setDoneStatus:(BOOL)doneStatus; -(BOOL)doneStatus; @@ -23,14 +23,14 @@ -(BOOL)doneStatus; @implementation ListItem { NSString *_itemDescription; - int _priority; + int _itemPriority; BOOL _doneStatus; NSDate *_dueDate; } -(id)init { if(self = [super init]) { - _priority = 1; + _itemPriority = 1; _doneStatus = NO; } return self; @@ -44,12 +44,12 @@ -(NSString *)itemDescription { return _itemDescription; } --(void)setPriority:(int)priority { - _priority = priority; +-(void)setItemPriority:(int)priority { + _itemPriority = priority; } --(int)getPriority { - return _priority; +-(int)itemPriority { + return _itemPriority; } -(void)setDoneStatus:(BOOL)doneStatus { @@ -294,7 +294,7 @@ -(void)newItem:(NSString *)listName { int priority; scanf("%d%*c", &priority); fpurge(stdin); - [newItem setPriority:priority]; + [newItem setItemPriority:priority]; [[[self getListByName:listName] listArray] addObject:newItem]; printf("\n to do item created successfully\n\n"); @@ -317,6 +317,29 @@ -(void)displayItems:(NSString *)listName withPrompt:(BOOL)prompt{ } +//////////// call this in displayItems //////////////////////////////////////////////// +-(NSArray *)sortItems:(NSMutableArray *)array + by:(NSString *)descriptor + ascending:(BOOL)ascending { + + NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] init]; + + if ([descriptor isEqualToString:@"itemPriority"]) { + sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:descriptor + ascending:ascending]; + } else { + sortDescriptor = [NSSortDescriptor + sortDescriptorWithKey:descriptor + ascending:ascending + selector:@selector(localizedStandardCompare:)]; + } + + return [array sortedArrayUsingDescriptors:@[sortDescriptor]]; + +} +///////////////////////////////////////////////////////////////////////////////////////////// + + -(void)formatItems:(NSMutableArray *)array { if ([array count] == 0) { @@ -351,7 +374,7 @@ -(void)formatItems:(NSMutableArray *)array { biggestNumPadding, [(num = [NSString stringWithFormat:@"%d", i]) UTF8String], longestLength, [[array[i] itemDescription] UTF8String], - (int)[array[i] getPriority], + (int)[array[i] itemPriority], [[array[i] doneStatus] ? @"Y" : @"N" UTF8String]); } printf("\n"); @@ -510,35 +533,35 @@ int main(int argc, const char * argv[]) { ListItem *item1 = [[ListItem alloc] init]; [item1 setItemDescription:@"do laundry"]; - [item1 setPriority:3]; + [item1 setItemPriority:3]; ListItem *item2 = [[ListItem alloc] init]; [item2 setItemDescription:@"kill bad guys"]; - [item2 setPriority:2]; + [item2 setItemPriority:2]; ListItem *item3 = [[ListItem alloc] init]; [item3 setItemDescription:@"call Robin"]; - [item3 setPriority:4]; + [item3 setItemPriority:4]; ListItem *item4 = [[ListItem alloc] init]; [item4 setItemDescription:@"polish bat-mobile"]; ListItem *item5 = [[ListItem alloc] init]; [item5 setItemDescription:@"grab a beer with Joker"]; - [item5 setPriority:3]; + [item5 setItemPriority:3]; ListItem *item6 = [[ListItem alloc] init]; [item6 setItemDescription:@"look mysterious"]; ListItem *item7 = [[ListItem alloc] init]; [item7 setItemDescription:@"get haircut"]; - [item7 setPriority:1]; + [item7 setItemPriority:1]; ListItem *item8 = [[ListItem alloc] init]; [item8 setItemDescription:@"buy flowers for catwoman"]; - [item8 setPriority:3]; + [item8 setItemPriority:3]; ListItem *item9 = [[ListItem alloc] init]; [item9 setItemDescription:@"fire alfred"]; - [item9 setPriority:2]; + [item9 setItemPriority:2]; ListItem *item10 = [[ListItem alloc] init]; [item10 setItemDescription:@"march at pride"]; - [item10 setPriority:4]; + [item10 setItemPriority:4]; ListItem *item11 = [[ListItem alloc] init]; [item11 setItemDescription:@"get wonder woman to teach me how to use a lasso"]; - [item11 setPriority:2]; + [item11 setItemPriority:2]; List *list = [[List alloc] init]; [list addListItem:item1]; From 9f5bedfbae2843e0b40fddc69cb9f56871f86319 Mon Sep 17 00:00:00 2001 From: Jackie Meggesto Date: Mon, 29 Jun 2015 21:39:40 -0400 Subject: [PATCH 29/43] working on editing items from UI --- TodoList/TodoList/main.m | 173 ++++++++++++++++++++++++++++++--------- 1 file changed, 136 insertions(+), 37 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 5bb82c8..8fd956f 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -14,8 +14,8 @@ @interface ListItem : NSObject -(void)setItemDescription:(NSString *)itemDescription; -(NSString *)itemDescription; --(void)setPriority:(int)priority; --(int)getPriority; +-(void)setItemPriority:(int)priority; +-(int)itemPriority; -(void)setDoneStatus:(BOOL)doneStatus; -(BOOL)doneStatus; @@ -23,14 +23,14 @@ -(BOOL)doneStatus; @implementation ListItem { NSString *_itemDescription; - int _priority; + int _itemPriority; BOOL _doneStatus; NSDate *_dueDate; } -(id)init { if(self = [super init]) { - _priority = 1; + _itemPriority = 1; _doneStatus = NO; } return self; @@ -44,12 +44,12 @@ -(NSString *)itemDescription { return _itemDescription; } --(void)setPriority:(int)priority { - _priority = priority; +-(void)setItemPriority:(int)priority { + _itemPriority = priority; } --(int)getPriority { - return _priority; +-(int)itemPriority { + return _itemPriority; } -(void)setDoneStatus:(BOOL)doneStatus { @@ -70,7 +70,9 @@ @interface List : NSObject -(void)addListItem:(ListItem *)listItem; -(NSMutableArray *)listArray; -(void)removeListItem:(int)index; --(void)editListItem:(int)index withString:(NSString *)string; +-(void)editListItemDescription:(int)index withString:(NSString *)string; +-(void)editListPriority:(int)index withPriority:(int)priority; +-(void)editListDoneStatus:(int)index withDoneStatus:(BOOL)doneStatus; -(void)setName:(NSString*)name; -(NSString*)name; @@ -112,7 +114,7 @@ -(void)removeListItem:(int)index { } } --(void)editListItem:(int)index withString:(NSString *)string { +-(void)editListItemDescription:(int)index withString:(NSString *)string { if (index < [self.listArray count]) { [[self.listArray objectAtIndex:index] setItemDescription:string]; @@ -121,7 +123,22 @@ -(void)editListItem:(int)index withString:(NSString *)string { NSLog(@"\n The list item you input does not exist"); } } - +-(void)editListPriority:(int)index withPriority:(int)priority { + if (index < [self.listArray count]) { + [[self.listArray objectAtIndex:index] setItemPriority:priority]; + + } else { + NSLog(@"\n The list item you input does not exist"); + } +} +-(void)editListDoneStatus:(int)index withDoneStatus:(BOOL)doneStatus { + if (index < [self.listArray count]) { + [[self.listArray objectAtIndex:index] setDoneStatus:doneStatus]; + + } else { + NSLog(@"\n The list item you input does not exist"); + } +} -(NSUInteger)showNumberOfItems { return [self.listArray count]; @@ -294,7 +311,7 @@ -(void)newItem:(NSString *)listName { int priority; scanf("%d%*c", &priority); fpurge(stdin); - [newItem setPriority:priority]; + [newItem setItemPriority:priority]; [[[self getListByName:listName] listArray] addObject:newItem]; printf("\n to do item created successfully\n\n"); @@ -351,13 +368,27 @@ -(void)formatItems:(NSMutableArray *)array { biggestNumPadding, [(num = [NSString stringWithFormat:@"%d", i]) UTF8String], longestLength, [[array[i] itemDescription] UTF8String], - (int)[array[i] getPriority], + (int)[array[i] itemPriority], [[array[i] doneStatus] ? @"Y" : @"N" UTF8String]); } printf("\n"); } - +-(void)deleteItemPrompt:(NSString*)listname { + + printf("\n Do you want to delete more items? y/n\n"); + NSString *prompt = [self parse]; + if ([prompt isEqualToString:@"y"]) { + [self deleteItems:listname]; + } else if ([prompt isEqualToString:@"n"]) { + printf("Exiting deletion"); + [self commandTree:[self parse]]; + } else { + printf("Invalid input."); + [self deleteItemPrompt:listname]; + } +} -(void)deleteItems:(NSString *)listName { + [self getListByName:listName]; while (true) { printf("\n\n DELETING ITEMS IN LIST %s\n", [listName UTF8String]); @@ -368,20 +399,11 @@ -(void)deleteItems:(NSString *)listName { fpurge(stdin); [[self getListByName:listName] removeListItem:input]; printf("\n Item has been deleted.\n"); - printf("\n Do you want to delete more items? y/n\n"); - NSString *deletion = [self parse]; - if ([deletion isEqualToString:@"y"]) { - printf("\n\n RETURNING TO NORMAL PROMPT\n"); - continue; - } else if ([deletion isEqualToString:@"n"]) { - break; - } else { - printf("\n Invalid command.\n"); - } - + [self deleteItemPrompt:listName]; + } - [self commandTree:[self parse]]; + } -(void)displayAllItems:(NSString *)order { @@ -406,6 +428,80 @@ -(void)displayAllItems:(NSString *)order { [self commandTree:[self parse]]; } +-(void)editItemsInListSelector:(NSString*)listname { + int itemInput; + int itemInput2; + int itemInput3; + NSString *myInput; + scanf("%d%*c", &itemInput); + fpurge(stdin); + printf("What edit would you like to perform on that item? \n 1) Reassign priority \n 2) Edit description \n 3) Change completion status"); + scanf("%d%*c", &itemInput2); + fpurge(stdin); + if (itemInput2 == 1) { + printf("please enter a value between 1 (greatest priority) and 4 (least priority \n"); + [[self getListByName:listname] editListPriority:itemInput withPriority:(scanf("%d", &itemInput3))]; + fpurge(stdin); + } else if (itemInput2 == 2) { + printf("Input a new description for this item: \n"); + [[self getListByName:listname] editListItemDescription:itemInput withString:[self parse]]; + } else if (itemInput2 == 3) { + printf("Please enter 'y' if this item is done, or 'n' if the item is not done \n"); + myInput = [self parse]; + if ([myInput isEqualToString:@"y"]) { + [[self getListByName:listname] editListDoneStatus:itemInput withDoneStatus:YES]; + } else if ([myInput isEqualToString:@"n"]) { + [[self getListByName:listname] editListDoneStatus:itemInput withDoneStatus:NO]; + } else { + printf("invalid input"); + } + } +} +-(void)editItemPrompt:(NSString*)listname { + + printf("\n Do you want to edit more items? y/n\n"); + NSString *prompt = [self parse]; + if ([prompt isEqualToString:@"y"]) { + [self editItemsInList:listname]; + } else if ([prompt isEqualToString:@"n"]) { + printf("Exiting item editing"); + [self commandTree:[self parse]]; + } else { + printf("Invalid input."); + [self editItemPrompt:listname]; + } +} +-(void)editItemsInList:(NSString*)listname { + [self getListByName:listname]; + while (true) { + printf("\n\n EDITING ITEMS IN LIST %s\n", [listname UTF8String]); + [self displayItems:listname withPrompt:NO]; + printf(" Please select an item to be edited:\n\n "); + [self editItemsInListSelector:listname]; + [self editItemPrompt:listname]; + +// NSString *input = [self parse]; +// int itemInput; +// int itemInput2; +// int itemInput3; +// scanf("%d%*c", &itemInput); +// fpurge(stdin); +// printf("What edit would you like to perform on that item? \n 1) Reassign priority \n 2) Edit description \n 3) Change completion status"); +// scanf("%d%*c", &itemInput2); +// fpurge(stdin); +// if (itemInput2 == 1) { +// [[self getListByName:listname] editListPriority:itemInput withPriority:(scanf("%d%*c", &itemInput3))]; +// } else if (itemInput2 == 2) { +// [[self getListByName:listname] editListItemDescription:itemInput withString:[self parse]]; +// } else if (itemInput2 == 3) { +// +// } + + // [self *will create new method for editItemsInListPrompt* deleteItemPrompt:listname]; + + + } +} -(NSString *)snip:(NSString *)toDelete fromCommand:(NSString *)command { command = [command stringByReplacingOccurrencesOfString:toDelete @@ -433,7 +529,9 @@ -(void)commandTree:(NSString *)command { } else if ([command containsString:@"delete items in "]) { [self deleteItems:[self snip:@"delete items in " fromCommand:command]]; } else if ([command containsString:@"display all items "]) { - [self displayAllItems:[self snip:@"display all items " fromCommand:command]]; + [self editItemsInList:[self snip:@"display all items " fromCommand:command]]; + } else if ([command containsString:@"edit items in "]) { + [self editItemsInList:[self snip:@"edit items in " fromCommand:command]]; } else if ([command isEqualToString:@"exit"]) { exit(0); } else { @@ -478,6 +576,7 @@ -(void)help { printf("\n new item in \n"); printf("\n display items in \n"); printf("\n delete items in \n"); + printf("\n edit items in \n"); printf("\n display all items first\n"); printf("\n sort selectors:\n\n"); printf(" high priority\n"); @@ -510,35 +609,35 @@ int main(int argc, const char * argv[]) { ListItem *item1 = [[ListItem alloc] init]; [item1 setItemDescription:@"do laundry"]; - [item1 setPriority:3]; + [item1 setItemPriority:3]; ListItem *item2 = [[ListItem alloc] init]; [item2 setItemDescription:@"kill bad guys"]; - [item2 setPriority:2]; + [item2 setItemPriority:2]; ListItem *item3 = [[ListItem alloc] init]; [item3 setItemDescription:@"call Robin"]; - [item3 setPriority:4]; + [item3 setItemPriority:4]; ListItem *item4 = [[ListItem alloc] init]; [item4 setItemDescription:@"polish bat-mobile"]; ListItem *item5 = [[ListItem alloc] init]; [item5 setItemDescription:@"grab a beer with Joker"]; - [item5 setPriority:3]; + [item5 setItemPriority:3]; ListItem *item6 = [[ListItem alloc] init]; [item6 setItemDescription:@"look mysterious"]; ListItem *item7 = [[ListItem alloc] init]; [item7 setItemDescription:@"get haircut"]; - [item7 setPriority:1]; + [item7 setItemPriority:1]; ListItem *item8 = [[ListItem alloc] init]; [item8 setItemDescription:@"buy flowers for catwoman"]; - [item8 setPriority:3]; + [item8 setItemPriority:3]; ListItem *item9 = [[ListItem alloc] init]; [item9 setItemDescription:@"fire alfred"]; - [item9 setPriority:2]; + [item9 setItemPriority:2]; ListItem *item10 = [[ListItem alloc] init]; [item10 setItemDescription:@"march at pride"]; - [item10 setPriority:4]; + [item10 setItemPriority:4]; ListItem *item11 = [[ListItem alloc] init]; [item11 setItemDescription:@"get wonder woman to teach me how to use a lasso"]; - [item11 setPriority:2]; + [item11 setItemPriority:2]; List *list = [[List alloc] init]; [list addListItem:item1]; @@ -558,7 +657,7 @@ int main(int argc, const char * argv[]) { [list2 addListItem:item11]; [list2 setName:@"more urgentest"]; - [list editListItem:0 withString:@"hit Bernie Sanders with a batarang"]; + [list editListItemDescription:0 withString:@"hit Bernie Sanders with a batarang"]; ListManager *myListManager = [[ListManager alloc]init]; [myListManager addList:list]; From 6e7e65aa3722408c0aea6a5bacc08527572ba47d Mon Sep 17 00:00:00 2001 From: elberdev Date: Mon, 29 Jun 2015 21:39:47 -0400 Subject: [PATCH 30/43] built sortItems method to sort by item properties. still has to be implemented into other methods --- TodoList/TodoList/main.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index aa6fce0..cfff448 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -317,7 +317,7 @@ -(void)displayItems:(NSString *)listName withPrompt:(BOOL)prompt{ } -//////////// call this in displayItems //////////////////////////////////////////////// +//////////// call this in displayItems ////////////////////////////////////////////////////// -(NSArray *)sortItems:(NSMutableArray *)array by:(NSString *)descriptor ascending:(BOOL)ascending { From b0472bc15ee8f750106b27e48b9b44369847bac1 Mon Sep 17 00:00:00 2001 From: Jackie Meggesto Date: Mon, 29 Jun 2015 21:56:20 -0400 Subject: [PATCH 31/43] fixed error where reassignment of item priority did not function correctly --- TodoList/TodoList/main.m | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 8fd956f..4edad02 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -429,29 +429,30 @@ -(void)displayAllItems:(NSString *)order { } -(void)editItemsInListSelector:(NSString*)listname { - int itemInput; - int itemInput2; - int itemInput3; + int itemIndex; + int editOption; + int newPriority; NSString *myInput; - scanf("%d%*c", &itemInput); + scanf("%d%*c", &itemIndex); fpurge(stdin); - printf("What edit would you like to perform on that item? \n 1) Reassign priority \n 2) Edit description \n 3) Change completion status"); - scanf("%d%*c", &itemInput2); + printf("What edit would you like to perform on that item? \n 1) Reassign priority \n 2) Edit description \n 3) Change completion status \n"); + scanf("%d%*c", &editOption); fpurge(stdin); - if (itemInput2 == 1) { - printf("please enter a value between 1 (greatest priority) and 4 (least priority \n"); - [[self getListByName:listname] editListPriority:itemInput withPriority:(scanf("%d", &itemInput3))]; + if (editOption == 1) { + printf("please enter a value between 1 (greatest priority) and 4 (least priority) \n"); + scanf("%d", &newPriority); fpurge(stdin); - } else if (itemInput2 == 2) { + [[self getListByName:listname] editListPriority:itemIndex withPriority:newPriority]; + } else if (editOption == 2) { printf("Input a new description for this item: \n"); - [[self getListByName:listname] editListItemDescription:itemInput withString:[self parse]]; - } else if (itemInput2 == 3) { + [[self getListByName:listname] editListItemDescription:itemIndex withString:[self parse]]; + } else if (editOption == 3) { printf("Please enter 'y' if this item is done, or 'n' if the item is not done \n"); myInput = [self parse]; if ([myInput isEqualToString:@"y"]) { - [[self getListByName:listname] editListDoneStatus:itemInput withDoneStatus:YES]; + [[self getListByName:listname] editListDoneStatus:itemIndex withDoneStatus:YES]; } else if ([myInput isEqualToString:@"n"]) { - [[self getListByName:listname] editListDoneStatus:itemInput withDoneStatus:NO]; + [[self getListByName:listname] editListDoneStatus:itemIndex withDoneStatus:NO]; } else { printf("invalid input"); } From 99907e0137fcb03604c410ef007b306b0818f835 Mon Sep 17 00:00:00 2001 From: elberdev Date: Mon, 29 Jun 2015 21:57:40 -0400 Subject: [PATCH 32/43] deleted unnecessary commented out code --- TodoList/TodoList/main.m | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index cfff448..0d5fdc0 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -418,14 +418,6 @@ -(void)displayAllItems:(NSString *)order { [self formatItems:combinedList]; -// if([order isEqualTo:@"urgent first"]) { -// for (int i = 1; i <= 4; i++) { -// for (int j = 0; j < [combinedList count]; j++) { -// -// } -// } -// } - [self commandTree:[self parse]]; } @@ -524,12 +516,6 @@ -(void)run { int main(int argc, const char * argv[]) { @autoreleasepool { - - // insert code here... -// char string[256]; -// scanf("%255s", &string); -// NSString *firstName = [NSString stringWithCString:string encoding:1]; -// NSLog(@"%@", firstName); ListItem *item1 = [[ListItem alloc] init]; [item1 setItemDescription:@"do laundry"]; From 2b43064c2a1fce86167bed908a3dd8782c41d2f3 Mon Sep 17 00:00:00 2001 From: elberdev Date: Tue, 30 Jun 2015 10:17:37 -0400 Subject: [PATCH 33/43] cleaned up look of edit items interface a little, deleted an entire method that was not being used, deleted extra --if(nil)-- code that was no longer needed (taken care of in init statements), and fixed display all item command to connect to the correct method again (i think we made some copy-paste mistake yesterday that broke it) --- TodoList/TodoList/main.m | 135 +++++++++++++++------------------------ 1 file changed, 53 insertions(+), 82 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 77e6fc9..fafbe38 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -8,7 +8,6 @@ #import - //*************************** listItem class *********************************// @interface ListItem : NSObject @@ -25,7 +24,7 @@ @implementation ListItem { NSString *_itemDescription; int _itemPriority; BOOL _doneStatus; - NSDate *_dueDate; +// NSDate *_dueDate; } -(id)init { @@ -67,14 +66,14 @@ -(BOOL)doneStatus { //******************************** List class ********************************// @interface List : NSObject --(void)addListItem:(ListItem *)listItem; +-(void)setName:(NSString*)name; +-(NSString*)name; -(NSMutableArray *)listArray; +-(void)addListItem:(ListItem *)listItem; -(void)removeListItem:(int)index; -(void)editListItemDescription:(int)index withString:(NSString *)string; -(void)editListPriority:(int)index withPriority:(int)priority; -(void)editListDoneStatus:(int)index withDoneStatus:(BOOL)doneStatus; --(void)setName:(NSString*)name; --(NSString*)name; @end @@ -86,6 +85,7 @@ @implementation List { -(id)init { if (self = [super init]) { _listArray = [[NSMutableArray alloc] init]; + _name = [[NSString alloc] init]; } return self; } @@ -95,9 +95,6 @@ -(void)setName:(NSString*)name { } -(NSString*)name { - if (_name == nil) { - _name = [[NSString alloc] init]; - } return _name; } @@ -106,7 +103,6 @@ -(void)addListItem:(ListItem *)listItem { } -(void)removeListItem:(int)index { - if (index < [self.listArray count]) { [self.listArray removeObjectAtIndex:index]; } else { @@ -115,22 +111,21 @@ -(void)removeListItem:(int)index { } -(void)editListItemDescription:(int)index withString:(NSString *)string { - if (index < [self.listArray count]) { [[self.listArray objectAtIndex:index] setItemDescription:string]; - } else { NSLog(@"\n The list item you input does not exist"); } } + -(void)editListPriority:(int)index withPriority:(int)priority { if (index < [self.listArray count]) { [[self.listArray objectAtIndex:index] setItemPriority:priority]; - } else { NSLog(@"\n The list item you input does not exist"); } } + -(void)editListDoneStatus:(int)index withDoneStatus:(BOOL)doneStatus { if (index < [self.listArray count]) { [[self.listArray objectAtIndex:index] setDoneStatus:doneStatus]; @@ -139,8 +134,8 @@ -(void)editListDoneStatus:(int)index withDoneStatus:(BOOL)doneStatus { NSLog(@"\n The list item you input does not exist"); } } + -(NSUInteger)showNumberOfItems { - return [self.listArray count]; } @@ -174,18 +169,10 @@ -(id)init { } -(void)addList:(List *)list { - if (_listDatabase == nil) { - _listDatabase = [[NSMutableArray alloc] init]; - } - [_listDatabase addObject:list]; } -(void)removeList:(NSString *)name { - if (_listDatabase == nil) { - _listDatabase = [[NSMutableArray alloc] init]; - } - BOOL found = NO; for (int i = 0; i < [_listDatabase count]; i++) { @@ -202,35 +189,16 @@ -(void)removeList:(NSString *)name { } -(List*)getListByName:(NSString*)listname { - if (_listDatabase == nil) { - _listDatabase = [[NSMutableArray alloc] init]; - } - for (int i = 0; i < [_listDatabase count]; i++) { if ([listname isEqualToString:[_listDatabase[i] name]]) { return _listDatabase[i]; } } - printf("\n There are no lists by that name.\n\n"); + printf("\n There are no lists by that name\n\n"); [self commandTree:[self parse]]; return nil; } --(void)createList { - List *list = [[List alloc] init]; - - printf("\n Please enter a name for your list: "); - char nameC[256]; - scanf("%255s[^\n]%*c", nameC); - fpurge(stdin); - NSString *name = [NSString stringWithCString:nameC - encoding:NSUTF8StringEncoding]; - - [list setName:name]; - [self addList: list]; - -} - -(void)newList:(NSString *)newListName { List *list = [[List alloc] init]; @@ -283,7 +251,7 @@ -(void)renameList:(NSString *)listName { -(void)displayList:(NSString *)listName { if ([_listDatabase count] == 0) { - printf("\n\n NO TO-DO LISTS TO DISPLAY\n"); + printf("\n\n NO TO-DO LISTS TO DISPLAY\n"); } else if ([listName isEqualToString:@"all"]) { printf("\n\n DISPLAYING ALL TO-DO LISTS\n"); for (int i = 0; i < [_listDatabase count]; i++) { @@ -311,7 +279,11 @@ -(void)newItem:(NSString *)listName { int priority; scanf("%d%*c", &priority); fpurge(stdin); - [newItem setItemPriority:priority]; + if (0 < priority && priority < 5) { + [newItem setItemPriority:priority]; + } else { + printf("\n INVALID INPUT\n"); + } [[[self getListByName:listName] listArray] addObject:newItem]; printf("\n to do item created successfully\n\n"); @@ -352,11 +324,9 @@ -(NSArray *)sortItems:(NSMutableArray *)array } return [array sortedArrayUsingDescriptors:@[sortDescriptor]]; - } ///////////////////////////////////////////////////////////////////////////////////////////// - -(void)formatItems:(NSMutableArray *)array { if ([array count] == 0) { @@ -396,6 +366,7 @@ -(void)formatItems:(NSMutableArray *)array { } printf("\n"); } + -(void)deleteItemPrompt:(NSString*)listname { printf("\n Do you want to delete more items? y/n\n"); @@ -403,13 +374,14 @@ -(void)deleteItemPrompt:(NSString*)listname { if ([prompt isEqualToString:@"y"]) { [self deleteItems:listname]; } else if ([prompt isEqualToString:@"n"]) { - printf("Exiting deletion"); + printf("\n EXITING DELETION\n\n"); [self commandTree:[self parse]]; } else { - printf("Invalid input."); + printf("\n INVALID INPUT\n"); [self deleteItemPrompt:listname]; } } + -(void)deleteItems:(NSString *)listName { [self getListByName:listName]; @@ -424,7 +396,6 @@ -(void)deleteItems:(NSString *)listName { printf("\n Item has been deleted.\n"); [self deleteItemPrompt:listName]; - } } @@ -439,40 +410,59 @@ -(void)displayAllItems:(NSString *)order { } [self formatItems:combinedList]; - [self commandTree:[self parse]]; } + -(void)editItemsInListSelector:(NSString*)listname { int itemIndex; int editOption; int newPriority; NSString *myInput; + + printf("\n "); scanf("%d%*c", &itemIndex); fpurge(stdin); - printf("What edit would you like to perform on that item? \n 1) Reassign priority \n 2) Edit description \n 3) Change completion status \n"); + + printf("\n What edit would you like to perform on that item?\n"); + printf("\n 1) Reassign priority\n"); + printf("\n 2) Edit description\n"); + printf("\n 3) Change completion status\n"); + + printf("\n\n "); scanf("%d%*c", &editOption); fpurge(stdin); + if (editOption == 1) { - printf("please enter a value between 1 (greatest priority) and 4 (least priority) \n"); + printf("\n Enter a value from 1 (greatest priority) to 4 (least priority)\n"); + printf("\n "); scanf("%d", &newPriority); fpurge(stdin); - [[self getListByName:listname] editListPriority:itemIndex withPriority:newPriority]; + if (0 < newPriority && newPriority < 5) { + [[self getListByName:listname] editListPriority:itemIndex + withPriority:newPriority]; + } else { + printf("\n INVALID INPUT\n"); + } } else if (editOption == 2) { - printf("Input a new description for this item: \n"); - [[self getListByName:listname] editListItemDescription:itemIndex withString:[self parse]]; + printf("\n Input a new description for this item:\n"); + [[self getListByName:listname] editListItemDescription:itemIndex + withString:[self parse]]; } else if (editOption == 3) { - printf("Please enter 'y' if this item is done, or 'n' if the item is not done \n"); + printf("\n Please enter 'y' for done, or 'n' for not done \n"); myInput = [self parse]; if ([myInput isEqualToString:@"y"]) { - [[self getListByName:listname] editListDoneStatus:itemIndex withDoneStatus:YES]; + [[self getListByName:listname] editListDoneStatus:itemIndex + withDoneStatus:YES]; } else if ([myInput isEqualToString:@"n"]) { - [[self getListByName:listname] editListDoneStatus:itemIndex withDoneStatus:NO]; + [[self getListByName:listname] editListDoneStatus:itemIndex + withDoneStatus:NO]; } else { - printf("invalid input"); + printf("\n INVALID INPUT\n"); } } } + -(void)editItemPrompt:(NSString*)listname { printf("\n Do you want to edit more items? y/n\n"); @@ -480,42 +470,23 @@ -(void)editItemPrompt:(NSString*)listname { if ([prompt isEqualToString:@"y"]) { [self editItemsInList:listname]; } else if ([prompt isEqualToString:@"n"]) { - printf("Exiting item editing"); + printf("\n EXITING ITEM EDITING\n"); [self commandTree:[self parse]]; } else { - printf("Invalid input."); + printf("\n INVALID INPUT\n"); [self editItemPrompt:listname]; } } + -(void)editItemsInList:(NSString*)listname { [self getListByName:listname]; while (true) { printf("\n\n EDITING ITEMS IN LIST %s\n", [listname UTF8String]); [self displayItems:listname withPrompt:NO]; - printf(" Please select an item to be edited:\n\n "); + printf(" Please select an item to be edited:\n\n"); [self editItemsInListSelector:listname]; [self editItemPrompt:listname]; -// NSString *input = [self parse]; -// int itemInput; -// int itemInput2; -// int itemInput3; -// scanf("%d%*c", &itemInput); -// fpurge(stdin); -// printf("What edit would you like to perform on that item? \n 1) Reassign priority \n 2) Edit description \n 3) Change completion status"); -// scanf("%d%*c", &itemInput2); -// fpurge(stdin); -// if (itemInput2 == 1) { -// [[self getListByName:listname] editListPriority:itemInput withPriority:(scanf("%d%*c", &itemInput3))]; -// } else if (itemInput2 == 2) { -// [[self getListByName:listname] editListItemDescription:itemInput withString:[self parse]]; -// } else if (itemInput2 == 3) { -// -// } - - // [self *will create new method for editItemsInListPrompt* deleteItemPrompt:listname]; - - } } @@ -545,7 +516,7 @@ -(void)commandTree:(NSString *)command { } else if ([command containsString:@"delete items in "]) { [self deleteItems:[self snip:@"delete items in " fromCommand:command]]; } else if ([command containsString:@"display all items "]) { - [self editItemsInList:[self snip:@"display all items " fromCommand:command]]; + [self displayAllItems:[self snip:@"display all items " fromCommand:command]]; } else if ([command containsString:@"edit items in "]) { [self editItemsInList:[self snip:@"edit items in " fromCommand:command]]; } else if ([command isEqualToString:@"exit"]) { From 8d58abc515365c191f3d3ec64166aa85cf5ed6ff Mon Sep 17 00:00:00 2001 From: elberdev Date: Tue, 30 Jun 2015 11:17:40 -0400 Subject: [PATCH 34/43] implemented sort for -display all items- command and its variations. removed -withPrompt:- parameter from displayItems method and removed -display items in - functionality since it was redundant. Our code is actually getting leaner! --- TodoList/TodoList/main.m | 103 +++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 47 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index fafbe38..84f9c0f 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -159,11 +159,14 @@ -(void)run; @implementation ListManager { NSMutableArray *_listDatabase; + BOOL _ascending; + NSString *_sortDescriptorKey; } -(id)init { if (self = [super init]) { _listDatabase = [[NSMutableArray alloc] init]; + _sortDescriptorKey = [[NSString alloc] init]; } return self; } @@ -260,7 +263,7 @@ -(void)displayList:(NSString *)listName { } } else { printf("\n\n DISPLAYING LIST %s\n", [listName UTF8String]); - [self displayItems:listName withPrompt:NO]; + [self displayItems:listName]; } printf("\n"); @@ -290,42 +293,12 @@ -(void)newItem:(NSString *)listName { [self commandTree:[self parse]]; } --(void)displayItems:(NSString *)listName withPrompt:(BOOL)prompt{ - if (prompt == YES) { - printf("\n\n DISPLAYING ITEMS IN LIST %s\n\n", [listName UTF8String]); - } - +-(void)displayItems:(NSString *)listName { List *list = [self getListByName:listName]; NSMutableArray *array = [list listArray]; [self formatItems:array]; - - if (prompt == YES) { - [self commandTree:[self parse]]; - } - -} - -//////////// call this in displayItems ////////////////////////////////////////////////////// --(NSArray *)sortItems:(NSMutableArray *)array - by:(NSString *)descriptor - ascending:(BOOL)ascending { - - NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] init]; - - if ([descriptor isEqualToString:@"itemPriority"]) { - sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:descriptor - ascending:ascending]; - } else { - sortDescriptor = [NSSortDescriptor - sortDescriptorWithKey:descriptor - ascending:ascending - selector:@selector(localizedStandardCompare:)]; - } - - return [array sortedArrayUsingDescriptors:@[sortDescriptor]]; } -///////////////////////////////////////////////////////////////////////////////////////////// -(void)formatItems:(NSMutableArray *)array { @@ -352,12 +325,12 @@ -(void)formatItems:(NSMutableArray *)array { } // crazy c formatting I have to use to make everything pretty - printf("\n | %*s %-*s priority completed\n", biggestNumPadding, + printf("\n | %*s %-*s priority done\n", biggestNumPadding, [[NSString stringWithFormat:@" "] UTF8String], longestLength, [description UTF8String]); for (int i = 0; i < [array count]; i++) { - printf(" |\n | %*s) %-*s %d %s \n", + printf(" |\n | %*s) %-*s %d %s\n", biggestNumPadding, [(num = [NSString stringWithFormat:@"%d", i]) UTF8String], longestLength, [[array[i] itemDescription] UTF8String], @@ -387,7 +360,7 @@ -(void)deleteItems:(NSString *)listName { [self getListByName:listName]; while (true) { printf("\n\n DELETING ITEMS IN LIST %s\n", [listName UTF8String]); - [self displayItems:listName withPrompt:NO]; + [self displayItems:listName]; printf(" Please select an item to be deleted:\n\n "); int input; scanf("%d%*c", &input); @@ -400,7 +373,37 @@ -(void)deleteItems:(NSString *)listName { } --(void)displayAllItems:(NSString *)order { +-(NSArray *)sortItems:(NSMutableArray *)array { + + NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] init]; + sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:_sortDescriptorKey + ascending:_ascending]; + // selector:@selector(localizedStandardCompare:)]; + // Don't forget to use this last parameter ^^^^^^^^^^^^^^^^^^^^ if you want to + // compare strings instead of numbers + + return [array sortedArrayUsingDescriptors:@[sortDescriptor]]; +} + +-(void)prioritySort:(NSString *)command { + if ([command containsString:@" high priority first"]) { + _ascending = YES; + _sortDescriptorKey = [NSString stringWithFormat:@"itemPriority"]; + } else if ([command containsString:@" low priority first"]) { + _ascending = NO; + _sortDescriptorKey = [NSString stringWithFormat:@"itemPriority"]; + } else if ([command containsString:@" not done first"]) { + _ascending = YES; + _sortDescriptorKey = [NSString stringWithFormat:@"doneStatus"]; + } else if ([command containsString:@" done first"]) { + _ascending = NO; + _sortDescriptorKey = [NSString stringWithFormat:@"doneStatus"]; + } else { + return; + } +} + +-(void)displayAllItems:(NSString *)command { NSMutableArray *combinedList = [[NSMutableArray alloc] init]; for (int i = 0; i < [_listDatabase count]; i++) { @@ -409,6 +412,15 @@ -(void)displayAllItems:(NSString *)order { } } + if ([command isEqualToString:@" high priority first"] || + [command isEqualToString:@" low priority first"] || + [command isEqualToString:@" done first"] || + [command isEqualToString:@" not done first"]) { + + [self prioritySort:command]; + combinedList = [NSMutableArray arrayWithArray:[self sortItems:combinedList]]; + } + [self formatItems:combinedList]; [self commandTree:[self parse]]; @@ -482,7 +494,7 @@ -(void)editItemsInList:(NSString*)listname { [self getListByName:listname]; while (true) { printf("\n\n EDITING ITEMS IN LIST %s\n", [listname UTF8String]); - [self displayItems:listname withPrompt:NO]; + [self displayItems:listname]; printf(" Please select an item to be edited:\n\n"); [self editItemsInListSelector:listname]; [self editItemPrompt:listname]; @@ -510,13 +522,10 @@ -(void)commandTree:(NSString *)command { [self displayList:[self snip:@"display list " fromCommand:command]]; } else if ([command containsString:@"new item in "]) { [self newItem:[self snip:@"new item in " fromCommand:command]]; - } else if ([command containsString:@"display items in "]) { - [self displayItems:[self snip:@"display items in " fromCommand:command] - withPrompt:YES]; } else if ([command containsString:@"delete items in "]) { [self deleteItems:[self snip:@"delete items in " fromCommand:command]]; - } else if ([command containsString:@"display all items "]) { - [self displayAllItems:[self snip:@"display all items " fromCommand:command]]; + } else if ([command containsString:@"display all items"]) { + [self displayAllItems:[self snip:@"display all items" fromCommand:command]]; } else if ([command containsString:@"edit items in "]) { [self editItemsInList:[self snip:@"edit items in " fromCommand:command]]; } else if ([command isEqualToString:@"exit"]) { @@ -561,17 +570,17 @@ -(void)help { printf("\n rename list \n"); printf("\n display list \n"); printf("\n new item in \n"); - printf("\n display items in \n"); +// printf("\n display items in \n"); printf("\n delete items in \n"); printf("\n edit items in \n"); printf("\n display all items first\n"); printf("\n sort selectors:\n\n"); printf(" high priority\n"); printf(" low priority\n"); - printf(" closest due date\n"); - printf(" farthest due date\n"); - printf(" completed\n"); - printf(" not completed\n"); +// printf(" closest due date\n"); +// printf(" farthest due date\n"); + printf(" done\n"); + printf(" not done\n"); printf("\n exit \n\n"); [self commandTree:[self parse]]; } From 2e2faa6b5addbad3d80de93bb6913453c68c078a Mon Sep 17 00:00:00 2001 From: Jackie Meggesto Date: Tue, 30 Jun 2015 13:58:41 -0400 Subject: [PATCH 35/43] changed 'helplp' section to reflect recently implemented functionality --- TodoList/TodoList/main.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 84f9c0f..f5ef9e3 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -575,8 +575,8 @@ -(void)help { printf("\n edit items in \n"); printf("\n display all items first\n"); printf("\n sort selectors:\n\n"); - printf(" high priority\n"); - printf(" low priority\n"); + printf(" high priority first\n"); + printf(" low priority first\n"); // printf(" closest due date\n"); // printf(" farthest due date\n"); printf(" done\n"); From 73c0a871e8beb88fa7cf213267d8b32bfc3b846e Mon Sep 17 00:00:00 2001 From: elberdev Date: Tue, 30 Jun 2015 14:02:29 -0400 Subject: [PATCH 36/43] minor aesthetic differences --- TodoList/TodoList/main.m | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 84f9c0f..02367b7 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -106,7 +106,7 @@ -(void)removeListItem:(int)index { if (index < [self.listArray count]) { [self.listArray removeObjectAtIndex:index]; } else { - printf("The list item you input does not exist\n"); + printf("\n The list item you input does not exist\n"); } } @@ -114,7 +114,7 @@ -(void)editListItemDescription:(int)index withString:(NSString *)string { if (index < [self.listArray count]) { [[self.listArray objectAtIndex:index] setItemDescription:string]; } else { - NSLog(@"\n The list item you input does not exist"); + printf("\n The list item you input does not exist\n"); } } @@ -122,7 +122,7 @@ -(void)editListPriority:(int)index withPriority:(int)priority { if (index < [self.listArray count]) { [[self.listArray objectAtIndex:index] setItemPriority:priority]; } else { - NSLog(@"\n The list item you input does not exist"); + printf("\n The list item you input does not exist\n"); } } @@ -131,7 +131,7 @@ -(void)editListDoneStatus:(int)index withDoneStatus:(BOOL)doneStatus { [[self.listArray objectAtIndex:index] setDoneStatus:doneStatus]; } else { - NSLog(@"\n The list item you input does not exist"); + printf("\n The list item you input does not exist\n"); } } @@ -188,7 +188,6 @@ -(void)removeList:(NSString *)name { if (found == NO) { printf("\nThere are no lists matching that name"); } - } -(List*)getListByName:(NSString*)listname { @@ -215,7 +214,6 @@ -(void)newList:(NSString *)newListName { -(void)deleteList:(NSString *)listName { [self getListByName:listName]; - NSString *confirm; while (true) { @@ -237,11 +235,9 @@ -(void)deleteList:(NSString *)listName { printf("\n"); [self commandTree:[self parse]]; - } -(void)renameList:(NSString *)listName { - [self getListByName:listName]; printf("\n\n PLEASE ENTER NEW NAME FOR LIST %s\n", [listName UTF8String]); NSString *newName = [self parse]; @@ -301,7 +297,6 @@ -(void)displayItems:(NSString *)listName { } -(void)formatItems:(NSMutableArray *)array { - if ([array count] == 0) { printf("\n No items to display\n\n"); return; @@ -341,7 +336,6 @@ -(void)formatItems:(NSMutableArray *)array { } -(void)deleteItemPrompt:(NSString*)listname { - printf("\n Do you want to delete more items? y/n\n"); NSString *prompt = [self parse]; if ([prompt isEqualToString:@"y"]) { @@ -356,7 +350,6 @@ -(void)deleteItemPrompt:(NSString*)listname { } -(void)deleteItems:(NSString *)listName { - [self getListByName:listName]; while (true) { printf("\n\n DELETING ITEMS IN LIST %s\n", [listName UTF8String]); @@ -374,7 +367,6 @@ -(void)deleteItems:(NSString *)listName { } -(NSArray *)sortItems:(NSMutableArray *)array { - NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] init]; sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:_sortDescriptorKey ascending:_ascending]; @@ -423,7 +415,6 @@ -(void)displayAllItems:(NSString *)command { [self formatItems:combinedList]; [self commandTree:[self parse]]; - } -(void)editItemsInListSelector:(NSString*)listname { @@ -476,7 +467,6 @@ -(void)editItemsInListSelector:(NSString*)listname { } -(void)editItemPrompt:(NSString*)listname { - printf("\n Do you want to edit more items? y/n\n"); NSString *prompt = [self parse]; if ([prompt isEqualToString:@"y"]) { @@ -505,7 +495,6 @@ -(void)editItemsInList:(NSString*)listname { -(NSString *)snip:(NSString *)toDelete fromCommand:(NSString *)command { command = [command stringByReplacingOccurrencesOfString:toDelete withString:@""]; - return command; } @@ -538,7 +527,6 @@ -(void)commandTree:(NSString *)command { } -(NSString *)parse { - printf("\n "); /* Allocate memory and check if okay. */ @@ -559,7 +547,6 @@ -(NSString *)parse { // change C string to NSString NSString *command = [NSString stringWithCString:commandC encoding:NSUTF8StringEncoding]; - return command; } From dc4ee3f378f4f68b43fb7dad3ce3fef91db27977 Mon Sep 17 00:00:00 2001 From: elberdev Date: Tue, 30 Jun 2015 16:13:10 -0400 Subject: [PATCH 37/43] implemented list sorting 100 percent. just need to handle annoying false warnign that pops in... --- TodoList/TodoList/main.m | 59 ++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 02367b7..3a84234 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -197,6 +197,7 @@ -(List*)getListByName:(NSString*)listname { } } printf("\n There are no lists by that name\n\n"); + [self commandTree:[self parse]]; return nil; } @@ -251,8 +252,8 @@ -(void)displayList:(NSString *)listName { if ([_listDatabase count] == 0) { printf("\n\n NO TO-DO LISTS TO DISPLAY\n"); - } else if ([listName isEqualToString:@"all"]) { - printf("\n\n DISPLAYING ALL TO-DO LISTS\n"); + } else if ([listName isEqualToString:@"summary"]) { + printf("\n\n DISPLAYING LIST SUMMARY\n"); for (int i = 0; i < [_listDatabase count]; i++) { printf("\n %s: %lu items\n", [[_listDatabase[i] name] UTF8String], (unsigned long)[_listDatabase[i] showNumberOfItems]); @@ -290,12 +291,21 @@ -(void)newItem:(NSString *)listName { } -(void)displayItems:(NSString *)listName { + [self prioritySort:listName]; + List *list = [self getListByName:listName]; NSMutableArray *array = [list listArray]; [self formatItems:array]; } +-(void)displayItemsWithSort:(NSString *)listName { + List *list = [self getListByName:listName]; + NSMutableArray *array = [list listArray]; + NSArray *sortedArray = [self sortItems:array]; + [self formatItems:[NSMutableArray arrayWithArray:sortedArray]]; +} + -(void)formatItems:(NSMutableArray *)array { if ([array count] == 0) { printf("\n No items to display\n\n"); @@ -381,18 +391,28 @@ -(void)prioritySort:(NSString *)command { if ([command containsString:@" high priority first"]) { _ascending = YES; _sortDescriptorKey = [NSString stringWithFormat:@"itemPriority"]; + command = [self snip:@" high priority first" fromCommand:command]; } else if ([command containsString:@" low priority first"]) { _ascending = NO; _sortDescriptorKey = [NSString stringWithFormat:@"itemPriority"]; + command = [self snip:@" low priority first" fromCommand:command]; } else if ([command containsString:@" not done first"]) { _ascending = YES; _sortDescriptorKey = [NSString stringWithFormat:@"doneStatus"]; + command = [self snip:@" not done first" fromCommand:command]; } else if ([command containsString:@" done first"]) { _ascending = NO; _sortDescriptorKey = [NSString stringWithFormat:@"doneStatus"]; + command = [self snip:@" done first" fromCommand:command]; } else { return; } + + // executes only when displaying an individual sorted list + if (![command isEqualToString:@""]) { + [self displayItemsWithSort:command]; + } + } -(void)displayAllItems:(NSString *)command { @@ -551,24 +571,27 @@ -(NSString *)parse { } -(void)help { - printf("\n\n AVAILABLE COMMANDS:\n"); - printf("\n new list \n"); - printf("\n delete list \n"); - printf("\n rename list \n"); - printf("\n display list \n"); - printf("\n new item in \n"); -// printf("\n display items in \n"); - printf("\n delete items in \n"); - printf("\n edit items in \n"); - printf("\n display all items first\n"); - printf("\n sort selectors:\n\n"); - printf(" high priority\n"); - printf(" low priority\n"); + printf("\n\n GENERAL COMMANDS:\n"); + printf("\n display list summary\n"); + printf(" display list \n"); + printf(" new list \n"); + printf(" delete list \n"); + printf(" rename list \n"); + printf(" display all items\n"); + printf(" new item in \n"); + printf(" edit items in \n"); + printf(" delete items in \n"); + printf(" exit\n"); + printf("\n SORTING COMMANDS:\n"); + printf("\n display list first\n"); + printf(" display all items first\n"); + printf("\n SORT SELECTORS:\n\n"); + printf(" high priority\n"); + printf(" low priority\n"); // printf(" closest due date\n"); // printf(" farthest due date\n"); - printf(" done\n"); - printf(" not done\n"); - printf("\n exit \n\n"); + printf(" done\n"); + printf(" not done\n\n"); [self commandTree:[self parse]]; } From 5401d009f41348f8e145cc012ba87cce7057def6 Mon Sep 17 00:00:00 2001 From: elberdev Date: Tue, 30 Jun 2015 20:33:56 -0400 Subject: [PATCH 38/43] fixed error message bug --- TodoList/TodoList/main.m | 65 +++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 3a84234..0be8709 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -191,15 +191,18 @@ -(void)removeList:(NSString *)name { } -(List*)getListByName:(NSString*)listname { + List *list = [[List alloc]init]; for (int i = 0; i < [_listDatabase count]; i++) { if ([listname isEqualToString:[_listDatabase[i] name]]) { - return _listDatabase[i]; + list = _listDatabase[i]; } } - printf("\n There are no lists by that name\n\n"); + + if (list == nil) { + printf("\n There are no lists by that name\n\n"); + } - [self commandTree:[self parse]]; - return nil; + return list; } -(void)newList:(NSString *)newListName { @@ -209,12 +212,12 @@ -(void)newList:(NSString *)newListName { [self addList:list]; printf("\n\n A NEW LIST HAS BEEN CREATED:\n"); printf("\n %s\n\n", [newListName UTF8String]); - - [self commandTree:[self parse]]; } -(void)deleteList:(NSString *)listName { - [self getListByName:listName]; + if ([self getListByName:listName] == nil) { + return; + } NSString *confirm; while (true) { @@ -234,22 +237,20 @@ -(void)deleteList:(NSString *)listName { } } printf("\n"); - - [self commandTree:[self parse]]; } -(void)renameList:(NSString *)listName { - [self getListByName:listName]; + if ([self getListByName:listName] == nil) { + return; + } printf("\n\n PLEASE ENTER NEW NAME FOR LIST %s\n", [listName UTF8String]); NSString *newName = [self parse]; [[self getListByName:listName] setName:newName]; printf("\n List %s has been renamed %s\n\n", [listName UTF8String], [newName UTF8String]); - [self commandTree:[self parse]]; } -(void)displayList:(NSString *)listName { - if ([_listDatabase count] == 0) { printf("\n\n NO TO-DO LISTS TO DISPLAY\n"); } else if ([listName isEqualToString:@"summary"]) { @@ -263,8 +264,6 @@ -(void)displayList:(NSString *)listName { [self displayItems:listName]; } printf("\n"); - - [self commandTree:[self parse]]; } -(void)newItem:(NSString *)listName { @@ -287,20 +286,27 @@ -(void)newItem:(NSString *)listName { [[[self getListByName:listName] listArray] addObject:newItem]; printf("\n to do item created successfully\n\n"); - [self commandTree:[self parse]]; } -(void)displayItems:(NSString *)listName { - [self prioritySort:listName]; - List *list = [self getListByName:listName]; + if (list == nil) { + return; + } + NSMutableArray *array = [list listArray]; + if (array == nil) { + return; + } [self formatItems:array]; } -(void)displayItemsWithSort:(NSString *)listName { List *list = [self getListByName:listName]; + if (list == nil) { + return; + } NSMutableArray *array = [list listArray]; NSArray *sortedArray = [self sortItems:array]; [self formatItems:[NSMutableArray arrayWithArray:sortedArray]]; @@ -388,29 +394,38 @@ -(NSArray *)sortItems:(NSMutableArray *)array { } -(void)prioritySort:(NSString *)command { + + BOOL sorting = NO; + if ([command containsString:@" high priority first"]) { + sorting = YES; _ascending = YES; _sortDescriptorKey = [NSString stringWithFormat:@"itemPriority"]; command = [self snip:@" high priority first" fromCommand:command]; } else if ([command containsString:@" low priority first"]) { + sorting = YES; _ascending = NO; _sortDescriptorKey = [NSString stringWithFormat:@"itemPriority"]; command = [self snip:@" low priority first" fromCommand:command]; } else if ([command containsString:@" not done first"]) { + sorting = YES; _ascending = YES; _sortDescriptorKey = [NSString stringWithFormat:@"doneStatus"]; command = [self snip:@" not done first" fromCommand:command]; } else if ([command containsString:@" done first"]) { + sorting = YES; _ascending = NO; _sortDescriptorKey = [NSString stringWithFormat:@"doneStatus"]; command = [self snip:@" done first" fromCommand:command]; } else { - return; + sorting = NO; } // executes only when displaying an individual sorted list - if (![command isEqualToString:@""]) { + if (sorting == YES) { [self displayItemsWithSort:command]; + } else { + [self displayItems:command]; } } @@ -433,8 +448,8 @@ -(void)displayAllItems:(NSString *)command { combinedList = [NSMutableArray arrayWithArray:[self sortItems:combinedList]]; } + printf("\n\n DISPLAYING ALL ITEMS%s\n", [command UTF8String]); [self formatItems:combinedList]; - [self commandTree:[self parse]]; } -(void)editItemsInListSelector:(NSString*)listname { @@ -528,7 +543,7 @@ -(void)commandTree:(NSString *)command { } else if ([command containsString:@"rename list "]) { [self renameList:[self snip:@"rename list " fromCommand:command]]; } else if ([command containsString:@"display list "]) { - [self displayList:[self snip:@"display list " fromCommand:command]]; + [self prioritySort:[self snip:@"display list " fromCommand:command]]; } else if ([command containsString:@"new item in "]) { [self newItem:[self snip:@"new item in " fromCommand:command]]; } else if ([command containsString:@"delete items in "]) { @@ -542,7 +557,6 @@ -(void)commandTree:(NSString *)command { } else { printf("\n NOT A RECOGNIZED COMMAND\n"); printf("\n Type 'help' for available commands\n\n"); - [self commandTree:[self parse]]; } } @@ -592,13 +606,14 @@ -(void)help { // printf(" farthest due date\n"); printf(" done\n"); printf(" not done\n\n"); - [self commandTree:[self parse]]; } -(void)run { printf("\n Welcome to the Elbo-Yucatan To-Do List Management System. \n"); printf("\n Type a command (or type 'help' for instructions)\n\n"); - [self commandTree:[self parse]]; + while (true) { + [self commandTree:[self parse]]; + } } @end //************************** end ListManager class ***************************// @@ -616,6 +631,7 @@ int main(int argc, const char * argv[]) { ListItem *item3 = [[ListItem alloc] init]; [item3 setItemDescription:@"call Robin"]; [item3 setItemPriority:4]; + [item3 setDoneStatus:YES]; ListItem *item4 = [[ListItem alloc] init]; [item4 setItemDescription:@"polish bat-mobile"]; ListItem *item5 = [[ListItem alloc] init]; @@ -629,6 +645,7 @@ int main(int argc, const char * argv[]) { ListItem *item8 = [[ListItem alloc] init]; [item8 setItemDescription:@"buy flowers for catwoman"]; [item8 setItemPriority:3]; + [item8 setDoneStatus:YES]; ListItem *item9 = [[ListItem alloc] init]; [item9 setItemDescription:@"fire alfred"]; [item9 setItemPriority:2]; From 0bee282cd8b3c39e5ff12472f6f54b3ad33edf95 Mon Sep 17 00:00:00 2001 From: elberdev Date: Tue, 30 Jun 2015 20:48:32 -0400 Subject: [PATCH 39/43] fixed display items messages --- TodoList/TodoList/main.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 0be8709..567e543 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -261,7 +261,7 @@ -(void)displayList:(NSString *)listName { } } else { printf("\n\n DISPLAYING LIST %s\n", [listName UTF8String]); - [self displayItems:listName]; + [self prioritySort:listName]; } printf("\n"); } @@ -543,7 +543,7 @@ -(void)commandTree:(NSString *)command { } else if ([command containsString:@"rename list "]) { [self renameList:[self snip:@"rename list " fromCommand:command]]; } else if ([command containsString:@"display list "]) { - [self prioritySort:[self snip:@"display list " fromCommand:command]]; + [self displayList:[self snip:@"display list " fromCommand:command]]; } else if ([command containsString:@"new item in "]) { [self newItem:[self snip:@"new item in " fromCommand:command]]; } else if ([command containsString:@"delete items in "]) { From d81025b17674aa715cf25556617ebec184a4a57a Mon Sep 17 00:00:00 2001 From: elberdev Date: Tue, 30 Jun 2015 21:45:51 -0400 Subject: [PATCH 40/43] fixing errors one by one. still have to catch errors in edit items --- TodoList/TodoList/main.m | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 567e543..41833c1 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -191,15 +191,20 @@ -(void)removeList:(NSString *)name { } -(List*)getListByName:(NSString*)listname { + + BOOL found = NO; List *list = [[List alloc]init]; + for (int i = 0; i < [_listDatabase count]; i++) { if ([listname isEqualToString:[_listDatabase[i] name]]) { + found = YES; list = _listDatabase[i]; } } - if (list == nil) { + if (found == NO) { printf("\n There are no lists by that name\n\n"); + return nil; } return list; @@ -219,7 +224,6 @@ -(void)deleteList:(NSString *)listName { return; } NSString *confirm; - while (true) { printf("\n\n ARE YOU SURE YOU WANT TO DELETE LIST %s?\n", [listName UTF8String]); @@ -260,6 +264,9 @@ -(void)displayList:(NSString *)listName { (unsigned long)[_listDatabase[i] showNumberOfItems]); } } else { + if ([self getListByName:listName] == nil) { + return; + } printf("\n\n DISPLAYING LIST %s\n", [listName UTF8String]); [self prioritySort:listName]; } @@ -267,7 +274,9 @@ -(void)displayList:(NSString *)listName { } -(void)newItem:(NSString *)listName { - [self getListByName:listName]; + if ([self getListByName:listName] == nil) { + return; + } ListItem *newItem = [[ListItem alloc]init]; printf("\n\n CREATING NEW ITEM IN LIST %s\n", [listName UTF8String]); @@ -366,7 +375,9 @@ -(void)deleteItemPrompt:(NSString*)listname { } -(void)deleteItems:(NSString *)listName { - [self getListByName:listName]; + if ([self getListByName:listName] == nil) { + return; + } while (true) { printf("\n\n DELETING ITEMS IN LIST %s\n", [listName UTF8String]); [self displayItems:listName]; @@ -515,14 +526,16 @@ -(void)editItemPrompt:(NSString*)listname { } } --(void)editItemsInList:(NSString*)listname { - [self getListByName:listname]; +-(void)editItemsInList:(NSString*)listName { + if ([self getListByName:listName] == nil) { + return; + } while (true) { - printf("\n\n EDITING ITEMS IN LIST %s\n", [listname UTF8String]); - [self displayItems:listname]; + printf("\n\n EDITING ITEMS IN LIST %s\n", [listName UTF8String]); + [self displayItems:listName]; printf(" Please select an item to be edited:\n\n"); - [self editItemsInListSelector:listname]; - [self editItemPrompt:listname]; + [self editItemsInListSelector:listName]; + [self editItemPrompt:listName]; } } From 8772d9406bf37b1e5e768c59a9150fa45a8542f5 Mon Sep 17 00:00:00 2001 From: elberdev Date: Wed, 1 Jul 2015 10:02:33 -0400 Subject: [PATCH 41/43] finally have the sorting working right as rain --- TodoList/TodoList/main.m | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 41833c1..64d94ee 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -264,10 +264,6 @@ -(void)displayList:(NSString *)listName { (unsigned long)[_listDatabase[i] showNumberOfItems]); } } else { - if ([self getListByName:listName] == nil) { - return; - } - printf("\n\n DISPLAYING LIST %s\n", [listName UTF8String]); [self prioritySort:listName]; } printf("\n"); @@ -302,20 +298,18 @@ -(void)displayItems:(NSString *)listName { if (list == nil) { return; } - + printf("\n\n DISPLAYING LIST %s\n", [listName UTF8String]); NSMutableArray *array = [list listArray]; - if (array == nil) { - return; - } - [self formatItems:array]; } --(void)displayItemsWithSort:(NSString *)listName { +-(void)displayItems:(NSString *)listName withSort:(NSString *)sortDescriptor { List *list = [self getListByName:listName]; if (list == nil) { return; } + printf("\n\n DISPLAYING LIST %s,%s\n", [listName UTF8String], + [sortDescriptor UTF8String]); NSMutableArray *array = [list listArray]; NSArray *sortedArray = [self sortItems:array]; [self formatItems:[NSMutableArray arrayWithArray:sortedArray]]; @@ -406,24 +400,29 @@ -(NSArray *)sortItems:(NSMutableArray *)array { -(void)prioritySort:(NSString *)command { + NSString *sortDescriptor = [[NSString alloc] init]; BOOL sorting = NO; if ([command containsString:@" high priority first"]) { + sortDescriptor = @" high priority first"; sorting = YES; _ascending = YES; _sortDescriptorKey = [NSString stringWithFormat:@"itemPriority"]; command = [self snip:@" high priority first" fromCommand:command]; } else if ([command containsString:@" low priority first"]) { + sortDescriptor = @" low priority first"; sorting = YES; _ascending = NO; _sortDescriptorKey = [NSString stringWithFormat:@"itemPriority"]; command = [self snip:@" low priority first" fromCommand:command]; } else if ([command containsString:@" not done first"]) { + sortDescriptor = @" not done first"; sorting = YES; _ascending = YES; _sortDescriptorKey = [NSString stringWithFormat:@"doneStatus"]; command = [self snip:@" not done first" fromCommand:command]; } else if ([command containsString:@" done first"]) { + sortDescriptor = @" done first"; sorting = YES; _ascending = NO; _sortDescriptorKey = [NSString stringWithFormat:@"doneStatus"]; @@ -434,7 +433,7 @@ -(void)prioritySort:(NSString *)command { // executes only when displaying an individual sorted list if (sorting == YES) { - [self displayItemsWithSort:command]; + [self displayItems:command withSort:sortDescriptor]; } else { [self displayItems:command]; } From 8ad07931790757348daca0ff4ac1bf945ff2c24a Mon Sep 17 00:00:00 2001 From: elberdev Date: Wed, 1 Jul 2015 11:15:53 -0400 Subject: [PATCH 42/43] added some while loops to --delete items-- and --edit items-- to catch invalid input. I AM DONE WITH THIS PROJECT! lol --- TodoList/TodoList/main.m | 172 ++++++++++++++++++++++++--------------- 1 file changed, 105 insertions(+), 67 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 64d94ee..9a0331b 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -279,28 +279,32 @@ -(void)newItem:(NSString *)listName { printf("\n Input to do item description: \n"); NSString *description = [self parse]; [newItem setItemDescription:description]; - printf("\n Input item priority from 1 (most pressing) to 4 (least pressing)\n\n "); + int priority; - scanf("%d%*c", &priority); - fpurge(stdin); - if (0 < priority && priority < 5) { - [newItem setItemPriority:priority]; - } else { - printf("\n INVALID INPUT\n"); + while (true) { + printf("\n Input item priority from 1 (most pressing) to 4 (least pressing)\n\n "); + scanf("%d%*c", &priority); + fpurge(stdin); + if (0 < priority && priority < 5) { + [newItem setItemPriority:priority]; + break; + } else { + printf("\n INVALID INPUT\n"); + } } [[[self getListByName:listName] listArray] addObject:newItem]; - - printf("\n to do item created successfully\n\n"); + printf("\n TO DO ITEM CREATED SUCCESSFULLY\n\n"); } --(void)displayItems:(NSString *)listName { +-(int)displayItems:(NSString *)listName { List *list = [self getListByName:listName]; if (list == nil) { - return; + return 0; } printf("\n\n DISPLAYING LIST %s\n", [listName UTF8String]); NSMutableArray *array = [list listArray]; [self formatItems:array]; + return (int)[array count]; } -(void)displayItems:(NSString *)listName withSort:(NSString *)sortDescriptor { @@ -372,19 +376,25 @@ -(void)deleteItems:(NSString *)listName { if ([self getListByName:listName] == nil) { return; } + printf("\n\n DELETING ITEMS IN LIST %s\n", [listName UTF8String]); + + int itemIndex; + int count; while (true) { - printf("\n\n DELETING ITEMS IN LIST %s\n", [listName UTF8String]); - [self displayItems:listName]; - printf(" Please select an item to be deleted:\n\n "); - int input; - scanf("%d%*c", &input); + count = [self displayItems:listName]; + printf(" Please select an item to be deleted:\n\n"); + printf("\n "); + scanf("%d%*c", &itemIndex); fpurge(stdin); - [[self getListByName:listName] removeListItem:input]; - printf("\n Item has been deleted.\n"); - [self deleteItemPrompt:listName]; - + if(0 <= itemIndex && itemIndex < count) { + break; + } else { + printf("\n INVALID INPUT"); + } } - + [[self getListByName:listName] removeListItem:itemIndex]; + printf("\n Item has been deleted\n"); + [self deleteItemPrompt:listName]; } -(NSArray *)sortItems:(NSMutableArray *)array { @@ -440,7 +450,7 @@ -(void)prioritySort:(NSString *)command { } --(void)displayAllItems:(NSString *)command { +-(void)displayAllItems:(NSString *)command withSort:(BOOL)sort { NSMutableArray *combinedList = [[NSMutableArray alloc] init]; for (int i = 0; i < [_listDatabase count]; i++) { @@ -456,57 +466,86 @@ -(void)displayAllItems:(NSString *)command { [self prioritySort:command]; combinedList = [NSMutableArray arrayWithArray:[self sortItems:combinedList]]; + } else { + if (sort == YES) { + printf("\n INVALID SORT SELECTOR\n\n"); + return; + } } - printf("\n\n DISPLAYING ALL ITEMS%s\n", [command UTF8String]); + printf("\n\n DISPLAYING ALL ITEMS,%s\n", [command UTF8String]); [self formatItems:combinedList]; } --(void)editItemsInListSelector:(NSString*)listname { - int itemIndex; - int editOption; - int newPriority; - NSString *myInput; - - printf("\n "); - scanf("%d%*c", &itemIndex); - fpurge(stdin); - - printf("\n What edit would you like to perform on that item?\n"); - printf("\n 1) Reassign priority\n"); - printf("\n 2) Edit description\n"); - printf("\n 3) Change completion status\n"); +-(void)editItemsInListSelector:(NSString*)listName { - printf("\n\n "); - scanf("%d%*c", &editOption); - fpurge(stdin); - - if (editOption == 1) { - printf("\n Enter a value from 1 (greatest priority) to 4 (least priority)\n"); + int itemIndex; + int count; + while (true) { + count = [self displayItems:listName]; + printf(" Please select an item to be edited:\n\n"); printf("\n "); - scanf("%d", &newPriority); + scanf("%d%*c", &itemIndex); + fpurge(stdin); + if(0 <= itemIndex && itemIndex < count) { + break; + } + printf("\n INVALID INPUT"); + } + + int editOption; + while (true) { + printf("\n What edit would you like to perform on that item?\n"); + printf("\n 1) Reassign priority\n"); + printf("\n 2) Edit description\n"); + printf("\n 3) Change completion status\n"); + + printf("\n\n "); + scanf("%d%*c", &editOption); fpurge(stdin); - if (0 < newPriority && newPriority < 5) { - [[self getListByName:listname] editListPriority:itemIndex - withPriority:newPriority]; + if(0 < editOption && editOption < 4) { + break; } else { printf("\n INVALID INPUT\n"); } + } + + if (editOption == 1) { + int newPriority; + while (true) { + printf("\n Enter a value from 1 (greatest priority) to 4 (least priority)\n"); + printf("\n "); + scanf("%d", &newPriority); + fpurge(stdin); + if (0 < newPriority && newPriority < 5) { + [[self getListByName:listName] editListPriority:itemIndex + withPriority:newPriority]; + break; + } else { + printf("\n INVALID INPUT\n"); + } + } + } else if (editOption == 2) { printf("\n Input a new description for this item:\n"); - [[self getListByName:listname] editListItemDescription:itemIndex + [[self getListByName:listName] editListItemDescription:itemIndex withString:[self parse]]; } else if (editOption == 3) { - printf("\n Please enter 'y' for done, or 'n' for not done \n"); - myInput = [self parse]; - if ([myInput isEqualToString:@"y"]) { - [[self getListByName:listname] editListDoneStatus:itemIndex - withDoneStatus:YES]; - } else if ([myInput isEqualToString:@"n"]) { - [[self getListByName:listname] editListDoneStatus:itemIndex - withDoneStatus:NO]; - } else { - printf("\n INVALID INPUT\n"); + NSString *myInput; + while (true) { + printf("\n Please enter 'y' for done, or 'n' for not done \n"); + myInput = [self parse]; + if ([myInput isEqualToString:@"y"]) { + [[self getListByName:listName] editListDoneStatus:itemIndex + withDoneStatus:YES]; + break; + } else if ([myInput isEqualToString:@"n"]) { + [[self getListByName:listName] editListDoneStatus:itemIndex + withDoneStatus:NO]; + break; + } else { + printf("\n INVALID INPUT\n"); + } } } } @@ -529,14 +568,9 @@ -(void)editItemsInList:(NSString*)listName { if ([self getListByName:listName] == nil) { return; } - while (true) { - printf("\n\n EDITING ITEMS IN LIST %s\n", [listName UTF8String]); - [self displayItems:listName]; - printf(" Please select an item to be edited:\n\n"); - [self editItemsInListSelector:listName]; - [self editItemPrompt:listName]; - - } + printf("\n\n EDITING ITEMS IN LIST %s\n", [listName UTF8String]); + [self editItemsInListSelector:listName]; + [self editItemPrompt:listName]; } -(NSString *)snip:(NSString *)toDelete fromCommand:(NSString *)command { @@ -560,8 +594,12 @@ -(void)commandTree:(NSString *)command { [self newItem:[self snip:@"new item in " fromCommand:command]]; } else if ([command containsString:@"delete items in "]) { [self deleteItems:[self snip:@"delete items in " fromCommand:command]]; + } else if ([command isEqualToString:@"display all items"]) { + [self displayAllItems:[self snip:@"display all items" fromCommand:command] + withSort:NO]; } else if ([command containsString:@"display all items"]) { - [self displayAllItems:[self snip:@"display all items" fromCommand:command]]; + [self displayAllItems:[self snip:@"display all items" fromCommand:command] + withSort:YES]; } else if ([command containsString:@"edit items in "]) { [self editItemsInList:[self snip:@"edit items in " fromCommand:command]]; } else if ([command isEqualToString:@"exit"]) { From b3b9c1f49e0a0c3c747e0fb07ddf0a6b0126b7f4 Mon Sep 17 00:00:00 2001 From: elberdev Date: Wed, 1 Jul 2015 17:13:17 -0400 Subject: [PATCH 43/43] added some slight error-handling tweaks --- TodoList/TodoList/main.m | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 9a0331b..ac17d5f 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -479,7 +479,7 @@ -(void)displayAllItems:(NSString *)command withSort:(BOOL)sort { -(void)editItemsInListSelector:(NSString*)listName { - int itemIndex; + int itemIndex = -1; int count; while (true) { count = [self displayItems:listName]; @@ -493,7 +493,7 @@ -(void)editItemsInListSelector:(NSString*)listName { printf("\n INVALID INPUT"); } - int editOption; + int editOption = -1; while (true) { printf("\n What edit would you like to perform on that item?\n"); printf("\n 1) Reassign priority\n"); @@ -511,7 +511,7 @@ -(void)editItemsInListSelector:(NSString*)listName { } if (editOption == 1) { - int newPriority; + int newPriority = -1; while (true) { printf("\n Enter a value from 1 (greatest priority) to 4 (least priority)\n"); printf("\n "); @@ -531,7 +531,7 @@ -(void)editItemsInListSelector:(NSString*)listName { [[self getListByName:listName] editListItemDescription:itemIndex withString:[self parse]]; } else if (editOption == 3) { - NSString *myInput; + NSString *myInput = @"z"; while (true) { printf("\n Please enter 'y' for done, or 'n' for not done \n"); myInput = [self parse]; @@ -652,8 +652,6 @@ -(void)help { printf("\n SORT SELECTORS:\n\n"); printf(" high priority\n"); printf(" low priority\n"); -// printf(" closest due date\n"); -// printf(" farthest due date\n"); printf(" done\n"); printf(" not done\n\n"); }