Commit 49e3ceafb3e1133f69b3f64207f69f5b84f1c0f7
- Diff rendering mode:
- inline
- side by side
hildon/hildon-live-search.c
(34 / 37)
|   | |||
| 119 | 119 | (GtkTreePath *)v2) == 0; | |
| 120 | 120 | } | |
| 121 | 121 | ||
| 122 | |||
| 123 | static void | ||
| 124 | refilter (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 | |||
| 135 | 122 | static gboolean | |
| 136 | 123 | model_get_root (GtkTreeModelFilter *filter, | |
| 137 | 124 | GtkTreeModel *base_model, | |
| … | … | ||
| 154 | 154 | GtkTreeIter iter_child; | |
| 155 | 155 | GtkTreePath *path; | |
| 156 | 156 | ||
| 157 | if (!GTK_IS_TREE_VIEW (priv->kb_focus_widget)) | ||
| 158 | return; | ||
| 159 | |||
| 157 | 160 | g_assert (priv->selection_map == NULL); | |
| 158 | 161 | ||
| 159 | 162 | base_model = gtk_tree_model_filter_get_model (priv->filter); | |
| … | … | ||
| 224 | 224 | GtkTreeSelection *selection; | |
| 225 | 225 | GtkTreeIter iter_child; | |
| 226 | 226 | ||
| 227 | if (!GTK_IS_TREE_VIEW (priv->kb_focus_widget)) | ||
| 228 | return; | ||
| 229 | |||
| 227 | 230 | base_model = gtk_tree_model_filter_get_model (priv->filter); | |
| 228 | 231 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->kb_focus_widget)); | |
| 229 | 232 | ||
| … | … | ||
| 279 | 279 | GtkTreeSelection *selection; | |
| 280 | 280 | GtkTreeIter iter_child; | |
| 281 | 281 | ||
| 282 | if (!GTK_IS_TREE_VIEW (priv->kb_focus_widget)) | ||
| 283 | return; | ||
| 284 | |||
| 282 | 285 | base_model = gtk_tree_model_filter_get_model (priv->filter); | |
| 283 | 286 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->kb_focus_widget)); | |
| 284 | 287 | ||
| … | … | ||
| 320 | 320 | } | |
| 321 | 321 | ||
| 322 | 322 | static void | |
| 323 | refilter (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 | |||
| 342 | static void | ||
| 323 | 343 | on_entry_changed (GtkEntry *entry, | |
| 324 | 344 | gpointer user_data) | |
| 325 | 345 | { | |
| … | … | ||
| 347 | 347 | HildonLiveSearchPrivate *priv; | |
| 348 | 348 | const char *text; | |
| 349 | 349 | glong len; | |
| 350 | char *old_prefix; | ||
| 351 | 350 | ||
| 352 | 351 | g_return_if_fail (HILDON_IS_LIVE_SEARCH (livesearch)); | |
| 353 | 352 | priv = livesearch->priv; | |
| 354 | 353 | ||
| 355 | 354 | text = gtk_entry_get_text (GTK_ENTRY (entry)); | |
| 356 | 355 | len = g_utf8_strlen (text, -1); | |
| 357 | |||
| 358 | old_prefix = priv->prefix; | ||
| 359 | |||
| 360 | 356 | if (len < 1) { | |
| 361 | 357 | 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 | } | ||
| 367 | 358 | } | |
| 368 | 359 | ||
| 369 | if (GTK_IS_TREE_VIEW (priv->kb_focus_widget)) | ||
| 370 | selection_map_update_map_from_selection (priv); | ||
| 371 | |||
| 360 | g_free (priv->prefix); | ||
| 372 | 361 | priv->prefix = g_strdup (text); | |
| 362 | |||
| 373 | 363 | refilter (livesearch); | |
| 374 | 364 | ||
| 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); | ||
| 381 | 368 | gtk_widget_hide (GTK_WIDGET (livesearch)); | |
| 382 | 369 | } else { | |
| 383 | 370 | gtk_widget_show (GTK_WIDGET (livesearch)); | |
| 384 | 371 | } | |
| 385 | 372 | ||
| 386 | g_free (old_prefix); | ||
| 387 | |||
| 388 | 373 | /* Any change in the entry implies a change in HildonLiveSearch:text. */ | |
| 389 | 374 | g_object_notify (G_OBJECT (livesearch), "text"); | |
| 390 | 375 | } | |
| … | … | ||
| 844 | 844 | } | |
| 845 | 845 | ||
| 846 | 846 | refilter (livesearch); | |
| 847 | |||
| 848 | if (priv->prefix) { | ||
| 849 | selection_map_create (priv); | ||
| 850 | } | ||
| 851 | 847 | ||
| 852 | 848 | g_object_notify (G_OBJECT (livesearch), "filter"); | |
| 853 | 849 | } |

