[gnome-software] Make subcategory list scrollable



commit 1d33cbbfb2ff900980e9e3aebb68887500796a4f
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Sep 5 23:25:17 2013 -0400

    Make subcategory list scrollable
    
    Show a scrollbar when the subcategory list becomes too large to
    fit in the window. This requires some trickery to get the frame
    to show where it belongs.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=707515

 src/gnome-software.ui   |   28 +++++++++++++++++++---------
 src/gs-shell-category.c |   37 +++++++++++++++++++++++++++++++++----
 2 files changed, 52 insertions(+), 13 deletions(-)
---
diff --git a/src/gnome-software.ui b/src/gnome-software.ui
index a554892..e85f79f 100644
--- a/src/gnome-software.ui
+++ b/src/gnome-software.ui
@@ -803,23 +803,33 @@ with multi-level undo.
               <object class="GsBox" id="box_category">
                 <property name="visible">True</property>
                 <child>
-                  <object class="GtkFrame" id="frame_filter">
+                  <object class="GtkScrolledWindow" id="scrolledwindow_filter">
                     <property name="visible">True</property>
                     <property name="margin-top">18</property>
                     <property name="margin-bottom">18</property>
                     <property name="margin-left">12</property>
                     <property name="margin-right">12</property>
-                    <property name="shadow_type">in</property>
-                    <property name="halign">fill</property>
-                    <property name="valign">start</property>
-                    <style>
-                      <class name="view"/>
-                    </style>
+                    <property name="can_focus">True</property>
+                    <property name="hscrollbar_policy">never</property>
+                    <property name="vscrollbar_policy">automatic</property>
+                    <property name="shadow_type">none</property>
+                    <property name="valign">fill</property>
                     <child>
-                      <object class="GtkListBox" id="listbox_filter">
+                      <object class="GtkFrame" id="frame_filter">
                         <property name="visible">True</property>
-                        <property name="selection_mode">browse</property>
+                        <property name="shadow_type">in</property>
                         <property name="halign">fill</property>
+                        <property name="valign">start</property>
+                        <style>
+                          <class name="view"/>
+                        </style>
+                        <child>
+                          <object class="GtkListBox" id="listbox_filter">
+                            <property name="visible">True</property>
+                            <property name="selection_mode">browse</property>
+                            <property name="halign">fill</property>
+                          </object>
+                        </child>
                       </object>
                     </child>
                   </object>
diff --git a/src/gs-shell-category.c b/src/gs-shell-category.c
index dbce924..c913657 100644
--- a/src/gs-shell-category.c
+++ b/src/gs-shell-category.c
@@ -225,10 +225,17 @@ gs_shell_category_create_filter_list (GsShellCategory *shell, GsCategory *catego
         GtkWidget *row;
         GList *list, *l;
         GsCategory *s;
+        GtkWidget *frame, *swin;
 
         grid = GTK_WIDGET (gtk_builder_get_object (priv->builder, "category_detail_grid"));
         gs_container_remove_all (GTK_CONTAINER (grid));
 
+
+        frame = GTK_WIDGET (gtk_builder_get_object (priv->builder, "frame_filter"));
+        swin = GTK_WIDGET (gtk_builder_get_object (priv->builder, "scrolledwindow_filter"));
+        gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
+        gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin), GTK_SHADOW_NONE);
+
         list = gs_category_get_subcategories (category);
         if (!list)
                 return;
@@ -335,6 +342,22 @@ gs_shell_category_class_init (GsShellCategoryClass *klass)
        g_type_class_add_private (klass, sizeof (GsShellCategoryPrivate));
 }
 
+static void
+scrollbar_mapped_cb (GtkWidget *sb, GtkScrolledWindow *swin)
+{
+        GtkWidget *frame;
+
+        frame = gtk_bin_get_child (GTK_BIN (gtk_bin_get_child (GTK_BIN (swin))));
+        if (gtk_widget_get_mapped (GTK_WIDGET (sb))) {
+                gtk_scrolled_window_set_shadow_type (swin, GTK_SHADOW_IN);
+                gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
+        }
+        else {
+                gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
+                gtk_scrolled_window_set_shadow_type (swin, GTK_SHADOW_NONE);
+        }
+}
+
 void
 gs_shell_category_setup (GsShellCategory *shell_category,
                          GsShell *shell,
@@ -343,16 +366,22 @@ gs_shell_category_setup (GsShellCategory *shell_category,
                          GCancellable *cancellable)
 {
        GsShellCategoryPrivate *priv = shell_category->priv;
-        GtkWidget *list_box;
+        GtkWidget *widget;
+        GtkWidget *sw;
 
        priv->plugin_loader = g_object_ref (plugin_loader);
         priv->builder = g_object_ref (builder);
        priv->cancellable = g_cancellable_new ();
         priv->shell = shell;
 
-        list_box = GTK_WIDGET (gtk_builder_get_object (priv->builder, "listbox_filter"));
-        g_signal_connect (list_box, "row-selected", G_CALLBACK (filter_selected), shell_category);
-        gtk_list_box_set_header_func (GTK_LIST_BOX (list_box), add_separator, NULL, NULL);
+        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "listbox_filter"));
+        g_signal_connect (widget, "row-selected", G_CALLBACK (filter_selected), shell_category);
+        gtk_list_box_set_header_func (GTK_LIST_BOX (widget), add_separator, NULL, NULL);
+
+        sw = GTK_WIDGET (gtk_builder_get_object (priv->builder, "scrolledwindow_filter"));
+        widget = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (sw));
+        g_signal_connect (widget, "map", G_CALLBACK (scrollbar_mapped_cb), sw);
+        g_signal_connect (widget, "unmap", G_CALLBACK (scrollbar_mapped_cb), sw);
 }
 
 GsShellCategory *


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