diff options
-rw-r--r-- | src/calcurse.c | 66 | ||||
-rw-r--r-- | src/calcurse.h | 26 | ||||
-rw-r--r-- | src/io.c | 4 | ||||
-rw-r--r-- | src/todo.c | 179 | ||||
-rw-r--r-- | src/ui-todo.c | 207 | ||||
-rw-r--r-- | src/wins.c | 2 |
6 files changed, 242 insertions, 242 deletions
diff --git a/src/calcurse.c b/src/calcurse.c index 3bb1c8c..227c83f 100644 --- a/src/calcurse.c +++ b/src/calcurse.c @@ -70,8 +70,8 @@ static inline void key_generic_change_view(void) /* Select the event to highlight. */ switch (wins_slctd()) { case TOD: - if ((todo_hilt() == 0) && (todo_nb() > 0)) - todo_hilt_set(1); + if ((ui_todo_hilt() == 0) && (ui_todo_nb() > 0)) + ui_todo_hilt_set(1); break; case APP: if ((ui_day_hilt() == 0) && ((inday.nb_events + inday.nb_apoints) > 0)) @@ -111,8 +111,8 @@ static inline void key_view_item(void) { if ((wins_slctd() == APP) && (ui_day_hilt() != 0)) day_popup_item(day_get_item(ui_day_hilt())); - else if ((wins_slctd() == TOD) && (todo_hilt() != 0)) - item_in_popup(NULL, NULL, todo_saved_mesg(), _("To do :")); + else if ((wins_slctd() == TOD) && (ui_todo_hilt() != 0)) + item_in_popup(NULL, NULL, ui_todo_saved_mesg(), _("To do :")); wins_update(FLAG_ALL); } @@ -134,8 +134,8 @@ static inline void key_generic_add_appt(void) static inline void key_generic_add_todo(void) { ui_todo_add(); - if (todo_hilt() == 0 && todo_nb() == 1) - todo_hilt_increase(1); + if (ui_todo_hilt() == 0 && ui_todo_nb() == 1) + ui_todo_hilt_increase(1); wins_update(FLAG_TOD | FLAG_STA); } @@ -149,8 +149,8 @@ static inline void key_add_item(void) break; case TOD: ui_todo_add(); - if (todo_hilt() == 0 && todo_nb() == 1) - todo_hilt_increase(1); + if (ui_todo_hilt() == 0 && ui_todo_nb() == 1) + ui_todo_hilt_increase(1); wins_update(FLAG_TOD | FLAG_STA); break; default: @@ -164,7 +164,7 @@ static inline void key_edit_item(void) ui_day_item_edit(); inday = do_storage(0); wins_update(FLAG_CAL | FLAG_APP | FLAG_STA); - } else if (wins_slctd() == TOD && todo_hilt() != 0) { + } else if (wins_slctd() == TOD && ui_todo_hilt() != 0) { ui_todo_edit(); wins_update(FLAG_TOD | FLAG_STA); } @@ -176,7 +176,7 @@ static inline void key_del_item(void) ui_day_item_delete(&inday.nb_events, &inday.nb_apoints, reg); inday = do_storage(0); wins_update(FLAG_CAL | FLAG_APP | FLAG_STA); - } else if (wins_slctd() == TOD && todo_hilt() != 0) { + } else if (wins_slctd() == TOD && ui_todo_hilt() != 0) { ui_todo_delete(); wins_update(FLAG_TOD | FLAG_STA); } @@ -214,8 +214,8 @@ static inline void key_flag_item(void) day_item_switch_notify(day_get_item(ui_day_hilt())); inday = do_storage(0); wins_update(FLAG_APP); - } else if (wins_slctd() == TOD && todo_hilt() != 0) { - todo_flag(todo_get_item(todo_hilt())); + } else if (wins_slctd() == TOD && ui_todo_hilt() != 0) { + todo_flag(todo_get_item(ui_todo_hilt())); wins_update(FLAG_TOD); } } @@ -224,19 +224,19 @@ static inline void key_pipe_item(void) { if (wins_slctd() == APP && ui_day_hilt() != 0) ui_day_item_pipe(); - else if (wins_slctd() == TOD && todo_hilt() != 0) + else if (wins_slctd() == TOD && ui_todo_hilt() != 0) ui_todo_pipe(); wins_update(FLAG_ALL); } static inline void change_priority(int diff) { - if (wins_slctd() == TOD && todo_hilt() != 0) { - todo_chg_priority(todo_get_item(todo_hilt()), diff); - if (todo_hilt_pos() < 0) - todo_set_first(todo_hilt()); - else if (todo_hilt_pos() >= win[TOD].h - 4) - todo_set_first(todo_hilt() - win[TOD].h + 5); + if (wins_slctd() == TOD && ui_todo_hilt() != 0) { + ui_todo_chg_priority(todo_get_item(ui_todo_hilt()), diff); + if (ui_todo_hilt_pos() < 0) + ui_todo_set_first(ui_todo_hilt()); + else if (ui_todo_hilt_pos() >= win[TOD].h - 4) + ui_todo_set_first(ui_todo_hilt() - win[TOD].h + 5); wins_update(FLAG_TOD); } } @@ -256,8 +256,8 @@ static inline void key_edit_note(void) if (wins_slctd() == APP && ui_day_hilt() != 0) { day_edit_note(day_get_item(ui_day_hilt()), conf.editor); inday = do_storage(0); - } else if (wins_slctd() == TOD && todo_hilt() != 0) - todo_edit_note(todo_get_item(todo_hilt()), conf.editor); + } else if (wins_slctd() == TOD && ui_todo_hilt() != 0) + todo_edit_note(todo_get_item(ui_todo_hilt()), conf.editor); wins_update(FLAG_ALL); } @@ -265,8 +265,8 @@ static inline void key_view_note(void) { if (wins_slctd() == APP && ui_day_hilt() != 0) day_view_note(day_get_item(ui_day_hilt()), conf.pager); - else if (wins_slctd() == TOD && todo_hilt() != 0) - todo_view_note(todo_get_item(todo_hilt()), conf.pager); + else if (wins_slctd() == TOD && ui_todo_hilt() != 0) + todo_view_note(todo_get_item(ui_todo_hilt()), conf.pager); wins_update(FLAG_ALL); } @@ -359,11 +359,11 @@ static inline void key_move_up(void) ui_day_scroll_pad_up(inday.nb_events); wins_update(FLAG_APP); } else if (wins_slctd() == TOD) { - if (count >= todo_hilt()) - count = todo_hilt() - 1; - todo_hilt_decrease(count); - if (todo_hilt_pos() < 0) - todo_first_increase(todo_hilt_pos()); + if (count >= ui_todo_hilt()) + count = ui_todo_hilt() - 1; + ui_todo_hilt_decrease(count); + if (ui_todo_hilt_pos() < 0) + ui_todo_first_increase(ui_todo_hilt_pos()); wins_update(FLAG_TOD); } } @@ -386,11 +386,11 @@ static inline void key_move_down(void) ui_day_scroll_pad_down(inday.nb_events, win[APP].h); wins_update(FLAG_APP); } else if (wins_slctd() == TOD) { - if (count > todo_nb() - todo_hilt()) - count = todo_nb() - todo_hilt(); - todo_hilt_increase(count); - if (todo_hilt_pos() >= win[TOD].h - 4) - todo_first_increase(todo_hilt_pos() - win[TOD].h + 5); + if (count > ui_todo_nb() - ui_todo_hilt()) + count = ui_todo_nb() - ui_todo_hilt(); + ui_todo_hilt_increase(count); + if (ui_todo_hilt_pos() >= win[TOD].h - 4) + ui_todo_first_increase(ui_todo_hilt_pos() - win[TOD].h + 5); wins_update(FLAG_TOD); } } diff --git a/src/calcurse.h b/src/calcurse.h index 46eb56c..22c4fe8 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -914,24 +914,24 @@ void sigs_unignore(void); /* todo.c */ extern llist_t todolist; struct todo *todo_get_item(int); -void todo_hilt_set(int); -void todo_hilt_decrease(int); -void todo_hilt_increase(int); -int todo_hilt(void); -int todo_nb(void); -void todo_set_nb(int); -void todo_set_first(int); -void todo_first_increase(int); -void todo_first_decrease(int); -int todo_hilt_pos(void); -char *todo_saved_mesg(void); +void ui_todo_hilt_set(int); +void ui_todo_hilt_decrease(int); +void ui_todo_hilt_increase(int); +int ui_todo_hilt(void); +int ui_todo_nb(void); +void ui_todo_set_nb(int); +void ui_todo_set_first(int); +void ui_todo_first_increase(int); +void ui_todo_first_decrease(int); +int ui_todo_hilt_pos(void); +char *ui_todo_saved_mesg(void); struct todo *todo_add(char *, int, char *); void todo_write(struct todo *, FILE *); void todo_delete_note(struct todo *); void todo_delete(struct todo *); void todo_flag(struct todo *); -void todo_chg_priority(struct todo *, int); -void todo_update_panel(int); +void ui_todo_chg_priority(struct todo *, int); +void ui_todo_update_panel(int); void todo_edit_note(struct todo *, const char *); void todo_view_note(struct todo *, const char *); void todo_free(struct todo *); @@ -640,7 +640,7 @@ void io_load_todo(void) ++nb_tod; } file_close(data_file, __FILE_POS__); - todo_set_nb(nb_tod); + ui_todo_set_nb(nb_tod); } static void @@ -1022,7 +1022,7 @@ void io_import_data(enum import_type type, const char *stream_name) snprintf(stats_str[3], BUFSIZ, _("%d skipped"), stats.skipped); /* Update the number of todo items. */ - todo_set_nb(todo_nb() + stats.todos); + ui_todo_set_nb(ui_todo_nb() + stats.todos); if (ui_mode == UI_CURSES && conf.system_dialogs) { char read[BUFSIZ], stat[BUFSIZ]; @@ -41,10 +41,6 @@ #include "calcurse.h" llist_t todolist; -static int hilt = 0; -static int todos = 0; -static int first = 1; -static char *msgsav; /* Returns a structure containing the selected item. */ struct todo *todo_get_item(int item_number) @@ -52,71 +48,6 @@ struct todo *todo_get_item(int item_number) return LLIST_GET_DATA(LLIST_NTH(&todolist, item_number - 1)); } -/* Sets which todo is highlighted. */ -void todo_hilt_set(int highlighted) -{ - hilt = highlighted; -} - -void todo_hilt_decrease(int n) -{ - hilt -= n; -} - -void todo_hilt_increase(int n) -{ - hilt += n; -} - -/* Return which todo is highlighted. */ -int todo_hilt(void) -{ - return hilt; -} - -/* Return the number of todos. */ -int todo_nb(void) -{ - return todos; -} - -/* Set the number of todos. */ -void todo_set_nb(int nb) -{ - todos = nb; -} - -/* Set which one is the first todo to be displayed. */ -void todo_set_first(int nb) -{ - first = nb; -} - -void todo_first_increase(int n) -{ - first += n; -} - -void todo_first_decrease(int n) -{ - first -= n; -} - -/* - * Return the position of the hilghlighted item, relative to the first one - * displayed. - */ -int todo_hilt_pos(void) -{ - return hilt - first; -} - -/* Return the last visited todo. */ -char *todo_saved_mesg(void) -{ - return msgsav; -} - static int todo_cmp_id(struct todo *a, struct todo *b) { /* @@ -207,116 +138,6 @@ static int todo_get_position(struct todo *needle) return -1; /* avoid compiler warnings */ } -/* Change an item priority by pressing '+' or '-' inside TODO panel. */ -void todo_chg_priority(struct todo *backup, int diff) -{ - char backup_mesg[BUFSIZ]; - int backup_id; - char backup_note[MAX_NOTESIZ + 1]; - - strncpy(backup_mesg, backup->mesg, strlen(backup->mesg) + 1); - backup_id = backup->id; - if (backup->note) - strncpy(backup_note, backup->note, MAX_NOTESIZ + 1); - else - backup_note[0] = '\0'; - - backup_id += diff; - if (backup_id < 1) - backup_id = 1; - else if (backup_id > 9) - backup_id = 9; - - todo_delete(todo_get_item(hilt)); - backup = todo_add(backup_mesg, backup_id, backup_note); - hilt = todo_get_position(backup); -} - -/* Display todo items in the corresponding panel. */ -static void -display_todo_item(int incolor, char *msg, int prio, int note, int width, int y, - int x) -{ - WINDOW *w; - int ch_note; - char buf[width * UTF8_MAXLEN], priostr[2]; - int i; - - w = win[TOD].p; - ch_note = (note) ? '>' : '.'; - if (prio > 0) - snprintf(priostr, sizeof priostr, "%d", prio); - else - strncpy(priostr, "X", sizeof priostr); - - if (incolor == 0) - custom_apply_attr(w, ATTR_HIGHEST); - if (utf8_strwidth(msg) < width) - mvwprintw(w, y, x, "%s%c %s", priostr, ch_note, msg); - else { - for (i = 0; msg[i] && width > 0; i++) { - if (!UTF8_ISCONT(msg[i])) - width -= utf8_width(&msg[i]); - buf[i] = msg[i]; - } - if (i) - buf[i - 1] = 0; - else - buf[0] = 0; - mvwprintw(w, y, x, "%s%c %s...", priostr, ch_note, buf); - } - if (incolor == 0) - custom_remove_attr(w, ATTR_HIGHEST); -} - -/* Updates the ToDo panel. */ -void todo_update_panel(int which_pan) -{ - llist_item_t *i; - int len = win[TOD].w - 8; - int num_todo = 0; - int title_lines = conf.compact_panels ? 1 : 3; - int y_offset = title_lines, x_offset = 1; - int t_realpos = -1; - int todo_lines = 1; - int max_items = win[TOD].h - 4; - int incolor = -1; - - if ((int)win[TOD].h < 4) - return; - - /* Print todo item in the panel. */ - erase_window_part(win[TOD].p, 1, title_lines, win[TOD].w - 2, win[TOD].h - 2); - LLIST_FOREACH(&todolist, i) { - struct todo *todo = LLIST_TS_GET_DATA(i); - num_todo++; - t_realpos = num_todo - first; - incolor = (which_pan == TOD) ? num_todo - hilt : num_todo; - if (incolor == 0) - msgsav = todo->mesg; - if (t_realpos >= 0 && t_realpos < max_items) { - display_todo_item(incolor, todo->mesg, todo->id, - (todo->note != NULL) ? 1 : 0, len, y_offset, x_offset); - y_offset = y_offset + todo_lines; - } - } - - /* Draw the scrollbar if necessary. */ - if (todos > max_items) { - int sbar_length = max_items * (max_items + 1) / todos; - int highend = max_items * first / todos; - unsigned hilt_bar = (which_pan == TOD) ? 1 : 0; - int sbar_top = highend + title_lines; - - if ((sbar_top + sbar_length) > win[TOD].h - 1) - sbar_length = win[TOD].h - 1 - sbar_top; - draw_scrollbar(win[TOD].p, sbar_top, win[TOD].w - 2, - sbar_length, title_lines, win[TOD].h - 1, hilt_bar); - } - - wnoutrefresh(win[TOD].p); -} - /* Attach a note to a todo */ void todo_edit_note(struct todo *i, const char *editor) { diff --git a/src/ui-todo.c b/src/ui-todo.c index d8f659c..145d911 100644 --- a/src/ui-todo.c +++ b/src/ui-todo.c @@ -36,6 +36,11 @@ #include "calcurse.h" +static int hilt = 0; +static int todos = 0; +static int first = 1; +static char *msgsav; + /* Request user to enter a new todo item. */ void ui_todo_add(void) { @@ -52,7 +57,7 @@ void ui_todo_add(void) ch = wgetch(win[KEY].p); } todo_add(todo_input, ch - '0', NULL); - todo_set_nb(todo_nb() + 1); + ui_todo_set_nb(ui_todo_nb() + 1); } } @@ -67,31 +72,31 @@ void ui_todo_delete(void) const int nb_erase_choice = 2; int answer; - if ((todo_nb() <= 0) || + if ((ui_todo_nb() <= 0) || (conf.confirm_delete && (status_ask_bool(del_todo_str) != 1))) { wins_erase_status_bar(); return; } /* This todo item doesn't have any note associated. */ - if (todo_get_item(todo_hilt())->note == NULL) + if (todo_get_item(ui_todo_hilt())->note == NULL) answer = 1; else answer = status_ask_choice(erase_warning, erase_choice, nb_erase_choice); switch (answer) { case 1: - todo_delete(todo_get_item(todo_hilt())); - todo_set_nb(todo_nb() - 1); - if (todo_hilt() > 1) - todo_hilt_decrease(1); - if (todo_nb() == 0) - todo_hilt_set(0); - if (todo_hilt_pos() < 0) - todo_first_decrease(1); + todo_delete(todo_get_item(ui_todo_hilt())); + ui_todo_set_nb(ui_todo_nb() - 1); + if (ui_todo_hilt() > 1) + ui_todo_hilt_decrease(1); + if (ui_todo_nb() == 0) + ui_todo_hilt_set(0); + if (ui_todo_hilt_pos() < 0) + ui_todo_first_decrease(1); break; case 2: - todo_delete_note(todo_get_item(todo_hilt())); + todo_delete_note(todo_get_item(ui_todo_hilt())); break; default: wins_erase_status_bar(); @@ -106,7 +111,7 @@ void ui_todo_edit(void) const char *mesg = _("Enter the new ToDo description :"); status_mesg(mesg, ""); - i = todo_get_item(todo_hilt()); + i = todo_get_item(ui_todo_hilt()); updatestring(win[STA].p, &i->mesg, 0, 1); } @@ -128,7 +133,7 @@ void ui_todo_pipe(void) if ((pid = shell_exec(NULL, &pout, *arg, arg))) { fpout = fdopen(pout, "w"); - todo = todo_get_item(todo_hilt()); + todo = todo_get_item(ui_todo_hilt()); todo_write(todo, fpout); fclose(fpout); @@ -138,3 +143,177 @@ void ui_todo_pipe(void) wins_unprepare_external(); } +/* Sets which todo is highlighted. */ +void ui_todo_hilt_set(int highlighted) +{ + hilt = highlighted; +} + +void ui_todo_hilt_decrease(int n) +{ + hilt -= n; +} + +void ui_todo_hilt_increase(int n) +{ + hilt += n; +} + +/* Return which todo is highlighted. */ +int ui_todo_hilt(void) +{ + return hilt; +} + +/* Set the number of todos. */ +void ui_todo_set_nb(int nb) +{ + todos = nb; +} + +/* Set which one is the first todo to be displayed. */ +void ui_todo_set_first(int nb) +{ + first = nb; +} + +void ui_todo_first_increase(int n) +{ + first += n; +} + +void ui_todo_first_decrease(int n) +{ + first -= n; +} + +/* + * Return the position of the hilghlighted item, relative to the first one + * displayed. + */ +int ui_todo_hilt_pos(void) +{ + return hilt - first; +} + +/* Return the number of todos. */ +int ui_todo_nb(void) +{ + return todos; +} + +/* Return the last visited todo. */ +char *ui_todo_saved_mesg(void) +{ + return msgsav; +} + +/* Display todo items in the corresponding panel. */ +static void +display_todo_item(int incolor, char *msg, int prio, int note, int width, int y, + int x) +{ + WINDOW *w; + int ch_note; + char buf[width * UTF8_MAXLEN], priostr[2]; + int i; + + w = win[TOD].p; + ch_note = (note) ? '>' : '.'; + if (prio > 0) + snprintf(priostr, sizeof priostr, "%d", prio); + else + strncpy(priostr, "X", sizeof priostr); + + if (incolor == 0) + custom_apply_attr(w, ATTR_HIGHEST); + if (utf8_strwidth(msg) < width) + mvwprintw(w, y, x, "%s%c %s", priostr, ch_note, msg); + else { + for (i = 0; msg[i] && width > 0; i++) { + if (!UTF8_ISCONT(msg[i])) + width -= utf8_width(&msg[i]); + buf[i] = msg[i]; + } + if (i) + buf[i - 1] = 0; + else + buf[0] = 0; + mvwprintw(w, y, x, "%s%c %s...", priostr, ch_note, buf); + } + if (incolor == 0) + custom_remove_attr(w, ATTR_HIGHEST); +} + +/* Updates the ToDo panel. */ +void ui_todo_update_panel(int which_pan) +{ + llist_item_t *i; + int len = win[TOD].w - 8; + int num_todo = 0; + int title_lines = conf.compact_panels ? 1 : 3; + int y_offset = title_lines, x_offset = 1; + int t_realpos = -1; + int todo_lines = 1; + int max_items = win[TOD].h - 4; + int incolor = -1; + + if ((int)win[TOD].h < 4) + return; + + /* Print todo item in the panel. */ + erase_window_part(win[TOD].p, 1, title_lines, win[TOD].w - 2, win[TOD].h - 2); + LLIST_FOREACH(&todolist, i) { + struct todo *todo = LLIST_TS_GET_DATA(i); + num_todo++; + t_realpos = num_todo - first; + incolor = (which_pan == TOD) ? num_todo - hilt : num_todo; + if (incolor == 0) + msgsav = todo->mesg; + if (t_realpos >= 0 && t_realpos < max_items) { + display_todo_item(incolor, todo->mesg, todo->id, + (todo->note != NULL) ? 1 : 0, len, y_offset, x_offset); + y_offset = y_offset + todo_lines; + } + } + + /* Draw the scrollbar if necessary. */ + if (todos > max_items) { + int sbar_length = max_items * (max_items + 1) / todos; + int highend = max_items * first / todos; + unsigned hilt_bar = (which_pan == TOD) ? 1 : 0; + int sbar_top = highend + title_lines; + + if ((sbar_top + sbar_length) > win[TOD].h - 1) + sbar_length = win[TOD].h - 1 - sbar_top; + draw_scrollbar(win[TOD].p, sbar_top, win[TOD].w - 2, + sbar_length, title_lines, win[TOD].h - 1, hilt_bar); + } + + wnoutrefresh(win[TOD].p); +} + +/* Change an item priority by pressing '+' or '-' inside TODO panel. */ +void ui_todo_chg_priority(struct todo *backup, int diff) +{ + char backup_mesg[BUFSIZ]; + int backup_id; + char backup_note[MAX_NOTESIZ + 1]; + + strncpy(backup_mesg, backup->mesg, strlen(backup->mesg) + 1); + backup_id = backup->id; + if (backup->note) + strncpy(backup_note, backup->note, MAX_NOTESIZ + 1); + else + backup_note[0] = '\0'; + + backup_id += diff; + if (backup_id < 1) + backup_id = 1; + else if (backup_id > 9) + backup_id = 9; + + todo_delete(todo_get_item(hilt)); + backup = todo_add(backup_mesg, backup_id, backup_note); + hilt = todo_get_position(backup); +} @@ -497,7 +497,7 @@ void wins_update_panels(int flags) if (flags & FLAG_APP) ui_day_update_panel(slctd_win); if (flags & FLAG_TOD) - todo_update_panel(slctd_win); + ui_todo_update_panel(slctd_win); if (flags & FLAG_CAL) calendar_update_panel(&win[CAL]); } |