Add an item parameter to various todo_*() functions

These functions operate on arbitrary items. Pull out the code that gets
the currently selected item, get the current selection when one of the
functions is called and pass it as a parameter.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2012-06-26 14:07:14 +02:00
parent 318e685ffe
commit 954e3fd8ee
3 changed files with 12 additions and 19 deletions

View File

@ -315,7 +315,7 @@ int main(int argc, char **argv)
inday = do_storage(0); inday = do_storage(0);
wins_update(FLAG_APP); wins_update(FLAG_APP);
} else if (wins_slctd() == TOD && todo_hilt() != 0) { } else if (wins_slctd() == TOD && todo_hilt() != 0) {
todo_flag(); todo_flag(todo_get_item(todo_hilt()));
wins_update(FLAG_TOD); wins_update(FLAG_TOD);
} }
break; break;
@ -331,7 +331,7 @@ int main(int argc, char **argv)
case KEY_RAISE_PRIORITY: case KEY_RAISE_PRIORITY:
case KEY_LOWER_PRIORITY: case KEY_LOWER_PRIORITY:
if (wins_slctd() == TOD && todo_hilt() != 0) { if (wins_slctd() == TOD && todo_hilt() != 0) {
todo_chg_priority(key); todo_chg_priority(todo_get_item(todo_hilt()), key);
if (todo_hilt_pos() < 0) if (todo_hilt_pos() < 0)
todo_set_first(todo_hilt()); todo_set_first(todo_hilt());
else if (todo_hilt_pos() >= win[TOD].h - 4) else if (todo_hilt_pos() >= win[TOD].h - 4)
@ -345,7 +345,7 @@ int main(int argc, char **argv)
day_edit_note(day_get_item(apoint_hilt()), conf.editor); day_edit_note(day_get_item(apoint_hilt()), conf.editor);
inday = do_storage(0); inday = do_storage(0);
} else if (wins_slctd() == TOD && todo_hilt() != 0) } else if (wins_slctd() == TOD && todo_hilt() != 0)
todo_edit_note(conf.editor); todo_edit_note(todo_get_item(todo_hilt()), conf.editor);
wins_update(FLAG_ALL); wins_update(FLAG_ALL);
break; break;
@ -353,7 +353,7 @@ int main(int argc, char **argv)
if (wins_slctd() == APP && apoint_hilt() != 0) if (wins_slctd() == APP && apoint_hilt() != 0)
day_view_note(day_get_item(apoint_hilt()), conf.pager); day_view_note(day_get_item(apoint_hilt()), conf.pager);
else if (wins_slctd() == TOD && todo_hilt() != 0) else if (wins_slctd() == TOD && todo_hilt() != 0)
todo_view_note(conf.pager); todo_view_note(todo_get_item(todo_hilt()), conf.pager);
wins_update(FLAG_ALL); wins_update(FLAG_ALL);
break; break;

View File

@ -901,11 +901,11 @@ struct todo *todo_add(char *, int, char *);
void todo_write(struct todo *, FILE *); void todo_write(struct todo *, FILE *);
void todo_delete_note_bynum(unsigned); void todo_delete_note_bynum(unsigned);
void todo_delete(struct todo *); void todo_delete(struct todo *);
void todo_flag(void); void todo_flag(struct todo *);
void todo_chg_priority(int); void todo_chg_priority(struct todo *, int);
void todo_update_panel(int); void todo_update_panel(int);
void todo_edit_note(const char *); void todo_edit_note(struct todo *, const char *);
void todo_view_note(const char *); void todo_view_note(struct todo *, const char *);
void todo_init_list(void); void todo_init_list(void);
void todo_free_list(void); void todo_free_list(void);

View File

@ -189,11 +189,8 @@ void todo_delete(struct todo *todo)
* This way, it is easy to retrive its original priority if the user decides * This way, it is easy to retrive its original priority if the user decides
* that in fact it was not completed. * that in fact it was not completed.
*/ */
void todo_flag(void) void todo_flag(struct todo *t)
{ {
struct todo *t;
t = todo_get_item(hilt);
t->id = -t->id; t->id = -t->id;
} }
@ -217,14 +214,12 @@ static int todo_get_position(struct todo *needle)
} }
/* Change an item priority by pressing '+' or '-' inside TODO panel. */ /* Change an item priority by pressing '+' or '-' inside TODO panel. */
void todo_chg_priority(int action) void todo_chg_priority(struct todo *backup, int action)
{ {
struct todo *backup;
char backup_mesg[BUFSIZ]; char backup_mesg[BUFSIZ];
int backup_id; int backup_id;
char backup_note[MAX_NOTESIZ + 1]; char backup_note[MAX_NOTESIZ + 1];
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 (backup->note) if (backup->note)
@ -338,16 +333,14 @@ void todo_update_panel(int which_pan)
} }
/* Attach a note to a todo */ /* Attach a note to a todo */
void todo_edit_note(const char *editor) void todo_edit_note(struct todo *i, const char *editor)
{ {
struct todo *i = todo_get_item(hilt);
edit_note(&i->note, editor); edit_note(&i->note, editor);
} }
/* View a note previously attached to a todo */ /* View a note previously attached to a todo */
void todo_view_note(const char *pager) void todo_view_note(struct todo *i, const char *pager)
{ {
struct todo *i = todo_get_item(hilt);
view_note(i->note, pager); view_note(i->note, pager);
} }