[nautilus/wip/antoniof/new-pathbar: 6/9] pathbar: Move current location menu to discrete button




commit 2eec8aeb99ceffd81dcf65b62eba4b4bca345114
Author: António Fernandes <antoniof gnome org>
Date:   Fri Nov 26 14:24:24 2021 +0000

    pathbar: Move current location menu to discrete button
    
    This should address discoverability concerns and follows latest design.

 src/nautilus-pathbar.c        | 54 ++++++++++++++++++++-----------------------
 src/resources/css/Adwaita.css | 10 +++++---
 2 files changed, 32 insertions(+), 32 deletions(-)
---
diff --git a/src/nautilus-pathbar.c b/src/nautilus-pathbar.c
index c2031a0d1..2537b8fc8 100644
--- a/src/nautilus-pathbar.c
+++ b/src/nautilus-pathbar.c
@@ -72,7 +72,6 @@ typedef struct
     GtkWidget *image;
     GtkWidget *label;
     GtkWidget *separator;
-    GtkWidget *disclosure_arrow;
     GtkWidget *container;
 
     NautilusPathBar *path_bar;
@@ -100,6 +99,7 @@ struct _NautilusPathBar
 
     NautilusFile *context_menu_file;
     GtkPopover *current_view_menu_popover;
+    GtkWidget *current_view_menu_button;
     GtkPopover *button_menu_popover;
     GMenu *current_view_menu;
     GMenu *extensions_section;
@@ -213,6 +213,15 @@ on_adjustment_changed (GtkAdjustment *adjustment)
     gtk_adjustment_set_value (adjustment, gtk_adjustment_get_upper (adjustment));
 }
 
+static gboolean
+bind_current_view_menu_model_to_popover (NautilusPathBar *self)
+{
+    gtk_popover_bind_model (self->current_view_menu_popover,
+                            G_MENU_MODEL (self->current_view_menu),
+                            NULL);
+    return G_SOURCE_REMOVE;
+}
+
 static void
 nautilus_path_bar_init (NautilusPathBar *self)
 {
@@ -234,6 +243,12 @@ nautilus_path_bar_init (NautilusPathBar *self)
     self->buttons_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
     gtk_container_add (GTK_CONTAINER (self->scrolled), self->buttons_box);
 
+    self->current_view_menu_button = gtk_menu_button_new ();
+    gtk_container_add (GTK_CONTAINER (self->current_view_menu_button),
+                       gtk_image_new_from_icon_name ("view-more-symbolic",
+                                                     GTK_ICON_SIZE_MENU));
+    gtk_container_add (GTK_CONTAINER (self), self->current_view_menu_button);
+
     builder = gtk_builder_new ();
 
     /* Add context menu for pathbar buttons */
@@ -263,8 +278,14 @@ nautilus_path_bar_init (NautilusPathBar *self)
 
     g_object_unref (builder);
 
-    gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)),
+    gtk_menu_button_set_popover (GTK_MENU_BUTTON (self->current_view_menu_button),
+                                 GTK_WIDGET (self->current_view_menu_popover));
+    bind_current_view_menu_model_to_popover (self);
+
+    gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self->buttons_box)),
                                  "nautilus-path-bar");
+    gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)),
+                                 GTK_STYLE_CLASS_LINKED);
 
     /* Action group */
     self->action_group = G_ACTION_GROUP (g_simple_action_group_new ());
@@ -458,13 +479,13 @@ nautilus_path_bar_set_templates_menu (NautilusPathBar *self,
     {
         /* Workaround to avoid leaking duplicated GtkStack pages each time the
          * templates menu is set. Unbinding the model is the only way to clear
-         * all children. For that reason, we need to rebind the popover before
-         * it is shown again.
+         * all children. After that's done, on idle, we rebind it.
          * See https://gitlab.gnome.org/GNOME/nautilus/-/issues/1705 */
         gtk_popover_bind_model (self->current_view_menu_popover, NULL, NULL);
     }
 
     nautilus_gmenu_set_from_model (self->templates_submenu, menu);
+    g_idle_add ((GSourceFunc) bind_current_view_menu_model_to_popover, self);
 }
 
 /* Changes the icons wherever it is needed */
@@ -563,14 +584,6 @@ button_clicked_cb (GtkButton *button,
     {
         if (g_file_equal (button_data->path, self->current_path))
         {
-            /* Workaround to avoid leaking duplicated GtkStack pages each time the
-             * templates menu is set. Unbinding the model is the only way to clear
-             * all children. For that reason, we need to rebind the popover before
-             * it is shown again.
-             * See https://gitlab.gnome.org/GNOME/nautilus/-/issues/1705 */
-            gtk_popover_bind_model (self->current_view_menu_popover,
-                                    G_MENU_MODEL (self->current_view_menu),
-                                    NULL);
             gtk_popover_popup (self->current_view_menu_popover);
         }
         else
@@ -698,14 +711,6 @@ on_multi_press_gesture_pressed (GtkGestureMultiPress *gesture,
         {
             if (g_file_equal (button_data->path, self->current_path))
             {
-                /* Workaround to avoid leaking duplicated GtkStack pages each time the
-                 * templates menu is set. Unbinding the model is the only way to clear
-                 * all children. For that reason, we need to rebind the popover before
-                 * it is shown again.
-                 * See https://gitlab.gnome.org/GNOME/nautilus/-/issues/1705 */
-                gtk_popover_bind_model (self->current_view_menu_popover,
-                                        G_MENU_MODEL (self->current_view_menu),
-                                        NULL);
                 gtk_popover_popup (self->current_view_menu_popover);
             }
             else
@@ -1096,15 +1101,12 @@ make_button_data (NautilusPathBar *self,
         case OTHER_LOCATIONS_BUTTON:
         {
             button_data->label = gtk_label_new (NULL);
-            button_data->disclosure_arrow = gtk_image_new_from_icon_name ("pan-down-symbolic",
-                                                                          GTK_ICON_SIZE_MENU);
             child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
             button_data->container = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
             gtk_box_pack_start (GTK_BOX (button_data->container), button_data->button, FALSE, FALSE, 0);
 
             gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
             gtk_box_pack_start (GTK_BOX (child), button_data->label, FALSE, FALSE, 0);
-            gtk_box_pack_start (GTK_BOX (child), button_data->disclosure_arrow, FALSE, FALSE, 0);
         }
         break;
 
@@ -1118,23 +1120,17 @@ make_button_data (NautilusPathBar *self,
             gtk_style_context_add_class (gtk_widget_get_style_context (separator_label), "dim-label");
             button_data->label = gtk_label_new (NULL);
             child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
-            button_data->disclosure_arrow = gtk_image_new_from_icon_name ("pan-down-symbolic",
-                                                                          GTK_ICON_SIZE_MENU);
             button_data->container = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
             gtk_box_pack_start (GTK_BOX (button_data->container), separator_label, FALSE, FALSE, 0);
             gtk_box_pack_start (GTK_BOX (button_data->container), button_data->button, FALSE, FALSE, 0);
 
             gtk_box_pack_start (GTK_BOX (child), button_data->label, FALSE, FALSE, 0);
-            gtk_box_pack_start (GTK_BOX (child), button_data->disclosure_arrow, FALSE, FALSE, 0);
         }
         break;
     }
 
-    gtk_widget_set_no_show_all (button_data->disclosure_arrow, TRUE);
     if (current_dir)
     {
-        gtk_widget_show (button_data->disclosure_arrow);
-        gtk_popover_set_relative_to (self->current_view_menu_popover, button_data->button);
         gtk_style_context_add_class (gtk_widget_get_style_context (button_data->button),
                                      "current-dir");
     }
diff --git a/src/resources/css/Adwaita.css b/src/resources/css/Adwaita.css
index 61ee99830..c43dd78e2 100644
--- a/src/resources/css/Adwaita.css
+++ b/src/resources/css/Adwaita.css
@@ -49,18 +49,22 @@
 
 /* Path bar */
 
-.path-bar-box {
-  border-radius: 5px;
+.path-bar-box scrolledwindow {
+  border-radius: 5px 0px 0px 5px;
   border: 1px @borders solid;
+  border-right-width: 0px;
   background-color: @theme_bg_color;
 }
 
+.path-bar-box button {
+  margin: 0px;
+}
+
 .nautilus-path-bar button {
   background-image: none;
   box-shadow: none;
   border-radius: 7px;
   border-width: 0px;
-  margin: 0px;
   -gtk-icon-shadow: none;
 }
 


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