[gnome-builder/wip/project-selector] project-selector: handle toggle on checkbox



commit 9b1fcb4cd82b2208422933765528da88384c3a4b
Author: Christian Hergert <christian hergert me>
Date:   Tue Apr 7 22:53:44 2015 -0700

    project-selector: handle toggle on checkbox

 src/dialogs/gb-projects-dialog.c    |   40 +++++++++++++++++++++++-----------
 src/dialogs/gb-recent-project-row.c |   16 ++++++++++++++
 2 files changed, 43 insertions(+), 13 deletions(-)
---
diff --git a/src/dialogs/gb-projects-dialog.c b/src/dialogs/gb-projects-dialog.c
index 382a497..9d4f5ff 100644
--- a/src/dialogs/gb-projects-dialog.c
+++ b/src/dialogs/gb-projects-dialog.c
@@ -58,6 +58,28 @@ struct _GbProjectsDialog
 G_DEFINE_TYPE (GbProjectsDialog, gb_projects_dialog, GTK_TYPE_APPLICATION_WINDOW)
 
 static void
+gb_projects_dialog_update_delete_sensitivity (GbProjectsDialog *self)
+{
+  gboolean selected = FALSE;
+  GList *children;
+  GList *iter;
+
+  g_assert (GB_IS_PROJECTS_DIALOG (self));
+
+  children = gtk_container_get_children (GTK_CONTAINER (self->listbox));
+
+  for (iter = children; !selected && iter; iter = iter->next)
+    {
+      if (gb_recent_project_row_get_selected (iter->data))
+        selected = TRUE;
+    }
+
+  gtk_widget_set_sensitive (GTK_WIDGET (self->delete_button), selected);
+
+  g_list_free (children);
+}
+
+static void
 gb_projects_dialog__listbox_row_activated_cb (GbProjectsDialog *self,
                                               GtkListBoxRow    *row,
                                               GtkListBox       *listbox)
@@ -76,22 +98,9 @@ gb_projects_dialog__listbox_row_activated_cb (GbProjectsDialog *self,
   if (gtk_toggle_button_get_active (self->select_button))
     {
       gboolean selected;
-      GList *children;
-      GList *iter;
 
       selected = !gb_recent_project_row_get_selected (GB_RECENT_PROJECT_ROW (row));
       gb_recent_project_row_set_selected (GB_RECENT_PROJECT_ROW (row), selected);
-
-      children = gtk_container_get_children (GTK_CONTAINER (listbox));
-      for (iter = children; !selected && iter; iter = iter->next)
-        {
-          if (gb_recent_project_row_get_selected (iter->data))
-            selected = TRUE;
-        }
-      g_list_free (children);
-
-      gtk_widget_set_sensitive (GTK_WIDGET (self->delete_button), selected);
-
       return;
     }
 
@@ -121,6 +130,11 @@ gb_projects_dialog__recent_projects_added (GbProjectsDialog  *self,
                       "project-info", project_info,
                       "visible", TRUE,
                       NULL);
+  g_signal_connect_object (row,
+                           "notify::selected",
+                           G_CALLBACK (gb_projects_dialog_update_delete_sensitivity),
+                           self,
+                           G_CONNECT_SWAPPED);
   g_object_bind_property (self->select_button, "active", row, "selection-mode",
                           G_BINDING_SYNC_CREATE);
   gtk_container_add (GTK_CONTAINER (self->listbox), row);
diff --git a/src/dialogs/gb-recent-project-row.c b/src/dialogs/gb-recent-project-row.c
index 63a6cf3..baf176c 100644
--- a/src/dialogs/gb-recent-project-row.c
+++ b/src/dialogs/gb-recent-project-row.c
@@ -117,6 +117,16 @@ gb_recent_project_row_set_project_info (GbRecentProjectRow *self,
 }
 
 static void
+gb_recent_project_row__check_button_toggled (GbRecentProjectRow *self,
+                                             GtkToggleButton    *toggle_button)
+{
+  g_assert (GB_IS_RECENT_PROJECT_ROW (self));
+  g_assert (GTK_IS_TOGGLE_BUTTON (toggle_button));
+
+  g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_SELECTED]);
+}
+
+static void
 gb_recent_project_row_finalize (GObject *object)
 {
   GbRecentProjectRow *self = (GbRecentProjectRow *)object;
@@ -228,6 +238,12 @@ static void
 gb_recent_project_row_init (GbRecentProjectRow *self)
 {
   gtk_widget_init_template (GTK_WIDGET (self));
+
+  g_signal_connect_object (self->check_button,
+                           "toggled",
+                           G_CALLBACK (gb_recent_project_row__check_button_toggled),
+                           self,
+                           G_CONNECT_SWAPPED);
 }
 
 IdeProjectInfo *


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