From fdf70aa967f489ec5d2d32d286d99a63068d81e1 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Fri, 21 Nov 2014 12:11:14 +0100 Subject: [PATCH] added incremental search --- NEWS | 3 ++- src/glade/ptask.glade | 55 +++++++++++++++------------------------------------ src/main.c | 4 ++-- src/ui_tasktree.c | 46 +++++++++++++++++++++++++++++++++++------- src/ui_tasktree.h | 2 +- 5 files changed, 60 insertions(+), 50 deletions(-) diff --git a/NEWS b/NEWS index 9822120..91f5808 100644 --- a/NEWS +++ b/NEWS @@ -3,8 +3,9 @@ What's New v0.0.9 ------ - * fixed potention memory leak when failing to convert time to string + * fixed potential memory leak when failing to convert time to string which is unlikely. + * added incremental search. v0.0.8 ------ diff --git a/src/glade/ptask.glade b/src/glade/ptask.glade index 1339f60..f5d610b 100644 --- a/src/glade/ptask.glade +++ b/src/glade/ptask.glade @@ -1,5 +1,5 @@ - + @@ -64,8 +64,6 @@ 0 0 - 1 - 1 @@ -79,8 +77,6 @@ 1 0 - 1 - 1 @@ -184,8 +180,6 @@ 0 0 - 1 - 1 @@ -202,8 +196,6 @@ 1 0 - 1 - 1 @@ -220,8 +212,6 @@ 0 1 - 1 - 1 @@ -238,8 +228,6 @@ 0 2 - 1 - 1 @@ -263,8 +251,6 @@ 1 2 - 1 - 1 @@ -286,8 +272,6 @@ 1 1 - 1 - 1 @@ -528,13 +512,27 @@ False False + 1 + + + + + True + True + gtk-find + + + + False + True + end 2 False - False + True 1 @@ -766,8 +764,6 @@ 0 1 - 1 - 1 @@ -784,8 +780,6 @@ 0 5 - 1 - 1 @@ -808,8 +802,6 @@ 1 5 - 1 - 1 @@ -825,8 +817,6 @@ 1 1 - 1 - 1 @@ -843,8 +833,6 @@ 0 3 - 1 - 1 @@ -859,8 +847,6 @@ 1 3 - 1 - 1 @@ -877,8 +863,6 @@ 0 2 - 1 - 1 @@ -902,8 +886,6 @@ 1 2 - 1 - 1 @@ -972,7 +954,6 @@ 0 0 2 - 1 @@ -989,8 +970,6 @@ 0 4 - 1 - 1 @@ -1007,8 +986,6 @@ 1 4 - 1 - 1 diff --git a/src/main.c b/src/main.c index 83dfda6..8dc69ba 100644 --- a/src/main.c +++ b/src/main.c @@ -98,7 +98,7 @@ void refresh() old_tasks = tasks; current_prj = ui_projecttree_get_project(); current_uuid = ui_tasktree_get_task_uuid(); - ui_tasktree_update(NULL, NULL); + ui_tasktree_update(NULL); } else { old_tasks = NULL; current_prj = NULL; @@ -109,7 +109,7 @@ void refresh() if (tasks) { ui_projecttree_update(tasks); - ui_tasktree_update(tasks, current_prj); + ui_tasktree_update(tasks); if (current_uuid) ui_tasktree_set_selected_task(current_uuid); } else { diff --git a/src/ui_tasktree.c b/src/ui_tasktree.c index 506e8f9..00dd1d3 100644 --- a/src/ui_tasktree.c +++ b/src/ui_tasktree.c @@ -47,6 +47,7 @@ static const char * const MENU_NAMES[] = { static GtkTreeView *w_treeview; static GtkMenu *w_menu; static struct task **current_tasks; +static gchar *search_keywords; enum { COL_ID, @@ -292,14 +293,18 @@ void ui_tasktree_set_selected_task(const char *uuid) } -void ui_tasktree_update(struct task **tasks, const char *prj_filter) +void ui_tasktree_update(struct task **tasks) { GtkTreeModel *model; struct task **tasks_cur; struct task *task; GtkTreeIter iter; - const char *prj; + const char *prj, *prj_filter; char *s; + gchar *desc; + int ok; + + prj_filter = ui_projecttree_get_project(); current_tasks = tasks; @@ -318,6 +323,22 @@ void ui_tasktree_update(struct task **tasks, const char *prj_filter) if (prj_filter && strcmp(prj, prj_filter)) continue; + if (search_keywords + && strlen(search_keywords) + && task->description) { + desc = g_ascii_strup(task->description, -1); + + if (strstr(desc, search_keywords)) + ok = 1; + else + ok = 0; + + free(desc); + + if (!ok) + continue; + } + gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set(GTK_LIST_STORE(model), @@ -373,11 +394,6 @@ void ui_tasktree_update(struct task **tasks, const char *prj_filter) } -void ui_tasktree_update_filter(const char *prj_filter) -{ - ui_tasktree_update(current_tasks, prj_filter); -} - gboolean tasktree_button_press_event_cbk(GtkWidget *widget, GdkEventButton *evt, gpointer data) @@ -477,3 +493,19 @@ void tasktree_stop_activate_cbk(GtkAction *action, gpointer data) log_fct_exit(); } + +void +ui_tasktree_search_changed_cbk(GtkEntry *entry, gchar *preedit, gpointer data) +{ + if (search_keywords) + g_free(search_keywords); + + search_keywords = g_ascii_strup(gtk_entry_get_text(entry), -1); + + ui_tasktree_update(current_tasks); +} + +void ui_tasktree_update_filter(const char *prj) +{ + ui_tasktree_update(current_tasks); +} diff --git a/src/ui_tasktree.h b/src/ui_tasktree.h index 1506a58..93b5427 100644 --- a/src/ui_tasktree.h +++ b/src/ui_tasktree.h @@ -29,7 +29,7 @@ void ui_tasktree_save_settings(); struct task *ui_tasktree_get_selected_task(); void ui_tasktree_set_selected_task(const char *uuid); const char *ui_tasktree_get_task_uuid(); -void ui_tasktree_update(struct task **, const char *); +void ui_tasktree_update(struct task **); void ui_tasktree_update_filter(const char *); #endif -- 2.7.4