added incremental search
authorJean-Philippe Orsini <jeanfi@gmail.com>
Fri, 21 Nov 2014 11:11:14 +0000 (12:11 +0100)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Fri, 21 Nov 2014 11:11:14 +0000 (12:11 +0100)
NEWS
src/glade/ptask.glade
src/main.c
src/ui_tasktree.c
src/ui_tasktree.h

diff --git a/NEWS b/NEWS
index 9822120..91f5808 100644 (file)
--- 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
 ------
index 1339f60..f5d610b 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.16.1 -->
+<!-- Generated with glade 3.18.3 -->
 <interface>
   <requires lib="gtk+" version="3.0"/>
   <object class="GtkDialog" id="diag_preferences">
@@ -64,8 +64,6 @@
               <packing>
                 <property name="left_attach">0</property>
                 <property name="top_attach">0</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
               </packing>
             </child>
             <child>
@@ -79,8 +77,6 @@
               <packing>
                 <property name="left_attach">1</property>
                 <property name="top_attach">0</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
               </packing>
             </child>
           </object>
               <packing>
                 <property name="left_attach">0</property>
                 <property name="top_attach">0</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
               </packing>
             </child>
             <child>
               <packing>
                 <property name="left_attach">1</property>
                 <property name="top_attach">0</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
               </packing>
             </child>
             <child>
               <packing>
                 <property name="left_attach">0</property>
                 <property name="top_attach">1</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
               </packing>
             </child>
             <child>
               <packing>
                 <property name="left_attach">0</property>
                 <property name="top_attach">2</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
               </packing>
             </child>
             <child>
               <packing>
                 <property name="left_attach">1</property>
                 <property name="top_attach">2</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
               </packing>
             </child>
             <child>
               <packing>
                 <property name="left_attach">1</property>
                 <property name="top_attach">1</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
               </packing>
             </child>
           </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="tasktree_search">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="secondary_icon_stock">gtk-find</property>
+                <signal name="changed" handler="ui_tasktree_search_changed_cbk" swapped="no"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="pack_type">end</property>
                 <property name="position">2</property>
               </packing>
             </child>
           </object>
           <packing>
             <property name="expand">False</property>
-            <property name="fill">False</property>
+            <property name="fill">True</property>
             <property name="position">1</property>
           </packing>
         </child>
                           <packing>
                             <property name="left_attach">0</property>
                             <property name="top_attach">1</property>
-                            <property name="width">1</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
                           <packing>
                             <property name="left_attach">0</property>
                             <property name="top_attach">5</property>
-                            <property name="width">1</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
                           <packing>
                             <property name="left_attach">1</property>
                             <property name="top_attach">5</property>
-                            <property name="width">1</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
                           <packing>
                             <property name="left_attach">1</property>
                             <property name="top_attach">1</property>
-                            <property name="width">1</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
                           <packing>
                             <property name="left_attach">0</property>
                             <property name="top_attach">3</property>
-                            <property name="width">1</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
                           <packing>
                             <property name="left_attach">1</property>
                             <property name="top_attach">3</property>
-                            <property name="width">1</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
                           <packing>
                             <property name="left_attach">0</property>
                             <property name="top_attach">2</property>
-                            <property name="width">1</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
                           <packing>
                             <property name="left_attach">1</property>
                             <property name="top_attach">2</property>
-                            <property name="width">1</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
                             <property name="left_attach">0</property>
                             <property name="top_attach">0</property>
                             <property name="width">2</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
                           <packing>
                             <property name="left_attach">0</property>
                             <property name="top_attach">4</property>
-                            <property name="width">1</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
                           <packing>
                             <property name="left_attach">1</property>
                             <property name="top_attach">4</property>
-                            <property name="width">1</property>
-                            <property name="height">1</property>
                           </packing>
                         </child>
                       </object>
index 83dfda6..8dc69ba 100644 (file)
@@ -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 {
index 506e8f9..00dd1d3 100644 (file)
@@ -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);
+}
index 1506a58..93b5427 100644 (file)
@@ -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