[gnome-todo] task-row: Save task title when changed
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo] task-row: Save task title when changed
- Date: Mon, 5 Feb 2018 01:04:44 +0000 (UTC)
commit 14c9bea8b9ac80dba2c53106b98b1f183727f8a6
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sun Feb 4 23:00:35 2018 -0200
task-row: Save task title when changed
data/ui/task-row.ui | 2 ++
src/gtd-task-row.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+)
---
diff --git a/data/ui/task-row.ui b/data/ui/task-row.ui
index 1232ed3..f9fbe1a 100644
--- a/data/ui/task-row.ui
+++ b/data/ui/task-row.ui
@@ -98,6 +98,8 @@
<property name="halign">start</property>
<property name="width-chars">5</property>
<property name="propagate-natural-width">True</property>
+ <signal name="activate" handler="on_task_title_changed_cb" object="GtdTaskRow"
swapped="yes" />
+ <signal name="notify::text" handler="on_task_title_changed_cb"
object="GtdTaskRow" swapped="yes" />
<style>
<class name="title" />
</style>
diff --git a/src/gtd-task-row.c b/src/gtd-task-row.c
index 85aebf6..9c8b0f8 100644
--- a/src/gtd-task-row.c
+++ b/src/gtd-task-row.c
@@ -62,11 +62,13 @@ struct _GtdTaskRow
GtdTask *task;
gint destroy_row_timeout_id;
+ gint update_title_timeout_id;
gboolean active;
};
#define PRIORITY_ICON_SIZE 8
+
G_DEFINE_TYPE (GtdTaskRow, gtd_task_row, GTK_TYPE_LIST_BOX_ROW)
enum
@@ -87,6 +89,7 @@ enum
static guint signals[NUM_SIGNALS] = { 0, };
+
/*
* Auxiliary methods
*/
@@ -434,6 +437,26 @@ gtd_task_row__destroy_cb (GtkWidget *row)
return G_SOURCE_REMOVE;
}
+static gboolean
+on_update_title_timeout_cb (gpointer data)
+{
+ GtdTaskRow *self = data;
+
+ gtd_manager_update_task (gtd_manager_get_default (), self->task);
+ self->update_title_timeout_id = 0;
+
+ return G_SOURCE_REMOVE;
+}
+
+static void
+on_task_title_changed_cb (GtdTaskRow *self)
+{
+ if (self->update_title_timeout_id > 0)
+ g_source_remove (self->update_title_timeout_id);
+
+ self->update_title_timeout_id = g_timeout_add_seconds (2, on_update_title_timeout_cb, self);
+}
+
/*
* GtkWidget overrides
@@ -465,6 +488,13 @@ gtd_task_row_finalize (GObject *object)
{
GtdTaskRow *self = GTD_TASK_ROW (object);
+ if (self->update_title_timeout_id > 0)
+ {
+ if (self->task)
+ gtd_manager_update_task (gtd_manager_get_default (), self->task);
+ self->update_title_timeout_id = 0;
+ }
+
g_clear_object (&self->task);
G_OBJECT_CLASS (gtd_task_row_parent_class)->finalize (object);
@@ -651,6 +681,7 @@ gtd_task_row_class_init (GtdTaskRowClass *klass)
gtk_widget_class_bind_template_callback (widget_class, mouse_over_dnd_event_cb);
gtk_widget_class_bind_template_callback (widget_class, remove_task_cb);
gtk_widget_class_bind_template_callback (widget_class, toggle_active_cb);
+ gtk_widget_class_bind_template_callback (widget_class, on_task_title_changed_cb);
gtk_widget_class_set_css_name (widget_class, "taskrow");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]