[nautilus/wip/antoniof/gtk4-preparation-step-container-api: 15/20] notebook: Stop using GtkContainer methods
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/gtk4-preparation-step-container-api: 15/20] notebook: Stop using GtkContainer methods
- Date: Mon, 6 Dec 2021 00:27:54 +0000 (UTC)
commit 4770f1f51df8e36050186ca602e03025a725c364
Author: António Fernandes <antoniof gnome org>
Date: Tue Nov 23 18:35:11 2021 +0000
notebook: Stop using GtkContainer methods
GtkContainer is gone in GTK4.
Replace all usage of its API, except gtk_container_child_set() because
there is no replacement for "tab-expand" in GTK3.
src/nautilus-notebook.c | 55 +++++++++++++++++++++++--------------------------
1 file changed, 26 insertions(+), 29 deletions(-)
---
diff --git a/src/nautilus-notebook.c b/src/nautilus-notebook.c
index 9d2fb1dcf..7a7212945 100644
--- a/src/nautilus-notebook.c
+++ b/src/nautilus-notebook.c
@@ -42,8 +42,6 @@ static int nautilus_notebook_insert_page (GtkNotebook *notebook,
GtkWidget *tab_label,
GtkWidget *menu_label,
int position);
-static void nautilus_notebook_remove (GtkContainer *container,
- GtkWidget *tab_widget);
enum
{
@@ -78,13 +76,10 @@ static void
nautilus_notebook_class_init (NautilusNotebookClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
GtkNotebookClass *notebook_class = GTK_NOTEBOOK_CLASS (klass);
object_class->dispose = nautilus_notebook_dispose;
- container_class->remove = nautilus_notebook_remove;
-
notebook_class->insert_page = nautilus_notebook_insert_page;
signals[TAB_CLOSE_REQUEST] =
@@ -187,6 +182,16 @@ button_press_cb (GtkGestureMultiPress *gesture,
}
}
+static void
+on_page_removed (GtkNotebook *notebook,
+ GtkWidget *child,
+ guint page_num,
+ gpointer user_data)
+{
+ gtk_notebook_set_show_tabs (notebook,
+ gtk_notebook_get_n_pages (notebook) > 1);
+}
+
static void
nautilus_notebook_init (NautilusNotebook *notebook)
{
@@ -194,6 +199,8 @@ nautilus_notebook_init (NautilusNotebook *notebook)
gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE);
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
+ g_signal_connect (notebook, "page-removed", G_CALLBACK (on_page_removed), NULL);
+
notebook->multi_press_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (notebook));
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (notebook->multi_press_gesture),
@@ -207,18 +214,24 @@ gboolean
nautilus_notebook_contains_slot (NautilusNotebook *notebook,
NautilusWindowSlot *slot)
{
- GList *children;
- GList *l;
+ GtkNotebook *container = GTK_NOTEBOOK (notebook);
+ GtkWidget *child;
+ gint n_pages;
gboolean found = FALSE;
- children = gtk_container_get_children (GTK_CONTAINER (notebook));
- for (l = children; l != NULL && !found; l = l->next)
+ g_return_val_if_fail (slot != NULL, FALSE);
+
+ n_pages = gtk_notebook_get_n_pages (container);
+ for (gint i = 0; i < n_pages; i++)
{
- found = l->data == slot;
+ child = gtk_notebook_get_nth_page (container, i);
+ if ((gpointer) child == (gpointer) slot)
+ {
+ found = TRUE;
+ break;
+ }
}
- g_list_free (children);
-
return found;
}
@@ -335,7 +348,6 @@ build_tab_label (NautilusNotebook *notebook,
GtkWidget *box;
GtkWidget *label;
GtkWidget *close_button;
- GtkWidget *image;
GtkWidget *spinner;
GtkWidget *icon;
@@ -361,7 +373,7 @@ build_tab_label (NautilusNotebook *notebook,
gtk_widget_show (label);
/* Tab close button */
- close_button = gtk_button_new ();
+ close_button = gtk_button_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_MENU);
gtk_button_set_relief (GTK_BUTTON (close_button),
GTK_RELIEF_NONE);
/* don't allow focus on the close button */
@@ -369,14 +381,10 @@ build_tab_label (NautilusNotebook *notebook,
gtk_widget_set_name (close_button, "nautilus-tab-close-button");
- image = gtk_image_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_MENU);
gtk_widget_set_tooltip_text (close_button, _("Close tab"));
g_signal_connect_object (close_button, "clicked",
G_CALLBACK (close_button_clicked_cb), slot, 0);
- gtk_container_add (GTK_CONTAINER (close_button), image);
- gtk_widget_show (image);
-
gtk_box_pack_end (GTK_BOX (box), close_button, FALSE, FALSE, 0);
gtk_widget_show (close_button);
@@ -450,17 +458,6 @@ nautilus_notebook_add_tab (NautilusNotebook *notebook,
return position;
}
-static void
-nautilus_notebook_remove (GtkContainer *container,
- GtkWidget *tab_widget)
-{
- GtkNotebook *gnotebook = GTK_NOTEBOOK (container);
- GTK_CONTAINER_CLASS (nautilus_notebook_parent_class)->remove (container, tab_widget);
-
- gtk_notebook_set_show_tabs (gnotebook,
- gtk_notebook_get_n_pages (gnotebook) > 1);
-}
-
void
nautilus_notebook_reorder_current_child_relative (NautilusNotebook *notebook,
int offset)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]