[gnome-todo] task-list-view: Remove subtasks handling
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo] task-list-view: Remove subtasks handling
- Date: Fri, 30 Apr 2021 17:26:22 +0000 (UTC)
commit 8f08d02e9661b066e667d1cf38deca98e1613538
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Apr 21 17:45:18 2021 -0300
task-list-view: Remove subtasks handling
Subtasks will be replaced by a more sophisticated system
to manage dependencies in the future. For now, let's begin
by cleaning up the current subtasks implementation.
src/gui/gtd-task-list-view.c | 226 ++--------------------
src/gui/gtd-task-list-view.h | 5 -
src/gui/gtd-task-row.c | 59 ------
src/gui/gtd-task-row.h | 8 -
src/plugins/all-tasks-panel/gtd-all-tasks-panel.c | 1 -
src/plugins/inbox-panel/gtd-inbox-panel.c | 1 -
src/plugins/next-week-panel/gtd-next-week-panel.c | 1 -
src/plugins/scheduled-panel/gtd-panel-scheduled.c | 1 -
src/plugins/today-panel/gtd-panel-today.c | 1 -
9 files changed, 14 insertions(+), 289 deletions(-)
---
diff --git a/src/gui/gtd-task-list-view.c b/src/gui/gtd-task-list-view.c
index afbae26a..4faf1af9 100644
--- a/src/gui/gtd-task-list-view.c
+++ b/src/gui/gtd-task-list-view.c
@@ -80,7 +80,6 @@ typedef struct
gboolean can_toggle;
gboolean show_due_date;
gboolean show_list_name;
- gboolean handle_subtasks;
GListModel *model;
GDateTime *default_date;
@@ -180,16 +179,12 @@ typedef struct
enum {
PROP_0,
- PROP_HANDLE_SUBTASKS,
PROP_SHOW_LIST_NAME,
PROP_SHOW_DUE_DATE,
PROP_SHOW_NEW_TASK_ROW,
LAST_PROP
};
-typedef gboolean (*IterateSubtaskFunc) (GtdTaskListView *self,
- GtdTask *task);
-
/*
* Auxiliary methods
@@ -222,27 +217,6 @@ set_active_row (GtdTaskListView *self,
}
}
-static gboolean
-iterate_subtasks (GtdTaskListView *self,
- GtdTask *task,
- IterateSubtaskFunc func)
-{
- GtdTask *aux;
-
- if (!func (self, task))
- return FALSE;
-
- for (aux = gtd_task_get_first_subtask (task);
- aux;
- aux = gtd_task_get_next_sibling (aux))
- {
- if (!iterate_subtasks (self, aux, func))
- return FALSE;
- }
-
- return TRUE;
-}
-
static void
schedule_scroll_to_bottom (GtdTaskListView *self)
{
@@ -350,12 +324,6 @@ create_row_for_task_cb (gpointer item,
row = gtd_task_row_new (item, priv->renderer);
- g_object_bind_property (self,
- "handle-subtasks",
- row,
- "handle-subtasks",
- G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
-
gtd_task_row_set_list_name_visible (GTD_TASK_ROW (row), priv->show_list_name);
gtd_task_row_set_due_date_visible (GTD_TASK_ROW (row), priv->show_due_date);
@@ -421,18 +389,6 @@ on_task_removed_cb (GObject *source,
g_warning ("Error removing task list: %s", error->message);
}
-static inline gboolean
-remove_task_cb (GtdTaskListView *self,
- GtdTask *task)
-{
- gtd_provider_remove_task (gtd_task_get_provider (task),
- task,
- NULL,
- on_task_removed_cb,
- self);
- return TRUE;
-}
-
static void
on_clear_completed_tasks_activated_cb (GSimpleAction *simple,
GVariant *parameter,
@@ -452,11 +408,11 @@ on_clear_completed_tasks_activated_cb (GSimpleAction *simple,
if (!gtd_task_get_complete (task))
continue;
- if (gtd_task_get_parent (task))
- gtd_task_remove_subtask (gtd_task_get_parent (task), task);
-
- /* Remove the subtasks recursively */
- iterate_subtasks (self, task, remove_task_cb);
+ gtd_provider_remove_task (gtd_task_get_provider (task),
+ task,
+ NULL,
+ on_task_removed_cb,
+ self);
}
}
@@ -464,17 +420,13 @@ static void
on_remove_task_action_cb (GtdNotification *notification,
gpointer user_data)
{
- RemoveTaskData *data;
- GtdTask *task;
+ RemoveTaskData *data = user_data;
- data = user_data;
- task = data->task;
-
- if (gtd_task_get_parent (task))
- gtd_task_remove_subtask (gtd_task_get_parent (task), task);
-
- /* Remove the subtasks recursively */
- iterate_subtasks (data->view, data->task, remove_task_cb);
+ gtd_provider_remove_task (gtd_task_get_provider (data->task),
+ data->task,
+ NULL,
+ on_task_removed_cb,
+ data->view);
g_clear_pointer (&data, g_free);
}
@@ -518,7 +470,7 @@ on_remove_task_row_cb (GtdTaskRow *row,
data->view = self;
data->task = task;
- /* Remove tasks and subtasks from the list */
+ /* Remove task from the list */
list = gtd_task_get_list (task);
gtd_task_list_remove_task (list, task);
@@ -635,19 +587,6 @@ internal_header_func (GtkListBoxRow *row,
* Drag n' Drop functions
*/
-static gboolean
-row_is_subtask_of (GtdTaskRow *row_a,
- GtdTaskRow *row_b)
-{
- GtdTask *task_a;
- GtdTask *task_b;
-
- task_a = gtd_task_row_get_task (row_a);
- task_b = gtd_task_row_get_task (row_b);
-
- return gtd_task_is_subtask (task_a, task_b);
-}
-
static GtkListBoxRow*
get_drop_row_at_y (GtdTaskListView *self,
gdouble y)
@@ -713,11 +652,7 @@ static void
unset_previously_highlighted_row (GtdTaskListView *self)
{
GtdTaskListViewPrivate *priv = gtd_task_list_view_get_instance_private (self);
- if (priv->highlighted_row)
- {
- gtd_task_row_unset_drag_offset (task_row_from_row (priv->highlighted_row));
- priv->highlighted_row = NULL;
- }
+ priv->highlighted_row = NULL;
}
static inline gboolean
@@ -800,13 +735,8 @@ on_drop_target_drag_motion_cb (GtkDropTarget *drop_target,
{
GtdTaskListViewPrivate *priv;
GtkListBoxRow *highlighted_row;
- GtdTaskRow *highlighted_task_row;
- GtdTaskRow *source_task_row;
- const GValue *value;
GdkDrop *drop;
- GtdTask *task;
GdkDrag *drag;
- gdouble x_offset;
GTD_ENTRY;
@@ -820,37 +750,12 @@ on_drop_target_drag_motion_cb (GtkDropTarget *drop_target,
GTD_GOTO (fail);
}
- value = gtk_drop_target_get_value (drop_target);
- task = g_value_get_object (value);
-
- source_task_row = g_hash_table_lookup (priv->task_to_row, task);
-
- /* Update the x value according to the current offset */
- if (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL)
- x += gtd_task_row_get_x_offset (source_task_row);
- else
- x -= gtd_task_row_get_x_offset (source_task_row);
-
unset_previously_highlighted_row (self);
highlighted_row = get_drop_row_at_y (self, y);
if (!highlighted_row)
GTD_GOTO (success);
- highlighted_task_row = task_row_from_row (highlighted_row);
-
- /* Forbid dropping a row over a subtask row */
- if (row_is_subtask_of (source_task_row, highlighted_task_row))
- GTD_GOTO (fail);
-
- gtk_widget_translate_coordinates (GTK_WIDGET (priv->listbox),
- GTK_WIDGET (highlighted_task_row),
- x,
- 0,
- &x_offset,
- NULL);
-
- gtd_task_row_set_drag_offset (highlighted_task_row, source_task_row, x_offset);
priv->highlighted_row = highlighted_row;
success:
@@ -873,7 +778,6 @@ on_drop_target_drag_drop_cb (GtkDropTarget *drop_target,
GtdProvider *provider;
GtdTaskRow *hovered_row;
GtkWidget *row;
- GtdTask *new_parent_task;
GtdTask *hovered_task;
GtdTask *source_task;
GdkDrop *drop;
@@ -896,6 +800,7 @@ on_drop_target_drag_drop_cb (GtkDropTarget *drop_target,
unset_previously_highlighted_row (self);
source_task = g_value_get_object (value);
+ g_assert (source_task != NULL);
/*
* When the drag operation began, the source row was hidden. Now is the time
@@ -907,34 +812,6 @@ on_drop_target_drag_drop_cb (GtkDropTarget *drop_target,
drop_row = get_drop_row_at_y (self, y);
hovered_row = task_row_from_row (drop_row);
hovered_task = gtd_task_row_get_task (hovered_row);
- new_parent_task = gtd_task_row_get_dnd_drop_task (hovered_row);
-
- g_assert (source_task != NULL);
- g_assert (source_task != new_parent_task);
-
- if (new_parent_task)
- {
- /* Forbid adding the parent task as a subtask */
- if (gtd_task_is_subtask (source_task, new_parent_task))
- {
- gdk_drop_finish (drop, 0);
- GTD_RETURN (FALSE);
- }
-
- GTD_TRACE_MSG ("Making '%s' (%s) subtask of '%s' (%s)",
- gtd_task_get_title (source_task),
- gtd_object_get_uid (GTD_OBJECT (source_task)),
- gtd_task_get_title (new_parent_task),
- gtd_object_get_uid (GTD_OBJECT (new_parent_task)));
-
- gtd_task_add_subtask (new_parent_task, source_task);
- }
- else
- {
- GtdTask *current_parent_task = gtd_task_get_parent (source_task);
- if (current_parent_task)
- gtd_task_remove_subtask (current_parent_task, source_task);
- }
/*
* FIXME: via DnD, we only support moving the task to below another
@@ -986,10 +863,6 @@ 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_DUE_DATE:
g_value_set_boolean (value, self->priv->show_due_date);
break;
@@ -1017,10 +890,6 @@ 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_DUE_DATE:
gtd_task_list_view_set_show_due_date (self, g_value_get_boolean (value));
break;
@@ -1099,20 +968,6 @@ gtd_task_list_view_class_init (GtdTaskListViewClass *klass)
g_type_ensure (GTD_TYPE_DND_ROW);
g_type_ensure (GTD_TYPE_EMPTY_LIST_WIDGET);
- /**
- * 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:
*
@@ -1190,7 +1045,6 @@ gtd_task_list_view_init (GtdTaskListView *self)
priv->task_to_row = g_hash_table_new (NULL, NULL);
priv->can_toggle = TRUE;
- priv->handle_subtasks = TRUE;
priv->show_due_date = TRUE;
priv->show_due_date = TRUE;
@@ -1499,58 +1353,6 @@ gtd_task_list_view_set_default_date (GtdTaskListView *self,
priv->default_date = default_date ? g_date_time_ref (default_date) : NULL;
}
-/**
- * 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");
-}
-
-
GtdTaskListSelectorBehavior
gtd_task_list_view_get_task_list_selector_behavior (GtdTaskListView *self)
{
diff --git a/src/gui/gtd-task-list-view.h b/src/gui/gtd-task-list-view.h
index be9e90ba..7258a20e 100644
--- a/src/gui/gtd-task-list-view.h
+++ b/src/gui/gtd-task-list-view.h
@@ -81,11 +81,6 @@ GDateTime* gtd_task_list_view_get_default_date (GtdTaskListView
void gtd_task_list_view_set_default_date (GtdTaskListView *self,
GDateTime *default_date);
-gboolean gtd_task_list_view_get_handle_subtasks (GtdTaskListView *self);
-
-void gtd_task_list_view_set_handle_subtasks (GtdTaskListView *self,
- gboolean handle_subtasks);
-
GtdTaskListSelectorBehavior gtd_task_list_view_get_task_list_selector_behavior (GtdTaskListView
*self);
void gtd_task_list_view_set_task_list_selector_behavior (GtdTaskListView
*self,
diff --git a/src/gui/gtd-task-row.c b/src/gui/gtd-task-row.c
index 876df1bd..116a8dad 100644
--- a/src/gui/gtd-task-row.c
+++ b/src/gui/gtd-task-row.c
@@ -925,44 +925,6 @@ gtd_task_row_set_sizegroups (GtdTaskRow *self,
gtk_size_group_add_widget (name_group, GTK_WIDGET (self->task_date_label));
}
-gint
-gtd_task_row_get_x_offset (GtdTaskRow *self)
-{
- g_return_val_if_fail (GTD_IS_TASK_ROW (self), -1);
-
- if (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL)
- return gtk_widget_get_width (GTK_WIDGET (self)) - self->clicked_x;
- else
- return self->clicked_x;
-}
-
-void
-gtd_task_row_set_drag_offset (GtdTaskRow *self,
- GtdTaskRow *source_row,
- gint x_offset)
-{
- gint current_task_depth;
- gint min_height;
- gint depth;
-
- g_return_if_fail (GTD_IS_TASK_ROW (self));
-
- /* Negative values are discarded */
- x_offset = MAX (x_offset, 0);
-
- /* Make the DnD frame match the height of the dragged row */
- gtk_widget_measure (GTK_WIDGET (self), GTK_ORIENTATION_VERTICAL, -1, &min_height, NULL, NULL, NULL);
- gtk_widget_set_size_request (self->dnd_frame, -1, min_height);
-
- current_task_depth = gtd_task_get_depth (self->task);
- depth = CLAMP (x_offset / 32, 0, current_task_depth + 1);
- gtk_widget_set_margin_start (self->dnd_frame, depth * 32 + 12);
-
- GTD_TRACE_MSG ("DnD frame height: %d, depth: %d", min_height, depth);
-
- gtk_widget_show (self->dnd_frame);
-}
-
void
gtd_task_row_unset_drag_offset (GtdTaskRow *self)
{
@@ -970,24 +932,3 @@ gtd_task_row_unset_drag_offset (GtdTaskRow *self)
gtk_widget_hide (self->dnd_frame);
}
-
-GtdTask*
-gtd_task_row_get_dnd_drop_task (GtdTaskRow *self)
-{
- GtdTask *task;
- gint task_depth;
- gint depth;
- gint i;
-
- g_return_val_if_fail (GTD_IS_TASK_ROW (self), NULL);
-
- task = self->task;
- task_depth = gtd_task_get_depth (task);
- depth = (gtk_widget_get_margin_start (self->dnd_frame) - 12) / 32;
-
- /* Find the real parent */
- for (i = task_depth - depth; i >= 0; i--)
- task = gtd_task_get_parent (task);
-
- return task;
-}
diff --git a/src/gui/gtd-task-row.h b/src/gui/gtd-task-row.h
index b51099ba..e2233cf6 100644
--- a/src/gui/gtd-task-row.h
+++ b/src/gui/gtd-task-row.h
@@ -54,16 +54,8 @@ void gtd_task_row_set_sizegroups (GtdTaskRow
GtkSizeGroup *name_group,
GtkSizeGroup *date_group);
-gint gtd_task_row_get_x_offset (GtdTaskRow *self);
-
-void gtd_task_row_set_drag_offset (GtdTaskRow *self,
- GtdTaskRow *source_row,
- gint x_offset);
-
void gtd_task_row_unset_drag_offset (GtdTaskRow *self);
-GtdTask* gtd_task_row_get_dnd_drop_task (GtdTaskRow *self);
-
G_END_DECLS
#endif /* GTD_TASK_ROW_H */
diff --git a/src/plugins/all-tasks-panel/gtd-all-tasks-panel.c
b/src/plugins/all-tasks-panel/gtd-all-tasks-panel.c
index 5126b0f7..182eeee4 100644
--- a/src/plugins/all-tasks-panel/gtd-all-tasks-panel.c
+++ b/src/plugins/all-tasks-panel/gtd-all-tasks-panel.c
@@ -481,7 +481,6 @@ gtd_all_tasks_panel_init (GtdAllTasksPanel *self)
/* The main view */
self->view = GTD_TASK_LIST_VIEW (gtd_task_list_view_new ());
gtd_task_list_view_set_model (GTD_TASK_LIST_VIEW (self->view), G_LIST_MODEL (self->sort_model));
- gtd_task_list_view_set_handle_subtasks (GTD_TASK_LIST_VIEW (self->view), FALSE);
gtd_task_list_view_set_show_list_name (GTD_TASK_LIST_VIEW (self->view), TRUE);
gtd_task_list_view_set_show_due_date (GTD_TASK_LIST_VIEW (self->view), FALSE);
diff --git a/src/plugins/inbox-panel/gtd-inbox-panel.c b/src/plugins/inbox-panel/gtd-inbox-panel.c
index 62272780..496ee060 100644
--- a/src/plugins/inbox-panel/gtd-inbox-panel.c
+++ b/src/plugins/inbox-panel/gtd-inbox-panel.c
@@ -251,7 +251,6 @@ gtd_inbox_panel_init (GtdInboxPanel *self)
/* The main view */
self->view = GTD_TASK_LIST_VIEW (gtd_task_list_view_new ());
gtd_task_list_view_set_model (GTD_TASK_LIST_VIEW (self->view), G_LIST_MODEL (self->filter_model));
- gtd_task_list_view_set_handle_subtasks (GTD_TASK_LIST_VIEW (self->view), FALSE);
gtd_task_list_view_set_show_list_name (GTD_TASK_LIST_VIEW (self->view), FALSE);
gtd_task_list_view_set_show_due_date (GTD_TASK_LIST_VIEW (self->view), FALSE);
gtd_task_list_view_set_task_list_selector_behavior (GTD_TASK_LIST_VIEW (self->view),
diff --git a/src/plugins/next-week-panel/gtd-next-week-panel.c
b/src/plugins/next-week-panel/gtd-next-week-panel.c
index 8241670a..41e5050e 100644
--- a/src/plugins/next-week-panel/gtd-next-week-panel.c
+++ b/src/plugins/next-week-panel/gtd-next-week-panel.c
@@ -542,7 +542,6 @@ gtd_next_week_panel_init (GtdNextWeekPanel *self)
/* The main view */
self->view = GTD_TASK_LIST_VIEW (gtd_task_list_view_new ());
gtd_task_list_view_set_model (GTD_TASK_LIST_VIEW (self->view), G_LIST_MODEL (self->sort_model));
- gtd_task_list_view_set_handle_subtasks (GTD_TASK_LIST_VIEW (self->view), FALSE);
gtd_task_list_view_set_show_list_name (GTD_TASK_LIST_VIEW (self->view), TRUE);
gtd_task_list_view_set_show_due_date (GTD_TASK_LIST_VIEW (self->view), FALSE);
gtd_task_list_view_set_default_date (self->view, now);
diff --git a/src/plugins/scheduled-panel/gtd-panel-scheduled.c
b/src/plugins/scheduled-panel/gtd-panel-scheduled.c
index e9df762a..c105ae46 100644
--- a/src/plugins/scheduled-panel/gtd-panel-scheduled.c
+++ b/src/plugins/scheduled-panel/gtd-panel-scheduled.c
@@ -487,7 +487,6 @@ gtd_panel_scheduled_init (GtdPanelScheduled *self)
/* The main view */
self->view = GTD_TASK_LIST_VIEW (gtd_task_list_view_new ());
gtd_task_list_view_set_model (self->view, G_LIST_MODEL (self->sort_model));
- gtd_task_list_view_set_handle_subtasks (self->view, FALSE);
gtd_task_list_view_set_show_list_name (self->view, TRUE);
gtd_task_list_view_set_show_due_date (self->view, FALSE);
gtd_task_list_view_set_default_date (self->view, now);
diff --git a/src/plugins/today-panel/gtd-panel-today.c b/src/plugins/today-panel/gtd-panel-today.c
index d9b553b8..4c547c7f 100644
--- a/src/plugins/today-panel/gtd-panel-today.c
+++ b/src/plugins/today-panel/gtd-panel-today.c
@@ -450,7 +450,6 @@ gtd_panel_today_init (GtdPanelToday *self)
/* The main view */
self->view = GTD_TASK_LIST_VIEW (gtd_task_list_view_new ());
gtd_task_list_view_set_model (self->view, G_LIST_MODEL (self->sort_model));
- gtd_task_list_view_set_handle_subtasks (self->view, FALSE);
gtd_task_list_view_set_show_list_name (self->view, TRUE);
gtd_task_list_view_set_show_due_date (self->view, FALSE);
gtd_task_list_view_set_default_date (self->view, now);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]