Compare commits

...

1 Commits

Author SHA1 Message Date
Michael Gratton
3a10e2e862 entry completion: Update popup visibility on manual complete
Currently, calling `gtk_entry_completion_complete()` does not adjust
the visbility of the popup used to show completion entries. This makes
it difficlt to dynamically populate the model based on what is being
entered into the completion's entry.

For example, if the model is being populated from a database, and no
matches have (yet) been added between typing a character and the 100ms
delay before completion is automatically triggered, the popup will not
be shown even after matches have been added.

This patch simply moves the related code from the private timeout method
to the public function and shuffles the position of some functions so as
to keep the compiler happy.
2019-06-16 00:12:35 +10:00

View File

@@ -953,6 +953,39 @@ gtk_entry_completion_selection_changed (GtkTreeSelection *selection,
}
}
static void
gtk_entry_completion_popup (GtkEntryCompletion *completion)
{
GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (completion->priv->entry));
if (gtk_widget_get_mapped (completion->priv->popup_window))
return;
if (!gtk_widget_get_mapped (GTK_WIDGET (text)))
return;
if (!gtk_widget_has_focus (GTK_WIDGET (text)))
return;
/* default on no match */
completion->priv->current_selected = -1;
gtk_widget_realize (completion->priv->popup_window);
_gtk_entry_completion_resize_popup (completion);
gtk_popover_popup (GTK_POPOVER (completion->priv->popup_window));
}
void
_gtk_entry_completion_popdown (GtkEntryCompletion *completion)
{
if (!gtk_widget_get_mapped (completion->priv->popup_window))
return;
gtk_popover_popdown (GTK_POPOVER (completion->priv->popup_window));
}
/* public API */
/**
@@ -1158,23 +1191,44 @@ gtk_entry_completion_complete (GtkEntryCompletion *completion)
g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
g_return_if_fail (GTK_IS_ENTRY (completion->priv->entry));
if (!completion->priv->filter_model)
return;
if (completion->priv->filter_model)
{
gint matches;
gint actions;
gboolean popup_single;
g_free (completion->priv->case_normalized_key);
g_free (completion->priv->case_normalized_key);
tmp = g_utf8_normalize (gtk_editable_get_text (GTK_EDITABLE (completion->priv->entry)),
-1, G_NORMALIZE_ALL);
completion->priv->case_normalized_key = g_utf8_casefold (tmp, -1);
g_free (tmp);
tmp = g_utf8_normalize (gtk_editable_get_text (GTK_EDITABLE (completion->priv->entry)),
-1, G_NORMALIZE_ALL);
completion->priv->case_normalized_key = g_utf8_casefold (tmp, -1);
g_free (tmp);
gtk_tree_model_filter_refilter (completion->priv->filter_model);
gtk_tree_model_filter_refilter (completion->priv->filter_model);
if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (completion->priv->filter_model), &iter))
g_signal_emit (completion, entry_completion_signals[NO_MATCHES], 0);
if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (completion->priv->filter_model), &iter))
g_signal_emit (completion, entry_completion_signals[NO_MATCHES], 0);
if (gtk_widget_get_visible (completion->priv->popup_window))
_gtk_entry_completion_resize_popup (completion);
matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
g_object_get (completion, "popup-single-match", &popup_single, NULL);
if ((matches > (popup_single ? 0: 1)) || actions > 0)
{
if (gtk_widget_get_visible (completion->priv->popup_window))
_gtk_entry_completion_resize_popup (completion);
else
gtk_entry_completion_popup (completion);
}
else
_gtk_entry_completion_popdown (completion);
}
else if (gtk_widget_get_visible (completion->priv->popup_window))
_gtk_entry_completion_popdown (completion);
if (gtk_widget_get_visible (completion->priv->popup_window))
_gtk_entry_completion_resize_popup (completion);
}
static void
@@ -1404,39 +1458,6 @@ _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
gtk_native_check_resize (GTK_NATIVE (completion->priv->popup_window));
}
static void
gtk_entry_completion_popup (GtkEntryCompletion *completion)
{
GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (completion->priv->entry));
if (gtk_widget_get_mapped (completion->priv->popup_window))
return;
if (!gtk_widget_get_mapped (GTK_WIDGET (text)))
return;
if (!gtk_widget_has_focus (GTK_WIDGET (text)))
return;
/* default on no match */
completion->priv->current_selected = -1;
gtk_widget_realize (completion->priv->popup_window);
_gtk_entry_completion_resize_popup (completion);
gtk_popover_popup (GTK_POPOVER (completion->priv->popup_window));
}
void
_gtk_entry_completion_popdown (GtkEntryCompletion *completion)
{
if (!gtk_widget_get_mapped (completion->priv->popup_window))
return;
gtk_popover_popdown (GTK_POPOVER (completion->priv->popup_window));
}
static gboolean
gtk_entry_completion_match_selected (GtkEntryCompletion *completion,
GtkTreeModel *model,
@@ -1888,31 +1909,8 @@ gtk_entry_completion_timeout (gpointer data)
g_utf8_strlen (gtk_editable_get_text (GTK_EDITABLE (completion->priv->entry)), -1)
>= completion->priv->minimum_key_length)
{
gint matches;
gint actions;
GtkTreeSelection *s;
gboolean popup_single;
gtk_entry_completion_complete (completion);
matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)));
s = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->action_view));
gtk_tree_selection_unselect_all (s);
actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
g_object_get (completion, "popup-single-match", &popup_single, NULL);
if ((matches > (popup_single ? 0: 1)) || actions > 0)
{
if (gtk_widget_get_visible (completion->priv->popup_window))
_gtk_entry_completion_resize_popup (completion);
else
gtk_entry_completion_popup (completion);
}
else
_gtk_entry_completion_popdown (completion);
gtk_entry_completion_complete (completion);
}
else if (gtk_widget_get_visible (completion->priv->popup_window))
_gtk_entry_completion_popdown (completion);