hilt_tod moved to static variable hilt

todo_hilt(), todo_hilt_set(), todo_hilt_decrease(), todo_hilt_increase(),
todo_saved_mesg(), todo_nb(), todo_set_nb(), todo_set_first(),
todo_first_increase(), todo_first_decrease(), todo_hilt_pos() added
This commit is contained in:
Frederic Culot 2007-08-15 15:35:25 +00:00
parent 2beb88e473
commit 9ee3eecfa6
2 changed files with 129 additions and 42 deletions

View File

@ -1,4 +1,4 @@
/* $calcurse: todo.c,v 1.13 2007/07/28 13:11:42 culot Exp $ */ /* $calcurse: todo.c,v 1.14 2007/08/15 15:35:25 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -32,10 +32,90 @@
#include "todo.h" #include "todo.h"
struct todo_s *todolist; struct todo_s *todolist;
static int hilt = 0;
static int todos = 0;
static int first = 1;
static char *msgsav;
/* Sets which todo is highlighted. */
void
todo_hilt_set(int highlighted)
{
hilt = highlighted;
}
void
todo_hilt_decrease(void)
{
hilt--;
}
void
todo_hilt_increase(void)
{
hilt++;
}
/* 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(void)
{
first++;
}
void
todo_first_decrease(void)
{
first--;
}
/*
* 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);
}
/* Request user to enter a new todo item. */ /* Request user to enter a new todo item. */
int void
todo_new_item(int total) todo_new_item(void)
{ {
int ch = 0; int ch = 0;
char *mesg = _("Enter the new ToDo item : "); char *mesg = _("Enter the new ToDo item : ");
@ -51,10 +131,8 @@ todo_new_item(int total)
ch = wgetch(swin); ch = wgetch(swin);
} }
todo_add(todo_input, ch - '0'); todo_add(todo_input, ch - '0');
total++; todos++;
} }
return total;
} }
/* Add an item in the todo linked list. */ /* Add an item in the todo linked list. */
@ -104,7 +182,7 @@ todo_delete_bynum(unsigned num)
/* Delete an item from the ToDo list. */ /* Delete an item from the ToDo list. */
void void
todo_delete(conf_t *conf, int *nb_tod, int *hilt_tod) todo_delete(conf_t *conf)
{ {
char *choices = "[y/n] "; char *choices = "[y/n] ";
char *del_todo_str = _("Do you really want to delete this task ?"); char *del_todo_str = _("Do you really want to delete this task ?");
@ -114,23 +192,25 @@ todo_delete(conf_t *conf, int *nb_tod, int *hilt_tod)
if (conf->confirm_delete) { if (conf->confirm_delete) {
status_mesg(del_todo_str, choices); status_mesg(del_todo_str, choices);
answer = wgetch(swin); answer = wgetch(swin);
if ( (answer == 'y') && (*nb_tod > 0) ) { if ( (answer == 'y') && (todos > 0) ) {
go_for_todo_del = true; go_for_todo_del = true;
} else { } else {
erase_status_bar(); erase_status_bar();
return; return;
} }
} else } else
if (*nb_tod > 0) if (todos > 0)
go_for_todo_del = true; go_for_todo_del = true;
if (go_for_todo_del) { if (go_for_todo_del) {
todo_delete_bynum(*hilt_tod - 1); todo_delete_bynum(hilt - 1);
(*nb_tod)--; todos--;
if (*hilt_tod > 1) if (hilt > 1)
(*hilt_tod)--; hilt--;
if (*nb_tod == 0) if (todos == 0)
*hilt_tod = 0; hilt = 0;
if (hilt - first < 0)
first--;
} }
} }
@ -175,15 +255,15 @@ todo_get_item(int item_number)
} }
/* Change an item priority by pressing '+' or '-' inside TODO panel. */ /* Change an item priority by pressing '+' or '-' inside TODO panel. */
int void
todo_chg_priority(int action, int item_num) todo_chg_priority(int action)
{ {
struct todo_s *backup; struct todo_s *backup;
char backup_mesg[BUFSIZ]; char backup_mesg[BUFSIZ];
int backup_id; int backup_id;
int do_chg = 1, new_position; int do_chg = 1;
backup = todo_get_item(item_num); backup = todo_get_item(hilt);
strncpy(backup_mesg, backup->mesg, strlen(backup->mesg) + 1); strncpy(backup_mesg, backup->mesg, strlen(backup->mesg) + 1);
backup_id = backup->id; backup_id = backup->id;
if (action == '+') { if (action == '+') {
@ -195,31 +275,27 @@ todo_chg_priority(int action, int item_num)
stderr); stderr);
} }
if (do_chg) { if (do_chg) {
todo_delete_bynum(item_num - 1); todo_delete_bynum(hilt - 1);
backup = todo_add(backup_mesg, backup_id); backup = todo_add(backup_mesg, backup_id);
new_position = todo_get_position(backup); hilt = todo_get_position(backup);
} else {
new_position = item_num;
} }
return new_position;
} }
/* Edit the description of an already existing todo item. */ /* Edit the description of an already existing todo item. */
void void
todo_edit_item(int item_num) todo_edit_item(void)
{ {
struct todo_s *i; struct todo_s *i;
char *mesg = _("Enter the new ToDo description :"); char *mesg = _("Enter the new ToDo description :");
status_mesg(mesg, ""); status_mesg(mesg, "");
i = todo_get_item(item_num); i = todo_get_item(hilt);
updatestring(swin, &i->mesg, 0, 1); updatestring(swin, &i->mesg, 0, 1);
} }
/* Updates the ToDo panel. */ /* Updates the ToDo panel. */
void void
todo_update_panel(window_t *wintod, int hilt_tod, int nb_tod, int which_pan, todo_update_panel(window_t *wintod, int which_pan)
int first_todo_onscreen, char **saved_t_mesg)
{ {
struct todo_s *i; struct todo_s *i;
int len = wintod->w - 6; int len = wintod->w - 6;
@ -236,10 +312,10 @@ todo_update_panel(window_t *wintod, int hilt_tod, int nb_tod, int which_pan,
erase_window_part(twin, 1, title_lines, wintod->w - 2, wintod->h - 2); erase_window_part(twin, 1, title_lines, wintod->w - 2, wintod->h - 2);
for (i = todolist; i != 0; i = i->next) { for (i = todolist; i != 0; i = i->next) {
num_todo++; num_todo++;
t_realpos = num_todo - first_todo_onscreen; t_realpos = num_todo - first;
incolor = num_todo - hilt_tod; incolor = num_todo - hilt;
if (incolor == 0) if (incolor == 0)
*saved_t_mesg = i->mesg; msgsav = i->mesg;
if (t_realpos >= 0 && t_realpos < max_items) { if (t_realpos >= 0 && t_realpos < max_items) {
snprintf(mesg, BUFSIZ, "%d. ", i->id); snprintf(mesg, BUFSIZ, "%d. ", i->id);
strncat(mesg, i->mesg, strlen(i->mesg)); strncat(mesg, i->mesg, strlen(i->mesg));
@ -250,10 +326,10 @@ todo_update_panel(window_t *wintod, int hilt_tod, int nb_tod, int which_pan,
} }
/* Draw the scrollbar if necessary. */ /* Draw the scrollbar if necessary. */
if (nb_tod > max_items){ if (todos > max_items){
float ratio = ((float) max_items) / ((float) nb_tod); float ratio = ((float) max_items) / ((float) todos);
int sbar_length = (int) (ratio * (max_items + 1)); int sbar_length = (int) (ratio * (max_items + 1));
int highend = (int) (ratio * first_todo_onscreen); int highend = (int) (ratio * first);
bool hilt_bar = (which_pan == TODO) ? true : false; bool hilt_bar = (which_pan == TODO) ? true : false;
int sbar_top = highend + title_lines; int sbar_top = highend + title_lines;

View File

@ -1,4 +1,4 @@
/* $calcurse: todo.h,v 1.8 2007/07/28 13:11:43 culot Exp $ */ /* $calcurse: todo.h,v 1.9 2007/08/15 15:35:25 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -37,11 +37,22 @@ struct todo_s {
extern struct todo_s *todolist; extern struct todo_s *todolist;
int todo_new_item(int); void todo_hilt_set(int);
void todo_hilt_decrease(void);
void todo_hilt_increase(void);
int todo_hilt(void);
int todo_nb(void);
void todo_set_nb(int);
void todo_set_first(int);
void todo_first_increase(void);
void todo_first_decrease(void);
int todo_hilt_pos(void);
char *todo_saved_mesg(void);
void todo_new_item(void);
struct todo_s *todo_add(char *, int); struct todo_s *todo_add(char *, int);
void todo_delete(conf_t *, int *, int *); void todo_delete(conf_t *);
int todo_chg_priority(int, int); void todo_chg_priority(int);
void todo_edit_item(int); void todo_edit_item(void);
void todo_update_panel(window_t *, int, int, int, int, char **); void todo_update_panel(window_t *, int);
#endif /* CALCURSE_TODO_H */ #endif /* CALCURSE_TODO_H */