Commit 730caf37 authored by Christian Hergert's avatar Christian Hergert
Browse files

suggestion: add DzlSuggestionEntry:suggestion property

This allows for notify::suggestion signal callbacks when the selected entry
changes.
parent 82f20d1d
......@@ -50,6 +50,7 @@ enum {
PROP_0,
PROP_MODEL,
PROP_TYPED_TEXT,
PROP_SUGGESTION,
N_PROPS
};
......@@ -314,6 +315,17 @@ dzl_suggestion_entry_activate_suggestion (DzlSuggestionEntry *self)
DZL_EXIT;
}
static void
dzl_suggestion_entry_notify_selected_cb (DzlSuggestionEntry *self,
GParamSpec *pspec,
DzlSuggestionPopover *popover)
{
g_assert (DZL_IS_SUGGESTION_ENTRY (self));
g_assert (DZL_IS_SUGGESTION_POPOVER (popover));
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SUGGESTION]);
}
static void
dzl_suggestion_entry_constructed (GObject *object)
{
......@@ -363,6 +375,10 @@ dzl_suggestion_entry_get_property (GObject *object,
g_value_set_object (value, dzl_suggestion_entry_get_model (self));
break;
case PROP_SUGGESTION:
g_value_set_object (value, dzl_suggestion_entry_get_suggestion (self));
break;
case PROP_TYPED_TEXT:
g_value_set_string (value, dzl_suggestion_entry_get_typed_text (self));
break;
......@@ -386,6 +402,10 @@ dzl_suggestion_entry_set_property (GObject *object,
dzl_suggestion_entry_set_model (self, g_value_get_object (value));
break;
case PROP_SUGGESTION:
dzl_suggestion_entry_set_suggestion (self, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
......@@ -425,6 +445,20 @@ dzl_suggestion_entry_class_init (DzlSuggestionEntryClass *klass)
NULL,
(G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
/**
* DzlSuggestionEntry:suggestion:
*
* The "suggestion" property is the currently selected suggestion, if any.
*
* Since: 3.30
*/
properties [PROP_SUGGESTION] =
g_param_spec_object ("suggestion",
"Suggestion",
"The currently selected suggestion",
DZL_TYPE_SUGGESTION,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
signals [HIDE_SUGGESTIONS] =
......@@ -505,6 +539,11 @@ dzl_suggestion_entry_init (DzlSuggestionEntry *self)
"relative-to", self,
"type", GTK_WINDOW_POPUP,
NULL);
g_signal_connect_object (priv->popover,
"notify::selected",
G_CALLBACK (dzl_suggestion_entry_notify_selected_cb),
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (priv->popover,
"suggestion-activated",
G_CALLBACK (dzl_suggestion_entry_suggestion_activated),
......
......@@ -235,6 +235,25 @@ load_css (void)
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
static void
notify_suggestion_cb (DzlSuggestionEntry *entry,
GParamSpec *pspec,
gpointer unused)
{
DzlSuggestion *suggestion;
g_assert (DZL_IS_SUGGESTION_ENTRY (entry));
if ((suggestion = dzl_suggestion_entry_get_suggestion (entry)))
{
g_print ("Suggestion changed to %s\n", dzl_suggestion_get_id (suggestion));
}
else
{
g_print ("Suggestion cleared\n");
}
}
int
main (gint argc,
gchar *argv[])
......@@ -291,6 +310,7 @@ main (gint argc,
"visible", TRUE,
"width-chars", 30,
NULL);
g_signal_connect (entry, "notify::suggestion", G_CALLBACK (notify_suggestion_cb), NULL);
dzl_suggestion_entry_set_position_func (DZL_SUGGESTION_ENTRY (entry),
dzl_suggestion_entry_window_position_func,
NULL, NULL);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment