[gnome-builder] libide/tweaks: add show-header property for section



commit 7303d6c63c2a9bc9e2d104c8042bc7db9715e087
Author: Christian Hergert <chergert redhat com>
Date:   Wed Aug 17 10:28:19 2022 -0700

    libide/tweaks: add show-header property for section
    
    That way we can use title to compare sections, yet still mark a section to
    not display the label.

 src/libide/tweaks/ide-tweaks-section.c  | 38 +++++++++++++++++++++++++++++++++
 src/libide/tweaks/ide-tweaks-section.h  | 13 +++++++----
 src/plugins/editorui/tweaks-language.ui |  1 +
 3 files changed, 48 insertions(+), 4 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-section.c b/src/libide/tweaks/ide-tweaks-section.c
index e05ad8473..5c62d3769 100644
--- a/src/libide/tweaks/ide-tweaks-section.c
+++ b/src/libide/tweaks/ide-tweaks-section.c
@@ -29,12 +29,14 @@ struct _IdeTweaksSection
 {
   IdeTweaksItem parent_instance;
   char *title;
+  guint show_header : 1;
 };
 
 G_DEFINE_FINAL_TYPE (IdeTweaksSection, ide_tweaks_section, IDE_TYPE_TWEAKS_ITEM)
 
 enum {
   PROP_0,
+  PROP_SHOW_HEADER,
   PROP_TITLE,
   N_PROPS
 };
@@ -71,6 +73,10 @@ ide_tweaks_section_get_property (GObject    *object,
 
   switch (prop_id)
     {
+    case PROP_SHOW_HEADER:
+      g_value_set_boolean (value, ide_tweaks_section_get_show_header (self));
+      break;
+
     case PROP_TITLE:
       g_value_set_string (value, ide_tweaks_section_get_title (self));
       break;
@@ -90,6 +96,10 @@ ide_tweaks_section_set_property (GObject      *object,
 
   switch (prop_id)
     {
+    case PROP_SHOW_HEADER:
+      ide_tweaks_section_set_show_header (self, g_value_get_boolean (value));
+      break;
+
     case PROP_TITLE:
       ide_tweaks_section_set_title (self, g_value_get_string (value));
       break;
@@ -111,6 +121,11 @@ ide_tweaks_section_class_init (IdeTweaksSectionClass *klass)
   object_class->get_property = ide_tweaks_section_get_property;
   object_class->set_property = ide_tweaks_section_set_property;
 
+  properties[PROP_SHOW_HEADER] =
+    g_param_spec_boolean ("show-header", NULL, NULL,
+                         FALSE,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
   properties[PROP_TITLE] =
     g_param_spec_string ("title", NULL, NULL,
                          NULL,
@@ -141,3 +156,26 @@ ide_tweaks_section_set_title (IdeTweaksSection *self,
   if (ide_set_string (&self->title, title))
     g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]);
 }
+
+gboolean
+ide_tweaks_section_get_show_header (IdeTweaksSection *self)
+{
+  g_return_val_if_fail (IDE_IS_TWEAKS_SECTION (self), FALSE);
+
+  return self->show_header;
+}
+
+void
+ide_tweaks_section_set_show_header (IdeTweaksSection *self,
+                                    gboolean          show_header)
+{
+  g_return_if_fail (IDE_IS_TWEAKS_SECTION (self));
+
+  show_header = !!show_header;
+
+  if (show_header != self->show_header)
+    {
+      self->show_header = show_header;
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SHOW_HEADER]);
+    }
+}
diff --git a/src/libide/tweaks/ide-tweaks-section.h b/src/libide/tweaks/ide-tweaks-section.h
index 2d908b30e..016af9c17 100644
--- a/src/libide/tweaks/ide-tweaks-section.h
+++ b/src/libide/tweaks/ide-tweaks-section.h
@@ -34,11 +34,16 @@ IDE_AVAILABLE_IN_ALL
 G_DECLARE_FINAL_TYPE (IdeTweaksSection, ide_tweaks_section, IDE, TWEAKS_SECTION, IdeTweaksItem)
 
 IDE_AVAILABLE_IN_ALL
-IdeTweaksSection *ide_tweaks_section_new       (void);
+IdeTweaksSection *ide_tweaks_section_new             (void);
 IDE_AVAILABLE_IN_ALL
-const char       *ide_tweaks_section_get_title (IdeTweaksSection *self);
+const char       *ide_tweaks_section_get_title       (IdeTweaksSection *self);
 IDE_AVAILABLE_IN_ALL
-void              ide_tweaks_section_set_title (IdeTweaksSection *self,
-                                                const char       *title);
+void              ide_tweaks_section_set_title       (IdeTweaksSection *self,
+                                                      const char       *title);
+IDE_AVAILABLE_IN_ALL
+gboolean          ide_tweaks_section_get_show_header (IdeTweaksSection *self);
+IDE_AVAILABLE_IN_ALL
+void              ide_tweaks_section_set_show_header (IdeTweaksSection *self,
+                                                      gboolean          show_header);
 
 G_END_DECLS
diff --git a/src/plugins/editorui/tweaks-language.ui b/src/plugins/editorui/tweaks-language.ui
index 03317d018..7b2c3981c 100644
--- a/src/plugins/editorui/tweaks-language.ui
+++ b/src/plugins/editorui/tweaks-language.ui
@@ -12,6 +12,7 @@
                 <property name="model">GtkSourceLanguages</property>
                 <child>
                   <object class="IdeTweaksSection">
+                    <property name="show-header">true</property>
                     <binding name="title">
                       <lookup name="section" type="GtkSourceLanguage">
                         <lookup name="item">language_page_factory</lookup>


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