From 1b75acf01b2f5a8d828aca3376022e156f1444ff Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 18 Jan 2016 18:09:23 +0100 Subject: Save active view on the todo panel Add a configuration option appearance.todoview and use it to automatically save the currently active todo panel view and restore it when restarting calcurse. Signed-off-by: Lukas Fleischer --- src/calcurse.h | 2 ++ src/config.c | 25 +++++++++++++++++++++++++ src/ui-todo.c | 11 +++++++++++ 3 files changed, 38 insertions(+) (limited to 'src') diff --git a/src/calcurse.h b/src/calcurse.h index 67f95fa..d2ee80b 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -1072,6 +1072,8 @@ void ui_todo_view_note(void); void ui_todo_edit_note(void); void ui_todo_view_prev(void); void ui_todo_view_next(void); +int ui_todo_get_view(void); +void ui_todo_set_view(int); /* utf8.c */ int utf8_width(char *); diff --git a/src/config.c b/src/config.c index a26bd1f..8b65740 100644 --- a/src/config.c +++ b/src/config.c @@ -59,6 +59,8 @@ static int config_parse_str(char *, const char *); static int config_serialize_str(char **, const char *); static int config_parse_calendar_view(void *, const char *); static int config_serialize_calendar_view(char **, void *); +static int config_parse_todo_view(void *, const char *); +static int config_serialize_todo_view(char **, void *); static int config_parse_default_panel(void *, const char *); static int config_serialize_default_panel(char **, void *); static int config_parse_first_day_of_week(void *, const char *); @@ -91,6 +93,7 @@ static const struct confvar confmap[] = { {"appearance.notifybar", CONFIG_HANDLER_BOOL(nbar.show)}, {"appearance.sidebarwidth", config_parse_sidebar_width, config_serialize_sidebar_width, NULL}, {"appearance.theme", config_parse_color_theme, config_serialize_color_theme, NULL}, + {"appearance.todoview", config_parse_todo_view, config_serialize_todo_view, NULL}, {"daemon.enable", CONFIG_HANDLER_BOOL(dmon.enable)}, {"daemon.log", CONFIG_HANDLER_BOOL(dmon.log)}, {"format.inputdate", config_parse_input_datefmt, config_serialize_input_datefmt, NULL}, @@ -206,6 +209,18 @@ static int config_parse_calendar_view(void *dummy, const char *val) return 1; } +static int config_parse_todo_view(void *dummy, const char *val) +{ + if (!strcmp(val, "show-completed")) + ui_todo_set_view(TODO_SHOW_COMPLETED_VIEW); + else if (!strcmp(val, "hide-completed")) + ui_todo_set_view(TODO_HIDE_COMPLETED_VIEW); + else + return 0; + + return 1; +} + static int config_parse_default_panel(void *dummy, const char *val) { if (!strcmp(val, "calendar")) @@ -378,6 +393,16 @@ static int config_serialize_calendar_view(char **buf, void *dummy) return 1; } +static int config_serialize_todo_view(char **buf, void *dummy) +{ + if (ui_todo_get_view() == TODO_SHOW_COMPLETED_VIEW) + *buf = mem_strdup("show-completed"); + else + *buf = mem_strdup("hide-completed"); + + return 1; +} + static int config_serialize_default_panel(char **buf, void *dummy) { if (conf.default_panel == CAL) diff --git a/src/ui-todo.c b/src/ui-todo.c index de19272..971c69d 100644 --- a/src/ui-todo.c +++ b/src/ui-todo.c @@ -327,3 +327,14 @@ void ui_todo_view_prev(void) ui_todo_view--; ui_todo_load_items(); } + +void ui_todo_set_view(int view) +{ + ui_todo_view = (view < 0 || view >= TODO_VIEWS) ? + TODO_SHOW_COMPLETED_VIEW : view; +} + +int ui_todo_get_view(void) +{ + return (int)ui_todo_view; +} -- cgit v1.2.3