[tepl] InfoBar: add the :handle-close-response property
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] InfoBar: add the :handle-close-response property
- Date: Tue, 10 Nov 2020 14:11:02 +0000 (UTC)
commit ade840c628854baab327420065b389729a9e1a3c
Author: Sébastien Wilmet <swilmet gnome org>
Date: Tue Nov 10 15:03:40 2020 +0100
InfoBar: add the :handle-close-response property
To have a proper API.
add_close_button() will be renamed to setup_close_button().
docs/reference/tepl-sections.txt | 2 +
tepl/tepl-info-bar.c | 119 +++++++++++++++++++++++++++++++++++++--
tepl/tepl-info-bar.h | 7 +++
3 files changed, 124 insertions(+), 4 deletions(-)
---
diff --git a/docs/reference/tepl-sections.txt b/docs/reference/tepl-sections.txt
index b43b33f..3623b54 100644
--- a/docs/reference/tepl-sections.txt
+++ b/docs/reference/tepl-sections.txt
@@ -241,6 +241,8 @@ tepl_info_bar_add_icon
tepl_info_bar_add_primary_message
tepl_info_bar_add_secondary_message
tepl_info_bar_add_content_widget
+tepl_info_bar_get_handle_close_response
+tepl_info_bar_set_handle_close_response
tepl_info_bar_add_close_button
tepl_info_bar_set_buttons_orientation
tepl_info_bar_create_label
diff --git a/tepl/tepl-info-bar.c b/tepl/tepl-info-bar.c
index 364e5bc..06e4440 100644
--- a/tepl/tepl-info-bar.c
+++ b/tepl/tepl-info-bar.c
@@ -37,8 +37,57 @@ struct _TeplInfoBarPrivate
guint handle_close_response : 1;
};
+enum
+{
+ PROP_0,
+ PROP_HANDLE_CLOSE_RESPONSE,
+ N_PROPERTIES
+};
+
+static GParamSpec *properties[N_PROPERTIES];
+
G_DEFINE_TYPE_WITH_PRIVATE (TeplInfoBar, tepl_info_bar, GTK_TYPE_INFO_BAR)
+static void
+tepl_info_bar_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TeplInfoBar *info_bar = TEPL_INFO_BAR (object);
+
+ switch (prop_id)
+ {
+ case PROP_HANDLE_CLOSE_RESPONSE:
+ g_value_set_boolean (value, tepl_info_bar_get_handle_close_response (info_bar));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+tepl_info_bar_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TeplInfoBar *info_bar = TEPL_INFO_BAR (object);
+
+ switch (prop_id)
+ {
+ case PROP_HANDLE_CLOSE_RESPONSE:
+ tepl_info_bar_set_handle_close_response (info_bar, g_value_get_boolean (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
static void
tepl_info_bar_response (GtkInfoBar *gtk_info_bar,
gint response_id)
@@ -64,9 +113,33 @@ tepl_info_bar_response (GtkInfoBar *gtk_info_bar,
static void
tepl_info_bar_class_init (TeplInfoBarClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkInfoBarClass *info_bar_class = GTK_INFO_BAR_CLASS (klass);
+ object_class->get_property = tepl_info_bar_get_property;
+ object_class->set_property = tepl_info_bar_set_property;
+
info_bar_class->response = tepl_info_bar_response;
+
+ /**
+ * TeplInfoBar:handle-close-response:
+ *
+ * If this property is %TRUE, then the #TeplInfoBar is destroyed with
+ * gtk_widget_destroy() when the #GtkInfoBar::response signal is
+ * received with the @response_id %GTK_RESPONSE_CLOSE.
+ *
+ * Since: 6.0
+ */
+ properties[PROP_HANDLE_CLOSE_RESPONSE] =
+ g_param_spec_boolean ("handle-close-response",
+ "handle-close-response",
+ "",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
static void
@@ -304,13 +377,51 @@ tepl_info_bar_add_content_widget (TeplInfoBar *info_bar,
gtk_container_add (GTK_CONTAINER (info_bar->priv->content_vgrid), content);
}
+/**
+ * tepl_info_bar_get_handle_close_response:
+ * @info_bar: a #TeplInfoBar.
+ *
+ * Returns: the value of the #TeplInfoBar:handle-close-response property.
+ * Since: 6.0
+ */
+gboolean
+tepl_info_bar_get_handle_close_response (TeplInfoBar *info_bar)
+{
+ g_return_val_if_fail (TEPL_IS_INFO_BAR (info_bar), FALSE);
+
+ return info_bar->priv->handle_close_response;
+}
+
+/**
+ * tepl_info_bar_set_handle_close_response:
+ * @info_bar: a #TeplInfoBar.
+ * @handle_close_response: the new value.
+ *
+ * Sets a new value to the #TeplInfoBar:handle-close-response property.
+ *
+ * Since: 6.0
+ */
+void
+tepl_info_bar_set_handle_close_response (TeplInfoBar *info_bar,
+ gboolean handle_close_response)
+{
+ g_return_if_fail (TEPL_IS_INFO_BAR (info_bar));
+
+ handle_close_response = handle_close_response != FALSE;
+
+ if (info_bar->priv->handle_close_response != handle_close_response)
+ {
+ info_bar->priv->handle_close_response = handle_close_response;
+ g_object_notify_by_pspec (G_OBJECT (info_bar), properties[PROP_HANDLE_CLOSE_RESPONSE]);
+ }
+}
+
/**
* tepl_info_bar_add_close_button:
* @info_bar: a #TeplInfoBar.
*
- * Calls gtk_info_bar_set_show_close_button(), and additionnally closes the
- * @info_bar when the #GtkInfoBar::response signal is received with the
- * @response_id %GTK_RESPONSE_CLOSE.
+ * Convenience function to set the #GtkInfoBar:show-close-button and
+ * #TeplInfoBar:handle-close-response properties to %TRUE.
*
* Since: 2.0
*/
@@ -320,7 +431,7 @@ tepl_info_bar_add_close_button (TeplInfoBar *info_bar)
g_return_if_fail (TEPL_IS_INFO_BAR (info_bar));
gtk_info_bar_set_show_close_button (GTK_INFO_BAR (info_bar), TRUE);
- info_bar->priv->handle_close_response = TRUE;
+ tepl_info_bar_set_handle_close_response (info_bar, TRUE);
}
/**
diff --git a/tepl/tepl-info-bar.h b/tepl/tepl-info-bar.h
index 8b5c3c1..425561c 100644
--- a/tepl/tepl-info-bar.h
+++ b/tepl/tepl-info-bar.h
@@ -65,6 +65,13 @@ _TEPL_EXTERN
void tepl_info_bar_add_content_widget (TeplInfoBar *info_bar,
GtkWidget *content);
+_TEPL_EXTERN
+gboolean tepl_info_bar_get_handle_close_response (TeplInfoBar *info_bar);
+
+_TEPL_EXTERN
+void tepl_info_bar_set_handle_close_response (TeplInfoBar *info_bar,
+ gboolean handle_close_response);
+
_TEPL_EXTERN
void tepl_info_bar_add_close_button (TeplInfoBar *info_bar);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]