[gnome-notes/fix-selection-bar: 1/3] selection-toolbar: Change how to show/hide




commit dd776c88235423eccd73c275a317d30c512615ad
Author: Isaque Galdino <igaldino gmail com>
Date:   Tue Aug 11 23:37:58 2020 -0300

    selection-toolbar: Change how to show/hide
    
    Remove redundant code to fade in/out the toolbar using gtk_revealer
    functions directly.
    
    Connect toolbar to controller so it can react to items being changed.

 src/bjb-list-view.c         |  5 +++
 src/bjb-selection-toolbar.c | 75 ++++++++++++++++++++++-----------------------
 2 files changed, 42 insertions(+), 38 deletions(-)
---
diff --git a/src/bjb-list-view.c b/src/bjb-list-view.c
index f8bf99c7..d4064fb8 100644
--- a/src/bjb-list-view.c
+++ b/src/bjb-list-view.c
@@ -172,4 +172,9 @@ bjb_list_view_set_selection_mode (BjbListView *self,
   gtk_container_foreach (GTK_CONTAINER (self->list_box),
                          bjb_list_view_show_select_button_cb,
                          GINT_TO_POINTER (mode));
+
+  g_signal_emit_by_name (GTK_WIDGET (self->list_box),
+                         "selected-rows-changed",
+                         0);
+
 }
diff --git a/src/bjb-selection-toolbar.c b/src/bjb-selection-toolbar.c
index 4157c610..9c6dfe76 100644
--- a/src/bjb-selection-toolbar.c
+++ b/src/bjb-selection-toolbar.c
@@ -272,42 +272,31 @@ bjb_selection_toolbar_set_item_visibility (BjbSelectionToolbar *self)
 }
 
 static void
-bjb_selection_toolbar_fade_in (BjbSelectionToolbar *self)
+on_selected_rows_changed_cb (BjbSelectionToolbar *self)
 {
-  gtk_revealer_set_reveal_child (GTK_REVEALER (self), TRUE);
-  //bjb_selection_toolbar_set_item_visibility
-}
-
-static void
-bjb_selection_toolbar_fade_out (BjbSelectionToolbar *self)
-{
-  gtk_revealer_set_reveal_child (GTK_REVEALER (self), FALSE);
-}
-
-static void
-on_selected_rows_changed_cb (BjbListView *view,
-                             gpointer     user_data)
-{
-  BjbSelectionToolbar *self;
-  GList *selection;
-
-  self = BJB_SELECTION_TOOLBAR (user_data);
-  selection = bjb_main_view_get_selected_items (self->view);
+  GList *selection = bjb_main_view_get_selected_items (self->view);
 
   if (g_list_length (selection) > 0)
-  {
-    gtk_widget_show (GTK_WIDGET (self));
-    bjb_selection_toolbar_set_item_visibility (self);
-    bjb_selection_toolbar_fade_in (self);
-  }
-  else
     {
-      bjb_selection_toolbar_fade_out (self);
+      gtk_widget_show (GTK_WIDGET (self));
+      bjb_selection_toolbar_set_item_visibility (self);
+      gtk_revealer_set_reveal_child (GTK_REVEALER (self), TRUE);
     }
+  else
+    gtk_revealer_set_reveal_child (GTK_REVEALER (self), FALSE);
 
   g_list_free (selection);
 }
 
+static void
+on_display_items_changed_cb (BjbSelectionToolbar *self)
+{
+  BjbController *controller = bjb_list_view_get_controller (self->selection);
+
+  if (!bjb_controller_get_selection_mode (controller))
+    gtk_revealer_set_reveal_child (GTK_REVEALER (self), FALSE);
+}
+
 static void
 bjb_selection_toolbar_init (BjbSelectionToolbar *self)
 {
@@ -323,14 +312,17 @@ bjb_selection_toolbar_get_property (GObject    *object,
   BjbSelectionToolbar *self = BJB_SELECTION_TOOLBAR (object);
 
   switch (property_id)
-  {
+    {
     case PROP_BJB_SELECTION:
       g_value_set_object(value, self->selection);
       break;
+    case PROP_BJB_MAIN_VIEW:
+      g_value_set_object(value, self->view);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
-  }
+    }
 }
 
 static void
@@ -342,7 +334,7 @@ bjb_selection_toolbar_set_property (GObject      *object,
   BjbSelectionToolbar *self = BJB_SELECTION_TOOLBAR (object);
 
   switch (property_id)
-  {
+    {
     case PROP_BJB_SELECTION:
       self->selection = g_value_get_object (value);
       break;
@@ -352,7 +344,7 @@ bjb_selection_toolbar_set_property (GObject      *object,
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
-  }
+    }
 }
 
 static void
@@ -362,10 +354,17 @@ bjb_selection_toolbar_constructed(GObject *obj)
 
   G_OBJECT_CLASS (bjb_selection_toolbar_parent_class)->constructed (obj);
 
-  g_signal_connect (bjb_list_view_get_list_box (self->selection),
-                    "selected-rows-changed",
-                    G_CALLBACK (on_selected_rows_changed_cb),
-                    self);
+  g_signal_connect_object (bjb_list_view_get_list_box (self->selection),
+                           "selected-rows-changed",
+                           G_CALLBACK (on_selected_rows_changed_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+
+  g_signal_connect_object (bjb_list_view_get_controller (self->selection),
+                           "display-items-changed",
+                           G_CALLBACK (on_display_items_changed_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
 }
 
 static void
@@ -417,11 +416,11 @@ bjb_selection_toolbar_class_init (BjbSelectionToolbarClass *class)
 
 
 BjbSelectionToolbar *
-bjb_selection_toolbar_new (BjbListView  *selection,
-                           BjbMainView  *bjb_main_view)
+bjb_selection_toolbar_new (BjbListView *selection,
+                           BjbMainView *bjb_main_view)
 {
   return g_object_new (BJB_TYPE_SELECTION_TOOLBAR,
                        "selection", selection,
-                       "bjbmainview",bjb_main_view,
+                       "bjbmainview", bjb_main_view,
                        NULL);
 }


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