summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Gratton <mike@vee.net>2019-06-15 23:25:20 +1000
committerMichael James Gratton <mike@vee.net>2019-06-16 00:12:35 +1000
commit3a10e2e862f61b850409f28d2dbeca3e87967401 (patch)
treefe4d1d89dc7cc7ccc21a520e61129f148457873e
parent8cfdd6c5919e0aab07b909c56abccc53a8f4aaec (diff)
downloadgtk+-wip/mjog/gtk-completion-show-on-complete-master.tar.gz
entry completion: Update popup visibility on manual completewip/mjog/gtk-completion-show-on-complete-master
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.
-rw-r--r--gtk/gtkentrycompletion.c136
1 files changed, 67 insertions, 69 deletions
diff --git a/gtk/gtkentrycompletion.c b/gtk/gtkentrycompletion.c
index de68a66e43..555dbc1402 100644
--- a/gtk/gtkentrycompletion.c
+++ b/gtk/gtkentrycompletion.c
@@ -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);