[libdazzle] suggestion: make compact a property for inspector



commit 748220d86694c7d965ead534769ba439b848e266
Author: Christian Hergert <chergert redhat com>
Date:   Thu Apr 25 15:16:54 2019 -0700

    suggestion: make compact a property for inspector
    
    This allows tweaking things from the inspector for testing purposes.

 src/suggestions/dzl-suggestion-entry.c | 64 ++++++++++++++++++++++++++++++++++
 src/suggestions/dzl-suggestion-entry.h |  9 ++---
 2 files changed, 69 insertions(+), 4 deletions(-)
---
diff --git a/src/suggestions/dzl-suggestion-entry.c b/src/suggestions/dzl-suggestion-entry.c
index fd4f236..896e5bb 100644
--- a/src/suggestions/dzl-suggestion-entry.c
+++ b/src/suggestions/dzl-suggestion-entry.c
@@ -45,6 +45,7 @@ typedef struct
   GDestroyNotify             func_data_destroy;
 
   guint                      activate_on_single_click : 1;
+  guint                      compact : 1;
 
   gint                       in_key_press;
   gint                       in_move_by;
@@ -53,6 +54,7 @@ typedef struct
 enum {
   PROP_0,
   PROP_ACTIVATE_ON_SINGLE_CLICK,
+  PROP_COMPACT,
   PROP_MODEL,
   PROP_TYPED_TEXT,
   PROP_SUGGESTION,
@@ -453,6 +455,10 @@ dzl_suggestion_entry_get_property (GObject    *object,
       g_value_set_boolean (value, dzl_suggestion_entry_get_activate_on_single_click (self));
       break;
 
+    case PROP_COMPACT:
+      g_value_set_boolean (value, dzl_suggestion_entry_get_compact (self));
+      break;
+
     case PROP_MODEL:
       g_value_set_object (value, dzl_suggestion_entry_get_model (self));
       break;
@@ -484,6 +490,10 @@ dzl_suggestion_entry_set_property (GObject      *object,
       dzl_suggestion_entry_set_activate_on_single_click (self, g_value_get_boolean (value));
       break;
 
+    case PROP_COMPACT:
+      dzl_suggestion_entry_set_compact (self, g_value_get_boolean (value));
+      break;
+
     case PROP_MODEL:
       dzl_suggestion_entry_set_model (self, g_value_get_object (value));
       break;
@@ -535,6 +545,22 @@ dzl_suggestion_entry_class_init (DzlSuggestionEntryClass *klass)
                           FALSE,
                           (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
 
+  /**
+   * DzlSuggestionEntry:compact:
+   *
+   * The "compact" property denotes if an alternate style should be used to
+   * reduce the width of the rows. This may be ideal in size contrained
+   * situations with portrait display.
+   *
+   * Since: 3.34
+   */
+  properties [PROP_COMPACT] =
+    g_param_spec_boolean ("compact",
+                          "Compact",
+                          "If compact mode should be used",
+                          FALSE,
+                          (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
   properties [PROP_MODEL] =
     g_param_spec_object ("model",
                          "Model",
@@ -1051,11 +1077,49 @@ dzl_suggestion_entry_get_popover (DzlSuggestionEntry *self)
   return GTK_WIDGET (priv->popover);
 }
 
+/**
+ * dzl_suggestion_entry_set_compact:
+ * @self: a #DzlSuggestionEntry
+ * @compact: if compact mode should be used
+ *
+ * Sets the #DzlSuggestionEntry:compact property.
+ *
+ * Since: 3.34
+ */
 void
 dzl_suggestion_entry_set_compact (DzlSuggestionEntry *self,
                                   gboolean            compact)
 {
   DzlSuggestionEntryPrivate *priv = dzl_suggestion_entry_get_instance_private (self);
 
+  g_return_if_fail (DZL_IS_SUGGESTION_ENTRY (self));
+
+  compact = !!compact;
+
+  if (priv->compact != compact)
+    {
+      priv->compact = compact;
       _dzl_suggestion_popover_set_compact (priv->popover, compact);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_COMPACT]);
+    }
+}
+
+/**
+ * dzl_suggestion_entry_get_compact:
+ * @self: a #DzlSuggestionEntry
+ *
+ * Gets the #DzlSuggestionEntry:compact property.
+ *
+ * Returns: %TRUE if compact-mode is in use.
+ *
+ * Since: 3.34
+ */
+gboolean
+dzl_suggestion_entry_get_compact (DzlSuggestionEntry *self)
+{
+  DzlSuggestionEntryPrivate *priv = dzl_suggestion_entry_get_instance_private (self);
+
+  g_return_val_if_fail (DZL_IS_SUGGESTION_ENTRY (self), FALSE);
+
+  return priv->compact;
 }
diff --git a/src/suggestions/dzl-suggestion-entry.h b/src/suggestions/dzl-suggestion-entry.h
index 24f5f20..0fddd6c 100644
--- a/src/suggestions/dzl-suggestion-entry.h
+++ b/src/suggestions/dzl-suggestion-entry.h
@@ -96,6 +96,11 @@ DZL_AVAILABLE_IN_3_30
 void           dzl_suggestion_entry_hide_suggestions             (DzlSuggestionEntry        *self);
 DZL_AVAILABLE_IN_3_32
 GtkWidget     *dzl_suggestion_entry_get_popover                  (DzlSuggestionEntry        *self);
+DZL_AVAILABLE_IN_3_34
+gboolean       dzl_suggestion_entry_get_compact                  (DzlSuggestionEntry        *self);
+DZL_AVAILABLE_IN_3_34
+void           dzl_suggestion_entry_set_compact                  (DzlSuggestionEntry        *self,
+                                                                  gboolean                   compact);
 
 DZL_AVAILABLE_IN_ALL
 void dzl_suggestion_entry_default_position_func (DzlSuggestionEntry *self,
@@ -108,10 +113,6 @@ void dzl_suggestion_entry_window_position_func  (DzlSuggestionEntry *self,
                                                  gboolean           *is_absolute,
                                                  gpointer            user_data);
 
-DZL_AVAILABLE_IN_3_34
-void dzl_suggestion_entry_set_compact           (DzlSuggestionEntry *self,
-                                                 gboolean            compact);
-
 G_END_DECLS
 
 #endif /* DZL_SUGGESTION_ENTRY_H */


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