[devhelp] Window: adapt GtkNotebook handling to make it work with DhTabLabel
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp] Window: adapt GtkNotebook handling to make it work with DhTabLabel
- Date: Sun, 11 Feb 2018 15:08:53 +0000 (UTC)
commit 53cd162d04e22bacbb512ef69c8d4c44981ac067
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun Feb 11 15:41:44 2018 +0100
Window: adapt GtkNotebook handling to make it work with DhTabLabel
When the close button is clicked in DhTabLabel, DhTabLabel destroys the
DhTab with gtk_widget_destroy(). Before, window_close_tab() was called,
which was responsible to update the GtkNotebook state accordingly. So
now the solution is to connect to more GtkNotebook signals, to show or
hide tabs, and to destroy the DhWindow when the last tab is closed.
src/dh-window.c | 69 ++++++++++++++++++++++++++++++++++++------------------
1 files changed, 46 insertions(+), 23 deletions(-)
---
diff --git a/src/dh-window.c b/src/dh-window.c
index cc09aae..055422d 100644
--- a/src/dh-window.c
+++ b/src/dh-window.c
@@ -221,23 +221,6 @@ print_cb (GSimpleAction *action,
}
static void
-window_close_tab (DhWindow *window,
- gint page_num)
-{
- DhWindowPrivate *priv = dh_window_get_instance_private (window);
- gint pages;
-
- gtk_notebook_remove_page (priv->notebook, page_num);
-
- pages = gtk_notebook_get_n_pages (priv->notebook);
-
- if (pages == 0)
- gtk_widget_destroy (GTK_WIDGET (window));
- else if (pages == 1)
- gtk_notebook_set_show_tabs (priv->notebook, FALSE);
-}
-
-static void
close_cb (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
@@ -247,7 +230,7 @@ close_cb (GSimpleAction *action,
gint page_num;
page_num = gtk_notebook_get_current_page (priv->notebook);
- window_close_tab (window, page_num);
+ gtk_notebook_remove_page (priv->notebook, page_num);
}
static void
@@ -594,6 +577,41 @@ search_next_button_clicked_cb (GtkButton *search_next_button,
}
static void
+show_or_hide_notebook_tabs (DhWindow *window)
+{
+ DhWindowPrivate *priv = dh_window_get_instance_private (window);
+ gint n_pages;
+
+ n_pages = gtk_notebook_get_n_pages (priv->notebook);
+ gtk_notebook_set_show_tabs (priv->notebook, n_pages > 1);
+}
+
+static void
+notebook_page_added_after_cb (GtkNotebook *notebook,
+ GtkWidget *child,
+ guint page_num,
+ DhWindow *window)
+{
+ show_or_hide_notebook_tabs (window);
+}
+
+static void
+notebook_page_removed_after_cb (GtkNotebook *notebook,
+ GtkWidget *child,
+ guint page_num,
+ DhWindow *window)
+{
+ gint n_pages;
+
+ n_pages = gtk_notebook_get_n_pages (notebook);
+
+ if (n_pages == 0)
+ gtk_widget_destroy (GTK_WIDGET (window));
+ else
+ show_or_hide_notebook_tabs (window);
+}
+
+static void
notebook_switch_page_after_cb (GtkNotebook *notebook,
GtkWidget *new_page,
guint new_page_num,
@@ -696,6 +714,16 @@ dh_window_init (DhWindow *window)
/* HTML tabs GtkNotebook */
g_signal_connect_after (priv->notebook,
+ "page-added",
+ G_CALLBACK (notebook_page_added_after_cb),
+ window);
+
+ g_signal_connect_after (priv->notebook,
+ "page-removed",
+ G_CALLBACK (notebook_page_removed_after_cb),
+ window);
+
+ g_signal_connect_after (priv->notebook,
"switch-page",
G_CALLBACK (notebook_switch_page_after_cb),
window);
@@ -944,11 +972,6 @@ window_open_new_tab (DhWindow *window,
"reorderable", TRUE,
NULL);
- if (gtk_notebook_get_n_pages (priv->notebook) > 1)
- gtk_notebook_set_show_tabs (priv->notebook, TRUE);
- else
- gtk_notebook_set_show_tabs (priv->notebook, FALSE);
-
if (location != NULL)
webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view), location);
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]