ui-todo.c: Refactor ui_todo_chg_priority()
Add the new item *before* deleting the old one and get rid of temporary buffers for the item message and note. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
8de7399360
commit
abca2f10b5
@ -294,26 +294,17 @@ void ui_todo_update_panel(int which_pan)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Change an item priority by pressing '+' or '-' inside TODO panel. */
|
/* Change an item priority by pressing '+' or '-' inside TODO panel. */
|
||||||
void ui_todo_chg_priority(struct todo *backup, int diff)
|
void ui_todo_chg_priority(struct todo *todo, int diff)
|
||||||
{
|
{
|
||||||
char backup_mesg[BUFSIZ];
|
int id = todo->id + diff;
|
||||||
int backup_id;
|
struct todo *todo_new;
|
||||||
char backup_note[MAX_NOTESIZ + 1];
|
|
||||||
|
|
||||||
strncpy(backup_mesg, backup->mesg, strlen(backup->mesg) + 1);
|
if (id < 1)
|
||||||
backup_id = backup->id;
|
id = 1;
|
||||||
if (backup->note)
|
else if (id > 9)
|
||||||
strncpy(backup_note, backup->note, MAX_NOTESIZ + 1);
|
id = 9;
|
||||||
else
|
|
||||||
backup_note[0] = '\0';
|
|
||||||
|
|
||||||
backup_id += diff;
|
todo_new = todo_add(todo->mesg, id, todo->note);
|
||||||
if (backup_id < 1)
|
todo_delete(todo);
|
||||||
backup_id = 1;
|
hilt = todo_get_position(todo_new);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user