GNOME Bugzilla – Bug 584402
_complete() does not work directly after _set_completion()
Last modified: 2018-02-10 03:46:02 UTC
Please describe the problem: The problem occured when I tried to implement tab-completion for the GtkEntry widget, because if I assign a completion it will be invoked on every change, but my goal was to use <TAB> to invoke the completion and intercept the automatic completion. The attempt was to catch GDK_Tab on keypress and then gtk_entry_set_completion() and invoke gtk_entry_completion_complete() afterwards. Unfortunately nothing happened (this is the bug). However if I enter a char or modify the text the completion will pop up. Workaround: We could also simulate a change by gtk_editable_insert_text (GTK_EDITABLE (widget), "", 0, &p); Steps to reproduce: 1. gtk_entry_set_completion((GtkEntry*)inputbox, completion); 2. gtk_entry_completion_complete(completion); Actual results: We set up completion and try to invoke it. Expected results: The completion should pop up. Does this happen every time? Actually nothing happens, and yes every time we setup the scenario. Other information: I traced back the calls a bit and noticed the following: gtkentry.c:4148 g_signal_emit_by_name (editable, "insert-text", text, new_text_length, position); :9358 g_source_set_closure (completion->priv->check_completion_idle, g_cclosure_new_object (G_CALLBACK (check_completion_callback), G_OBJECT (completion))); :9311 completion->priv->check_completion_idle = NULL; gtk_entry_completion_complete (completion); gtk_entry_completion_insert_prefix (completion); Hope this helps a bit :)
Hi, I faced with the same issue today, I think the problem is related to the callback being called from the GtkEntry instead of the GtkEntryCompletion. To replicate the bug you could do like that: 1. on a function disable the popup completion with: gtk_entry_completion_set_popup_completion(completion, FALSE); 2. bind the key-press-event signal to the entry 3. match for GDK_Tab and in the related if branch: gtk_entry_completion_set_popup_completion(completion, TRUE); gtk_entry_completion_complete(completion); gtk_entry_completion_set_popup_completion(completion, FALSE); return TRUE; In this way the completion window will not be showed. A workaround i found is to emit the "changed" signal on the GtkEntry before to call the .._completion_complete in this way: gboolean complete (GtkEntry *entry, GdkEventKey *ev, gpointer data) { GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION(data); if (ev->keyval == GDK_Tab) { gtk_entry_completion_set_popup_completion(completion, TRUE); GtkWidget *entry = gtk_entry_completion_get_entry(completion); g_signal_emit_by_name(entry, "changed", NULL); gtk_entry_completion_complete(completion); gtk_entry_completion_set_popup_completion(completion, FALSE); return TRUE; } return FALSE; } HTH Salvatore
We're moving to gitlab! As part of this move, we are closing bugs that haven't seen activity in more than 5 years. If this issue is still imporant to you and still relevant with GTK+ 3.22 or master, please consider creating a gitlab issue for it.