[epiphany/wip/exalm/bookmarks: 5/6] Ensure tag scrolled window has correct size



commit e81041298a27324582dd339a38300f0a1958e6c4
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sun Oct 6 16:23:37 2019 +0500

    Ensure tag scrolled window has correct size
    
    Specify min-children-per-line so that its natural height always matches
    content, and make bookmarks dialog unresizable so that it follows the
    flowbox height.
    
    Since scrollbar minimum height is larger than one row of tags, explicitly
    hide scrollbar when there are less than 3 tags, i.e. when there is only
    one row.

 src/bookmarks/ephy-bookmark-properties-grid.c | 20 ++++++++++++++++++++
 src/bookmarks/ephy-bookmark-row.c             |  1 +
 src/resources/gtk/bookmark-properties-grid.ui |  4 +++-
 3 files changed, 24 insertions(+), 1 deletion(-)
---
diff --git a/src/bookmarks/ephy-bookmark-properties-grid.c b/src/bookmarks/ephy-bookmark-properties-grid.c
index 8a229b80c..1a4333ee8 100644
--- a/src/bookmarks/ephy-bookmark-properties-grid.c
+++ b/src/bookmarks/ephy-bookmark-properties-grid.c
@@ -48,6 +48,7 @@ struct _EphyBookmarkPropertiesGrid {
   GtkWidget *address_entry;
   GtkWidget *popover_tags_label;
   GtkWidget *tags_box;
+  GtkWidget *tags_scrolled_window;
   GtkWidget *add_tag_entry;
   GtkWidget *add_tag_button;
   GtkWidget *remove_bookmark_button;
@@ -91,6 +92,21 @@ flow_box_sort_func (GtkFlowBoxChild *child1,
   return ephy_bookmark_tags_compare (tag1, tag2);
 }
 
+static void
+update_tags_scrollbar (EphyBookmarkPropertiesGrid *self)
+{
+  g_autoptr (GList) children = NULL;
+  gint n_tags;
+
+  children = gtk_container_get_children (GTK_CONTAINER (self->tags_box));
+  n_tags = g_list_length (children);
+
+  g_object_set (self->tags_scrolled_window,
+                "vscrollbar-policy",
+                (n_tags > 3) ? GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER,
+                NULL);
+}
+
 static void
 ephy_bookmark_properties_grid_tags_box_child_activated_cb (EphyBookmarkPropertiesGrid *self,
                                                            GtkFlowBoxChild            *child,
@@ -138,6 +154,7 @@ ephy_bookmark_properties_grid_tag_widget_button_clicked_cb (EphyBookmarkProperti
 
   flow_box_child = gtk_widget_get_parent (box);
   gtk_widget_destroy (flow_box_child);
+  update_tags_scrollbar (self);
 }
 
 static GtkWidget *
@@ -227,6 +244,7 @@ ephy_bookmarks_properties_grid_actions_add_tag (GSimpleAction *action,
   /* Create a new widget for the new tag */
   widget = ephy_bookmark_properties_grid_create_tag_widget (self, text, TRUE);
   gtk_flow_box_insert (GTK_FLOW_BOX (self->tags_box), widget, -1);
+  update_tags_scrollbar (self);
 
   /* Empty entry and disable button's action until new text is inserted */
   gtk_entry_set_text (GTK_ENTRY (self->add_tag_entry), "");
@@ -406,6 +424,7 @@ ephy_bookmark_properties_grid_constructed (GObject *object)
     widget = ephy_bookmark_properties_grid_create_tag_widget (self, tag, selected);
     gtk_flow_box_insert (GTK_FLOW_BOX (self->tags_box), widget, -1);
   }
+  update_tags_scrollbar (self);
 
   g_signal_connect_object (self->tags_box, "child-activated",
                            G_CALLBACK (ephy_bookmark_properties_grid_tags_box_child_activated_cb),
@@ -470,6 +489,7 @@ ephy_bookmark_properties_grid_class_init (EphyBookmarkPropertiesGridClass *klass
   gtk_widget_class_bind_template_child (widget_class, EphyBookmarkPropertiesGrid, address_entry);
   gtk_widget_class_bind_template_child (widget_class, EphyBookmarkPropertiesGrid, popover_tags_label);
   gtk_widget_class_bind_template_child (widget_class, EphyBookmarkPropertiesGrid, tags_box);
+  gtk_widget_class_bind_template_child (widget_class, EphyBookmarkPropertiesGrid, tags_scrolled_window);
   gtk_widget_class_bind_template_child (widget_class, EphyBookmarkPropertiesGrid, add_tag_entry);
   gtk_widget_class_bind_template_child (widget_class, EphyBookmarkPropertiesGrid, add_tag_button);
   gtk_widget_class_bind_template_child (widget_class, EphyBookmarkPropertiesGrid, remove_bookmark_button);
diff --git a/src/bookmarks/ephy-bookmark-row.c b/src/bookmarks/ephy-bookmark-row.c
index fe4979276..db79b4d5e 100644
--- a/src/bookmarks/ephy-bookmark-row.c
+++ b/src/bookmarks/ephy-bookmark-row.c
@@ -61,6 +61,7 @@ ephy_bookmark_row_button_clicked_cb (EphyBookmarkRow *row,
                          "title", _("Bookmark Properties"),
                          "transient-for", GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (row))),
                          "use-header-bar", TRUE,
+                         "resizable", FALSE,
                          "modal", TRUE,
                          NULL);
 
diff --git a/src/resources/gtk/bookmark-properties-grid.ui b/src/resources/gtk/bookmark-properties-grid.ui
index 3f28c3023..11d3d286d 100644
--- a/src/resources/gtk/bookmark-properties-grid.ui
+++ b/src/resources/gtk/bookmark-properties-grid.ui
@@ -103,11 +103,12 @@
       </packing>
     </child>
     <child>
-      <object class="GtkScrolledWindow">
+      <object class="GtkScrolledWindow" id="tags_scrolled_window">
         <property name="expand">True</property>
         <property name="max-content-height">132</property>
         <property name="min-content-height">38</property>
         <property name="hscrollbar-policy">never</property>
+        <property name="vscrollbar-policy">never</property>
         <property name="propagate-natural-width">True</property>
         <property name="propagate-natural-height">True</property>
         <property name="visible">true</property>
@@ -118,6 +119,7 @@
             <property name="selection-mode">none</property>
             <property name="homogeneous">true</property>
             <property name="valign">start</property>
+            <property name="min-children-per-line">3</property>
             <property name="max-children-per-line">3</property>
             <property name="visible">true</property>
           </object>


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