[recipes/wip/yield: 4/7] Make the yield unit editable
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/wip/yield: 4/7] Make the yield unit editable
- Date: Sun, 25 Jun 2017 03:46:41 +0000 (UTC)
commit 1472204f565260aaec1a7d74dfb0ed7b4d400c0d
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Jun 23 18:31:41 2017 -0400
Make the yield unit editable
This lets us the name of the yield from servings to, e.g, loafs.
src/gr-details-page.c | 52 ++++++++++++++---------------------------------
src/gr-details-page.ui | 2 +-
src/gr-edit-page.c | 17 ++++++---------
src/gr-edit-page.ui | 5 ++-
4 files changed, 27 insertions(+), 49 deletions(-)
---
diff --git a/src/gr-details-page.c b/src/gr-details-page.c
index bea2255..6fdab53 100644
--- a/src/gr-details-page.c
+++ b/src/gr-details-page.c
@@ -182,6 +182,20 @@ static void populate_ingredients (GrDetailsPage *page,
int denom);
static void
+update_yield_label (GrDetailsPage *page,
+ int serves)
+{
+ const char *yield;
+
+ yield = gr_recipe_get_yield (page->recipe);
+ if (yield && yield[0])
+ gtk_label_set_label (GTK_LABEL (page->yield_label), yield);
+ else
+ gtk_label_set_label (GTK_LABEL (page->yield_label),
+ serves == 1 ? _("serving") : _("servings"));
+}
+
+static void
serves_value_changed (GrDetailsPage *page)
{
int serves;
@@ -190,9 +204,7 @@ serves_value_changed (GrDetailsPage *page)
new_value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (page->serves_spin));
serves = gr_recipe_get_serves (page->recipe);
- gtk_label_set_label (GTK_LABEL (page->yield_label),
- new_value == 1 ? _("serving") : _("servings"));
-
+ update_yield_label (page, new_value);
populate_ingredients (page, new_value, serves);
}
@@ -561,35 +573,6 @@ scroll_up (GrDetailsPage *page)
gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
}
-static gboolean
-parse_yield (const char *text,
- char **amount,
- char **unit)
-{
- char *tmp;
- const char *str;
- GrNumber number;
- g_autofree char *num = NULL;
-
- if (text == NULL || text[0] == '\0')
- return FALSE;
-
- tmp = (char *)text;
- skip_whitespace (&tmp);
- str = tmp;
- if (!gr_number_parse (&number, &tmp, NULL)) {
- *unit = g_strdup (str);
- return FALSE;
- }
-
- *amount = gr_number_format (&number);
- skip_whitespace (&tmp);
- if (tmp)
- *unit = g_strdup (tmp);
-
- return TRUE;
-}
-
void
gr_details_page_set_recipe (GrDetailsPage *page,
GrRecipe *recipe)
@@ -612,7 +595,6 @@ gr_details_page_set_recipe (GrDetailsPage *page,
gboolean favorite;
int index;
g_autofree char *processed = NULL;
- const char *yield;
g_autofree char *amount = NULL;
g_autofree char *unit = NULL;
@@ -630,7 +612,6 @@ gr_details_page_set_recipe (GrDetailsPage *page,
instructions = gr_recipe_get_translated_instructions (recipe);
description = gr_recipe_get_translated_description (recipe);
index = gr_recipe_get_default_image (recipe);
- yield = gr_recipe_get_yield (recipe);
images = gr_recipe_get_images (recipe);
gr_image_viewer_set_images (GR_IMAGE_VIEWER (page->recipe_image), images, index);
@@ -696,8 +677,7 @@ gr_details_page_set_recipe (GrDetailsPage *page,
gtk_label_set_label (GTK_LABEL (page->instructions_label), processed);
gtk_label_set_track_visited_links (GTK_LABEL (page->instructions_label), FALSE);
- gtk_label_set_label (GTK_LABEL (page->yield_label),
- serves == 1 ? _("serving") : _("servings"));
+ update_yield_label (page, serves);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (page->serves_spin), serves);
gtk_widget_set_sensitive (page->serves_spin, ing != NULL);
diff --git a/src/gr-details-page.ui b/src/gr-details-page.ui
index d13216b..bdf1c59 100644
--- a/src/gr-details-page.ui
+++ b/src/gr-details-page.ui
@@ -184,7 +184,7 @@
<property name="orientation">horizontal</property>
<property name="halign">start</property>
<property name="valign">baseline</property>
- <property name="spacing">20</property>
+ <property name="spacing">10</property>
<child>
<object class="GtkSpinButton" id="serves_spin">
<property name="visible">1</property>
diff --git a/src/gr-edit-page.c b/src/gr-edit-page.c
index c0b3cb5..14f27d5 100644
--- a/src/gr-edit-page.c
+++ b/src/gr-edit-page.c
@@ -73,7 +73,7 @@ struct _GrEditPage
GtkWidget *description_field;
GtkWidget *instructions_field;
GtkWidget *serves_spin;
- GtkWidget *yield_label;
+ GtkWidget *yield_entry;
GtkWidget *gluten_free_check;
GtkWidget *nut_free_check;
GtkWidget *vegan_check;
@@ -1048,12 +1048,6 @@ set_unsaved (GrEditPage *page)
static void
serves_value_changed (GrEditPage *page)
{
- int new_value;
-
- new_value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (page->serves_spin));
-
- gtk_label_set_label (GTK_LABEL (page->yield_label),
- new_value == 1 ? _("serving") : _("servings"));
}
static void
@@ -1111,7 +1105,7 @@ gr_edit_page_class_init (GrEditPageClass *klass)
gtk_widget_class_bind_template_child (widget_class, GrEditPage, rotate_image_right_button);
gtk_widget_class_bind_template_child (widget_class, GrEditPage, author_label);
gtk_widget_class_bind_template_child (widget_class, GrEditPage, ingredients_box);
- gtk_widget_class_bind_template_child (widget_class, GrEditPage, yield_label);
+ gtk_widget_class_bind_template_child (widget_class, GrEditPage, yield_entry);
gtk_widget_class_bind_template_child (widget_class, GrEditPage, add_step_button);
gtk_widget_class_bind_template_child (widget_class, GrEditPage, link_image_button);
@@ -1379,7 +1373,7 @@ gr_edit_page_clear (GrEditPage *page)
set_combo_value (GTK_COMBO_BOX (page->prep_time_combo), "");
set_combo_value (GTK_COMBO_BOX (page->cook_time_combo), "");
gtk_spin_button_set_value (GTK_SPIN_BUTTON (page->serves_spin), 1);
- gtk_label_set_label (GTK_LABEL (page->yield_label), _("serving"));
+ gtk_entry_set_text (GTK_ENTRY (page->yield_entry), _("servings"));
set_spiciness (page, 0);
populate_ingredients (page, "");
set_text_view_text (GTK_TEXT_VIEW (page->description_field), "");
@@ -1489,7 +1483,7 @@ gr_edit_page_edit (GrEditPage *page,
set_combo_value (GTK_COMBO_BOX (page->cook_time_combo), cook_time);
set_spiciness (page, spiciness);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (page->serves_spin), serves);
- gtk_label_set_label (GTK_LABEL (page->yield_label), serves == 1 ? _("serving") : _("servings"));
+ gtk_entry_set_text (GTK_ENTRY (page->yield_entry), yield && yield[0] ? yield : _("servings"));
set_text_view_text (GTK_TEXT_VIEW (page->description_field), description);
rewrite_instructions_for_removed_image (page, instructions, -1);
gtk_stack_set_visible_child_name (GTK_STACK (page->preview_stack), "edit");
@@ -1564,6 +1558,7 @@ gr_edit_page_save (GrEditPage *page)
cook_time = get_combo_value (GTK_COMBO_BOX (page->cook_time_combo));
spiciness = get_spiciness (page);
serves = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (page->serves_spin));
+ yield = gtk_entry_get_text (GTK_ENTRY (page->yield_entry));
if (!collect_ingredients (page, &page->error_field, &ingredients)) {
g_set_error (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
_("Some ingredients need correction"));
@@ -1596,6 +1591,7 @@ gr_edit_page_save (GrEditPage *page)
"prep-time", prep_time,
"cook-time", cook_time,
"serves", serves,
+ "yield", yield && yield[0] ? yield : NULL,
"spiciness", spiciness,
"description", description,
"ingredients", ingredients,
@@ -1629,6 +1625,7 @@ gr_edit_page_save (GrEditPage *page)
"prep-time", prep_time,
"cook-time", cook_time,
"serves", serves,
+ "yield", yield && yield[0] ? yield : NULL,
"spiciness", spiciness,
"description", description,
"ingredients", ingredients,
diff --git a/src/gr-edit-page.ui b/src/gr-edit-page.ui
index 1982b74..bf2eec4 100644
--- a/src/gr-edit-page.ui
+++ b/src/gr-edit-page.ui
@@ -338,7 +338,7 @@
<property name="orientation">horizontal</property>
<property name="halign">start</property>
<property name="valign">baseline</property>
- <property name="spacing">20</property>
+ <property name="spacing">10</property>
<child>
<object class="GtkSpinButton" id="serves_spin">
<property name="visible">1</property>
@@ -350,10 +350,11 @@
</object>
</child>
<child>
- <object class="GtkLabel" id="yield_label">
+ <object class="GtkEntry" id="yield_entry">
<property name="visible">1</property>
<property name="valign">baseline</property>
<property name="margin-bottom">10</property>
+ <signal name="notify::text" handler="set_unsaved" swapped="yes"/>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]