summaryrefslogtreecommitdiff
path: root/gtk/gtkentrycompletion.c
diff options
context:
space:
mode:
Diffstat (limited to 'gtk/gtkentrycompletion.c')
-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);