typedef struct Menu Menu;
typedef struct MenuItem MenuItem;
-extern MenuItem* create_menuitem(char* contents);
+extern MenuItem* create_menuitem(char* title);
extern Menu* create_menu(char* menu_name, MenuItem** item_list);
+
extern WINDOW* get_menu_win(Menu* menu);
-extern int set_menu_win(Menu* menu, WINDOW* win);
extern WINDOW* get_menu_subwin(Menu* menu);
extern MenuItem* get_menu_item(Menu* menu, int index);
-extern int set_menu_focus(Menu* menu, bool focus);
extern int get_selected_item(Menu* menu);
-extern int set_selected_item(Menu* menu, int selected_item);
extern int get_menu_length(Menu* menu);
extern char* get_menu_name(Menu* menu);
+extern char* get_menuitem_title(MenuItem* menuitem);
+extern char* get_menuitem_descrip(MenuItem* menuitem);
+
+extern int set_menu_win(Menu* menu, WINDOW* win);
+extern int set_selected_item(Menu* menu, int selected_item);
+extern int set_menu_focus(Menu* menu, bool focus);
extern int insert_item(Menu* menu, MenuItem* menuitem, int index);
extern int delete_item(Menu* menu, int index);
#include <assert.h>
#include <md4c.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef enum SubTaskState {
SubTaskState_todo,
SubTaskState_done
} Board;
extern Board* begin_parse(char* board_path);
-extern int begin_write(Board* Board);
-
+extern int begin_write(char* board_path, Board* board);
extern void log_todo(Board* board);
+#ifdef __cplusplus
+}
+#endif
+
#endif
#define MAX_CONTENTS_LENGTH 256
typedef struct MenuItem {
- char* contents;
+ char* title;
char* description;
} MenuItem;
MenuItem*
-create_menuitem(char* contents)
+create_menuitem(char* title)
{
MenuItem* new_menuitem;
new_menuitem = malloc(sizeof(MenuItem));
- new_menuitem->contents = contents;
+ new_menuitem->title = title;
+ new_menuitem->description = 0; //TEMP FOR NOW
return new_menuitem;
}
return new_menu;
}
+/* getters */
WINDOW*
get_menu_win(Menu* menu)
{
return menu->menu_win;
}
-int
-set_menu_win(Menu* menu, WINDOW* win)
-{
- int height, width;
-
- menu->menu_win = win;
- getmaxyx(menu->menu_win, height, width);
-
- /* create a subwin (also prob free old subwin?) */
- menu->max_height = height-MENU_PAD_TOP-MENU_PAD_BOTTOM;
- menu->max_width = width-MENU_PAD_LEFT-MENU_PAD_RIGHT;
- menu->sub_win = derwin(
- menu->menu_win,
- menu->max_height,
- menu->max_width,
- MENU_PAD_TOP,
- MENU_PAD_LEFT
- );
-
- return 0;
-}
-
WINDOW*
get_menu_subwin(Menu* menu)
{
}
int
-set_menu_focus(Menu* menu, bool focus)
+get_selected_item(Menu* menu)
{
- menu->focused = focus;
-
- return 0;
+ return menu->selected_item;
}
int
-get_selected_item(Menu* menu)
+get_menu_length(Menu* menu)
{
- return menu->selected_item;
+ return menu->menu_length;
+}
+
+char*
+get_menu_name(Menu* menu)
+{
+ return menu->menu_name;
+}
+
+char*
+get_menuitem_title(MenuItem* menuitem)
+{
+ return menuitem->title;
+}
+
+char*
+get_menuitem_descrip(MenuItem* menuitem)
+{
+ return menuitem->description;
}
+
+/* setters */
int
-set_selected_item(Menu* menu, int selected_item)
+set_menu_win(Menu* menu, WINDOW* win)
{
- menu->selected_item = selected_item;
+ int height, width;
+
+ menu->menu_win = win;
+ getmaxyx(menu->menu_win, height, width);
+
+ /* create a subwin (also prob free old subwin?) */
+ menu->max_height = height-MENU_PAD_TOP-MENU_PAD_BOTTOM;
+ menu->max_width = width-MENU_PAD_LEFT-MENU_PAD_RIGHT;
+ menu->sub_win = derwin(
+ menu->menu_win,
+ menu->max_height,
+ menu->max_width,
+ MENU_PAD_TOP,
+ MENU_PAD_LEFT
+ );
return 0;
}
int
-get_menu_length(Menu* menu)
+set_selected_item(Menu* menu, int selected_item)
{
- return menu->menu_length;
+ menu->selected_item = selected_item;
+
+ return 0;
}
-char*
-get_menu_name(Menu* menu)
+int
+set_menu_focus(Menu* menu, bool focus)
{
- return menu->menu_name;
+ menu->focused = focus;
+
+ return 0;
}
+
int
swap_item(Menu* menu, int src_index, int dest_index)
{
- ar_swap_item(menu->menu_items, src_index, dest_index);
+ ar_swap_item((void**)menu->menu_items, src_index, dest_index);
return 0;
}
curs_on();
/* move cursor to right spot */
- ungetstr(menu->menu_items[insert_index]->contents);
+ ungetstr(menu->menu_items[insert_index]->title);
mvwgetnstr(menu->sub_win,
insert_index, // account for wrap later too
0,
/* copy out */
new_contents = strdup(temp);
- menu->menu_items[insert_index]->contents = new_contents;
+ menu->menu_items[insert_index]->title = new_contents;
/* delete if empty - maybe move this to a cleanup stage */
if (strlen(new_contents) == 0) {
char* wrapped_text;
/* wrap text by inserting newlines (maxwidth-1 for newline char)*/
- wrapped_text = wrap_text(menu->menu_items[i]->contents, menu->max_width-1, &wrapped_lines);
+ wrapped_text = wrap_text(menu->menu_items[i]->title, menu->max_width-1, &wrapped_lines);
/* color selected item */
wattron(menu->sub_win, COLOR_PAIR(
};
-void
-log_todo(Board* board)
-{
- for (int i = 0; i < board->todolist_count; i++) {
- TodoList* todolist;
- printf("List =-=-=-=-=-==-=-=-=-=-=-\n");
- todolist = board->todolist_list[i];
- printf("List name: %s\n", todolist->list_name);
- printf("Num of items: %d\n", todolist->item_count);
-
- for (int j = 0; j < todolist->item_count; j++) {
- TodoItem* todoitem;
- printf("Item =-=-=-=-=-\n");
- todoitem = todolist->item_list[j];
- printf("Item name: %s\n", todoitem->item_name);
- printf("Description: %s\n", todoitem->description);
- printf("Num of subtasks: %d\n", todoitem->subtask_count);
-
- for (int k = 0; k < todoitem->subtask_count; k++) {
- SubTask* subtask;
- int done;
-
- subtask = todoitem->subtask_list[k];
- printf("Subtask: %s, %d\n", subtask->subtask_name, subtask->done);
- }
- }
- }
-}
-
+/* reading */
Board*
begin_parse(char* board_path)
{
file = fopen(file_name, "r");
if (file == NULL) {
- printf("Something went wrong opening file\n");
+ perror("read_file > fopen");
return NULL;
}
{
#define st state->cur_todolist
- TodoList* todolist;
- TodoItem** item_list;
-
if (state->cur_todoitem == NULL) return;
/* append current item to todo list */
- todolist = state->cur_todolist;
- item_list = todolist->item_list;
-
st->item_count += 1;
st->item_list = realloc(st->item_list, st->item_count*sizeof(TodoItem*));
st->item_list[st->item_count-1] = state->cur_todoitem;
state->cur_todoitem = NULL;
+ #undef st
}
void
{
return;
}
+
+/* writing */
+int
+begin_write(char* board_path, Board* board)
+{ // TODO, make a backup file of board before write in case it crashes
+
+ FILE* file;
+
+ file = fopen(board_path, "w+");
+ if (file == NULL) {
+ perror("begin_write > fopen");
+ return -1;
+ }
+
+ for (int i = 0; i < board->todolist_count; i++) {
+ TodoList* cur_todolist = board->todolist_list[i];
+
+ fprintf(file, "## %s\n", cur_todolist->list_name);
+
+ for (int j = 0; j < cur_todolist->item_count; j++) {
+ TodoItem* cur_todoitem = cur_todolist->item_list[j];
+
+ fprintf(file, "### %s\n", cur_todoitem->item_name);
+
+ // write the other fields later!!!
+
+ }
+
+ }
+
+ fclose(file);
+
+ return 0;
+}
+
+/* others */
+void
+log_todo(Board* board)
+{
+ for (int i = 0; i < board->todolist_count; i++) {
+ TodoList* todolist;
+ printf("List =-=-=-=-=-==-=-=-=-=-=-\n");
+ todolist = board->todolist_list[i];
+ printf("List name: %s\n", todolist->list_name);
+ printf("Num of items: %d\n", todolist->item_count);
+
+ for (int j = 0; j < todolist->item_count; j++) {
+ TodoItem* todoitem;
+ printf("Item =-=-=-=-=-\n");
+ todoitem = todolist->item_list[j];
+ printf("Item name: %s\n", todoitem->item_name);
+ printf("Description: %s\n", todoitem->description);
+ printf("Num of subtasks: %d\n", todoitem->subtask_count);
+
+ for (int k = 0; k < todoitem->subtask_count; k++) {
+ SubTask* subtask;
+ int done;
+
+ subtask = todoitem->subtask_list[k];
+ printf("Subtask: %s, %d\n", subtask->subtask_name, subtask->done);
+ }
+ }
+ }
+}
break;
case BINDING_WRITE:
+ {
+ Board* writeboard;
+
+ writeboard = boardmenu_to_board(boardmenu);
+
+ /* mvprintw(30, 5, "%s", writeboard->todolist_list[0]->list_name); */
+ begin_write(boardfile_name, writeboard);
+
+ /* now free the writeborad */
+
+ }
+
break;
}
render_menu(boardmenu->menu_list[i]);
}
-
}
exit_tscurses();
Board*
boardmenu_to_board(BoardMenu* boardmenu)
-{
- Board newboard = malloc(sizeof(Board));
- TodoList** todolist_list = malloc(sizeof(TodoList*));
+{ // STRINGS are sharing the same address as the one in MENU
+ // and MENUITEM, this may break something if u free this board
+ // consider copying the string
+
+ Board* newboard = malloc(sizeof(Board));
+ TodoList** new_todolist_list = malloc(sizeof(TodoList*));
for (int i = 0; i < boardmenu->menu_count; i++) {
Menu* curmenu = boardmenu->menu_list[i];
new_todolist->list_name = get_menu_name(curmenu);
new_todolist->item_count = get_menu_length(curmenu);
- /* for (int j = 0; j < get_menu_length(curmenu); j++) { */
+ for (int j = 0; j < get_menu_length(curmenu); j++) {
+ MenuItem* curmenuitem = get_menu_item(curmenu, j);
+
+ TodoItem* new_todoitem = malloc(sizeof(TodoItem));
+
+ new_todoitem->item_name = get_menuitem_title(curmenuitem);
+ new_todoitem->description = get_menuitem_descrip(curmenuitem);
+ new_todoitem->due = 0; //TEMP!
+ new_todoitem->subtask_list = 0; //TEMP!
+ new_todoitem->subtask_count = 0; //TEMP!
+
+ item_list[j] = new_todoitem;
- /* } */
+ }
new_todolist->item_list = item_list;
+
+ new_todolist_list[i] = new_todolist;
}
- newboard->todolist_list = todolist_list;
+ newboard->todolist_list = new_todolist_list;
newboard->todolist_count = boardmenu->menu_count;
return newboard;
clear();
/* swap in array */
- ar_swap_item(boardmenu->menu_list, src_index, dest_index);
+ ar_swap_item((void*)boardmenu->menu_list, src_index, dest_index);
return 0;
}