Commit 6bf8106d authored by Christian Hergert's avatar Christian Hergert
Browse files

suggestion-entry: add DzlSuggestionEntry::activate-on-single-click

This allows specifying if the results should be activated by clicking on
the result, or if that should only emit a selection event.
parent 57c4c129
......@@ -43,12 +43,15 @@ typedef struct
gpointer func_data;
GDestroyNotify func_data_destroy;
guint activate_on_single_click : 1;
gint in_key_press;
gint in_move_by;
} DzlSuggestionEntryPrivate;
enum {
PROP_0,
PROP_ACTIVATE_ON_SINGLE_CLICK,
PROP_MODEL,
PROP_TYPED_TEXT,
PROP_SUGGESTION,
......@@ -78,6 +81,34 @@ static guint signals [N_SIGNALS];
static guint changed_signal_id;
static GtkEditableInterface *editable_parent_iface;
void
dzl_suggestion_entry_set_activate_on_single_click (DzlSuggestionEntry *self,
gboolean activate_on_single_click)
{
DzlSuggestionEntryPrivate *priv = dzl_suggestion_entry_get_instance_private (self);
g_assert (DZL_IS_SUGGESTION_ENTRY (self));
activate_on_single_click = !!activate_on_single_click;
if (activate_on_single_click != priv->activate_on_single_click)
{
priv->activate_on_single_click = activate_on_single_click;
_dzl_suggestion_popover_set_click_mode (priv->popover, activate_on_single_click);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ACTIVATE_ON_SINGLE_CLICK]);
}
}
gboolean
dzl_suggestion_entry_get_activate_on_single_click (DzlSuggestionEntry *self)
{
DzlSuggestionEntryPrivate *priv = dzl_suggestion_entry_get_instance_private (self);
g_return_val_if_fail (DZL_IS_SUGGESTION_ENTRY (self), FALSE);
return priv->activate_on_single_click;
}
static void
dzl_suggestion_entry_show_suggestions (DzlSuggestionEntry *self)
{
......@@ -403,6 +434,10 @@ dzl_suggestion_entry_get_property (GObject *object,
switch (prop_id)
{
case PROP_ACTIVATE_ON_SINGLE_CLICK:
g_value_set_boolean (value, dzl_suggestion_entry_get_activate_on_single_click (self));
break;
case PROP_MODEL:
g_value_set_object (value, dzl_suggestion_entry_get_model (self));
break;
......@@ -430,6 +465,10 @@ dzl_suggestion_entry_set_property (GObject *object,
switch (prop_id)
{
case PROP_ACTIVATE_ON_SINGLE_CLICK:
dzl_suggestion_entry_set_activate_on_single_click (self, g_value_get_boolean (value));
break;
case PROP_MODEL:
dzl_suggestion_entry_set_model (self, g_value_get_object (value));
break;
......@@ -464,6 +503,22 @@ dzl_suggestion_entry_class_init (DzlSuggestionEntryClass *klass)
klass->move_suggestion = dzl_suggestion_entry_move_suggestion;
klass->suggestion_activated = dzl_suggestion_entry_real_suggestion_activated;
/**
* DzlSuggestionEntry:activate-on-single-click:
*
* The "activate-on-single-click" property denotes if results should be
* activated simply by clicking on them. You may want to set this to
* %FALSE if you want the behavior to only select the item.
*
* Since: 3.30
*/
properties [PROP_ACTIVATE_ON_SINGLE_CLICK] =
g_param_spec_boolean ("activate-on-single-click",
"Activate on Single Click",
"If entries should be activated upon a single click",
FALSE,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
properties [PROP_MODEL] =
g_param_spec_object ("model",
"Model",
......@@ -584,6 +639,7 @@ dzl_suggestion_entry_init (DzlSuggestionEntry *self)
{
DzlSuggestionEntryPrivate *priv = dzl_suggestion_entry_get_instance_private (self);
priv->activate_on_single_click = TRUE;
priv->func = dzl_suggestion_entry_default_position_func;
priv->changed_handler =
......
......@@ -87,6 +87,11 @@ void dzl_suggestion_entry_set_position_func (DzlSuggestionEntry
DzlSuggestionPositionFunc func,
gpointer func_data,
GDestroyNotify func_data_destroy);
DZL_AVAILABLE_IN_3_30
gboolean dzl_suggestion_entry_get_activate_on_single_click (DzlSuggestionEntry *self);
DZL_AVAILABLE_IN_3_30
void dzl_suggestion_entry_set_activate_on_single_click (DzlSuggestionEntry *self,
gboolean activate_on_single_click);
DZL_AVAILABLE_IN_ALL
void dzl_suggestion_entry_default_position_func (DzlSuggestionEntry *self,
......
......@@ -1093,3 +1093,11 @@ _dzl_suggestion_popover_adjust_margin (DzlSuggestionPopover *self,
area->height += margin.top + margin.bottom;
}
void
_dzl_suggestion_popover_set_click_mode (DzlSuggestionPopover *self,
gboolean single_click)
{
g_assert (DZL_IS_SUGGESTION_POPOVER (self));
gtk_list_box_set_activate_on_single_click (GTK_LIST_BOX (self->list_box), single_click);
}
......@@ -30,6 +30,8 @@ void _dzl_suggestion_popover_set_max_height (DzlSuggestionPopover *popover,
gint max_height);
void _dzl_suggestion_popover_adjust_margin (DzlSuggestionPopover *popover,
GdkRectangle *area);
void _dzl_suggestion_popover_set_click_mode (DzlSuggestionPopover *popover,
gboolean single_click);
void _dzl_suggestion_row_set_ellipsize (DzlSuggestionRow *self,
PangoEllipsizeMode title,
PangoEllipsizeMode subtitle);
......
......@@ -323,6 +323,7 @@ main (gint argc,
gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (box)), "linked");
entry = g_object_new (DZL_TYPE_SUGGESTION_ENTRY,
"activate-on-single-click", FALSE,
"halign", GTK_ALIGN_CENTER,
"hexpand", FALSE,
"max-width-chars", 55,
......
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