[tepl] InfoBar: update icon when :message-type property changes
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] InfoBar: update icon when :message-type property changes
- Date: Tue, 10 Nov 2020 22:27:51 +0000 (UTC)
commit c2f9bd8ec6ccf6b7a6110da3175dda75b55692a4
Author: Sébastien Wilmet <swilmet gnome org>
Date: Tue Nov 10 23:20:55 2020 +0100
InfoBar: update icon when :message-type property changes
tepl/tepl-info-bar.c | 111 ++++++++++++++++++++++++++++-----------------------
tests/test-tab.c | 4 ++
2 files changed, 66 insertions(+), 49 deletions(-)
---
diff --git a/tepl/tepl-info-bar.c b/tepl/tepl-info-bar.c
index 2f64084..474852c 100644
--- a/tepl/tepl-info-bar.c
+++ b/tepl/tepl-info-bar.c
@@ -169,6 +169,63 @@ tepl_info_bar_class_init (TeplInfoBarClass *klass)
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
+static const gchar *
+get_icon_name_for_message_type (TeplInfoBar *info_bar)
+{
+ GtkMessageType msg_type;
+
+ msg_type = gtk_info_bar_get_message_type (GTK_INFO_BAR (info_bar));
+
+ switch (msg_type)
+ {
+ case GTK_MESSAGE_INFO:
+ return "dialog-information";
+
+ case GTK_MESSAGE_WARNING:
+ return "dialog-warning";
+
+ case GTK_MESSAGE_QUESTION:
+ return "dialog-question";
+
+ case GTK_MESSAGE_ERROR:
+ return "dialog-error";
+
+ case GTK_MESSAGE_OTHER:
+ default:
+ /* No icon */
+ break;
+ }
+
+ return NULL;
+}
+
+static void
+update_icon_state (TeplInfoBar *info_bar)
+{
+ const gchar *icon_name;
+
+ icon_name = get_icon_name_for_message_type (info_bar);
+
+ if (info_bar->priv->icon_from_message_type &&
+ icon_name != NULL)
+ {
+ gtk_image_set_from_icon_name (info_bar->priv->icon, icon_name, GTK_ICON_SIZE_DIALOG);
+ gtk_widget_show (GTK_WIDGET (info_bar->priv->icon));
+ }
+ else
+ {
+ gtk_widget_hide (GTK_WIDGET (info_bar->priv->icon));
+ }
+}
+
+static void
+message_type_notify_cb (TeplInfoBar *info_bar,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ update_icon_state (info_bar);
+}
+
static void
tepl_info_bar_init (TeplInfoBar *info_bar)
{
@@ -206,6 +263,11 @@ tepl_info_bar_init (TeplInfoBar *info_bar)
/* content_area */
content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
gtk_container_add (GTK_CONTAINER (content_area), GTK_WIDGET (content_hgrid));
+
+ g_signal_connect (info_bar,
+ "notify::message-type",
+ G_CALLBACK (message_type_notify_cb),
+ NULL);
}
/**
@@ -255,55 +317,6 @@ tepl_info_bar_new_simple (GtkMessageType msg_type,
return info_bar;
}
-static const gchar *
-get_icon_name_for_message_type (TeplInfoBar *info_bar)
-{
- GtkMessageType msg_type;
-
- msg_type = gtk_info_bar_get_message_type (GTK_INFO_BAR (info_bar));
-
- switch (msg_type)
- {
- case GTK_MESSAGE_INFO:
- return "dialog-information";
-
- case GTK_MESSAGE_WARNING:
- return "dialog-warning";
-
- case GTK_MESSAGE_QUESTION:
- return "dialog-question";
-
- case GTK_MESSAGE_ERROR:
- return "dialog-error";
-
- case GTK_MESSAGE_OTHER:
- default:
- /* No icon */
- break;
- }
-
- return NULL;
-}
-
-static void
-update_icon_state (TeplInfoBar *info_bar)
-{
- const gchar *icon_name;
-
- icon_name = get_icon_name_for_message_type (info_bar);
-
- if (info_bar->priv->icon_from_message_type &&
- icon_name != NULL)
- {
- gtk_image_set_from_icon_name (info_bar->priv->icon, icon_name, GTK_ICON_SIZE_DIALOG);
- gtk_widget_show (GTK_WIDGET (info_bar->priv->icon));
- }
- else
- {
- gtk_widget_hide (GTK_WIDGET (info_bar->priv->icon));
- }
-}
-
/**
* tepl_info_bar_get_icon_from_message_type:
* @info_bar: a #TeplInfoBar.
diff --git a/tests/test-tab.c b/tests/test-tab.c
index 44bda6c..fb91c17 100644
--- a/tests/test-tab.c
+++ b/tests/test-tab.c
@@ -31,6 +31,10 @@ basic_cb (GtkButton *button,
tepl_info_bar_setup_close_button (info_bar);
+ // Test changing the :message-type property. Is the icon correctly
+ // updated?
+ gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_QUESTION);
+
tepl_tab_add_info_bar (tab, GTK_INFO_BAR (info_bar));
gtk_widget_show (GTK_WIDGET (info_bar));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]