From b7fb2d1022c9e92a78024e6a8cefb4174e2d38db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= Date: Fri, 24 Dec 2021 00:34:29 +0000 Subject: [PATCH 1/4] general: Stop using gtk_box_pack_start() In preparation for a smoother GTK4 switch. --- src/nautilus-floating-bar.c | 4 ++-- src/nautilus-list-view.c | 2 +- src/nautilus-notebook.c | 5 +++-- src/nautilus-properties-window.c | 3 ++- src/nautilus-search-popover.c | 2 +- src/nautilus-window-slot.c | 5 ++--- src/nautilus-x-content-bar.c | 4 ++-- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/nautilus-floating-bar.c b/src/nautilus-floating-bar.c index 88157a9658..095e7288b3 100644 --- a/src/nautilus-floating-bar.c +++ b/src/nautilus-floating-bar.c @@ -339,7 +339,7 @@ nautilus_floating_bar_constructed (GObject *obj) box = GTK_WIDGET (obj); w = gtk_spinner_new (); - gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 0); + gtk_box_append (GTK_BOX (box), w); gtk_widget_set_visible (w, self->show_spinner); /* As a workaround for https://gitlab.gnome.org/GNOME/gtk/-/issues/1025, * ensure the spinner animates if and only if it's visible, to reduce CPU @@ -353,7 +353,7 @@ nautilus_floating_bar_constructed (GObject *obj) gtk_widget_set_margin_start (w, 8); labels_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - gtk_box_pack_start (GTK_BOX (box), labels_box, FALSE, TRUE, 0); + gtk_box_append (GTK_BOX (box), labels_box); g_object_set (labels_box, "hexpand", TRUE, "margin-top", 2, diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c index 0647ba29fb..74c8e6f4dc 100644 --- a/src/nautilus-list-view.c +++ b/src/nautilus-list-view.c @@ -3299,7 +3299,7 @@ create_column_editor (NautilusListView *view) column_chooser = nautilus_column_chooser_new (file); gtk_widget_set_vexpand (column_chooser, TRUE); - gtk_box_pack_start (GTK_BOX (box), column_chooser, FALSE, TRUE, 0); + gtk_box_append (GTK_BOX (box), column_chooser); g_signal_connect (column_chooser, "changed", G_CALLBACK (column_chooser_changed_callback), diff --git a/src/nautilus-notebook.c b/src/nautilus-notebook.c index d71e2f331b..26e615430e 100644 --- a/src/nautilus-notebook.c +++ b/src/nautilus-notebook.c @@ -29,6 +29,7 @@ #include "nautilus-window.h" #include "nautilus-window-slot.h" #include "nautilus-window-slot-dnd.h" +#include "nautilus-gtk4-helpers.h" #include #include @@ -250,11 +251,11 @@ build_tab_label (GtkNotebook *notebook, /* Spinner to be shown as load feedback */ spinner = gtk_spinner_new (); - gtk_box_pack_start (GTK_BOX (box), spinner, FALSE, FALSE, 0); + gtk_box_append (GTK_BOX (box), spinner); /* Dummy icon to allocate space for spinner */ icon = gtk_image_new (); - gtk_box_pack_start (GTK_BOX (box), icon, FALSE, FALSE, 0); + gtk_box_append (GTK_BOX (box), icon); /* don't show the icon */ /* Tab title */ diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c index a9671c89f3..c01c471ced 100644 --- a/src/nautilus-properties-window.c +++ b/src/nautilus-properties-window.c @@ -47,6 +47,7 @@ #include "nautilus-signaller.h" #include "nautilus-ui-utilities.h" #include "nautilus-signaller.h" +#include "nautilus-gtk4-helpers.h" static GHashTable *windows; static GHashTable *pending_lists; @@ -4624,7 +4625,7 @@ setup_app_chooser_area (NautilusPropertiesWindow *self) self->app_chooser_widget = gtk_app_chooser_widget_new (self->content_type); gtk_widget_set_vexpand (self->app_chooser_widget, TRUE); - gtk_box_pack_start (GTK_BOX (self->app_chooser_widget_box), self->app_chooser_widget, FALSE, TRUE, 0); + gtk_box_append (GTK_BOX (self->app_chooser_widget_box), self->app_chooser_widget); gtk_app_chooser_widget_set_show_default (GTK_APP_CHOOSER_WIDGET (self->app_chooser_widget), TRUE); gtk_app_chooser_widget_set_show_fallback (GTK_APP_CHOOSER_WIDGET (self->app_chooser_widget), TRUE); diff --git a/src/nautilus-search-popover.c b/src/nautilus-search-popover.c index 48d2481912..20fde27532 100644 --- a/src/nautilus-search-popover.c +++ b/src/nautilus-search-popover.c @@ -632,7 +632,7 @@ show_other_types_dialog (NautilusSearchPopover *popover) gtk_widget_set_vexpand (scrolled, TRUE); gtk_widget_show (scrolled); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), scrolled, FALSE, TRUE, 0); + gtk_box_append (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), scrolled); treeview = gtk_tree_view_new (); gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (store)); diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c index e1d3ae810d..16ae23a4a9 100644 --- a/src/nautilus-window-slot.c +++ b/src/nautilus-window-slot.c @@ -669,8 +669,7 @@ static void nautilus_window_slot_add_extra_location_widget (NautilusWindowSlot *self, GtkWidget *widget) { - gtk_box_pack_start (GTK_BOX (self->extra_location_widgets), - widget, FALSE, TRUE, 0); + gtk_box_append (GTK_BOX (self->extra_location_widgets), widget); gtk_widget_show (self->extra_location_widgets); } @@ -900,7 +899,7 @@ nautilus_window_slot_constructed (GObject *object) extras_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); self->extra_location_widgets = extras_vbox; - gtk_box_pack_start (GTK_BOX (self), extras_vbox, FALSE, FALSE, 0); + gtk_box_append (GTK_BOX (self), extras_vbox); gtk_widget_show (extras_vbox); self->query_editor = NAUTILUS_QUERY_EDITOR (nautilus_query_editor_new ()); diff --git a/src/nautilus-x-content-bar.c b/src/nautilus-x-content-bar.c index 8dec51f41a..03fa0cade3 100644 --- a/src/nautilus-x-content-bar.c +++ b/src/nautilus-x-content-bar.c @@ -196,9 +196,9 @@ nautilus_x_content_bar_set_x_content_types (NautilusXContentBar *bar, if (image != NULL) { - gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0); + gtk_box_append (GTK_BOX (box), image); } - gtk_box_pack_start (GTK_BOX (box), gtk_label_new (name), FALSE, FALSE, 0); + gtk_box_append (GTK_BOX (box), gtk_label_new (name)); gtk_button_set_child (GTK_BUTTON (button), box); -- GitLab From e99fe76744e95bfb462e075aa196c434d2cf5196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= Date: Fri, 24 Dec 2021 01:16:24 +0000 Subject: [PATCH 2/4] notebook: Stop using gtk_box_set_center_widget() and pack_end() In GTK, both are gone. Instead, there is a different container, GtkCenterbox, which should be used. To ease the transition, use aliases which match the center box API. --- src/nautilus-gtk4-helpers.c | 33 +++++++++++++++++++++++++++++ src/nautilus-gtk4-helpers.h | 10 +++++++++ src/nautilus-notebook.c | 41 ++++++++++++++++++++----------------- 3 files changed, 65 insertions(+), 19 deletions(-) diff --git a/src/nautilus-gtk4-helpers.c b/src/nautilus-gtk4-helpers.c index 247102e479..8f9c7bd356 100644 --- a/src/nautilus-gtk4-helpers.c +++ b/src/nautilus-gtk4-helpers.c @@ -109,6 +109,39 @@ gtk_check_button_set_active (GtkCheckButton *button, gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), setting); } + +void +gtk_center_box_set_start_widget (GtkCenterBox *center_box, + GtkWidget *widget) +{ + g_assert (GTK_IS_BOX (center_box)); + + gtk_box_pack_start (GTK_BOX (center_box), widget, FALSE, TRUE, 0); +} + +void +gtk_center_box_set_center_widget (GtkCenterBox *center_box, + GtkWidget *widget) +{ + g_assert (GTK_IS_BOX (center_box)); + + gtk_box_set_center_widget (GTK_BOX (center_box), widget); +} +void +gtk_center_box_set_end_widget (GtkCenterBox *center_box, + GtkWidget *widget) +{ + g_assert (GTK_IS_BOX (center_box)); + + gtk_box_pack_end (GTK_BOX (center_box), widget, FALSE, TRUE, 0); +} + +GtkWidget * +gtk_center_box_new (void) +{ + return gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); +} + gboolean gtk_check_button_get_active (GtkCheckButton *button) { diff --git a/src/nautilus-gtk4-helpers.h b/src/nautilus-gtk4-helpers.h index 24f3a0d5e7..77bf8089dd 100644 --- a/src/nautilus-gtk4-helpers.h +++ b/src/nautilus-gtk4-helpers.h @@ -9,6 +9,8 @@ G_BEGIN_DECLS #define AdwBin GtkBin #define ADW_BIN GTK_BIN +#define GtkCenterBox GtkBox +#define GTK_CENTER_BOX GTK_BOX void adw_bin_set_child (AdwBin *bin, GtkWidget *child); @@ -34,6 +36,14 @@ void gtk_popover_set_child (GtkPopover *popover, GtkWidget *child); void gtk_check_button_set_active (GtkCheckButton *button, gboolean setting); +void gtk_center_box_set_start_widget (GtkCenterBox *center_box, + GtkWidget *widget); +void gtk_center_box_set_center_widget (GtkCenterBox *center_box, + GtkWidget *widget); +void gtk_center_box_set_end_widget (GtkCenterBox *center_box, + GtkWidget *widget); + +GtkWidget *gtk_center_box_new (void); gboolean gtk_check_button_get_active (GtkCheckButton *button); GtkWidget *gtk_widget_get_first_child (GtkWidget *widget); diff --git a/src/nautilus-notebook.c b/src/nautilus-notebook.c index 26e615430e..f36c722ee0 100644 --- a/src/nautilus-notebook.c +++ b/src/nautilus-notebook.c @@ -195,7 +195,7 @@ void nautilus_notebook_sync_tab_label (GtkNotebook *notebook, NautilusWindowSlot *slot) { - GtkWidget *hbox, *label; + GtkWidget *cbox, *label; char *location_name; GFile *location; const gchar *title_name; @@ -203,10 +203,10 @@ nautilus_notebook_sync_tab_label (GtkNotebook *notebook, g_return_if_fail (GTK_IS_NOTEBOOK (notebook)); g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot)); - hbox = gtk_notebook_get_tab_label (notebook, GTK_WIDGET (slot)); - g_return_if_fail (GTK_IS_WIDGET (hbox)); + cbox = gtk_notebook_get_tab_label (notebook, GTK_WIDGET (slot)); + g_return_if_fail (GTK_IS_WIDGET (cbox)); - label = GTK_WIDGET (g_object_get_data (G_OBJECT (hbox), "label")); + label = GTK_WIDGET (g_object_get_data (G_OBJECT (cbox), "label")); g_return_if_fail (GTK_IS_WIDGET (label)); gtk_label_set_text (GTK_LABEL (label), nautilus_window_slot_get_title (slot)); @@ -214,7 +214,7 @@ nautilus_notebook_sync_tab_label (GtkNotebook *notebook, if (location != NULL) { - /* Set the tooltip on the label's parent (the tab label hbox), + /* Set the tooltip on the label's parent (the tab label cbox), * so it covers all of the tab label. */ location_name = g_file_get_parse_name (location); @@ -239,23 +239,26 @@ static GtkWidget * build_tab_label (GtkNotebook *notebook, NautilusWindowSlot *slot) { - GtkWidget *box; + GtkWidget *tab_label; + GtkWidget *start_box; GtkWidget *label; GtkWidget *close_button; GtkWidget *spinner; GtkWidget *icon; - /* When porting to Gtk+4, use GtkCenterBox instead */ - box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); - gtk_widget_show (box); + tab_label = gtk_center_box_new (); + gtk_widget_show (tab_label); + + start_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); + gtk_center_box_set_start_widget (GTK_CENTER_BOX (tab_label), start_box); /* Spinner to be shown as load feedback */ spinner = gtk_spinner_new (); - gtk_box_append (GTK_BOX (box), spinner); + gtk_box_append (GTK_BOX (start_box), spinner); /* Dummy icon to allocate space for spinner */ icon = gtk_image_new (); - gtk_box_append (GTK_BOX (box), icon); + gtk_box_append (GTK_BOX (start_box), icon); /* don't show the icon */ /* Tab title */ @@ -263,7 +266,7 @@ build_tab_label (GtkNotebook *notebook, gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END); gtk_label_set_single_line_mode (GTK_LABEL (label), TRUE); gtk_label_set_width_chars (GTK_LABEL (label), 6); - gtk_box_set_center_widget (GTK_BOX (box), label); + gtk_center_box_set_center_widget (GTK_CENTER_BOX (tab_label), label); gtk_widget_show (label); /* Tab close button */ @@ -278,20 +281,20 @@ build_tab_label (GtkNotebook *notebook, gtk_widget_set_tooltip_text (close_button, _("Close tab")); gtk_actionable_set_action_name (GTK_ACTIONABLE (close_button), "win.close-current-view"); - gtk_box_pack_end (GTK_BOX (box), close_button, FALSE, FALSE, 0); + gtk_center_box_set_end_widget (GTK_CENTER_BOX (tab_label), close_button); gtk_widget_show (close_button); - g_object_set_data (G_OBJECT (box), "nautilus-notebook-tab", GINT_TO_POINTER (1)); + g_object_set_data (G_OBJECT (tab_label), "nautilus-notebook-tab", GINT_TO_POINTER (1)); #if 0 && NAUTILUS_DND_NEEDS_GTK4_REIMPLEMENTATION nautilus_drag_slot_proxy_init (box, NULL, slot); #endif - g_object_set_data (G_OBJECT (box), "label", label); - g_object_set_data (G_OBJECT (box), "spinner", spinner); - g_object_set_data (G_OBJECT (box), "icon", icon); - g_object_set_data (G_OBJECT (box), "close-button", close_button); + g_object_set_data (G_OBJECT (tab_label), "label", label); + g_object_set_data (G_OBJECT (tab_label), "spinner", spinner); + g_object_set_data (G_OBJECT (tab_label), "icon", icon); + g_object_set_data (G_OBJECT (tab_label), "close-button", close_button); - return box; + return tab_label; } int -- GitLab From 7063e201d43da373836cef67ee354d0e83ce3153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= Date: Thu, 23 Dec 2021 11:18:58 +0000 Subject: [PATCH 3/4] ui: Take some gtk-builder-simplify changes These cleanups are going to make it easier to use gtk4-builder later. --- .../ui/nautilus-batch-rename-dialog.ui | 69 ++---- src/resources/ui/nautilus-column-chooser.ui | 45 ---- src/resources/ui/nautilus-compress-dialog.ui | 15 -- .../ui/nautilus-create-folder-dialog.ui | 9 - ...ilus-file-properties-change-permissions.ui | 16 -- src/resources/ui/nautilus-folder-is-empty.ui | 3 - .../ui/nautilus-no-search-results.ui | 4 - .../ui/nautilus-pathbar-context-menu.ui | 1 - .../ui/nautilus-preferences-window.ui | 8 - .../ui/nautilus-progress-info-widget.ui | 4 - .../ui/nautilus-properties-window.ui | 217 ------------------ .../ui/nautilus-rename-file-popover.ui | 6 - src/resources/ui/nautilus-search-popover.ui | 48 ---- src/resources/ui/nautilus-starred-is-empty.ui | 3 - src/resources/ui/nautilus-toolbar.ui | 52 ----- src/resources/ui/nautilus-trash-is-empty.ui | 3 - src/resources/ui/nautilus-window.ui | 15 +- 17 files changed, 24 insertions(+), 494 deletions(-) diff --git a/src/resources/ui/nautilus-batch-rename-dialog.ui b/src/resources/ui/nautilus-batch-rename-dialog.ui index 4f84fb5bf3..b10248128e 100644 --- a/src/resources/ui/nautilus-batch-rename-dialog.ui +++ b/src/resources/ui/nautilus-batch-rename-dialog.ui @@ -128,8 +128,6 @@ 6 6 True - False - False horizontal @@ -146,7 +144,6 @@ Rename _using a template True True - False True True @@ -157,7 +154,6 @@ Find and replace _text True True - False True True format_mode_button @@ -168,13 +164,11 @@ 3 0 - 1 True - False False True crossfade @@ -191,7 +185,6 @@ horizontal - 0 True center @@ -215,7 +208,6 @@ True horizontal - 0 True @@ -228,16 +220,15 @@ True 0 Add - False - + 0 @@ -258,7 +249,6 @@ True Automatic Numbering Order - False @@ -276,7 +266,6 @@ 180 0 Original Name (Ascending) - False @@ -320,43 +309,38 @@ True Existing Text - False False - - 0 - 0 - 1 - + + 0 + 0 + True True 375 - False True - - 1 - 0 - 3 - + + 1 + 0 + 3 + True Replace With - False False - - 0 - 1 - 1 - + + 0 + 1 + @@ -366,11 +350,11 @@ - - 1 - 1 - 3 - + + 1 + 1 + 3 + @@ -388,7 +372,6 @@ True - True False True in @@ -399,28 +382,24 @@ True - False True True - False GTK_SELECTION_NONE True - False GTK_SELECTION_NONE True - False GTK_SELECTION_NONE @@ -444,13 +423,9 @@ True - False True 0 - - start - @@ -459,7 +434,7 @@ True - + True diff --git a/src/resources/ui/nautilus-column-chooser.ui b/src/resources/ui/nautilus-column-chooser.ui index 5f44ea8f98..82eb3c22e6 100644 --- a/src/resources/ui/nautilus-column-chooser.ui +++ b/src/resources/ui/nautilus-column-chooser.ui @@ -21,7 +21,6 @@ True - False True @@ -66,109 +65,65 @@ - - False - True - 0 - True - False True - False True False True - False True - False go-up-symbolic - - False - True - 0 - True False True - False True - False go-down-symbolic - - False - True - 1 - - - False - True - 0 - True - False Reset to De_fault True True - False Replace the current List Columns settings with the default settings True - - False - True - 0 - - - False - True - end - 1 - - - False - True - 1 - diff --git a/src/resources/ui/nautilus-compress-dialog.ui b/src/resources/ui/nautilus-compress-dialog.ui index 4ba8236e38..050a1360ce 100644 --- a/src/resources/ui/nautilus-compress-dialog.ui +++ b/src/resources/ui/nautilus-compress-dialog.ui @@ -110,9 +110,6 @@ - - 1 - @@ -175,9 +172,6 @@ - - 2 - @@ -190,9 +184,6 @@ - - 3 - @@ -200,9 +191,6 @@ 6 0 - - 4 - @@ -211,9 +199,6 @@ False view-conceal - - 5 - diff --git a/src/resources/ui/nautilus-create-folder-dialog.ui b/src/resources/ui/nautilus-create-folder-dialog.ui index 75b9aa94da..1f53b7c5c8 100644 --- a/src/resources/ui/nautilus-create-folder-dialog.ui +++ b/src/resources/ui/nautilus-create-folder-dialog.ui @@ -22,18 +22,12 @@ True 0 - - 1 - True True - - 2 - @@ -46,9 +40,6 @@ - - 3 - diff --git a/src/resources/ui/nautilus-file-properties-change-permissions.ui b/src/resources/ui/nautilus-file-properties-change-permissions.ui index 820df23f03..fe9c21c291 100644 --- a/src/resources/ui/nautilus-file-properties-change-permissions.ui +++ b/src/resources/ui/nautilus-file-properties-change-permissions.ui @@ -23,7 +23,6 @@ - False vertical @@ -506,7 +463,6 @@ True - False True @@ -519,9 +475,7 @@ 20 20 True - False end - False location - 1 True - False vertical search - 2 @@ -194,7 +184,6 @@ True True - False Search center center @@ -202,7 +191,6 @@ True - False edit-find-symbolic 1 @@ -211,21 +199,16 @@ - - 2 - True - False True True - False Go back center center @@ -233,7 +216,6 @@ True - False go-previous-symbolic 1 @@ -242,15 +224,11 @@ - - 0 - True True - False Go forward center center @@ -258,7 +236,6 @@ True - False go-next-symbolic 1 @@ -267,9 +244,6 @@ - - 1 - - - 0 - @@ -358,7 +319,6 @@ True - False pan-down-symbolic @@ -366,30 +326,22 @@ - - 1 - - - 2 - True True - False center center app_menu True - False open-menu-symbolic 1 @@ -398,14 +350,10 @@ - - 3 - end - 3 diff --git a/src/resources/ui/nautilus-trash-is-empty.ui b/src/resources/ui/nautilus-trash-is-empty.ui index d41b93e6a2..bbc387aea8 100644 --- a/src/resources/ui/nautilus-trash-is-empty.ui +++ b/src/resources/ui/nautilus-trash-is-empty.ui @@ -3,7 +3,6 @@ - False center center True @@ -13,7 +12,6 @@ True - False 128 user-trash-symbolic