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




commit 022563a44a6c77e24fc1b46dde36c14b95e9a4a4
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-gtk4-helpers.c          |  9 ++++++
 src/nautilus-gtk4-helpers.h          |  2 ++
 src/nautilus-pathbar.c               | 54 +++++++++++++++++-------------------
 src/resources/css/Adwaita.css        | 17 ++++++++----
 src/resources/ui/nautilus-toolbar.ui |  3 --
 5 files changed, 48 insertions(+), 37 deletions(-)
---
diff --git a/src/nautilus-gtk4-helpers.c b/src/nautilus-gtk4-helpers.c
index 60da7672a..b81c955dc 100644
--- a/src/nautilus-gtk4-helpers.c
+++ b/src/nautilus-gtk4-helpers.c
@@ -9,6 +9,15 @@ gtk_button_set_child (GtkButton *button,
     gtk_container_add (GTK_CONTAINER (button), child);
 }
 
+void
+gtk_menu_button_set_child (GtkMenuButton *menu_button,
+                           GtkWidget     *child)
+{
+    g_assert (GTK_IS_MENU_BUTTON (menu_button));
+
+    gtk_container_add (GTK_CONTAINER (menu_button), child);
+}
+
 void
 gtk_box_append (GtkBox    *box,
                 GtkWidget *child)
diff --git a/src/nautilus-gtk4-helpers.h b/src/nautilus-gtk4-helpers.h
index 201183c15..ff1e0049f 100644
--- a/src/nautilus-gtk4-helpers.h
+++ b/src/nautilus-gtk4-helpers.h
@@ -9,6 +9,8 @@ G_BEGIN_DECLS
 
 void gtk_button_set_child          (GtkButton         *button,
                                     GtkWidget         *child);
+void gtk_menu_button_set_child     (GtkMenuButton     *menu_button,
+                                    GtkWidget         *child);
 void gtk_box_append                (GtkBox            *box,
                                     GtkWidget         *child);
 void gtk_box_remove                (GtkBox            *box,
diff --git a/src/nautilus-pathbar.c b/src/nautilus-pathbar.c
index 4d8bf618a..a9b1a6374 100644
--- a/src/nautilus-pathbar.c
+++ b/src/nautilus-pathbar.c
@@ -73,7 +73,6 @@ typedef struct
     GtkWidget *image;
     GtkWidget *label;
     GtkWidget *separator;
-    GtkWidget *disclosure_arrow;
     GtkWidget *container;
 
     NautilusPathBar *path_bar;
@@ -101,6 +100,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;
@@ -214,6 +214,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)
 {
@@ -235,6 +244,12 @@ nautilus_path_bar_init (NautilusPathBar *self)
     self->buttons_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
     gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (self->scrolled), self->buttons_box);
 
+    self->current_view_menu_button = gtk_menu_button_new ();
+    gtk_menu_button_set_child (GTK_MENU_BUTTON (self->current_view_menu_button),
+                               gtk_image_new_from_icon_name ("view-more-symbolic",
+                                                             GTK_ICON_SIZE_MENU));
+    gtk_box_append (GTK_BOX (self), self->current_view_menu_button);
+
     builder = gtk_builder_new ();
 
     /* Add context menu for pathbar buttons */
@@ -264,8 +279,16 @@ nautilus_path_bar_init (NautilusPathBar *self)
 
     g_object_unref (builder);
 
+    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)),
+                                 "linked");
     gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)),
                                  "nautilus-path-bar");
+    gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self->buttons_box)),
+                                 "path-buttons-box");
 
     /* Action group */
     self->action_group = G_ACTION_GROUP (g_simple_action_group_new ());
@@ -459,13 +482,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 */
@@ -564,14 +587,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
@@ -699,14 +714,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
@@ -1097,15 +1104,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_append (GTK_BOX (button_data->container), button_data->button);
 
             gtk_box_append (GTK_BOX (child), button_data->image);
             gtk_box_append (GTK_BOX (child), button_data->label);
-            gtk_box_append (GTK_BOX (child), button_data->disclosure_arrow);
         }
         break;
 
@@ -1119,23 +1123,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_append (GTK_BOX (button_data->container), separator_label);
             gtk_box_append (GTK_BOX (button_data->container), button_data->button);
 
             gtk_box_append (GTK_BOX (child), button_data->label);
-            gtk_box_append (GTK_BOX (child), button_data->disclosure_arrow);
         }
         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 3595b3b74..a9ab269c7 100644
--- a/src/resources/css/Adwaita.css
+++ b/src/resources/css/Adwaita.css
@@ -54,27 +54,32 @@
 
 /* Path bar */
 
-.path-bar-box {
-  border-radius: 5px;
+.nautilus-path-bar scrolledwindow {
+  border-radius: 5px 0px 0px 5px;
   border: 1px @borders solid;
+  border-right-width: 0px;
   background-color: @theme_bg_color;
 }
 
-.nautilus-path-bar button {
+.nautilus-path-bar > button,
+.path-buttons-box button {
+  margin: 0px;
+}
+
+.path-buttons-box button {
   background-image: none;
   box-shadow: none;
   border-radius: 7px;
   border-width: 0px;
-  margin: 0px;
   -gtk-icon-shadow: none;
 }
 
-.nautilus-path-bar button:not(.current-dir):not(:backdrop):hover {
+.path-buttons-box button:not(.current-dir):not(:backdrop):hover {
   background: alpha(@theme_fg_color, 0.15);
   box-shadow: inset 0 0 0 2px @theme_bg_color;
 }
 
-.nautilus-path-bar button:not(.current-dir):not(:backdrop):hover * {
+.path-buttons-box button:not(.current-dir):not(:backdrop):hover * {
   opacity: 1;
 }
 
diff --git a/src/resources/ui/nautilus-toolbar.ui b/src/resources/ui/nautilus-toolbar.ui
index 359f80aec..09145eac3 100644
--- a/src/resources/ui/nautilus-toolbar.ui
+++ b/src/resources/ui/nautilus-toolbar.ui
@@ -443,9 +443,6 @@
               <object class="GtkBox" id="path_bar_container">
                 <property name="can_focus">False</property>
                 <property name="valign">center</property>
-                <style>
-                  <class name="path-bar-box"/>
-                </style>
               </object>
               <packing>
                 <property name="name">pathbar</property>


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