[nautilus/wip/antoniof/new-pathbar: 19/28] pathbar: Add overflow scrolling




commit c7dfd1290d848516c15ce4e48c686eb870efc7bd
Author: António Fernandes <antoniof gnome org>
Date:   Fri Nov 26 11:53:00 2021 +0000

    pathbar: Add overflow scrolling
    
    Allows the pathbar to shrink with the window while ensuring it remains
    scrolled to the end to keep the current folder visible.

 src/nautilus-pathbar.c | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)
---
diff --git a/src/nautilus-pathbar.c b/src/nautilus-pathbar.c
index 563d65dde..3d9637887 100644
--- a/src/nautilus-pathbar.c
+++ b/src/nautilus-pathbar.c
@@ -86,6 +86,9 @@ struct _NautilusPathBar
 {
     GtkBox parent_instance;
 
+    GtkWidget *scrolled;
+    GtkWidget *buttons_box;
+
     GFile *current_path;
     gpointer current_button_data;
 
@@ -202,12 +205,34 @@ action_pathbar_properties (GSimpleAction *action,
     nautilus_file_list_free (files);
 }
 
+static void
+on_adjustment_changed (GtkAdjustment *adjustment)
+{
+    /* Automatically scroll to the end, to keep the current folder visible */
+    gtk_adjustment_set_value (adjustment, gtk_adjustment_get_upper (adjustment));
+}
+
 static void
 nautilus_path_bar_init (NautilusPathBar *self)
 {
+    GtkAdjustment *adjustment;
     GtkBuilder *builder;
     g_autoptr (GError) error = NULL;
 
+    self->scrolled = gtk_scrolled_window_new (NULL, NULL);
+    /* Scroll horizontally only and don't use internal scrollbar. */
+    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (self->scrolled),
+                                    /* hscrollbar-policy */ GTK_POLICY_EXTERNAL,
+                                    /* vscrollbar-policy */ GTK_POLICY_NEVER);
+    gtk_widget_set_hexpand (self->scrolled, TRUE);
+    gtk_box_append (GTK_BOX (self), self->scrolled);
+
+    adjustment = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (self->scrolled));
+    g_signal_connect (adjustment, "changed", (GCallback) on_adjustment_changed, NULL);
+
+    self->buttons_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+    gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (self->scrolled), self->buttons_box);
+
     builder = gtk_builder_new ();
 
     /* Add context menu for pathbar buttons */
@@ -237,7 +262,7 @@ nautilus_path_bar_init (NautilusPathBar *self)
 
     g_object_unref (builder);
 
-    gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)),
+    gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self->buttons_box)),
                                  GTK_STYLE_CLASS_LINKED);
     gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)),
                                  "nautilus-path-bar");
@@ -504,7 +529,7 @@ nautilus_path_bar_clear_buttons (NautilusPathBar *self)
 
         button_data = BUTTON_DATA (self->button_list->data);
 
-        gtk_box_remove (GTK_BOX (self), button_data->button);
+        gtk_box_remove (GTK_BOX (self->buttons_box), button_data->button);
 
         self->button_list = g_list_remove (self->button_list, button_data);
         button_data_free (button_data);
@@ -986,7 +1011,7 @@ button_data_file_changed (NautilusFile *file,
 
                     data = BUTTON_DATA (self->button_list->data);
 
-                    gtk_box_remove (GTK_BOX (self), data->button);
+                    gtk_box_remove (GTK_BOX (self->buttons_box), data->button);
                     self->button_list = g_list_remove (self->button_list, data);
                     button_data_free (data);
                 }
@@ -1055,7 +1080,7 @@ make_button_data (NautilusPathBar *self,
                                                                           GTK_ICON_SIZE_MENU);
             gtk_widget_set_margin_start (button_data->disclosure_arrow, 0);
             button_data->container = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-            gtk_container_add (GTK_CONTAINER (button_data->button), button_data->container);
+            gtk_button_set_child (GTK_BUTTON (button_data->button), button_data->container);
 
             gtk_box_pack_start (GTK_BOX (button_data->container), button_data->image, FALSE, FALSE, 0);
             gtk_box_pack_start (GTK_BOX (button_data->container), button_data->label, FALSE, FALSE, 0);
@@ -1072,7 +1097,7 @@ make_button_data (NautilusPathBar *self,
                                                                           GTK_ICON_SIZE_MENU);
             gtk_widget_set_margin_start (button_data->disclosure_arrow, 0);
             button_data->container = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-            gtk_container_add (GTK_CONTAINER (button_data->button), button_data->container);
+            gtk_button_set_child (GTK_BUTTON (button_data->button), button_data->container);
 
             gtk_box_pack_start (GTK_BOX (button_data->container), button_data->label, FALSE, FALSE, 0);
             gtk_box_pack_start (GTK_BOX (button_data->container), button_data->disclosure_arrow, FALSE, 
FALSE, 0);
@@ -1188,7 +1213,7 @@ nautilus_path_bar_update_path (NautilusPathBar *self,
     {
         GtkWidget *button;
         button = BUTTON_DATA (l->data)->button;
-        gtk_box_append (GTK_BOX (self), button);
+        gtk_box_append (GTK_BOX (self->buttons_box), button);
     }
 }
 


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