[libadwaita/wip/sophie-h/pref-row-markup: 2/8] preferences-row: Add use-markup property




commit 48fc097f1acaa5d2ee7a54e41bd5271d32b8fca8
Author: Sophie Herold <sophie hemio de>
Date:   Tue Feb 15 20:38:46 2022 +0100

    preferences-row: Add use-markup property

 src/adw-action-row.ui        |  4 +--
 src/adw-expander-row.ui      |  1 +
 src/adw-preferences-row.c    | 74 ++++++++++++++++++++++++++++++++++++++++++++
 src/adw-preferences-row.h    |  7 +++++
 src/adw-preferences-window.c |  2 ++
 5 files changed, 86 insertions(+), 2 deletions(-)
---
diff --git a/src/adw-action-row.ui b/src/adw-action-row.ui
index 32fbe9ec..3efdad57 100644
--- a/src/adw-action-row.ui
+++ b/src/adw-action-row.ui
@@ -58,7 +58,7 @@
                 <property name="wrap">True</property>
                 <property name="wrap-mode">word-char</property>
                 <property name="xalign">0</property>
-                <property name="use-markup">True</property>
+                <property name="use-markup" bind-source="AdwActionRow" bind-property="use-markup" 
bind-flags="sync-create"/>
                 <style>
                   <class name="title"/>
                 </style>
@@ -76,7 +76,7 @@
                 <property name="wrap">True</property>
                 <property name="wrap-mode">word-char</property>
                 <property name="xalign">0</property>
-                <property name="use-markup">True</property>
+                <property name="use-markup" bind-source="AdwActionRow" bind-property="use-markup" 
bind-flags="sync-create"/>
                 <style>
                   <class name="subtitle"/>
                 </style>
diff --git a/src/adw-expander-row.ui b/src/adw-expander-row.ui
index c4cbebdc..21e832c3 100644
--- a/src/adw-expander-row.ui
+++ b/src/adw-expander-row.ui
@@ -30,6 +30,7 @@
                 <property name="title" bind-source="AdwExpanderRow" bind-property="title" 
bind-flags="sync-create"/>
                 <property name="use-underline" bind-source="AdwExpanderRow" bind-property="use-underline" 
bind-flags="sync-create"/>
                 <property name="selectable" bind-source="AdwExpanderRow" bind-property="title-selectable" 
bind-flags="sync-create"/>
+                <property name="use-markup" bind-source="AdwExpanderRow" bind-property="use-markup" 
bind-flags="sync-create"/>
                 <style>
                   <class name="header"/>
                 </style>
diff --git a/src/adw-preferences-row.c b/src/adw-preferences-row.c
index d963781f..9aa157c0 100644
--- a/src/adw-preferences-row.c
+++ b/src/adw-preferences-row.c
@@ -30,6 +30,7 @@ typedef struct
 
   gboolean use_underline;
   gboolean title_selectable;
+  gboolean use_markup;
 } AdwPreferencesRowPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (AdwPreferencesRow, adw_preferences_row, GTK_TYPE_LIST_BOX_ROW)
@@ -39,6 +40,7 @@ enum {
   PROP_TITLE,
   PROP_USE_UNDERLINE,
   PROP_TITLE_SELECTABLE,
+  PROP_USE_MARKUP,
   LAST_PROP,
 };
 
@@ -62,6 +64,9 @@ adw_preferences_row_get_property (GObject    *object,
   case PROP_TITLE_SELECTABLE:
     g_value_set_boolean (value, adw_preferences_row_get_title_selectable (self));
     break;
+  case PROP_USE_MARKUP:
+    g_value_set_boolean (value, adw_preferences_row_get_use_markup (self));
+    break;
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   }
@@ -85,6 +90,9 @@ adw_preferences_row_set_property (GObject      *object,
   case PROP_TITLE_SELECTABLE:
     adw_preferences_row_set_title_selectable (self, g_value_get_boolean (value));
     break;
+  case PROP_USE_MARKUP:
+    adw_preferences_row_set_use_markup (self, g_value_get_boolean (value));
+    break;
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   }
@@ -154,6 +162,20 @@ adw_preferences_row_class_init (AdwPreferencesRowClass *klass)
                           FALSE,
                           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
 
+  /**
+   * AdwPreferencesRow:use-markup (attributes org.gtk.Property.get=adw_preferences_row_get_use_markup 
org.gtk.Property.set=adw_preferences_row_set_use_markup)
+   *
+   * Whether to use markup syntax for all elements.
+   *
+   * Since: 1.2
+   */
+  props[PROP_USE_MARKUP] =
+    g_param_spec_boolean ("use-markup",
+                          "Use markup",
+                          "Whether to use markup syntax for all elements",
+                          TRUE,
+                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_install_properties (object_class, LAST_PROP, props);
 }
 
@@ -162,6 +184,7 @@ adw_preferences_row_init (AdwPreferencesRow *self)
 {
     AdwPreferencesRowPrivate *priv = adw_preferences_row_get_instance_private (self);
     priv->title = g_strdup ("");
+    priv->use_markup = true;
 }
 
 /**
@@ -326,3 +349,54 @@ adw_preferences_row_set_title_selectable (AdwPreferencesRow *self,
 
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TITLE_SELECTABLE]);
 }
+
+/**
+ * adw_preferences_row_get_use_markup: (attributes org.gtk.Method.get_property=use-markup)
+ * @self: a preferences row
+ *
+ * Gets whether elements use markup.
+ *
+ * Returns: whether elements use markup.
+ *
+ * Since: 1.2
+ */
+gboolean
+adw_preferences_row_get_use_markup (AdwPreferencesRow *self)
+{
+  AdwPreferencesRowPrivate *priv;
+
+  g_return_val_if_fail (ADW_IS_PREFERENCES_ROW (self), FALSE);
+
+  priv = adw_preferences_row_get_instance_private (self);
+
+  return priv->use_markup;
+}
+
+/**
+ * adw_preferences_row_set_use_markup: (attributes org.gtk.Method.set_property=use-markup)
+ * @self: a preferences row
+ * @use_underline: `TRUE` if elements use markup
+ *
+ * Sets whether elements use markup.
+ *
+ * Since: 1.2
+ */
+void
+adw_preferences_row_set_use_markup (AdwPreferencesRow *self,
+                                       gboolean           use_markup)
+{
+  AdwPreferencesRowPrivate *priv;
+
+  g_return_if_fail (ADW_IS_PREFERENCES_ROW (self));
+
+  priv = adw_preferences_row_get_instance_private (self);
+
+  use_markup = !!use_markup;
+
+  if (priv->use_markup == use_markup)
+    return;
+
+  priv->use_markup = use_markup;
+
+  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_USE_MARKUP]);
+}
diff --git a/src/adw-preferences-row.h b/src/adw-preferences-row.h
index 8b469dad..2c088479 100644
--- a/src/adw-preferences-row.h
+++ b/src/adw-preferences-row.h
@@ -54,4 +54,11 @@ ADW_AVAILABLE_IN_ALL
 void     adw_preferences_row_set_title_selectable (AdwPreferencesRow *self,
                                                    gboolean           title_selectable);
 
+
+ADW_AVAILABLE_IN_ALL
+gboolean adw_preferences_row_get_use_markup (AdwPreferencesRow *self);
+ADW_AVAILABLE_IN_ALL
+void     adw_preferences_row_set_use_markup (AdwPreferencesRow *self,
+                                                gboolean           use_markup);
+
 G_END_DECLS
diff --git a/src/adw-preferences-window.c b/src/adw-preferences-window.c
index 0a8bba78..40c1b658 100644
--- a/src/adw-preferences-window.c
+++ b/src/adw-preferences-window.c
@@ -152,6 +152,8 @@ filter_search_results (AdwPreferencesRow    *row,
     }
   }
 
+  // TODO: Looks like a bug, that markup is not removed here?
+
   if (!!strstr (title, terms)) {
     result = TRUE;
   } else if (ADW_IS_ACTION_ROW (row)) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]