[nautilus/wip/cdavis/use-flap: 13/13] general: GtkPaned -> AdwFlap




commit 8856582236368d3b63787587e002e93bfc5250e9
Author: Christopher Davis <christopherdavis gnome org>
Date:   Sat Jul 9 12:38:10 2022 -0400

    general: GtkPaned -> AdwFlap
    
    Exchange the adjustable GtkPaned widget for AdwFlap. We lose
    a resizable sidebar, but gain an adaptive one.
    
    The loss of the resizable sidebar means that all settings related
    to it are removed. Because the flap handles small screen sizes,
    this commit also removes the setting to hide the sidebar.

 data/org.gnome.nautilus.gschema.xml  |   5 --
 src/nautilus-application.c           |  60 ------------------
 src/nautilus-toolbar.c               |  43 +++++++++++++
 src/nautilus-window.c                | 120 +++++++----------------------------
 src/nautilus-window.h                |   2 -
 src/resources/ui/nautilus-toolbar.ui |  12 ++--
 src/resources/ui/nautilus-window.ui  |  23 ++++---
 7 files changed, 87 insertions(+), 178 deletions(-)
---
diff --git a/data/org.gnome.nautilus.gschema.xml b/data/org.gnome.nautilus.gschema.xml
index 39a8ed753..7958d9c2e 100644
--- a/data/org.gnome.nautilus.gschema.xml
+++ b/data/org.gnome.nautilus.gschema.xml
@@ -251,11 +251,6 @@
       <summary>Whether the navigation window should be maximized</summary>
       <description>Whether the navigation window should be maximized by default.</description>
     </key>
-    <key type="i" name="sidebar-width">
-      <default>188</default>
-      <summary>Width of the side pane</summary>
-      <description>The default width of the side pane in new windows.</description>
-    </key>
     <key type="b" name="start-with-location-bar">
       <default>true</default>
       <summary>Show location bar in new windows</summary>
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index 77fd7d045..fc5479587 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -812,29 +812,6 @@ action_quit (GSimpleAction *action,
     g_list_free (windows);
 }
 
-static void
-action_show_hide_sidebar (GObject    *object,
-                          GParamSpec *pspec,
-                          gpointer   *user_data)
-{
-    GList *window, *windows;
-    GVariant *state = g_action_get_state (G_ACTION (object));
-
-    windows = gtk_application_get_windows (GTK_APPLICATION (user_data));
-
-    for (window = windows; window != NULL; window = window->next)
-    {
-        if (g_variant_get_boolean (state))
-        {
-            nautilus_window_show_sidebar (window->data);
-        }
-        else
-        {
-            nautilus_window_hide_sidebar (window->data);
-        }
-    }
-}
-
 static void
 action_show_help_overlay (GSimpleAction *action,
                           GVariant      *state,
@@ -846,29 +823,11 @@ action_show_help_overlay (GSimpleAction *action,
     g_action_group_activate_action (G_ACTION_GROUP (window), "show-help-overlay", NULL);
 }
 
-static gboolean
-variant_get_mapping (GValue   *value,
-                     GVariant *variant,
-                     gpointer  user_data)
-{
-    g_value_set_variant (value, variant);
-    return TRUE;
-}
-
-static GVariant *
-variant_set_mapping (const GValue       *value,
-                     const GVariantType *expected_type,
-                     gpointer            user_data)
-{
-    return g_value_get_variant (value);
-}
-
 const static GActionEntry app_entries[] =
 {
     { "new-window", action_new_window, NULL, NULL, NULL },
     { "clone-window", action_clone_window, NULL, NULL, NULL },
     { "preferences", action_preferences, NULL, NULL, NULL },
-    { "show-hide-sidebar", NULL, NULL, "true", NULL },
     { "about", action_about, NULL, NULL, NULL },
     { "help", action_help, NULL, NULL, NULL },
     { "quit", action_quit, NULL, NULL, NULL },
@@ -879,36 +838,17 @@ const static GActionEntry app_entries[] =
 static void
 nautilus_init_application_actions (NautilusApplication *app)
 {
-    GAction *sidebar_action;
-
     g_action_map_add_action_entries (G_ACTION_MAP (app),
                                      app_entries, G_N_ELEMENTS (app_entries),
                                      app);
 
 
-    sidebar_action = g_action_map_lookup_action (G_ACTION_MAP (app),
-                                                 "show-hide-sidebar");
-    g_signal_connect (sidebar_action,
-                      "notify::state",
-                      G_CALLBACK (action_show_hide_sidebar),
-                      app);
-    g_settings_bind_with_mapping (nautilus_window_state,
-                                  NAUTILUS_WINDOW_STATE_START_WITH_SIDEBAR,
-                                  sidebar_action,
-                                  "state",
-                                  G_SETTINGS_BIND_DEFAULT,
-                                  variant_get_mapping,
-                                  variant_set_mapping,
-                                  NULL, NULL);
-
     nautilus_application_set_accelerator (G_APPLICATION (app),
                                           "app.clone-window", "<Primary>n");
     nautilus_application_set_accelerator (G_APPLICATION (app),
                                           "app.help", "F1");
     nautilus_application_set_accelerator (G_APPLICATION (app),
                                           "app.quit", "<Primary>q");
-    nautilus_application_set_accelerator (G_APPLICATION (app),
-                                          "app.show-hide-sidebar", "F9");
 }
 
 static void
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index 57fe64dc3..6d3b5af01 100644
--- a/src/nautilus-toolbar.c
+++ b/src/nautilus-toolbar.c
@@ -85,6 +85,10 @@ struct _NautilusToolbar
     GtkWidget *app_button;
     GMenuModel *undo_redo_section;
 
+    GtkWidget *sidebar_button;
+    gboolean show_sidebar_button;
+    gboolean sidebar_button_active;
+
     GtkWidget *forward_button;
     GtkWidget *forward_menu;
 
@@ -110,6 +114,8 @@ enum
     PROP_SHOW_LOCATION_ENTRY,
     PROP_WINDOW_SLOT,
     PROP_SEARCHING,
+    PROP_SHOW_SIDEBAR_BUTTON,
+    PROP_SIDEBAR_BUTTON_ACTIVE,
     NUM_PROPERTIES
 };
 
@@ -916,6 +922,18 @@ nautilus_toolbar_get_property (GObject    *object,
         }
         break;
 
+        case PROP_SHOW_SIDEBAR_BUTTON:
+        {
+            g_value_set_boolean (value, self->show_sidebar_button);
+        }
+        break;
+
+        case PROP_SIDEBAR_BUTTON_ACTIVE:
+        {
+            g_value_set_boolean (value, self->sidebar_button_active);
+        }
+        break;
+
         default:
         {
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -1022,6 +1040,18 @@ nautilus_toolbar_set_property (GObject      *object,
         }
         break;
 
+        case PROP_SHOW_SIDEBAR_BUTTON:
+        {
+            self->show_sidebar_button = g_value_get_boolean (value);
+        }
+        break;
+
+        case PROP_SIDEBAR_BUTTON_ACTIVE:
+        {
+            self->sidebar_button_active = g_value_get_boolean (value);
+        }
+        break;
+
         default:
         {
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -1118,6 +1148,19 @@ nautilus_toolbar_class_init (NautilusToolbarClass *klass)
                               FALSE,
                               G_PARAM_READWRITE);
 
+    properties[PROP_SHOW_SIDEBAR_BUTTON] =
+        g_param_spec_boolean ("show-sidebar-button",
+                              "Whether to show the sidebar button",
+                              "Whether to show the sidebar button",
+                              FALSE,
+                              G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+    properties[PROP_SIDEBAR_BUTTON_ACTIVE] =
+        g_param_spec_boolean ("sidebar-button-active",
+                              "Whether or not the sidebar button is toggled",
+                              "Whether or not the sidebar button is toggled",
+                              FALSE,
+                              G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
     g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
 
     gtk_widget_class_set_template_from_resource (widget_class,
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 675c32613..437bcfc4d 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -104,11 +104,10 @@ struct _NautilusWindow
     GList *slots;
     NautilusWindowSlot *active_slot; /* weak reference */
 
-    GtkWidget *content_paned;
+    GtkWidget *content_flap;
 
     /* Side Pane */
-    int side_pane_width;
-    GtkWidget *places_sidebar;
+    GtkWidget *places_sidebar;     /* the actual GtkPlacesSidebar */
     GVolume *selected_volume;     /* the selected volume in the sidebar popup callback */
     GFile *selected_file;     /* the selected file in the sidebar popup callback */
 
@@ -804,62 +803,6 @@ nautilus_window_get_notebook (NautilusWindow *window)
     return window->notebook;
 }
 
-static gboolean
-save_sidebar_width_cb (gpointer user_data)
-{
-    NautilusWindow *window = user_data;
-
-
-    window->sidebar_width_handler_id = 0;
-
-    DEBUG ("Saving sidebar width: %d", window->side_pane_width);
-
-    g_settings_set_int (nautilus_window_state,
-                        NAUTILUS_WINDOW_STATE_SIDEBAR_WIDTH,
-                        window->side_pane_width);
-
-    return FALSE;
-}
-
-/* side pane helpers */
-static void
-side_pane_notify_position_callback (GObject    *object,
-                                    GParamSpec *pspec,
-                                    gpointer    user_data)
-{
-    NautilusWindow *window = user_data;
-    gint position;
-
-    if (window->sidebar_width_handler_id != 0)
-    {
-        g_source_remove (window->sidebar_width_handler_id);
-        window->sidebar_width_handler_id = 0;
-    }
-
-    position = gtk_paned_get_position (GTK_PANED (window->content_paned));
-    if (position != window->side_pane_width &&
-        position > 1)
-    {
-        window->side_pane_width = position;
-
-        window->sidebar_width_handler_id =
-            g_idle_add (save_sidebar_width_cb, window);
-    }
-}
-
-static void
-setup_side_pane_width (NautilusWindow *window)
-{
-    g_return_if_fail (window->places_sidebar != NULL);
-
-    window->side_pane_width =
-        g_settings_get_int (nautilus_window_state,
-                            NAUTILUS_WINDOW_STATE_SIDEBAR_WIDTH);
-
-    gtk_paned_set_position (GTK_PANED (window->content_paned),
-                            window->side_pane_width);
-}
-
 /* Callback used when the places sidebar changes location; we need to change the displayed folder */
 static void
 open_location_cb (NautilusWindow             *window,
@@ -1026,6 +969,23 @@ action_restore_tab (GSimpleAction *action,
     free_navigation_state (data);
 }
 
+static void
+action_toggle_sidebar (GSimpleAction *action,
+                       GVariant      *state,
+                       gpointer       user_data)
+{
+    NautilusWindow *window = NAUTILUS_WINDOW (user_data);
+
+    if (adw_flap_get_folded (ADW_FLAP (window->content_flap)))
+    {
+        gboolean revealed;
+
+        revealed = adw_flap_get_reveal_flap (ADW_FLAP (window->content_flap));
+        adw_flap_set_reveal_flap (ADW_FLAP (window->content_flap), !revealed);
+    }
+}
+
+
 static guint
 get_window_xid (NautilusWindow *window)
 {
@@ -1042,12 +1002,6 @@ get_window_xid (NautilusWindow *window)
 static void
 nautilus_window_set_up_sidebar (NautilusWindow *window)
 {
-    setup_side_pane_width (window);
-    g_signal_connect (window->content_paned,
-                      "notify::position",
-                      G_CALLBACK (side_pane_notify_position_callback),
-                      window);
-
     nautilus_gtk_places_sidebar_set_open_flags (NAUTILUS_GTK_PLACES_SIDEBAR (window->places_sidebar),
                                                 (NAUTILUS_GTK_PLACES_OPEN_NORMAL
                                                  | NAUTILUS_GTK_PLACES_OPEN_NEW_TAB
@@ -1068,27 +1022,6 @@ nautilus_window_set_up_sidebar (NautilusWindow *window)
                       G_CALLBACK (places_sidebar_drag_perform_drop_cb), window);
 }
 
-void
-nautilus_window_hide_sidebar (NautilusWindow *window)
-{
-    DEBUG ("Called hide_sidebar()");
-
-    g_return_if_fail (NAUTILUS_IS_WINDOW (window));
-
-    gtk_widget_hide (window->places_sidebar);
-}
-
-void
-nautilus_window_show_sidebar (NautilusWindow *window)
-{
-    DEBUG ("Called show_sidebar()");
-
-    g_return_if_fail (NAUTILUS_IS_WINDOW (window));
-
-    gtk_widget_show (window->places_sidebar);
-    setup_side_pane_width (window);
-}
-
 void
 nautilus_window_slot_close (NautilusWindow     *window,
                             NautilusWindowSlot *slot)
@@ -1603,14 +1536,13 @@ const GActionEntry win_entries[] =
     { "prompt-home-location", action_prompt_for_location_home },
     { "go-to-tab", NULL, "i", "0", action_go_to_tab },
     { "restore-tab", action_restore_tab },
+    { "toggle-sidebar", action_toggle_sidebar },
 };
 
 static void
 nautilus_window_initialize_actions (NautilusWindow *window)
 {
     GApplication *app;
-    GAction *action;
-    GVariant *state;
     gchar detailed_action[80];
     gchar accel[80];
     gint i;
@@ -1648,6 +1580,7 @@ nautilus_window_initialize_actions (NautilusWindow *window)
     nautilus_application_set_accelerators (app, "win.prompt-home-location", ACCELS ("asciitilde", 
"dead_tilde"));
     nautilus_application_set_accelerator (app, "win.current-location-menu", "F10");
     nautilus_application_set_accelerator (app, "win.restore-tab", "<shift><control>t");
+    nautilus_application_set_accelerator (app, "win.toggle-sidebar", "F9");
 
     /* Alt+N for the first 9 tabs */
     for (i = 0; i < 9; ++i)
@@ -1658,15 +1591,6 @@ nautilus_window_initialize_actions (NautilusWindow *window)
     }
 
 #undef ACCELS
-
-    action = g_action_map_lookup_action (G_ACTION_MAP (app), "show-hide-sidebar");
-    state = g_action_get_state (action);
-    if (g_variant_get_boolean (state))
-    {
-        nautilus_window_show_sidebar (window);
-    }
-
-    g_variant_unref (state);
 }
 
 
@@ -2258,7 +2182,7 @@ nautilus_window_class_init (NautilusWindowClass *class)
     gtk_widget_class_set_template_from_resource (wclass,
                                                  "/org/gnome/nautilus/ui/nautilus-window.ui");
     gtk_widget_class_bind_template_child (wclass, NautilusWindow, toolbar);
-    gtk_widget_class_bind_template_child (wclass, NautilusWindow, content_paned);
+    gtk_widget_class_bind_template_child (wclass, NautilusWindow, content_flap);
     gtk_widget_class_bind_template_child (wclass, NautilusWindow, places_sidebar);
     gtk_widget_class_bind_template_child (wclass, NautilusWindow, notebook);
     gtk_widget_class_bind_template_child (wclass, NautilusWindow, tab_menu);
diff --git a/src/nautilus-window.h b/src/nautilus-window.h
index ed8d6585e..8fba9aad9 100644
--- a/src/nautilus-window.h
+++ b/src/nautilus-window.h
@@ -76,8 +76,6 @@ void                 nautilus_window_slot_close            (NautilusWindow *wind
 
 void                 nautilus_window_sync_location_widgets (NautilusWindow *window);
 
-void     nautilus_window_hide_sidebar         (NautilusWindow *window);
-void     nautilus_window_show_sidebar         (NautilusWindow *window);
 void nautilus_window_reset_menus (NautilusWindow *window);
 
 GtkWidget *         nautilus_window_get_notebook (NautilusWindow *window);
diff --git a/src/resources/ui/nautilus-toolbar.ui b/src/resources/ui/nautilus-toolbar.ui
index 7103e4423..0bf8d79c2 100644
--- a/src/resources/ui/nautilus-toolbar.ui
+++ b/src/resources/ui/nautilus-toolbar.ui
@@ -62,10 +62,6 @@
         <attribute name="label" translatable="yes">Show _Hidden Files</attribute>
         <attribute name="action">view.show-hidden-files</attribute>
       </item>
-      <item>
-        <attribute name="label" translatable="yes">Show _Sidebar</attribute>
-        <attribute name="action">app.show-hide-sidebar</attribute>
-      </item>
     </section>
     <section>
       <item>
@@ -174,6 +170,14 @@
             </child>
           </object>
         </child>
+        <child type="start">
+          <object class="GtkToggleButton" id="show_sidebar_button">
+            <property name="visible" bind-source="NautilusToolbar" bind-property="show-sidebar-button" 
bind-flags="bidirectional|sync-create"/>
+            <property name="active" bind-source="NautilusToolbar" bind-property="sidebar-button-active" 
bind-flags="bidirectional|sync-create"/>
+            <property name="tooltip-text" translatable="yes">Show sidebar</property>
+            <property name="icon-name">sidebar-show-symbolic</property>
+          </object>
+        </child>
         <child type="start">
           <object class="GtkButton" id="back_button">
             <property name="focusable">True</property>
diff --git a/src/resources/ui/nautilus-window.ui b/src/resources/ui/nautilus-window.ui
index 2242e0ef6..dd9048f81 100644
--- a/src/resources/ui/nautilus-window.ui
+++ b/src/resources/ui/nautilus-window.ui
@@ -37,27 +37,32 @@
           <object class="GtkBox">
             <property name="orientation">vertical</property>
             <child>
-              <object class="NautilusToolbar" id="toolbar"/>
+              <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"/>
+              </object>
             </child>
             <child>
-              <object class="GtkPaned" id="content_paned">
-                <property name="shrink-end-child">False</property>
-                <property name="shrink-start-child">False</property>
-                <property name="resize-start-child">False</property>
-                <property name="vexpand">True</property>
-                <property name="hexpand">True</property>
-                <child>
+              <object class="AdwFlap" id="content_flap">
+                <child type="flap">
                   <object class="NautilusGtkPlacesSidebar" id="places_sidebar">
-                    <property name="visible">False</property>
                     <property name="vexpand">True</property>
                     <property name="show-other-locations">True</property>
                     <property name="show-starred-location">True</property>
+                    <property name="width-request">240</property>
+                    <style>
+                      <class name="background"/>
+                    </style>
                   </object>
                 </child>
+                <child type="separator">
+                  <object class="GtkSeparator"/>
+                </child>
                 <child>
                   <object class="GtkNotebook" id="notebook">
                     <property name="show-tabs">False</property>
                     <property name="show-border">False</property>
+                    <property name="width-request">360</property>
                   </object>
                 </child>
               </object>


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