[nautilus/wip/cdavis/use-flap: 2/2] general: GtkPaned -> AdwFlap
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/cdavis/use-flap: 2/2] general: GtkPaned -> AdwFlap
- Date: Sun, 10 Jul 2022 23:40:28 +0000 (UTC)
commit 91bc0ea9aaaf23e1ecb72c04aeb3420a0d2636ba
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. For windows narrower
than 600px, we fold the sidebar.
The loss of the resizable sidebar means that all settings related
to it are removed.
Fixes #2156
data/org.gnome.nautilus.gschema.xml | 5 --
src/nautilus-global-preferences.h | 1 -
src/nautilus-toolbar.c | 37 +++++++++++++++
src/nautilus-window.c | 89 ++++++++++--------------------------
src/resources/ui/nautilus-toolbar.ui | 8 ++++
src/resources/ui/nautilus-window.ui | 22 +++++----
6 files changed, 82 insertions(+), 80 deletions(-)
---
diff --git a/data/org.gnome.nautilus.gschema.xml b/data/org.gnome.nautilus.gschema.xml
index 7dbacbee1..7d7d2a624 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-global-preferences.h b/src/nautilus-global-preferences.h
index 53374aaef..6d3b0473c 100644
--- a/src/nautilus-global-preferences.h
+++ b/src/nautilus-global-preferences.h
@@ -59,7 +59,6 @@ typedef enum
/* Which views should be displayed for new windows */
#define NAUTILUS_WINDOW_STATE_INITIAL_SIZE "initial-size"
#define NAUTILUS_WINDOW_STATE_MAXIMIZED "maximized"
-#define NAUTILUS_WINDOW_STATE_SIDEBAR_WIDTH "sidebar-width"
/* Sorting order */
#define NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST "sort-directories-first"
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index 57fe64dc3..bc91c2ecb 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,13 @@ nautilus_toolbar_class_init (NautilusToolbarClass *klass)
FALSE,
G_PARAM_READWRITE);
+ properties[PROP_SHOW_SIDEBAR_BUTTON] =
+ g_param_spec_boolean ("show-sidebar-button", NULL, NULL, FALSE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ properties[PROP_SIDEBAR_BUTTON_ACTIVE] =
+ g_param_spec_boolean ("sidebar-button-active", NULL, NULL, 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 e3bb58c91..34f2aec72 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,19 @@ 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);
+ 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 +998,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
@@ -1582,12 +1532,14 @@ 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;
gchar detailed_action[80];
gchar accel[80];
gint i;
@@ -1625,6 +1577,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)
@@ -1635,6 +1588,10 @@ nautilus_window_initialize_actions (NautilusWindow *window)
}
#undef ACCELS
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "toggle-sidebar");
+ g_object_bind_property (window->content_flap, "folded",
+ action, "enabled", G_BINDING_SYNC_CREATE);
}
@@ -2226,7 +2183,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/resources/ui/nautilus-toolbar.ui b/src/resources/ui/nautilus-toolbar.ui
index e9ab53edd..0bf8d79c2 100644
--- a/src/resources/ui/nautilus-toolbar.ui
+++ b/src/resources/ui/nautilus-toolbar.ui
@@ -170,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 a5c9a836e..dd9048f81 100644
--- a/src/resources/ui/nautilus-window.ui
+++ b/src/resources/ui/nautilus-window.ui
@@ -37,26 +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="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]