[gnome-todo] task-list-view: track edited task with :enter and :exit
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo] task-list-view: track edited task with :enter and :exit
- Date: Tue, 1 Nov 2016 13:37:47 +0000 (UTC)
commit 4beb1e61a3231bfde4d978193248a5f3a8fdb8ce
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Mon Oct 31 18:00:06 2016 -0200
task-list-view: track edited task with :enter and :exit
We long provided these signals, but never used them. This commit
makes use of the :enter and :exit signals to track the task that
is being currently edited.
data/ui/list-view.ui | 2 +-
src/gtd-task-list-view.c | 150 +++++++++++++++++++++++++++++-----------------
src/gtd-task-row.c | 6 ++-
3 files changed, 102 insertions(+), 56 deletions(-)
---
diff --git a/data/ui/list-view.ui b/data/ui/list-view.ui
index 936a196..719b77a 100644
--- a/data/ui/list-view.ui
+++ b/data/ui/list-view.ui
@@ -41,12 +41,12 @@
<signal name="drag-drop" handler="listbox_drag_drop" object="GtdTaskListView"
swapped="no" />
<signal name="drag-leave" handler="listbox_drag_leave" object="GtdTaskListView"
swapped="no" />
<signal name="drag-motion" handler="listbox_drag_motion" object="GtdTaskListView"
swapped="no" />
- <signal name="row-activated" handler="gtd_task_list_view__row_activated"
object="GtdTaskListView" swapped="no" />
<child>
<object class="GtdTaskRow" id="new_task_row">
<property name="visible">True</property>
<property name="new-task-mode">True</property>
<signal name="create-task" handler="gtd_task_list_view__create_task"
object="GtdTaskListView" swapped="no" />
+ <signal name="exit" handler="task_row_exited_cb" object="GtdTaskListView"
swapped="yes" />
</object>
</child>
<child>
diff --git a/src/gtd-task-list-view.c b/src/gtd-task-list-view.c
index e907907..8dcab4c 100644
--- a/src/gtd-task-list-view.c
+++ b/src/gtd-task-list-view.c
@@ -778,6 +778,96 @@ gtd_task_list_view__done_button_clicked (GtkButton *button,
}
static void
+task_row_entered_cb (GtdTaskListView *self,
+ GtdTaskRow *row)
+{
+ GtdTaskListViewPrivate *priv = self->priv;
+ GtdTask *old_task;
+
+ if (row == priv->new_task_row)
+ return;
+
+ old_task = gtd_edit_pane_get_task (priv->edit_pane);
+
+ /* Save the task previously edited */
+ if (old_task)
+ {
+ gtd_manager_update_task (gtd_manager_get_default (), old_task);
+ real_save_task (self, old_task);
+ }
+
+ gtd_edit_pane_set_task (priv->edit_pane, gtd_task_row_get_task (row));
+
+ gtk_revealer_set_reveal_child (priv->edit_revealer, TRUE);
+ gtd_arrow_frame_set_row (priv->arrow_frame, row);
+}
+
+static void
+task_row_exited_cb (GtdTaskListView *self,
+ GtdTaskRow *row)
+{
+ GtdTaskListViewPrivate *priv = self->priv;
+ GtdTask *old_task;
+
+ old_task = gtd_edit_pane_get_task (priv->edit_pane);
+
+ /* Save the task previously edited */
+ if (old_task)
+ {
+ gtd_manager_update_task (gtd_manager_get_default (), old_task);
+ real_save_task (self, old_task);
+ }
+
+ gtd_edit_pane_set_task (priv->edit_pane, NULL);
+
+ gtk_revealer_set_reveal_child (priv->edit_revealer, FALSE);
+ gtd_arrow_frame_set_row (priv->arrow_frame, NULL);
+}
+
+static void
+insert_task (GtdTaskListView *self,
+ GtdTask *task)
+{
+ GtdTaskListViewPrivate *priv = self->priv;
+ GtkWidget *new_row;
+
+ new_row = gtd_task_row_new (task);
+
+ g_object_bind_property (self,
+ "handle-subtasks",
+ new_row,
+ "handle-subtasks",
+ G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
+
+ gtd_task_row_set_list_name_visible (GTD_TASK_ROW (new_row), priv->show_list_name);
+
+ g_signal_connect_swapped (new_row,
+ "enter",
+ G_CALLBACK (task_row_entered_cb),
+ self);
+
+ g_signal_connect_swapped (new_row,
+ "exit",
+ G_CALLBACK (task_row_exited_cb),
+ self);
+
+ gtk_list_box_insert (priv->listbox,
+ new_row,
+ 0);
+ gtd_task_row_reveal (GTD_TASK_ROW (new_row));
+}
+
+static void
+destroy_task_row (GtdTaskListView *self,
+ GtdTaskRow *row)
+{
+ g_signal_handlers_disconnect_by_func (row, task_row_entered_cb, self);
+ g_signal_handlers_disconnect_by_func (row, task_row_exited_cb, self);
+
+ gtd_task_row_destroy (row);
+}
+
+static void
remove_task (GtdTaskListView *view,
GtdTask *task)
{
@@ -803,8 +893,8 @@ remove_task (GtdTaskListView *view,
g_signal_handlers_disconnect_by_func (task,
task_completed_cb,
view);
- gtd_task_row_destroy (l->data);
+ destroy_task_row (view, l->data);
break;
}
}
@@ -815,22 +905,6 @@ remove_task (GtdTaskListView *view,
g_list_free (children);
}
-static void
-gtd_task_list_view__row_activated (GtkListBox *listbox,
- GtdTaskRow *row,
- gpointer user_data)
-{
- GtdTaskListViewPrivate *priv = GTD_TASK_LIST_VIEW (user_data)->priv;
-
- if (row == priv->new_task_row)
- return;
-
- gtd_edit_pane_set_task (priv->edit_pane, gtd_task_row_get_task (row));
-
- gtk_revealer_set_reveal_child (priv->edit_revealer, TRUE);
- gtd_arrow_frame_set_row (priv->arrow_frame, row);
-}
-
static inline gboolean
has_complete_parent (GtdTask *task)
{
@@ -852,7 +926,6 @@ gtd_task_list_view__add_task (GtdTaskListView *view,
GtdTask *task)
{
GtdTaskListViewPrivate *priv = view->priv;
- GtkWidget *new_row;
g_return_if_fail (GTD_IS_TASK_LIST_VIEW (view));
g_return_if_fail (GTD_IS_TASK (task));
@@ -863,20 +936,7 @@ gtd_task_list_view__add_task (GtdTaskListView *view,
return;
}
- new_row = gtd_task_row_new (task);
-
- g_object_bind_property (view,
- "handle-subtasks",
- new_row,
- "handle-subtasks",
- G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
-
- gtd_task_row_set_list_name_visible (GTD_TASK_ROW (new_row), priv->show_list_name);
-
- gtk_list_box_insert (priv->listbox,
- new_row,
- 0);
- gtd_task_row_reveal (GTD_TASK_ROW (new_row));
+ insert_task (view, task);
/* Check if it should show the empty state */
gtd_task_list_view__update_empty_state (view);
@@ -903,8 +963,7 @@ gtd_task_list_view__remove_row_for_task (GtdTaskListView *view,
if (!gtd_task_row_get_new_task_mode (l->data) &&
gtd_task_row_get_task (l->data) == task)
{
- gtd_task_row_destroy (l->data);
-
+ destroy_task_row (view, l->data);
break;
}
}
@@ -1514,10 +1573,10 @@ gtd_task_list_view_class_init (GtdTaskListViewClass *klass)
gtk_widget_class_bind_template_callback (widget_class, gtd_task_list_view__done_button_clicked);
gtk_widget_class_bind_template_callback (widget_class, gtd_task_list_view__edit_task_finished);
gtk_widget_class_bind_template_callback (widget_class, gtd_task_list_view__remove_task_cb);
- gtk_widget_class_bind_template_callback (widget_class, gtd_task_list_view__row_activated);
gtk_widget_class_bind_template_callback (widget_class, listbox_drag_drop);
gtk_widget_class_bind_template_callback (widget_class, listbox_drag_leave);
gtk_widget_class_bind_template_callback (widget_class, listbox_drag_motion);
+ gtk_widget_class_bind_template_callback (widget_class, task_row_exited_cb);
gtk_widget_class_set_css_name (widget_class, "task-list-view");
}
@@ -1870,8 +1929,6 @@ gtd_task_list_view_set_show_completed (GtdTaskListView *view,
for (l = list_of_tasks; l != NULL; l = l->next)
{
- GtkWidget *new_row;
-
/*
* Consider that not-complete tasks, and non-complete tasks with a non-complete
* parent, are already present.
@@ -1879,22 +1936,7 @@ gtd_task_list_view_set_show_completed (GtdTaskListView *view,
if (!gtd_task_get_complete (l->data) && !has_complete_parent (l->data))
continue;
- new_row = gtd_task_row_new (l->data);
-
- g_object_bind_property (view,
- "handle-subtasks",
- new_row,
- "handle-subtasks",
- G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
-
- gtd_task_row_set_list_name_visible (GTD_TASK_ROW (new_row), priv->show_list_name);
-
-
- gtk_list_box_insert (priv->listbox,
- new_row,
- 0);
-
- gtd_task_row_reveal (GTD_TASK_ROW (new_row));
+ insert_task (view, l->data);
}
g_list_free (list_of_tasks);
@@ -1920,7 +1962,7 @@ gtd_task_list_view_set_show_completed (GtdTaskListView *view,
/* Remove completed tasks, and also tasks with a completed parent */
if (gtd_task_get_complete (task) || has_complete_parent (task))
- gtd_task_row_destroy (l->data);
+ destroy_task_row (view, l->data);
}
g_list_free (children);
diff --git a/src/gtd-task-row.c b/src/gtd-task-row.c
index f2770ac..4f8001f 100644
--- a/src/gtd-task-row.c
+++ b/src/gtd-task-row.c
@@ -380,7 +380,7 @@ gtd_task_row__entry_focus_out (GtkWidget *widget,
}
static gboolean
-gtd_task_row__focus_in (GtkWidget *widget,
+gtd_task_row__focus_in (GtkWidget *widget,
GdkEventFocus *event)
{
GtdTaskRow *self = GTD_TASK_ROW (widget);
@@ -391,11 +391,15 @@ gtd_task_row__focus_in (GtkWidget *widget,
{
gtk_stack_set_visible_child_name (self->new_task_stack, "entry");
gtk_widget_grab_focus (GTK_WIDGET (self->new_task_entry));
+
+ g_signal_emit (self, signals[EXIT], 0);
}
else
{
gtk_stack_set_visible_child_name (self->task_stack, "title");
gtk_widget_grab_focus (GTK_WIDGET (self->title_entry));
+
+ g_signal_emit (self, signals[ENTER], 0);
}
return FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]