After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 308076 - GtkEntryCompletion popup does not resize after adding items to the model
GtkEntryCompletion popup does not resize after adding items to the model
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Widget: GtkEntry
unspecified
Other Linux
: Normal normal
: Small API
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2005-06-17 15:00 UTC by Vincent Noel
Modified: 2018-02-10 04:32 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
testcase.c (2.72 KB, text/plain)
2005-06-17 15:47 UTC, Vincent Noel
  Details
Another testcase (3.10 KB, text/plain)
2005-06-17 16:10 UTC, Vincent Noel
  Details
tiny patch for gtkentrycompletion.c (567 bytes, patch)
2005-06-17 16:23 UTC, Vincent Noel
none Details | Review
Correct patch for gtkentrycompletion.c (1008 bytes, patch)
2005-06-20 14:31 UTC, Vincent Noel
rejected Details | Review

Description Vincent Noel 2005-06-17 15:00:10 UTC
I've been trying to use a GtkEntryCompletion in gnome-dictionary in the
following way :

* The user types some characters in a GtkEntry with a GtkEntryCompletion.
* Based on these characters, possible completions are fetched on a dict server.
* The GtkEntryCompletion model is filled based on the results.

When I follow these steps, nothing appears on the screen (no completion popup).
Using a custom comparison function shows the completion is actually done, but
not displayed. This is because the completion is first done on an empty model,
thus the popup at first has no size, and this size is not updated when new
completions are added to the model.

To make this obvious, I've added two phony completions in the model *before*
fetching the real ones on the server. When doing this, the real completions
appear in the popup, but the popup still shows only 2 rows (you have to scroll
to see the new completions).
Comment 1 Vincent Noel 2005-06-17 15:47:08 UTC
Created attachment 47911 [details]
testcase.c

Here is a testcase adding new elements to the model after a 5-seconds timeout.
The completion does not show up (calling gtk_entry_completion_complete does not
help).

If the function add_items is called directly instead of using the timeout, the
completion shows up.

Or did I do something stupid somewhere ?
Comment 2 Vincent Noel 2005-06-17 15:48:33 UTC
I even tried ref'ing the model just in case, but same thing.
Comment 3 Vincent Noel 2005-06-17 16:10:14 UTC
Created attachment 47912 [details]
Another testcase

This testcase shows how the completions are there, but you can't see them
because the popup does not resize.
This program adds a first completion right away, then waits 5 seconds before
adding the rest. The popup is one line tall, and you have to scroll to see the
other completions. Thus if you omit the first completion, nothing shows up.
Comment 4 Vincent Noel 2005-06-17 16:23:49 UTC
Created attachment 47914 [details] [review]
tiny patch for gtkentrycompletion.c

This small patch for gtk+ fixes the issue, but I'm not sure if it's correct - I
guess the resizing function was not called there for a reason (some race
condition or something)
Comment 5 Matthias Clasen 2005-06-17 18:28:13 UTC
2005-06-17  Matthias Clasen  <mclasen@redhat.com>

	* gtk/gtkentrycompletion.c (gtk_entry_completion_complete): 
	Resize the popup if necessary.  (#308076, Vincent Noel)
Comment 6 Vincent Noel 2005-06-20 14:28:57 UTC
Well actually the patch only looked like it fixed the bug, but it didn't :P
If you take a longer look at the gtk_entry_completion_complete function, you'll
see that _gtk_entry_completion_resize_popup is already called there, but only if
the widget is GTK_WIDGET_VISIBLE. So the actual bug is that the widget was not
shown in the first place. Thus, with the patch, the popup correctly resized in
testcase2.c, but still did not show up in testcase.c. So all that is actually
required is a call to show the popup if items are present in the filtered model,
and everything will just work (resizing et al).

A new (correct) patch is coming up.
Comment 7 Vincent Noel 2005-06-20 14:31:51 UTC
Created attachment 48043 [details] [review]
Correct patch for gtkentrycompletion.c

With this patch the popup correctly shows up in both testcases.
Comment 8 Matthias Clasen 2005-06-20 17:31:33 UTC
This is a misunderstanding. I just added the call to resize the popup if its
visible a few days ago. But gtk_entry_completion_complete() is not meant to 
pop up the window. At least I did not understand it to, so far. 
The documentation may be a bit ambiguous.
Comment 9 Vincent Noel 2005-06-20 17:38:54 UTC
The problem is the following : if you add items to the model too long after the
user typed something in the entry, *and the popup is not visible yet*, then the
completions do not appear (because the popup does not get shown anywhere). If
the popup is already visible, and you add items, this function does the right
thing (ie resizes the popup). So there is two different behaviors here,
depending if the popup is already visible or not. Maybe the window popup should
be called somewhere else, but I'm pretty sure the resulting behavior is sane.

If gtk_entry_completion_complete is not meant to pop up the window, how do one
gets the completions to appear in testcase2.c ?
Comment 10 Matthias Clasen 2005-06-20 17:55:24 UTC
testcase2 looks pretty artificial to me. Why would you clear and then refill the
set of possible completions when the user types something ?
Comment 11 Vincent Noel 2005-06-20 18:03:50 UTC
Because I'm fetching the possible completions for the word the user just entered
on a dict server, and this takes some time (even on a pretty fast connection)...
I can't fill the model with every single possible dictionary word.

For example, if the user types "dictiona" the following completions appear :
dictionaries
dictionalrian
dictionary

If the user then removes the final "a", "Diction" must be added to the list.
Comment 12 Vincent Noel 2005-06-20 18:10:30 UTC
Moreover, the clearing of the model is not really the problem here. 
Maybe I'm not being very clear, so I'll try to summarize the issue better :

If you have a GtkEntry with a set of possible completions that do not fit the
present word in the entry, nothing appears. So far, so good.

If, later on, you add words to the model that fit the word in the entry, and
call gtk_entry_completion_complete, then the new completions should appear. If
you already had some fitting completions before, they appear. If you don't
(which is our case here) they don't. This is because
gtk_entry_completion_complete resizes the popup, which is fine if the popup was
already visible, but not enough if it isn't. There are two separate behaviors
depending on the state of the popup, which doesn't feel right to me.
Comment 13 Matthias Clasen 2005-06-20 18:33:01 UTC
ok, thats an interesting use case. 

My current understanding of gtk_entry_completion_complete() is that it is ok to
call at any time. That would no longer be the case if we made it pop up the
completions, since you don't want the completions popup to appear spontaneously
without user action, just because the set of completions changed.
Maybe we need new API here.
Comment 14 Vincent Noel 2005-06-20 18:47:56 UTC
I'm a little puzzled why would anyone call gtk_entry_completion_complete and
still want the popup hidden... As I see it, the only reason to call this
function is when you have new completions you want to show the user right now.
If there was no user action, you don't need to call the function, as it will be
called automatically on the next user action (right ?). 

However I'm sure there are good reasons why gtk_entry_completion_complete works
the way it does now :-)
Comment 15 Matthias Clasen 2006-12-22 15:46:51 UTC
The right fix here is to export gtk_entry_completion_popup/_popdown, I think.
Comment 16 Matthias Clasen 2018-02-10 04:32:59 UTC
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.