[nautilus/wip/antoniof/experimental-gtk4-build: 2/52] notebook: Stop using gtk_box_set_center_widget() and pack_end()
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/experimental-gtk4-build: 2/52] notebook: Stop using gtk_box_set_center_widget() and pack_end()
- Date: Fri, 31 Dec 2021 23:58:44 +0000 (UTC)
commit 693b5282c7a5552fa4ca6db6966a664fc1d28a2a
Author: António Fernandes <antoniof gnome org>
Date: Fri Dec 24 01:16:24 2021 +0000
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 0ddcce4f7..a5d643406 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 0e1ef4f57..815f017eb 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 26e615430..f36c722ee 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]