[libadwaita/nielsdg/adw-preferences-row-selectable] preferences-row: Add a "title-selectable" property
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/nielsdg/adw-preferences-row-selectable] preferences-row: Add a "title-selectable" property
- Date: Thu, 3 Feb 2022 09:17:58 +0000 (UTC)
commit dfcb6be1e11d3301d31d23001540251136d290cf
Author: Niels De Graef <nielsdegraef gmail com>
Date: Wed Jan 12 22:53:21 2022 +0100
preferences-row: Add a "title-selectable" property
For the GTK4 port of Contacts, we're using `AdwPreferencesRow`s and
`AdwActionRow`s.
In previous versions, we just used a `GtkLabel` to present the row. We
could then set the `"selectable"` property to TRUE, to deal with a major
use case when people use Contacts: to actually copy info (like a phone
number) into whatever other application they are using.
With `AdwPreferencesRow` that's not possible, so this would be a
regression.
Fixes https://gitlab.gnome.org/GNOME/libadwaita/-/issues/300
src/adw-action-row.ui | 1 +
src/adw-preferences-row.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++
src/adw-preferences-row.h | 6 ++++
3 files changed, 78 insertions(+)
---
diff --git a/src/adw-action-row.ui b/src/adw-action-row.ui
index af91eb4b..32fbe9ec 100644
--- a/src/adw-action-row.ui
+++ b/src/adw-action-row.ui
@@ -54,6 +54,7 @@
<property name="lines">0</property>
<property name="mnemonic-widget">AdwActionRow</property>
<property name="use-underline" bind-source="AdwActionRow" bind-property="use-underline"
bind-flags="sync-create"/>
+ <property name="selectable" bind-source="AdwActionRow" bind-property="title-selectable"
bind-flags="sync-create"/>
<property name="wrap">True</property>
<property name="wrap-mode">word-char</property>
<property name="xalign">0</property>
diff --git a/src/adw-preferences-row.c b/src/adw-preferences-row.c
index 7c40fc75..9d0f19c9 100644
--- a/src/adw-preferences-row.c
+++ b/src/adw-preferences-row.c
@@ -29,6 +29,7 @@ typedef struct
char *title;
gboolean use_underline;
+ gboolean title_selectable;
} AdwPreferencesRowPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (AdwPreferencesRow, adw_preferences_row, GTK_TYPE_LIST_BOX_ROW)
@@ -37,6 +38,7 @@ enum {
PROP_0,
PROP_TITLE,
PROP_USE_UNDERLINE,
+ PROP_TITLE_SELECTABLE,
LAST_PROP,
};
@@ -57,6 +59,9 @@ adw_preferences_row_get_property (GObject *object,
case PROP_USE_UNDERLINE:
g_value_set_boolean (value, adw_preferences_row_get_use_underline (self));
break;
+ case PROP_TITLE_SELECTABLE:
+ g_value_set_boolean (value, adw_preferences_row_get_title_selectable (self));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -77,6 +82,9 @@ adw_preferences_row_set_property (GObject *object,
case PROP_USE_UNDERLINE:
adw_preferences_row_set_use_underline (self, g_value_get_boolean (value));
break;
+ case PROP_TITLE_SELECTABLE:
+ adw_preferences_row_set_title_selectable (self, g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -130,6 +138,22 @@ adw_preferences_row_class_init (AdwPreferencesRowClass *klass)
FALSE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+ /**
+ * AdwPreferencesRow:title-selectable: (attributes
org.gtk.Property.get=adw_preferences_row_get_title_selectable
org.gtk.Property.set=adw_preferences_row_set_title_selectable)
+ *
+ * Whether the user can copy the title from the label.
+ *
+ * See also [property@Gtk.Label:selectable].
+ *
+ * Since: 1.0
+ */
+ props[PROP_TITLE_SELECTABLE] =
+ g_param_spec_boolean ("title-selectable",
+ "Title selectable",
+ "Whether the title should be selectable (i.e. the user can copy it)",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+
g_object_class_install_properties (object_class, LAST_PROP, props);
}
@@ -255,3 +279,50 @@ adw_preferences_row_set_use_underline (AdwPreferencesRow *self,
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_USE_UNDERLINE]);
}
+
+/**
+ * adw_preferences_row_get_title_selectable: (attributes org.gtk.Method.get_property=title-selectable)
+ * @self: a `AdwPreferencesRow`
+ *
+ * Gets whether the user can copy the title from the label
+ *
+ * Returns: whether the user can copy the title from the label
+ *
+ * Since: 1.0
+ */
+gboolean
+adw_preferences_row_get_title_selectable (AdwPreferencesRow *self)
+{
+ AdwPreferencesRowPrivate *priv = adw_preferences_row_get_instance_private (self);
+
+ g_return_val_if_fail (ADW_IS_PREFERENCES_ROW (self), FALSE);
+
+ return priv->title_selectable;
+}
+
+/**
+ * adw_preferences_row_set_title_selectable: (attributes org.gtk.Method.set_property=title-selectable)
+ * @self: a `AdwPreferencesRow`
+ * @title_selectable: `TRUE` if the user can copy the title from the label
+ *
+ * Sets whether the user can copy the title from the label
+ *
+ * Since: 1.0
+ */
+void
+adw_preferences_row_set_title_selectable (AdwPreferencesRow *self,
+ gboolean title_selectable)
+{
+ AdwPreferencesRowPrivate *priv = adw_preferences_row_get_instance_private (self);
+
+ g_return_if_fail (ADW_IS_PREFERENCES_ROW (self));
+
+ title_selectable = !!title_selectable;
+
+ if (priv->title_selectable == title_selectable)
+ return;
+
+ priv->title_selectable = title_selectable;
+
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TITLE_SELECTABLE]);
+}
diff --git a/src/adw-preferences-row.h b/src/adw-preferences-row.h
index d821546d..8b469dad 100644
--- a/src/adw-preferences-row.h
+++ b/src/adw-preferences-row.h
@@ -48,4 +48,10 @@ ADW_AVAILABLE_IN_ALL
void adw_preferences_row_set_use_underline (AdwPreferencesRow *self,
gboolean use_underline);
+ADW_AVAILABLE_IN_ALL
+gboolean adw_preferences_row_get_title_selectable (AdwPreferencesRow *self);
+ADW_AVAILABLE_IN_ALL
+void adw_preferences_row_set_title_selectable (AdwPreferencesRow *self,
+ gboolean title_selectable);
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]