[gnome-todo] gtd-sidebar-list-row: Add drag/drop handler
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo] gtd-sidebar-list-row: Add drag/drop handler
- Date: Tue, 28 Jun 2022 21:59:42 +0000 (UTC)
commit b8bf39f6f6394560753e8bbfb619b19248f0d895
Author: Jamie Murphy <hello jamiethalacker dev>
Date: Tue Jun 28 13:18:50 2022 -0700
gtd-sidebar-list-row: Add drag/drop handler
.../task-lists-workspace/gtd-sidebar-list-row.c | 69 ++++++++++++++++++++++
1 file changed, 69 insertions(+)
---
diff --git a/src/plugins/task-lists-workspace/gtd-sidebar-list-row.c
b/src/plugins/task-lists-workspace/gtd-sidebar-list-row.c
index a18b09c8..5919665f 100644
--- a/src/plugins/task-lists-workspace/gtd-sidebar-list-row.c
+++ b/src/plugins/task-lists-workspace/gtd-sidebar-list-row.c
@@ -135,6 +135,19 @@ set_list (GtdSidebarListRow *self,
* Callbacks
*/
+static void
+on_import_task_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ g_autoptr (GError) error = NULL;
+
+ gtd_task_list_import_task_finish (GTD_TASK_LIST (object), result, &error);
+
+ if (error)
+ g_warning ("Error updating task: %s", error->message);
+}
+
static void
on_list_changed_cb (GtdSidebarListRow *self)
{
@@ -161,6 +174,53 @@ on_rename_popover_hidden_cb (GtkPopover *popover,
gtk_widget_set_parent (GTK_WIDGET (popover), NULL);
}
+static gboolean
+on_task_drop (GtkDropTarget *target,
+ const GValue *value,
+ double x,
+ double y,
+ GtdSidebarListRow *self)
+{
+ GtdTask *task;
+
+ GTD_ENTRY;
+
+ task = g_value_get_object (value);
+ gtd_task_list_import_task (self->list,
+ task,
+ NULL,
+ on_import_task_cb,
+ self);
+
+ GTD_RETURN (TRUE);
+}
+
+
+static gboolean
+on_task_enter_drop (GtkDropTarget *target,
+ double x,
+ double y,
+ GtdSidebarListRow *self)
+{
+ GTD_ENTRY;
+
+ gtk_widget_set_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED , FALSE);
+
+ GTD_RETURN (TRUE);
+}
+
+static gboolean
+on_task_leave_drop (GtkDropTarget *target,
+ double x,
+ double y,
+ GtdSidebarListRow *self)
+{
+ GTD_ENTRY;
+
+ gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED);
+
+ GTD_RETURN (TRUE);
+}
/*
* GObject overrides
@@ -244,7 +304,16 @@ gtd_sidebar_list_row_class_init (GtdSidebarListRowClass *klass)
static void
gtd_sidebar_list_row_init (GtdSidebarListRow *self)
{
+ GtkDropTarget *target;
+
gtk_widget_init_template (GTK_WIDGET (self));
+
+ target = gtk_drop_target_new (GTD_TYPE_TASK, GDK_ACTION_MOVE);
+ gtk_drop_target_set_preload (target, TRUE);
+ g_signal_connect (target, "drop", G_CALLBACK (on_task_drop), self);
+ g_signal_connect (target, "enter", G_CALLBACK (on_task_enter_drop), self);
+ g_signal_connect (target, "leave", G_CALLBACK (on_task_leave_drop), self);
+ gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (target));
}
GtkWidget*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]