(no commit message)
[ptask.git] / src / main.c
index 759cf49..49e3622 100644 (file)
@@ -30,6 +30,7 @@ static struct task **tasks;
 static GtkTextView *w_note;
 static GtkEntry *w_description;
 static GtkTreeView *w_treeview;
+static GtkWidget *w_tasksave_btn;
 
 static struct task *get_selected_task(GtkTreeView *treeview)
 {
@@ -44,20 +45,21 @@ static struct task *get_selected_task(GtkTreeView *treeview)
 
        if (path) {
                i = gtk_tree_path_get_indices(path);
-               
-               if (i)
+
+               if (i) {
                        printf("row selected: %d\n", *i);
 
-               task = tasks[*i];
+                       task = tasks[*i];
+               } else {
+                       task = NULL;
+               }
 
                gtk_tree_path_free(path);
-
-               return task;
+       } else {
+               task = NULL;
        }
 
-       printf("get_selected_task returns NULL\n");
-
-       return NULL;
+       return task;
 }
 
 static void refresh()
@@ -67,7 +69,6 @@ static void refresh()
        struct task *task;
        int i;
        GtkTreeIter iter;
-       /*GtkTreeSelection *sel;*/
 
        tasks = get_all_tasks();
 
@@ -77,7 +78,7 @@ static void refresh()
                task = (*tasks_cur);
 
                gtk_list_store_append(GTK_LIST_STORE(model), &iter);
-               
+
                if (task->project)
                        gtk_list_store_set(GTK_LIST_STORE(model),
                                           &iter,
@@ -90,11 +91,6 @@ static void refresh()
                                   1, (*tasks_cur)->description,
                                   -1);
        }
-
-       /*
-       sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(w_treeview));
-       gtk_tree_model_get_iter_first(model, &iter);
-       gtk_tree_selection_select_iter(sel, &iter);*/
 }
 
 static int tasksave_clicked_cbk(GtkButton *btn, gpointer data)
@@ -107,7 +103,7 @@ static int tasksave_clicked_cbk(GtkButton *btn, gpointer data)
 
        task = get_selected_task(GTK_TREE_VIEW(w_treeview));
 
-       printf("tasksave_clicked_cbk %d\n", task->id);  
+       printf("tasksave_clicked_cbk %d\n", task->id);
 
        if (task->note) {
                buf = gtk_text_view_get_buffer(w_note);
@@ -131,11 +127,11 @@ static int tasksave_clicked_cbk(GtkButton *btn, gpointer data)
                      + strlen("\"")
                      + 1);
        sprintf(opts, " %s modify \"%s\"", task->uuid, txt);
-       
+
        task_exec(opts);
 
        free(txt);
-       
+
        refresh();
 
        return FALSE;
@@ -168,6 +164,9 @@ static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
                }
 
                gtk_entry_set_text(w_description, task->description);
+               gtk_widget_set_sensitive(w_tasksave_btn, 1);
+       } else {
+               gtk_widget_set_sensitive(w_tasksave_btn, 0);
        }
 
        return FALSE;
@@ -186,7 +185,6 @@ int main(int argc, char **argv)
                 PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "gtask.glade",
                 NULL);
        window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
-       printf("%p\n", window);
 
        w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview"));
 
@@ -198,11 +196,14 @@ int main(int argc, char **argv)
        refresh();
 
        g_signal_connect(w_treeview,
-                        "cursor-changed", (GCallback)cursor_changed_cbk, tasks);
+                        "cursor-changed", (GCallback)cursor_changed_cbk,
+                        tasks);
 
        btn = GTK_WIDGET(gtk_builder_get_object(builder, "tasksave"));
        g_signal_connect(btn,
                         "clicked", (GCallback)tasksave_clicked_cbk, tasks);
+       gtk_widget_set_sensitive(btn, 0);
+       w_tasksave_btn = btn;
 
        btn = GTK_WIDGET(gtk_builder_get_object(builder, "refresh"));
        g_signal_connect(btn,