[libdazzle: 1/2] prefs: allow toggling SearchEntry in the sidebar



commit 55a5f296f6de54a60634cb5c2507dfd755c38a60
Author: Yi-Soo An <yisooan gmail com>
Date:   Fri Feb 8 11:39:59 2019 +0900

    prefs: allow toggling SearchEntry in the sidebar
    
    Allow toggling SearchEntry is useful. For instance, an application
    may want to hide it by default when DzlPreferencesView instantiates.
    
    Also, support getter and setter to control it.

 src/prefs/dzl-preferences-view.c | 49 ++++++++++++++++++++++++++++++++++++++++
 src/prefs/dzl-preferences-view.h | 15 ++++++++----
 2 files changed, 59 insertions(+), 5 deletions(-)
---
diff --git a/src/prefs/dzl-preferences-view.c b/src/prefs/dzl-preferences-view.c
index 9ddf7b6..51cb746 100644
--- a/src/prefs/dzl-preferences-view.c
+++ b/src/prefs/dzl-preferences-view.c
@@ -48,6 +48,7 @@ typedef struct
   guint                  last_widget_id;
 
   guint                  use_sidebar : 1;
+  guint                  show_search_entry : 1;
 } DzlPreferencesViewPrivate;
 
 typedef struct
@@ -66,6 +67,7 @@ G_DEFINE_TYPE_WITH_CODE (DzlPreferencesView, dzl_preferences_view, GTK_TYPE_BIN,
 enum {
   PROP_0,
   PROP_USE_SIDEBAR,
+  PROP_SHOW_SEARCH_ENTRY,
   N_PROPS
 };
 
@@ -242,6 +244,10 @@ dzl_preferences_view_get_property (GObject    *object,
       g_value_set_boolean (value, dzl_preferences_view_get_use_sidebar (self));
       break;
 
+    case PROP_SHOW_SEARCH_ENTRY:
+      g_value_set_boolean (value, dzl_preferences_view_get_show_search_entry (self));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -261,6 +267,10 @@ dzl_preferences_view_set_property (GObject      *object,
       dzl_preferences_view_set_use_sidebar (self, g_value_get_boolean (value));
       break;
 
+    case PROP_SHOW_SEARCH_ENTRY:
+      dzl_preferences_view_set_show_search_entry (self, g_value_get_boolean (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -293,6 +303,13 @@ dzl_preferences_view_class_init (DzlPreferencesViewClass *klass)
                           FALSE,
                           (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_SHOW_SEARCH_ENTRY] =
+    g_param_spec_boolean ("show-search-entry",
+                          "Show SearchEntry",
+                          "Show SearchEntry in the sidebar",
+                          FALSE,
+                          (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
   g_object_class_install_properties (object_class, N_PROPS, properties);
 }
 
@@ -363,6 +380,7 @@ dzl_preferences_view_init (DzlPreferencesView *self)
   };
 
   priv->use_sidebar = TRUE;
+  priv->show_search_entry = TRUE;
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
@@ -1131,3 +1149,34 @@ dzl_preferences_view_set_use_sidebar (DzlPreferencesView *self,
       g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_USE_SIDEBAR]);
     }
 }
+
+gboolean
+dzl_preferences_view_get_show_search_entry (DzlPreferencesView *self)
+{
+  DzlPreferencesViewPrivate *priv = dzl_preferences_view_get_instance_private (self);
+
+  g_return_val_if_fail (DZL_IS_PREFERENCES_VIEW (self), FALSE);
+
+  return priv->show_search_entry;
+}
+
+void
+dzl_preferences_view_set_show_search_entry (DzlPreferencesView *self,
+                                            gboolean            show_search_entry)
+{
+  DzlPreferencesViewPrivate *priv = dzl_preferences_view_get_instance_private (self);
+
+  g_return_if_fail (DZL_IS_PREFERENCES_VIEW (self));
+
+  if (!dzl_preferences_view_get_use_sidebar (self))
+    return;
+
+  if (priv->show_search_entry != show_search_entry)
+    {
+      priv->show_search_entry = show_search_entry;
+
+      gtk_widget_set_visible (GTK_WIDGET (priv->search_entry), show_search_entry);
+
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SHOW_SEARCH_ENTRY]);
+    }
+}
diff --git a/src/prefs/dzl-preferences-view.h b/src/prefs/dzl-preferences-view.h
index f3a282c..815899a 100644
--- a/src/prefs/dzl-preferences-view.h
+++ b/src/prefs/dzl-preferences-view.h
@@ -41,14 +41,19 @@ struct _DzlPreferencesViewClass
 };
 
 DZL_AVAILABLE_IN_3_28
-GtkWidget *dzl_preferences_view_new             (void);
+GtkWidget *dzl_preferences_view_new                   (void);
 DZL_AVAILABLE_IN_ALL
-void       dzl_preferences_view_reapply_filter  (DzlPreferencesView *self);
+void       dzl_preferences_view_reapply_filter        (DzlPreferencesView *self);
 DZL_AVAILABLE_IN_3_30
-gboolean   dzl_preferences_view_get_use_sidebar (DzlPreferencesView *self);
+gboolean   dzl_preferences_view_get_use_sidebar       (DzlPreferencesView *self);
 DZL_AVAILABLE_IN_3_30
-void       dzl_preferences_view_set_use_sidebar (DzlPreferencesView *self,
-                                                 gboolean            use_sidebar);
+void       dzl_preferences_view_set_use_sidebar       (DzlPreferencesView *self,
+                                                       gboolean            use_sidebar);
+DZL_AVAILABLE_IN_3_30
+gboolean   dzl_preferences_view_get_show_search_entry (DzlPreferencesView *self);
+DZL_AVAILABLE_IN_3_30
+void       dzl_preferences_view_set_show_search_entry (DzlPreferencesView *self,
+                                                       gboolean            show_search_entry);
 
 G_END_DECLS
 


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