[recipes/recipe-link: 8/8] Some more work on the recipe popover
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/recipe-link: 8/8] Some more work on the recipe popover
- Date: Fri, 30 Dec 2016 12:18:28 +0000 (UTC)
commit c38f48dbd465c2e29ebd52b6a093293fac9cdf02
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Dec 30 07:16:33 2016 -0500
Some more work on the recipe popover
We should the chef now, and we use proper filtering in the list.
src/gr-edit-page.c | 105 ++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 85 insertions(+), 20 deletions(-)
---
diff --git a/src/gr-edit-page.c b/src/gr-edit-page.c
index bd1d0e9..8a4033b 100644
--- a/src/gr-edit-page.c
+++ b/src/gr-edit-page.c
@@ -832,28 +832,34 @@ populate_units_list (GrEditPage *self)
G_CALLBACK (unit_row_activated), self);
}
-static void
-recipe_filter_changed (GrEditPage *self)
+static gboolean
+recipe_filter_func (GtkListBoxRow *row,
+ gpointer data)
{
- const char *term;
- g_autofree char *cf_term = NULL;
- g_autofree char *s = NULL;
+ GrEditPage *self = data;
+ const char *cf;
- term = gtk_entry_get_text (GTK_ENTRY (self->recipe_filter_entry));
- cf_term = g_utf8_casefold (term, -1);
- s = g_strconcat ("na:", cf_term, NULL);
+ if (!self->recipe_term)
+ return TRUE;
+
+ cf = (const char *)g_object_get_data (G_OBJECT (row), "term");
- gr_recipe_search_set_query (self->search, s);
+ return g_str_has_prefix (cf, self->recipe_term);
}
static void
-recipe_filter_stop (GrEditPage *self)
+recipe_filter_changed (GrEditPage *self)
{
- gtk_entry_set_text (GTK_ENTRY (self->recipe_filter_entry), "");
+ const char *term;
+
+ term = gtk_entry_get_text (GTK_ENTRY (self->recipe_filter_entry));
+ g_free (self->recipe_term);
+ self->recipe_term = g_utf8_casefold (term, -1);
+ gtk_list_box_invalidate_filter (GTK_LIST_BOX (self->recipe_list));
}
static void
-recipe_filter_activated (GrEditPage *self)
+recipe_filter_stop (GrEditPage *self)
{
}
@@ -889,18 +895,26 @@ recipe_row_activated (GtkListBox *list,
gtk_text_buffer_insert_with_tags (buffer, &iter, name, -1, tag, NULL);
gtk_popover_popdown (GTK_POPOVER (self->recipe_popover));
- container_remove_all (GTK_CONTAINER (self->recipe_list));
gtk_entry_set_text (GTK_ENTRY (self->recipe_filter_entry), "");
gtk_widget_grab_focus (self->instructions_field);
}
+static void
+recipe_filter_activated (GrEditPage *self)
+{
+ GtkListBoxRow *row;
+
+ row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (self->recipe_list), 0);
+ if (row) {
+ recipe_row_activated (GTK_LIST_BOX (self->recipe_list), row, self);
+ }
+}
static void
search_started (GrRecipeSearch *search,
GrEditPage *page)
{
- container_remove_all (GTK_CONTAINER (page->recipe_list));
}
static void
@@ -909,24 +923,49 @@ search_hits_added (GrRecipeSearch *search,
GrEditPage *page)
{
GList *l;
+ GrRecipeStore *store;
+
+ store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
for (l = hits; l; l = l->next) {
GrRecipe *recipe = l->data;
+ GtkWidget *box;
GtkWidget *label;
GtkWidget *row;
+ const char *author;
+ char *tmp;
+ g_autoptr(GrChef) chef = NULL;
- label = gtk_label_new (gr_recipe_get_name (recipe));
- gtk_label_set_xalign (GTK_LABEL (label), 0.0);
- g_object_set (label,
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 20);
+ gtk_widget_show (box);
+ g_object_set (box,
"margin-start", 20,
"margin-end", 20,
"margin-top", 10,
"margin-bottom", 10,
NULL);
+
+ label = gtk_label_new (gr_recipe_get_name (recipe));
+ gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_widget_show (label);
- gtk_container_add (GTK_CONTAINER (page->recipe_list), label);
- row = gtk_widget_get_parent (label);
+ gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
+
+ author = gr_recipe_get_author (recipe);
+ chef = gr_recipe_store_get_chef (store, author ? author : "");
+ if (chef) {
+ tmp = g_strdup_printf (_("by %s"), gr_chef_get_name (chef));
+ label = gtk_label_new (tmp);
+ g_free (tmp);
+ gtk_label_set_xalign (GTK_LABEL (label), 1.0);
+ gtk_widget_show (label);
+ gtk_style_context_add_class (gtk_widget_get_style_context (label), "dim-label");
+ gtk_box_pack_start (GTK_BOX (box), label, FALSE, TRUE, 0);
+ }
+
+ gtk_container_add (GTK_CONTAINER (page->recipe_list), box);
+ row = gtk_widget_get_parent (box);
g_object_set_data_full (G_OBJECT (row), "recipe", g_object_ref (recipe), g_object_unref);
+ g_object_set_data_full (G_OBJECT (row), "term", g_utf8_casefold (gr_recipe_get_name
(recipe), -1), g_free);
}
}
@@ -953,7 +992,6 @@ static void
search_finished (GrRecipeSearch *search,
GrEditPage *page)
{
- // FIXME show placeholder if no matches ?
}
static void
@@ -991,6 +1029,9 @@ populate_recipe_list (GrEditPage *self)
gtk_list_box_set_header_func (GTK_LIST_BOX (self->recipe_list),
all_headers, self, NULL);
+ gtk_list_box_set_filter_func (GTK_LIST_BOX (self->recipe_list),
+ recipe_filter_func, self, NULL);
+
g_signal_connect (self->recipe_list, "row-activated",
G_CALLBACK (recipe_row_activated), self);
@@ -1007,11 +1048,34 @@ populate_recipe_list (GrEditPage *self)
static void
add_recipe_link (GtkButton *button, GrEditPage *page)
{
+ if (gtk_list_box_get_row_at_index (GTK_LIST_BOX (page->recipe_list), 0) == NULL) {
+ gr_recipe_search_stop (page->search);
+ gr_recipe_search_set_query (page->search, "na:");
+ }
+
gtk_entry_set_text (GTK_ENTRY (page->recipe_filter_entry), "");
gtk_popover_popup (GTK_POPOVER (page->recipe_popover));
}
static void
+recipe_reload (GrEditPage *page)
+{
+ container_remove_all (GTK_CONTAINER (page->recipe_list));
+}
+
+static void
+connect_store_signals (GrEditPage *page)
+{
+ GrRecipeStore *store;
+
+ store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
+
+ g_signal_connect_swapped (store, "recipe-added", G_CALLBACK (recipe_reload), page);
+ g_signal_connect_swapped (store, "recipe-removed", G_CALLBACK (recipe_reload), page);
+ g_signal_connect_swapped (store, "recipe-changed", G_CALLBACK (recipe_reload), page);
+}
+
+static void
gr_edit_page_init (GrEditPage *page)
{
gtk_widget_set_has_window (GTK_WIDGET (page), FALSE);
@@ -1025,6 +1089,7 @@ gr_edit_page_init (GrEditPage *page)
populate_ingredients_list (page);
populate_units_list (page);
populate_recipe_list (page);
+ connect_store_signals (page);
#ifdef ENABLE_GSPELL
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]