[nautilus/wip/toolbar-start-end: 2/4] window, toolbar: Change toolbar visibility based on size




commit 25dc8c66aca1cabd347fd8a8dbc0d454c6f5854b
Author: Christopher Davis <christopherdavis gnome org>
Date:   Fri Jul 22 23:41:35 2022 -0400

    window, toolbar: Change toolbar visibility based on size
    
    Show a bottom bar at small sizes, while hiding the start
    and end children.

 src/nautilus-toolbar.c               | 18 +++++++++++++
 src/nautilus-window.c                | 52 ++++++++++++++++++++++++++++++++++++
 src/resources/ui/nautilus-toolbar.ui | 20 +++++++++++---
 src/resources/ui/nautilus-window.ui  | 16 +++++++++++
 4 files changed, 102 insertions(+), 4 deletions(-)
---
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index 7043d092b..c8619d962 100644
--- a/src/nautilus-toolbar.c
+++ b/src/nautilus-toolbar.c
@@ -64,6 +64,8 @@ struct _NautilusToolbar
     gboolean show_sidebar_button;
     gboolean sidebar_button_active;
 
+    gboolean show_toolbar_children;
+
     GtkWidget *search_button;
 
     GtkWidget *location_entry_close_button;
@@ -81,6 +83,7 @@ enum
     PROP_SEARCHING,
     PROP_SHOW_SIDEBAR_BUTTON,
     PROP_SIDEBAR_BUTTON_ACTIVE,
+    PROP_SHOW_TOOLBAR_CHILDREN,
     NUM_PROPERTIES
 };
 
@@ -302,6 +305,12 @@ nautilus_toolbar_get_property (GObject    *object,
         }
         break;
 
+        case PROP_SHOW_TOOLBAR_CHILDREN:
+        {
+            g_value_set_boolean (value, self->show_toolbar_children);
+        }
+        break;
+
         default:
         {
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -419,6 +428,12 @@ nautilus_toolbar_set_property (GObject      *object,
         }
         break;
 
+        case PROP_SHOW_TOOLBAR_CHILDREN:
+        {
+            self->show_toolbar_children = g_value_get_boolean (value);
+        }
+        break;
+
         default:
         {
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -510,6 +525,9 @@ nautilus_toolbar_class_init (NautilusToolbarClass *klass)
     properties[PROP_SIDEBAR_BUTTON_ACTIVE] =
         g_param_spec_boolean ("sidebar-button-active", NULL, NULL, FALSE,
                               G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+    properties[PROP_SHOW_TOOLBAR_CHILDREN] =
+        g_param_spec_boolean ("show-toolbar-children", NULL, NULL, TRUE,
+                              G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
     g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
 
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index ca037ab1a..36c264fcb 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -126,6 +126,8 @@ struct _NautilusWindow
     gulong bookmarks_id;
 
     GQueue *tab_data_queue;
+
+    gboolean mobile;
 };
 
 enum
@@ -143,6 +145,7 @@ enum
 {
     PROP_0,
     PROP_ACTIVE_SLOT,
+    PROP_MOBILE,
     N_PROPS
 };
 
@@ -1539,6 +1542,36 @@ nautilus_window_initialize_actions (NautilusWindow *window)
                             action, "enabled", G_BINDING_SYNC_CREATE);
 }
 
+static gboolean
+nautilus_window_get_mobile (NautilusWindow *self)
+{
+    return self->mobile;
+}
+
+static void
+nautilus_window_set_mobile (NautilusWindow *self,
+                            gboolean        mobile)
+{
+    if (self->mobile == mobile)
+    {
+        return;
+    }
+
+    self->mobile = mobile;
+
+    g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MOBILE]);
+}
+
+static void
+nautilus_window_size_allocate (GtkWidget *self,
+                               int        width,
+                               int        height,
+                               int        baseline)
+{
+    GTK_WIDGET_CLASS (nautilus_window_parent_class)->size_allocate (self, width, height, baseline);
+
+    nautilus_window_set_mobile (NAUTILUS_WINDOW (self), width < 700);
+}
 
 static void
 nautilus_window_constructed (GObject *self)
@@ -2129,6 +2162,12 @@ nautilus_window_get_property (GObject    *object,
         }
         break;
 
+        case PROP_MOBILE:
+        {
+            g_value_set_boolean (value, nautilus_window_get_mobile (self));
+        }
+        break;
+
         default:
         {
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -2152,6 +2191,12 @@ nautilus_window_set_property (GObject      *object,
         }
         break;
 
+        case PROP_MOBILE:
+        {
+            nautilus_window_set_mobile (self, g_value_get_boolean (value));
+        }
+        break;
+
         default:
         {
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -2175,6 +2220,7 @@ nautilus_window_class_init (NautilusWindowClass *class)
     wclass->show = nautilus_window_show;
     wclass->realize = nautilus_window_realize;
     wclass->grab_focus = nautilus_window_grab_focus;
+    wclass->size_allocate = nautilus_window_size_allocate;
 
     winclass->close_request = nautilus_window_close_request;
 
@@ -2184,6 +2230,12 @@ nautilus_window_class_init (NautilusWindowClass *class)
                              NAUTILUS_TYPE_WINDOW_SLOT,
                              G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
 
+    properties[PROP_MOBILE] =
+        g_param_spec_boolean ("mobile",
+                              NULL, NULL,
+                              FALSE,
+                              G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
     g_object_class_install_properties (oclass, N_PROPS, properties);
 
     gtk_widget_class_set_template_from_resource (wclass,
diff --git a/src/resources/ui/nautilus-toolbar.ui b/src/resources/ui/nautilus-toolbar.ui
index c324f6591..d29bc95f7 100644
--- a/src/resources/ui/nautilus-toolbar.ui
+++ b/src/resources/ui/nautilus-toolbar.ui
@@ -126,8 +126,14 @@
           </object>
         </child>
         <child type="start">
-          <object class="NautilusToolbarStart">
-            <property name="window-slot" bind-source="NautilusToolbar" bind-property="window-slot" 
bind-flags="sync-create"/>
+          <object class="GtkRevealer">
+            <property name="reveal-child" bind-source="NautilusToolbar" 
bind-property="show-toolbar-children" bind-flags="sync-create"/>
+            <property name="transition-type">slide-right</property>
+            <property name="child">
+              <object class="NautilusToolbarStart">
+                <property name="window-slot" bind-source="NautilusToolbar" bind-property="window-slot" 
bind-flags="sync-create"/>
+              </object>
+            </property>
           </object>
         </child>
         <child type="end">
@@ -163,8 +169,14 @@
           </object>
         </child>
         <child type="end">
-          <object class="NautilusToolbarEnd">
-            <property name="window-slot" bind-source="NautilusToolbar" bind-property="window-slot" 
bind-flags="sync-create"/>
+          <object class="GtkRevealer">
+            <property name="reveal-child" bind-source="NautilusToolbar" 
bind-property="show-toolbar-children" bind-flags="sync-create"/>
+            <property name="transition-type">slide-left</property>
+            <property name="child">
+              <object class="NautilusToolbarEnd">
+                <property name="window-slot" bind-source="NautilusToolbar" bind-property="window-slot" 
bind-flags="sync-create"/>
+              </object>
+            </property>
           </object>
         </child>
       </object>
diff --git a/src/resources/ui/nautilus-window.ui b/src/resources/ui/nautilus-window.ui
index fed197148..e67f050bc 100644
--- a/src/resources/ui/nautilus-window.ui
+++ b/src/resources/ui/nautilus-window.ui
@@ -37,6 +37,7 @@
               <object class="NautilusToolbar" id="toolbar">
                 <property name="show-sidebar-button" bind-source="content_flap" bind-property="folded" 
bind-flags="sync-create"/>
                 <property name="sidebar-button-active" bind-source="content_flap" 
bind-property="reveal-flap" bind-flags="bidirectional|sync-create"/>
+                <property name="show-toolbar-children" bind-source="NautilusWindow" bind-property="mobile" 
bind-flags="sync-create|invert-boolean"/>
                 <property name="window-slot" bind-source="NautilusWindow" bind-property="active-slot" 
bind-flags="sync-create"/>
               </object>
             </child>
@@ -74,6 +75,21 @@
                 </child>
               </object>
             </child>
+            <child>
+              <object class="GtkActionBar">
+                <property name="revealed" bind-source="NautilusWindow" bind-property="mobile" 
bind-flags="sync-create"/>
+                <child type="start">
+                  <object class="NautilusToolbarStart">
+                    <property name="window-slot" bind-source="NautilusWindow" bind-property="active-slot" 
bind-flags="sync-create"/>
+                  </object>
+                </child>
+                <child type="end">
+                  <object class="NautilusToolbarEnd">
+                    <property name="window-slot" bind-source="NautilusWindow" bind-property="active-slot" 
bind-flags="sync-create"/>
+                  </object>
+                </child>
+              </object>
+            </child>
           </object>
         </property>
       </object>


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