[gnome-todo/wip/gbsneto/subtasks: 29/37] task-list-view: add ::handle-subtasks property and API



commit 4fb2fdd9c6f02c73a30e8498aa1d4a963a6be924
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Oct 14 16:39:05 2016 -0300

    task-list-view: add ::handle-subtasks property and API
    
    So we can control whether we want to display subtasks or not.

 src/gtd-task-list-view.c |   88 ++++++++++++++++++++++++++++++++++++++++++++++
 src/gtd-task-list-view.h |    5 +++
 src/gtd-task-row.c       |   55 ++++++++++++++++++++++++++++-
 src/gtd-task-row.h       |    5 +++
 4 files changed, 152 insertions(+), 1 deletions(-)
---
diff --git a/src/gtd-task-list-view.c b/src/gtd-task-list-view.c
index a21459c..6b36e98 100644
--- a/src/gtd-task-list-view.c
+++ b/src/gtd-task-list-view.c
@@ -79,6 +79,7 @@ typedef struct
   gint                   complete_tasks;
   gboolean               show_list_name;
   gboolean               show_completed;
+  gboolean               handle_subtasks : 1;
   GList                 *list;
   GtdTaskList           *task_list;
   GDateTime             *default_date;
@@ -144,6 +145,7 @@ typedef struct
 enum {
   PROP_0,
   PROP_COLOR,
+  PROP_HANDLE_SUBTASKS,
   PROP_SHOW_COMPLETED,
   PROP_SHOW_LIST_NAME,
   PROP_SHOW_NEW_TASK_ROW,
@@ -766,6 +768,12 @@ gtd_task_list_view__add_task (GtdTaskListView *view,
 
   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);
 
   if (!gtd_task_get_complete (task))
@@ -962,6 +970,10 @@ gtd_task_list_view_get_property (GObject    *object,
 
   switch (prop_id)
     {
+    case PROP_HANDLE_SUBTASKS:
+      g_value_set_boolean (value, self->priv->handle_subtasks);
+      break;
+
     case PROP_SHOW_COMPLETED:
       g_value_set_boolean (value, self->priv->show_completed);
       break;
@@ -989,6 +1001,10 @@ gtd_task_list_view_set_property (GObject      *object,
 
   switch (prop_id)
     {
+    case PROP_HANDLE_SUBTASKS:
+      gtd_task_list_view_set_handle_subtasks (self, g_value_get_boolean (value));
+      break;
+
     case PROP_SHOW_COMPLETED:
       gtd_task_list_view_set_show_completed (self, g_value_get_boolean (value));
       break;
@@ -1222,6 +1238,20 @@ gtd_task_list_view_class_init (GtdTaskListViewClass *klass)
                             G_PARAM_READWRITE));
 
   /**
+   * GtdTaskListView::handle-subtasks:
+   *
+   * Whether the list is able to handle subtasks.
+   */
+  g_object_class_install_property (
+        object_class,
+        PROP_HANDLE_SUBTASKS,
+        g_param_spec_boolean ("handle-subtasks",
+                              "Whether it handles subtasks",
+                              "Whether the list handles subtasks, or not",
+                              TRUE,
+                              G_PARAM_READWRITE));
+
+  /**
    * GtdTaskListView::show-new-task-row:
    *
    * Whether the list shows the "New Task" row or not.
@@ -1291,6 +1321,7 @@ gtd_task_list_view_init (GtdTaskListView *self)
 {
   self->priv = gtd_task_list_view_get_instance_private (self);
   self->priv->can_toggle = TRUE;
+  self->priv->handle_subtasks = TRUE;
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
@@ -1630,6 +1661,12 @@ gtd_task_list_view_set_show_completed (GtdTaskListView *view,
 
               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);
 
 
@@ -1852,3 +1889,54 @@ gtd_task_list_view_set_color (GtdTaskListView *self,
       g_object_notify (G_OBJECT (self), "color");
     }
 }
+
+/**
+ * gtd_task_list_view_get_handle_subtasks:
+ * @self: a #GtdTaskListView
+ *
+ * Retirves whether @self handle subtasks, i.e. make the rows
+ * change padding depending on their depth, show an arrow button
+ * to toggle subtasks, among others.
+ *
+ * Returns: %TRUE if @self handles subtasks, %FALSE otherwise
+ */
+gboolean
+gtd_task_list_view_get_handle_subtasks (GtdTaskListView *self)
+{
+  GtdTaskListViewPrivate *priv;
+
+  g_return_val_if_fail (GTD_IS_TASK_LIST_VIEW (self), FALSE);
+
+  priv = gtd_task_list_view_get_instance_private (self);
+
+  return priv->handle_subtasks;
+}
+
+/**
+ * gtd_task_list_view_set_handle_subtasks:
+ * @self: a #GtdTaskListView
+ * @handle_subtasks: %TRUE to make @self handle subtasks, %FALSE to disable subtasks.
+ *
+ * If %TRUE, makes @self handle subtasks, adjust the task rows according to their
+ * hierarchy level at the subtask tree and show the arrow button to toggle subtasks
+ * of a given task.
+ *
+ * Drag and drop tasks will only work if @self handles subtasks as well.
+ */
+void
+gtd_task_list_view_set_handle_subtasks (GtdTaskListView *self,
+                                        gboolean         handle_subtasks)
+{
+  GtdTaskListViewPrivate *priv;
+
+  g_return_if_fail (GTD_IS_TASK_LIST_VIEW (self));
+
+  priv = gtd_task_list_view_get_instance_private (self);
+
+  if (priv->handle_subtasks == handle_subtasks)
+    return;
+
+  priv->handle_subtasks = handle_subtasks;
+
+  g_object_notify (G_OBJECT (self), "handle-subtasks");
+}
diff --git a/src/gtd-task-list-view.h b/src/gtd-task-list-view.h
index 0ceeb4a..588f0d3 100644
--- a/src/gtd-task-list-view.h
+++ b/src/gtd-task-list-view.h
@@ -106,6 +106,11 @@ GdkRGBA*                  gtd_task_list_view_get_color          (GtdTaskListView
 void                      gtd_task_list_view_set_color          (GtdTaskListView        *self,
                                                                  GdkRGBA                *color);
 
+gboolean                  gtd_task_list_view_get_handle_subtasks (GtdTaskListView       *self);
+
+void                      gtd_task_list_view_set_handle_subtasks (GtdTaskListView       *self,
+                                                                  gboolean               handle_subtasks);
+
 G_END_DECLS
 
 #endif /* GTD_TASK_LIST_VIEW_H */
diff --git a/src/gtd-task-row.c b/src/gtd-task-row.c
index 729516b..9117cbd 100644
--- a/src/gtd-task-row.c
+++ b/src/gtd-task-row.c
@@ -52,6 +52,8 @@ struct _GtdTaskRow
   gdouble                    clicked_x;
   gdouble                    clicked_y;
 
+  gboolean                   handle_subtasks : 1;
+
   /* data */
   gboolean                   new_task_mode;
   GtdTask                   *task;
@@ -74,6 +76,7 @@ enum {
 
 enum {
   PROP_0,
+  PROP_HANDLE_SUBTASKS,
   PROP_NEW_TASK_MODE,
   PROP_TASK,
   LAST_PROP
@@ -266,7 +269,8 @@ depth_changed_cb (GtdTaskRow *self,
                   GParamSpec *pspec,
                   GtdTask    *task)
 {
-  gtk_widget_set_margin_start (self->dnd_box, 32 * gtd_task_get_depth (task));
+  gtk_widget_set_margin_start (self->dnd_box,
+                               self->handle_subtasks ? 32 * gtd_task_get_depth (task) : 0);
 }
 
 static gboolean
@@ -493,6 +497,10 @@ gtd_task_row_get_property (GObject    *object,
 
   switch (prop_id)
     {
+    case PROP_HANDLE_SUBTASKS:
+      g_value_set_boolean (value, self->handle_subtasks);
+      break;
+
     case PROP_NEW_TASK_MODE:
       g_value_set_boolean (value, self->new_task_mode);
       break;
@@ -516,6 +524,10 @@ gtd_task_row_set_property (GObject      *object,
 
   switch (prop_id)
     {
+    case PROP_HANDLE_SUBTASKS:
+      gtd_task_row_set_handle_subtasks (self, g_value_get_boolean (value));
+      break;
+
     case PROP_NEW_TASK_MODE:
       gtd_task_row_set_new_task_mode (self, g_value_get_boolean (value));
       break;
@@ -555,6 +567,20 @@ gtd_task_row_class_init (GtdTaskRowClass *klass)
   row_class->activate = gtd_task_row_activate;
 
   /**
+   * GtdTaskRow::handle-subtasks:
+   *
+   * If the row consider the task's subtasks to adjust various UI properties.
+   */
+  g_object_class_install_property (
+          object_class,
+          PROP_HANDLE_SUBTASKS,
+          g_param_spec_boolean ("handle-subtasks",
+                                "If the row adapts to subtasks",
+                                "Whether the row adapts to the task's subtasks",
+                                TRUE,
+                                G_PARAM_READWRITE));
+
+  /**
    * GtdTaskRow::new-task-mode:
    *
    * If the row is used to add new tasks.
@@ -673,6 +699,8 @@ gtd_task_row_class_init (GtdTaskRowClass *klass)
 static void
 gtd_task_row_init (GtdTaskRow *self)
 {
+  self->handle_subtasks = TRUE;
+
   gtk_widget_init_template (GTK_WIDGET (self));
 
   /* The source of DnD is the drag icon */
@@ -921,3 +949,28 @@ gtd_task_row_is_drag_valid (GtdTaskRow     *self,
 
   return TRUE;
 }
+
+gboolean
+gtd_task_row_get_handle_subtasks (GtdTaskRow *self)
+{
+  g_return_val_if_fail (GTD_IS_TASK_ROW (self), FALSE);
+
+  return self->handle_subtasks;
+}
+
+void
+gtd_task_row_set_handle_subtasks (GtdTaskRow *self,
+                                  gboolean    handle_subtasks)
+{
+  g_return_if_fail (GTD_IS_TASK_ROW (self));
+
+  if (self->handle_subtasks == handle_subtasks)
+    return;
+
+  self->handle_subtasks = handle_subtasks;
+
+  gtk_widget_set_visible (self->dnd_event_box, handle_subtasks);
+  depth_changed_cb (self, NULL, self->task);
+
+  g_object_notify (G_OBJECT (self), "handle-subtasks");
+}
diff --git a/src/gtd-task-row.h b/src/gtd-task-row.h
index cabbbe4..4d6f053 100644
--- a/src/gtd-task-row.h
+++ b/src/gtd-task-row.h
@@ -52,6 +52,11 @@ void                      gtd_task_row_destroy                  (GtdTaskRow
 gboolean                  gtd_task_row_is_drag_valid            (GtdTaskRow          *self,
                                                                  GdkDragContext      *context);
 
+gboolean                  gtd_task_row_get_handle_subtasks      (GtdTaskRow          *self);
+
+void                      gtd_task_row_set_handle_subtasks      (GtdTaskRow          *self,
+                                                                 gboolean             handle_subtasks);
+
 G_END_DECLS
 
 #endif /* GTD_TASK_ROW_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]