[glade] GladeWidget: Added new name related APIs
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade] GladeWidget: Added new name related APIs
- Date: Thu, 28 Jan 2016 10:47:45 +0000 (UTC)
commit 61e9156b91433c73d9ba97f42a07924959f7efbe
Author: Tristan Van Berkom <tristan upstairslabs com>
Date: Thu Jan 28 11:45:42 2016 +0100
GladeWidget: Added new name related APIs
o glade_widget_get_display_name()
Gets the name which should be displayed in the UI
o glade_widget_has_name()
Checks whether the user has assigned a name to the widget or not.
gladeui/glade-widget.c | 40 ++++++++++++++++++++++++++++++++++++++++
gladeui/glade-widget.h | 2 ++
2 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/gladeui/glade-widget.c b/gladeui/glade-widget.c
index a3c2e8a..1388f4c 100644
--- a/gladeui/glade-widget.c
+++ b/gladeui/glade-widget.c
@@ -2710,6 +2710,9 @@ glade_widget_set_name (GladeWidget *widget, const gchar *name)
* @widget: a #GladeWidget
*
* Returns: a pointer to @widget's name
+ *
+ * This is what will be serialized as the widget's ID, unless
+ * the name currently carries the %GLADE_UNNAMED_PREFIX.
*/
const gchar *
glade_widget_get_name (GladeWidget *widget)
@@ -2718,6 +2721,43 @@ glade_widget_get_name (GladeWidget *widget)
return widget->priv->name;
}
+
+/**
+ * glade_widget_get_display_name:
+ * @widget: a #GladeWidget
+ *
+ * Returns: a pointer to @widget's displayable name
+ *
+ * This should be used to display the widget's ID in
+ * the UI, it will automatically return an "(unnamed)"
+ * string if the widget is not intended to be serialized
+ * with an ID (i.e. the user did not provide a name).
+ */
+G_CONST_RETURN gchar *
+glade_widget_get_display_name (GladeWidget *widget)
+{
+ g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL);
+
+ if (g_str_has_prefix (widget->priv->name, GLADE_UNNAMED_PREFIX))
+ return _("(unnamed)");
+
+ return widget->priv->name;
+}
+
+/**
+ * glade_widget_has_name:
+ * @widget: a #GladeWidget
+ *
+ * Returns: whether the user has named this widget with an ID
+ */
+gboolean
+glade_widget_has_name (GladeWidget *widget)
+{
+ g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE);
+
+ return !g_str_has_prefix (widget->priv->name, GLADE_UNNAMED_PREFIX);
+}
+
/**
* glade_widget_set_is_composite:
* @widget: a #GladeWidget
diff --git a/gladeui/glade-widget.h b/gladeui/glade-widget.h
index e4d258a..41f9313 100644
--- a/gladeui/glade-widget.h
+++ b/gladeui/glade-widget.h
@@ -348,6 +348,8 @@ void glade_widget_set_name (GladeWidget *widget,
const gchar *name);
G_CONST_RETURN gchar *glade_widget_get_name (GladeWidget *widget);
+G_CONST_RETURN gchar *glade_widget_get_display_name (GladeWidget *widget);
+gboolean glade_widget_has_name (GladeWidget *widget);
void glade_widget_set_is_composite (GladeWidget *widget,
gboolean composite);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]