aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui-todo.c
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@calcurse.org>2016-01-18 19:19:18 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2016-01-18 19:19:18 +0100
commitdf1bc59812c87a006904b3aac0543f71cf5484e1 (patch)
treefdc6560e9e1a34cdf5367747216580d0f5bad437 /src/ui-todo.c
parent25a049951cc955b51c2c30b977ebb6cfa7160054 (diff)
downloadcalcurse-df1bc59812c87a006904b3aac0543f71cf5484e1.tar.gz
calcurse-df1bc59812c87a006904b3aac0543f71cf5484e1.zip
Make automatic selection of todo items smarter
* Automatically focus new todo items after adding them to the list. * Keep selection when an item is moved (e.g. by changing its priority). * Focus the next item in the list when an item is removed. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/ui-todo.c')
-rw-r--r--src/ui-todo.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/ui-todo.c b/src/ui-todo.c
index b6da02d..8ad2533 100644
--- a/src/ui-todo.c
+++ b/src/ui-todo.c
@@ -44,6 +44,14 @@ static struct todo *ui_todo_selitem(void)
ui_todo_view == TODO_HIDE_COMPLETED_VIEW);
}
+static void ui_todo_set_selitem(struct todo *todo)
+{
+ int n = todo_get_position(todo,
+ ui_todo_view == TODO_HIDE_COMPLETED_VIEW);
+ if (n >= 0)
+ listbox_set_sel(&lb_todo, n);
+}
+
/* Request user to enter a new todo item. */
void ui_todo_add(void)
{
@@ -60,9 +68,10 @@ void ui_todo_add(void)
status_mesg(mesg_id, "");
ch = wgetch(win[KEY].p);
}
- todo_add(todo_input, ch - '0', 0, NULL);
+ struct todo *todo = todo_add(todo_input, ch - '0', 0, NULL);
ui_todo_load_items();
io_set_modified();
+ ui_todo_set_selitem(todo);
}
}
@@ -123,8 +132,7 @@ void ui_todo_edit(void)
todo_resort(item);
ui_todo_load_items();
io_set_modified();
-
- listbox_set_sel(&lb_todo, todo_get_position(item));
+ ui_todo_set_selitem(item);
}
/* Pipe a todo item to an external program. */
@@ -291,8 +299,7 @@ void ui_todo_chg_priority(int diff)
item_new = todo_add(item->mesg, id, item->completed, item->note);
todo_delete(item);
io_set_modified();
-
- listbox_set_sel(&lb_todo, todo_get_position(item_new));
+ ui_todo_set_selitem(item_new);
}
void ui_todo_popup_item(void)
@@ -313,8 +320,7 @@ void ui_todo_flag(void)
todo_flag(item);
ui_todo_load_items();
io_set_modified();
-
- listbox_set_sel(&lb_todo, todo_get_position(item));
+ ui_todo_set_selitem(item);
}
void ui_todo_view_note(void)