Commit 49e3ceafb3e1133f69b3f64207f69f5b84f1c0f7

  • avatar
  • Claudio Saavedra (Committer)
  • Wed Mar 03 15:49:43 CET 2010
  • avatar
  • Xavier Claessens <xavier.claessens @coll…ora.co.uk> (Author)
  • Wed Mar 03 15:33:03 CET 2010
Fix consistency of selection map in HildonLiveSearch

Fixes NB#158744 (1st selected contact from the list is replaced with
the next one instead of appending both to the list)

Signed-off-by: Claudio Saavedra <csaavedra@igalia.com>
  
119119 (GtkTreePath *)v2) == 0;
120120}
121121
122
123static void
124refilter (HildonLiveSearch *livesearch)
125{
126 HildonLiveSearchPrivate *priv = livesearch->priv;
127 gboolean handled = FALSE;
128
129 g_signal_emit (livesearch, signals[REFILTER], 0, &handled);
130 if (!handled && priv->filter)
131 gtk_tree_model_filter_refilter (priv->filter);
132}
133
134
135122static gboolean
136123model_get_root (GtkTreeModelFilter *filter,
137124 GtkTreeModel *base_model,
154154 GtkTreeIter iter_child;
155155 GtkTreePath *path;
156156
157 if (!GTK_IS_TREE_VIEW (priv->kb_focus_widget))
158 return;
159
157160 g_assert (priv->selection_map == NULL);
158161
159162 base_model = gtk_tree_model_filter_get_model (priv->filter);
224224 GtkTreeSelection *selection;
225225 GtkTreeIter iter_child;
226226
227 if (!GTK_IS_TREE_VIEW (priv->kb_focus_widget))
228 return;
229
227230 base_model = gtk_tree_model_filter_get_model (priv->filter);
228231 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->kb_focus_widget));
229232
279279 GtkTreeSelection *selection;
280280 GtkTreeIter iter_child;
281281
282 if (!GTK_IS_TREE_VIEW (priv->kb_focus_widget))
283 return;
284
282285 base_model = gtk_tree_model_filter_get_model (priv->filter);
283286 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->kb_focus_widget));
284287
320320}
321321
322322static void
323refilter (HildonLiveSearch *livesearch)
324{
325 HildonLiveSearchPrivate *priv = livesearch->priv;
326 gboolean handled = FALSE;
327
328 /* Create/update selection map from current selection */
329 if (priv->selection_map == NULL)
330 selection_map_create (priv);
331 selection_map_update_map_from_selection (priv);
332
333 /* Filter the model */
334 g_signal_emit (livesearch, signals[REFILTER], 0, &handled);
335 if (!handled && priv->filter)
336 gtk_tree_model_filter_refilter (priv->filter);
337
338 /* Restore selection from mapping */
339 selection_map_update_selection_from_map (priv);
340}
341
342static void
323343on_entry_changed (GtkEntry *entry,
324344 gpointer user_data)
325345{
347347 HildonLiveSearchPrivate *priv;
348348 const char *text;
349349 glong len;
350 char *old_prefix;
351350
352351 g_return_if_fail (HILDON_IS_LIVE_SEARCH (livesearch));
353352 priv = livesearch->priv;
354353
355354 text = gtk_entry_get_text (GTK_ENTRY (entry));
356355 len = g_utf8_strlen (text, -1);
357
358 old_prefix = priv->prefix;
359
360356 if (len < 1) {
361357 text = NULL;
362 } else {
363 if (((old_prefix == NULL) || (strlen (old_prefix) == 0)) &&
364 GTK_IS_TREE_VIEW (priv->kb_focus_widget)) {
365 selection_map_create (priv);
366 }
367358 }
368359
369 if (GTK_IS_TREE_VIEW (priv->kb_focus_widget))
370 selection_map_update_map_from_selection (priv);
371
360 g_free (priv->prefix);
372361 priv->prefix = g_strdup (text);
362
373363 refilter (livesearch);
374364
375 if (GTK_IS_TREE_VIEW (priv->kb_focus_widget))
376 selection_map_update_selection_from_map (priv);
377
378 if (len < 1) {
379 if (GTK_IS_TREE_VIEW (priv->kb_focus_widget))
380 selection_map_destroy (priv);
365 /* Show the livesearch only if there is text in it */
366 if (priv->prefix == NULL) {
367 selection_map_destroy (priv);
381368 gtk_widget_hide (GTK_WIDGET (livesearch));
382369 } else {
383370 gtk_widget_show (GTK_WIDGET (livesearch));
384371 }
385372
386 g_free (old_prefix);
387
388373 /* Any change in the entry implies a change in HildonLiveSearch:text. */
389374 g_object_notify (G_OBJECT (livesearch), "text");
390375}
844844 }
845845
846846 refilter (livesearch);
847
848 if (priv->prefix) {
849 selection_map_create (priv);
850 }
851847
852848 g_object_notify (G_OBJECT (livesearch), "filter");
853849}