[libpanel] widget: add PanelWidget:tooltip property
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpanel] widget: add PanelWidget:tooltip property
- Date: Tue, 27 Sep 2022 04:41:49 +0000 (UTC)
commit e24a3920cdd09995b25039d78a6af5b5d6b5855b
Author: Christian Hergert <chergert redhat com>
Date: Mon Sep 26 21:19:08 2022 -0700
widget: add PanelWidget:tooltip property
This is to be used to bind to AdwTabPage:tooltip so that we can have
tooltips specified in pages that are different than the title. Trying to
not get too crazy though with things beyond text.
src/panel-widget.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++-------
src/panel-widget.h | 5 ++++
2 files changed, 67 insertions(+), 9 deletions(-)
---
diff --git a/src/panel-widget.c b/src/panel-widget.c
index 33232cd..f6244ae 100644
--- a/src/panel-widget.c
+++ b/src/panel-widget.c
@@ -61,6 +61,7 @@ typedef struct
char *icon_name;
GIcon *icon;
char *id;
+ char *tooltip;
GMenuModel *menu_model;
PanelSaveDelegate *save_delegate;
PanelActionMuxer *action_muxer;
@@ -104,6 +105,7 @@ enum {
PROP_REORDERABLE,
PROP_SAVE_DELEGATE,
PROP_TITLE,
+ PROP_TOOLTIP,
N_PROPS
};
@@ -396,6 +398,10 @@ panel_widget_get_property (GObject *object,
g_value_set_string (value, panel_widget_get_title (self));
break;
+ case PROP_TOOLTIP:
+ g_value_set_string (value, panel_widget_get_tooltip (self));
+ break;
+
case PROP_CHILD:
g_value_set_object (value, panel_widget_get_child (self));
break;
@@ -459,6 +465,10 @@ panel_widget_set_property (GObject *object,
panel_widget_set_title (self, g_value_get_string (value));
break;
+ case PROP_TOOLTIP:
+ panel_widget_set_tooltip (self, g_value_get_string (value));
+ break;
+
case PROP_CHILD:
panel_widget_set_child (self, g_value_get_object (value));
break;
@@ -582,6 +592,18 @@ panel_widget_class_init (PanelWidgetClass *klass)
NULL,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+ /**
+ * PanelWidget:tooltip:
+ *
+ * The tooltip to display in tabs for the widget.
+ *
+ * Since: 1.2
+ */
+ properties [PROP_TOOLTIP] =
+ g_param_spec_string ("tooltip", NULL, NULL,
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
/**
* PanelWidget:child:
*
@@ -724,11 +746,9 @@ panel_widget_set_icon_name (PanelWidget *self,
g_return_if_fail (PANEL_IS_WIDGET (self));
- if (g_strcmp0 (priv->icon_name, icon_name) != 0)
+ if (panel_set_string (&priv->icon_name, icon_name))
{
g_clear_object (&priv->icon);
- g_free (priv->icon_name);
- priv->icon_name = g_strdup (icon_name);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ICON_NAME]);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ICON]);
}
@@ -866,12 +886,45 @@ panel_widget_set_title (PanelWidget *self,
g_return_if_fail (PANEL_IS_WIDGET (self));
- if (g_strcmp0 (priv->title, title) != 0)
- {
- g_free (priv->title);
- priv->title = g_strdup (title);
- g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]);
- }
+ if (panel_set_string (&priv->title, title))
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]);
+}
+
+/**
+ * panel_widget_get_tooltip:
+ * @self: a #PanelWidget
+ *
+ * Gets the tooltip for the widget.
+ *
+ * Returns: (transfer none) (nullable): the tooltip or %NULL
+ */
+const char *
+panel_widget_get_tooltip (PanelWidget *self)
+{
+ PanelWidgetPrivate *priv = panel_widget_get_instance_private (self);
+
+ g_return_val_if_fail (PANEL_IS_WIDGET (self), NULL);
+
+ return priv->tooltip;
+}
+
+/**
+ * panel_widget_set_tooltip:
+ * @self: a #PanelWidget
+ * @tooltip: (transfer none) (nullable): the tooltip or %NULL
+ *
+ * Sets the tooltip for the widget to be displayed in tabs.
+ */
+void
+panel_widget_set_tooltip (PanelWidget *self,
+ const char *tooltip)
+{
+ PanelWidgetPrivate *priv = panel_widget_get_instance_private (self);
+
+ g_return_if_fail (PANEL_IS_WIDGET (self));
+
+ if (panel_set_string (&priv->tooltip, tooltip))
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TOOLTIP]);
}
/**
diff --git a/src/panel-widget.h b/src/panel-widget.h
index bd16564..7dca167 100644
--- a/src/panel-widget.h
+++ b/src/panel-widget.h
@@ -103,6 +103,11 @@ const char *panel_widget_get_kind (PanelWidget
PANEL_AVAILABLE_IN_ALL
void panel_widget_set_kind (PanelWidget *self,
const char *kind);
+PANEL_AVAILABLE_IN_1_2
+const char *panel_widget_get_tooltip (PanelWidget *self);
+PANEL_AVAILABLE_IN_1_2
+void panel_widget_set_tooltip (PanelWidget *self,
+ const char *tooltip);
PANEL_AVAILABLE_IN_ALL
gboolean panel_widget_get_busy (PanelWidget *self);
PANEL_AVAILABLE_IN_ALL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]