[gnome-todo] sidebar: Move list deletion to panel menu



commit 8c353b5cf2a00631f445c7eb282026b9c310b954
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Dec 15 20:27:10 2018 -0200

    sidebar: Move list deletion to panel menu
    
    This implements the proposed mockups.

 src/gtd-task-list-panel.c          |  34 ++++++++++++
 src/gtd-task-list-panel.ui         |  11 +++-
 src/sidebar/gtd-sidebar-list-row.c |  92 ---------------------------------
 src/sidebar/gtd-sidebar.c          | 103 +++++++++++++++++++++++++++++++++++++
 4 files changed, 146 insertions(+), 94 deletions(-)
---
diff --git a/src/gtd-task-list-panel.c b/src/gtd-task-list-panel.c
index 47ba0b4..ee92184 100644
--- a/src/gtd-task-list-panel.c
+++ b/src/gtd-task-list-panel.c
@@ -21,6 +21,7 @@
 #define G_LOG_DOMAIN "GtdTaskListPanel"
 
 #include "gtd-color-button.h"
+#include "gtd-debug.h"
 #include "gtd-panel.h"
 #include "gtd-provider.h"
 #include "gtd-task-list.h"
@@ -62,6 +63,13 @@ enum
   N_PROPS
 };
 
+enum
+{
+  LIST_DELETED,
+  N_SIGNALS
+};
+
+static guint signals[N_SIGNALS] = { 0, };
 
 /*
  * Auxilary methods
@@ -175,6 +183,20 @@ on_colors_flowbox_child_activated_cb (GtkFlowBox       *colors_flowbox,
   self->previous_color_button = color_button;
 }
 
+static void
+on_delete_button_clicked_cb (GtkModelButton   *button,
+                             GtdTaskListPanel *self)
+{
+  GtdTaskList *list;
+
+  list = GTD_TASK_LIST (gtd_task_list_view_get_model (self->task_list_view));
+  g_assert (list != NULL);
+
+  GTD_TRACE_MSG ("Emitting GtdTaskListPanel:list-deleted");
+
+  g_signal_emit (self, signals[LIST_DELETED], 0, list);
+}
+
 
 /*
  * GtdPanel iface
@@ -326,6 +348,17 @@ gtd_task_list_panel_class_init (GtdTaskListPanelClass *klass)
   g_object_class_override_property (object_class, PROP_SUBTITLE, "subtitle");
   g_object_class_override_property (object_class, PROP_TITLE, "title");
 
+  signals[LIST_DELETED] = g_signal_new ("list-deleted",
+                                        GTD_TYPE_TASK_LIST_PANEL,
+                                        G_SIGNAL_RUN_LAST,
+                                        0,
+                                        NULL,
+                                        NULL,
+                                        NULL,
+                                        G_TYPE_NONE,
+                                        1,
+                                        GTD_TYPE_TASK_LIST);
+
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/todo/ui/gtd-task-list-panel.ui");
 
   gtk_widget_class_bind_template_child (widget_class, GtdTaskListPanel, colors_flowbox);
@@ -333,6 +366,7 @@ gtd_task_list_panel_class_init (GtdTaskListPanelClass *klass)
   gtk_widget_class_bind_template_child (widget_class, GtdTaskListPanel, task_list_view);
 
   gtk_widget_class_bind_template_callback (widget_class, on_colors_flowbox_child_activated_cb);
+  gtk_widget_class_bind_template_callback (widget_class, on_delete_button_clicked_cb);
 }
 
 static void
diff --git a/src/gtd-task-list-panel.ui b/src/gtd-task-list-panel.ui
index 7de76b9..13bf558 100644
--- a/src/gtd-task-list-panel.ui
+++ b/src/gtd-task-list-panel.ui
@@ -31,6 +31,13 @@
           </object>
         </child>
 
+        <child>
+          <object class="GtkModelButton">
+            <property name="label" translatable="yes">Clear completed tasks…</property>
+            <property name="action-name">list.clear-completed-tasks</property>
+          </object>
+        </child>
+
         <child>
           <object class="GtkSeparator">
           </object>
@@ -38,8 +45,8 @@
 
         <child>
           <object class="GtkModelButton">
-            <property name="label" translatable="yes">Clear completed tasks…</property>
-            <property name="action-name">list.clear-completed-tasks</property>
+            <property name="label" translatable="yes">Delete</property>
+            <signal name="clicked" handler="on_delete_button_clicked_cb" object="GtdTaskListPanel" 
swapped="no" />
           </object>
         </child>
       </object>
diff --git a/src/sidebar/gtd-sidebar-list-row.c b/src/sidebar/gtd-sidebar-list-row.c
index 3d51619..4f35d2d 100644
--- a/src/sidebar/gtd-sidebar-list-row.c
+++ b/src/sidebar/gtd-sidebar-list-row.c
@@ -73,46 +73,6 @@ static GParamSpec *properties [N_PROPS];
  * Auxiliary methods
  */
 
-static void
-activate_row_below (GtdSidebarListRow *self)
-{
-  g_autoptr (GList) children = NULL;
-  GtkWidget *next_row;
-  GtkWidget *listbox;
-  GList *l;
-  gboolean after_deleted;
-
-  listbox = gtk_widget_get_parent (GTK_WIDGET (self));
-  children = gtk_container_get_children (GTK_CONTAINER (listbox));
-  after_deleted = FALSE;
-  next_row = NULL;
-
-  for (l = children; l; l = l->next)
-    {
-      GtkWidget *row = l->data;
-
-      if (row == (GtkWidget*) self)
-        {
-          after_deleted = TRUE;
-          continue;
-        }
-
-      if (!gtk_widget_get_visible (row) ||
-          !gtk_list_box_row_get_activatable (GTK_LIST_BOX_ROW (row)))
-        {
-          continue;
-        }
-
-      next_row = row;
-
-      if (after_deleted)
-        break;
-    }
-
-  if (next_row)
-    g_signal_emit_by_name (next_row, "activate");
-}
-
 static void
 update_color_icon (GtdSidebarListRow *self)
 {
@@ -222,57 +182,6 @@ popup_menu (GtdSidebarListRow *self)
  * Callbacks
  */
 
-static void
-delete_list_cb (GtdNotification *notification,
-                gpointer         user_data)
-{
-  GtdTaskList *list;
-  GtdProvider *provider;
-
-  list = GTD_TASK_LIST (user_data);
-  provider = gtd_task_list_get_provider (list);
-
-  g_assert (provider != NULL);
-  g_assert (gtd_task_list_is_removable (list));
-
-  gtd_provider_remove_task_list (provider, list);
-}
-
-static void
-undo_delete_list_cb (GtdNotification *notification,
-                     gpointer         user_data)
-{
-  gtk_widget_show (GTK_WIDGET (user_data));
-}
-
-static void
-on_delete_action_activated_cb (GSimpleAction *action,
-                               GVariant      *parameters,
-                               gpointer       user_data)
-{
-  GtdSidebarListRow *self;
-  GtdNotification *notification;
-  g_autofree gchar *title = NULL;
-
-  self = GTD_SIDEBAR_LIST_ROW (user_data);
-
-  title = g_strdup_printf (_("Task list <b>%s</b> removed"), gtd_task_list_get_name (self->list));
-  notification = gtd_notification_new (title, 6000.0);
-  gtd_notification_set_primary_action (notification, delete_list_cb, self->list);
-  gtd_notification_set_secondary_action (notification, _("Undo"), undo_delete_list_cb, self);
-
-  gtd_manager_send_notification (gtd_manager_get_default (), notification);
-
-  /*
-   * If the deleted list is selected, go to the next one (or previous, if
-   * there are no other task list after this one).
-   */
-  if (gtk_list_box_row_is_selected (GTK_LIST_BOX_ROW (self)))
-    activate_row_below (self);
-
-  gtk_widget_hide (GTK_WIDGET (self));
-}
-
 static void
 on_rename_action_activated_cb (GSimpleAction *action,
                                GVariant      *parameters,
@@ -466,7 +375,6 @@ gtd_sidebar_list_row_init (GtdSidebarListRow *self)
 {
   const GActionEntry entries[] =
   {
-    { "delete", on_delete_action_activated_cb },
     { "rename", on_rename_action_activated_cb },
   };
 
diff --git a/src/sidebar/gtd-sidebar.c b/src/sidebar/gtd-sidebar.c
index 0aea533..696b6e2 100644
--- a/src/sidebar/gtd-sidebar.c
+++ b/src/sidebar/gtd-sidebar.c
@@ -31,6 +31,9 @@
 #include "gtd-task-list.h"
 #include "gtd-task-list-panel.h"
 #include "gtd-utils.h"
+#include "notification/gtd-notification.h"
+
+#include <glib/gi18n.h>
 
 struct _GtdSidebar
 {
@@ -57,6 +60,45 @@ enum
  * Auxiliary methods
  */
 
+static void
+activate_row_below (GtdSidebar        *self,
+                    GtdSidebarListRow *current_row)
+{
+  g_autoptr (GList) children = NULL;
+  GtkWidget *next_row;
+  GList *l;
+  gboolean after_deleted;
+
+  children = gtk_container_get_children (GTK_CONTAINER (self->listbox));
+  after_deleted = FALSE;
+  next_row = NULL;
+
+  for (l = children; l; l = l->next)
+    {
+      GtkWidget *row = l->data;
+
+      if (row == (GtkWidget*) current_row)
+        {
+          after_deleted = TRUE;
+          continue;
+        }
+
+      if (!gtk_widget_get_visible (row) ||
+          !gtk_list_box_row_get_activatable (GTK_LIST_BOX_ROW (row)))
+        {
+          continue;
+        }
+
+      next_row = row;
+
+      if (after_deleted)
+        break;
+    }
+
+  if (next_row)
+    g_signal_emit_by_name (next_row, "activate");
+}
+
 static void
 add_task_list (GtdSidebar  *self,
                GtdTaskList *list)
@@ -220,6 +262,62 @@ on_panel_removed_cb (GtdManager *manager,
     gtk_widget_destroy (GTK_WIDGET (row));
 }
 
+static void
+delete_list_cb (GtdNotification *notification,
+                gpointer         user_data)
+{
+  GtdTaskList *list;
+  GtdProvider *provider;
+
+  list = GTD_TASK_LIST (user_data);
+  provider = gtd_task_list_get_provider (list);
+
+  g_assert (provider != NULL);
+  g_assert (gtd_task_list_is_removable (list));
+
+  gtd_provider_remove_task_list (provider, list);
+}
+
+static void
+undo_delete_list_cb (GtdNotification *notification,
+                     gpointer         user_data)
+{
+  g_assert (GTD_IS_SIDEBAR_LIST_ROW (user_data));
+
+  gtk_widget_show (GTK_WIDGET (user_data));
+}
+
+static void
+on_task_list_panel_list_deleted_cb (GtdTaskListPanel *panel,
+                                    GtdTaskList      *list,
+                                    GtdSidebar       *self)
+{
+  GtdSidebarListRow *row;
+  GtdNotification *notification;
+  g_autofree gchar *title = NULL;
+
+  row = (GtdSidebarListRow*) get_row_for_task_list (self, list);
+  g_assert (row != NULL && GTD_IS_SIDEBAR_LIST_ROW (row));
+
+  GTD_TRACE_MSG ("Removing task list row from sidebar");
+
+  title = g_strdup_printf (_("Task list <b>%s</b> removed"), gtd_task_list_get_name (list));
+  notification = gtd_notification_new (title, 6000.0);
+  gtd_notification_set_primary_action (notification, delete_list_cb, list);
+  gtd_notification_set_secondary_action (notification, _("Undo"), undo_delete_list_cb, row);
+
+  gtd_manager_send_notification (gtd_manager_get_default (), notification);
+
+  /*
+   * If the deleted list is selected, go to the next one (or previous, if
+   * there are no other task list after this one).
+   */
+  if (gtk_list_box_row_is_selected (GTK_LIST_BOX_ROW (row)))
+    activate_row_below (self, row);
+
+  gtk_widget_hide (GTK_WIDGET (row));
+}
+
 static void
 on_listbox_row_activated_cb (GtkListBox    *panels_listbox,
                              GtkListBoxRow *row,
@@ -560,6 +658,11 @@ gtd_sidebar_set_task_list_panel (GtdSidebar *self,
   g_assert (self->task_list_panel == NULL);
 
   self->task_list_panel = g_object_ref (task_list_panel);
+  g_signal_connect_object (self->task_list_panel,
+                           "list-deleted",
+                           G_CALLBACK (on_task_list_panel_list_deleted_cb),
+                           self,
+                           0);
 }
 
 void


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