[gnome-software] Make the overview's category expander able to hide the categories back



commit 95d79017d031eb243c782b8483ff22932173d4bc
Author: Joaquim Rocha <jrocha endlessm com>
Date:   Sun Nov 27 10:50:38 2016 +0100

    Make the overview's category expander able to hide the categories back
    
    The categories expander was only expanding the categories and it would
    be hidden when the secondary categories were shown, having no direct way
    of hiding them back. This patch keeps the expander visible, allowing the
    user to hide the secondary categories back.

 src/gs-shell-overview.c  |   50 +++++++++++++++-----
 src/gs-shell-overview.ui |  119 +++++++++++++++++++++++++++-------------------
 2 files changed, 108 insertions(+), 61 deletions(-)
---
diff --git a/src/gs-shell-overview.c b/src/gs-shell-overview.c
index 65ee29f..5d26f67 100644
--- a/src/gs-shell-overview.c
+++ b/src/gs-shell-overview.c
@@ -66,8 +66,9 @@ typedef struct
        GtkWidget               *popular_heading;
        GtkWidget               *scrolledwindow_overview;
        GtkWidget               *stack_overview;
-       GtkWidget               *categories_expander_button;
-       GtkWidget               *categories_expander;
+       GtkWidget               *categories_expander_button_down;
+       GtkWidget               *categories_expander_button_up;
+       GtkWidget               *categories_expander_box;
        GtkWidget               *categories_more;
 } GsShellOverviewPrivate;
 
@@ -408,7 +409,7 @@ gs_shell_overview_get_categories_cb (GObject *source_object,
        }
 
        /* show the expander if we have too many children */
-       gtk_widget_set_visible (priv->categories_expander,
+       gtk_widget_set_visible (priv->categories_expander_box,
                                added_cnt > MAX_CATS_PER_SECTION);
 out:
        if (added_cnt > 0)
@@ -589,9 +590,7 @@ gs_shell_overview_switch_to (GsPage *page, gboolean scroll_up)
        gtk_widget_show (widget);
 
        /* hide the expander */
-       gtk_revealer_set_transition_duration (GTK_REVEALER (priv->categories_expander), 0);
        gtk_revealer_set_transition_duration (GTK_REVEALER (priv->categories_more), 0);
-       gtk_revealer_set_reveal_child (GTK_REVEALER (priv->categories_expander), TRUE);
        gtk_revealer_set_reveal_child (GTK_REVEALER (priv->categories_more), FALSE);
 
        if (scroll_up) {
@@ -607,16 +606,36 @@ gs_shell_overview_switch_to (GsPage *page, gboolean scroll_up)
 }
 
 static void
-gs_shell_overview_categories_expander_cb (GtkButton *button, GsShellOverview *self)
+categories_more_revealer_changed_cb (GtkRevealer *revealer,
+                                    GParamSpec *pspec,
+                                    GsShellOverview *self)
+{
+       GsShellOverviewPrivate *priv = gs_shell_overview_get_instance_private (self);
+       gboolean child_revealed = gtk_revealer_get_child_revealed (revealer);
+
+       gtk_widget_set_visible (priv->categories_expander_button_up,
+                               child_revealed);
+       gtk_widget_set_visible (priv->categories_expander_button_down,
+                               !child_revealed);
+}
+
+static void
+gs_shell_overview_categories_expander_down_cb (GtkButton *button, GsShellOverview *self)
 {
        GsShellOverviewPrivate *priv = gs_shell_overview_get_instance_private (self);
-       gtk_revealer_set_transition_duration (GTK_REVEALER (priv->categories_expander), 250);
        gtk_revealer_set_transition_duration (GTK_REVEALER (priv->categories_more), 250);
-       gtk_revealer_set_reveal_child (GTK_REVEALER (priv->categories_expander), FALSE);
        gtk_revealer_set_reveal_child (GTK_REVEALER (priv->categories_more), TRUE);
 }
 
 static void
+gs_shell_overview_categories_expander_up_cb (GtkButton *button, GsShellOverview *self)
+{
+       GsShellOverviewPrivate *priv = gs_shell_overview_get_instance_private (self);
+       gtk_revealer_set_transition_duration (GTK_REVEALER (priv->categories_more), 250);
+       gtk_revealer_set_reveal_child (GTK_REVEALER (priv->categories_more), FALSE);
+}
+
+static void
 g_shell_overview_get_sources_cb (GsPluginLoader *plugin_loader,
                                 GAsyncResult *res,
                                 GsShellOverview *self)
@@ -783,8 +802,10 @@ gs_shell_overview_setup (GsShellOverview *self,
        }
 
        /* handle category expander */
-       g_signal_connect (priv->categories_expander_button, "clicked",
-                         G_CALLBACK (gs_shell_overview_categories_expander_cb), self);
+       g_signal_connect (priv->categories_expander_button_down, "clicked",
+                         G_CALLBACK (gs_shell_overview_categories_expander_down_cb), self);
+       g_signal_connect (priv->categories_expander_button_up, "clicked",
+                         G_CALLBACK (gs_shell_overview_categories_expander_up_cb), self);
 
        /* search button */
        search_bar = GTK_SEARCH_BAR (gtk_builder_get_object (priv->builder,
@@ -821,6 +842,10 @@ gs_shell_overview_init (GsShellOverview *self)
        g_signal_connect (priv->settings, "changed",
                          G_CALLBACK (settings_changed_cb),
                          self);
+       gtk_revealer_set_transition_duration (GTK_REVEALER (priv->categories_more), 250);
+       g_signal_connect (priv->categories_more, "notify::child-revealed",
+                         G_CALLBACK (categories_more_revealer_changed_cb),
+                         self);
 }
 
 static void
@@ -883,8 +908,9 @@ gs_shell_overview_class_init (GsShellOverviewClass *klass)
        gtk_widget_class_bind_template_child_private (widget_class, GsShellOverview, popular_heading);
        gtk_widget_class_bind_template_child_private (widget_class, GsShellOverview, scrolledwindow_overview);
        gtk_widget_class_bind_template_child_private (widget_class, GsShellOverview, stack_overview);
-       gtk_widget_class_bind_template_child_private (widget_class, GsShellOverview, 
categories_expander_button);
-       gtk_widget_class_bind_template_child_private (widget_class, GsShellOverview, categories_expander);
+       gtk_widget_class_bind_template_child_private (widget_class, GsShellOverview, 
categories_expander_button_down);
+       gtk_widget_class_bind_template_child_private (widget_class, GsShellOverview, 
categories_expander_button_up);
+       gtk_widget_class_bind_template_child_private (widget_class, GsShellOverview, categories_expander_box);
        gtk_widget_class_bind_template_child_private (widget_class, GsShellOverview, categories_more);
 }
 
diff --git a/src/gs-shell-overview.ui b/src/gs-shell-overview.ui
index 1bf86e1..37c97da 100644
--- a/src/gs-shell-overview.ui
+++ b/src/gs-shell-overview.ui
@@ -210,68 +210,89 @@
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkRevealer" id="categories_expander">
+                          <object class="GtkBox" id="categories_expander_box">
                             <property name="visible">True</property>
-                            <property name="transition-type">slide-up</property>
-                            <property name="reveal-child">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="vexpand">False</property>
+                            <property name="orientation">horizontal</property>
+                            <property name="margin_start">24</property>
+                            <property name="margin_end">24</property>
+                            <property name="margin-bottom">12</property>
                             <child>
-                              <object class="GtkBox" id="categories_expander_box">
+                              <object class="GtkSeparator" id="categories_expander_lsep">
                                 <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="vexpand">False</property>
                                 <property name="orientation">horizontal</property>
-                                <property name="margin_start">24</property>
-                                <property name="margin_end">24</property>
-                                <property name="margin-bottom">12</property>
-                                <child>
-                                  <object class="GtkSeparator" id="categories_expander_lsep">
-                                    <property name="visible">True</property>
-                                    <property name="orientation">horizontal</property>
-                                    <property name="expand">True</property>
-                                    <property name="valign">center</property>
-                                  </object>
-                                  <packing>
-                                    <property name="position">0</property>
-                                  </packing>
-                                </child>
+                                <property name="expand">True</property>
+                                <property name="valign">center</property>
+                              </object>
+                              <packing>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkButton" id="categories_expander_button_down">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="margin-start">9</property>
+                                <property name="margin-end">9</property>
+                                <property name="valign">center</property>
+                                <property name="relief">none</property>
+                                <style>
+                                  <class name="round-button"/>
+                                </style>
                                 <child>
-                                  <object class="GtkButton" id="categories_expander_button">
+                                  <object class="GtkImage" id="categories_expander_image_down">
                                     <property name="visible">True</property>
-                                    <property name="can_focus">True</property>
-                                    <property name="receives_default">False</property>
-                                    <property name="margin-start">9</property>
-                                    <property name="margin-end">9</property>
-                                    <property name="valign">center</property>
-                                    <style>
-                                      <class name="round-button"/>
-                                    </style>
-                                    <child>
-                                      <object class="GtkImage" id="categories_expander_image">
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">False</property>
-                                        <property name="icon_name">view-more-symbolic</property>
-                                        <property name="icon_size">1</property>
-                                      </object>
-                                    </child>
+                                    <property name="can_focus">False</property>
+                                    <property name="icon_name">pan-down-symbolic</property>
+                                    <property name="icon_size">1</property>
                                   </object>
-                                  <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">True</property>
-                                    <property name="position">1</property>
-                                  </packing>
                                 </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkButton" id="categories_expander_button_up">
+                                <property name="visible">False</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="margin-start">9</property>
+                                <property name="margin-end">9</property>
+                                <property name="valign">center</property>
+                                <property name="relief">none</property>
+                                <style>
+                                  <class name="round-button"/>
+                                </style>
                                 <child>
-                                  <object class="GtkSeparator" id="categories_expander_rsep">
+                                  <object class="GtkImage" id="categories_expander_image_up">
                                     <property name="visible">True</property>
-                                    <property name="orientation">horizontal</property>
-                                    <property name="expand">True</property>
-                                    <property name="valign">center</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="icon_name">pan-up-symbolic</property>
+                                    <property name="icon_size">1</property>
                                   </object>
-                                  <packing>
-                                    <property name="position">2</property>
-                                  </packing>
                                 </child>
                               </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">2</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkSeparator" id="categories_expander_rsep">
+                                <property name="visible">True</property>
+                                <property name="orientation">horizontal</property>
+                                <property name="expand">True</property>
+                                <property name="valign">center</property>
+                              </object>
+                              <packing>
+                                <property name="position">3</property>
+                              </packing>
                             </child>
                           </object>
                           <packing>


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