[recipes/wip/yield: 3/8] details, edit: rename serves to yield
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/wip/yield: 3/8] details, edit: rename serves to yield
- Date: Sun, 25 Jun 2017 13:33:16 +0000 (UTC)
commit 9d642c6a25cef9a4ec57de80d117ed042275af95
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jun 18 23:09:38 2017 -0400
details, edit: rename serves to yield
This is in preparation for allowing more general yields, like
'loafs'. For now, still just support servings.
src/gr-details-page.c | 41 +++++++++++++++++++++++++++++++
src/gr-details-page.ui | 62 +++++++++++++++++++++++++++++++-----------------
src/gr-edit-page.c | 19 ++++++++++++++
src/gr-edit-page.ui | 27 +++++++++++++++++----
4 files changed, 122 insertions(+), 27 deletions(-)
---
diff --git a/src/gr-details-page.c b/src/gr-details-page.c
index 31d0b1f..bea2255 100644
--- a/src/gr-details-page.c
+++ b/src/gr-details-page.c
@@ -71,6 +71,7 @@ struct _GrDetailsPage
GtkWidget *season_desc;
GtkWidget *season_label;
GtkWidget *serves_spin;
+ GtkWidget *yield_label;
GtkWidget *warning_box;
GtkWidget *spicy_warning;
GtkWidget *garlic_warning;
@@ -188,6 +189,10 @@ 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"));
+
populate_ingredients (page, new_value, serves);
}
@@ -393,6 +398,7 @@ gr_details_page_class_init (GrDetailsPageClass *klass)
gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, season_desc);
gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, season_label);
gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, serves_spin);
+ gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, yield_label);
gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, warning_box);
gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, spicy_warning);
gtk_widget_class_bind_template_child (widget_class, GrDetailsPage, garlic_warning);
@@ -555,6 +561,35 @@ 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)
@@ -577,6 +612,9 @@ 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;
g_set_object (&page->recipe, recipe);
@@ -592,6 +630,7 @@ 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);
@@ -657,6 +696,8 @@ 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"));
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 1803c7c..d13216b 100644
--- a/src/gr-details-page.ui
+++ b/src/gr-details-page.ui
@@ -161,7 +161,9 @@
<child>
<object class="GtkLabel">
<property name="visible">1</property>
- <property name="label" translatable="yes">Serves</property>
+ <property name="label" translatable="yes">_Yield</property>
+ <property name="use-underline">1</property>
+ <property name="mnemonic-widget">serves_spin</property>
<property name="valign">baseline</property>
<property name="xalign">1</property>
<property name="margin-start">20</property>
@@ -177,15 +179,31 @@
</packing>
</child>
<child>
- <object class="GtkSpinButton" id="serves_spin">
+ <object class="GtkBox">
<property name="visible">1</property>
+ <property name="orientation">horizontal</property>
<property name="halign">start</property>
<property name="valign">baseline</property>
- <property name="hexpand">1</property>
- <property name="adjustment">serves_adjustment</property>
- <property name="width-chars">2</property>
- <property name="margin-bottom">8</property>
- <signal name="value-changed" handler="serves_value_changed" swapped="yes"/>
+ <property name="spacing">20</property>
+ <child>
+ <object class="GtkSpinButton" id="serves_spin">
+ <property name="visible">1</property>
+ <property name="halign">start</property>
+ <property name="valign">baseline</property>
+ <property name="adjustment">serves_adjustment</property>
+ <property name="width-chars">2</property>
+ <property name="margin-bottom">8</property>
+ <signal name="value-changed" handler="serves_value_changed" swapped="yes"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="yield_label">
+ <property name="visible">1</property>
+ <property name="xalign">0</property>
+ <property name="valign">baseline</property>
+ <property name="margin-bottom">15</property>
+ </object>
+ </child>
</object>
<packing>
<property name="left-attach">1</property>
@@ -207,7 +225,7 @@
</object>
<packing>
<property name="left-attach">0</property>
- <property name="top-attach">1</property>
+ <property name="top-attach">2</property>
</packing>
</child>
<child>
@@ -219,7 +237,7 @@
</object>
<packing>
<property name="left-attach">1</property>
- <property name="top-attach">1</property>
+ <property name="top-attach">2</property>
</packing>
</child>
<child>
@@ -237,7 +255,7 @@
</object>
<packing>
<property name="left-attach">0</property>
- <property name="top-attach">2</property>
+ <property name="top-attach">3</property>
</packing>
</child>
<child>
@@ -249,7 +267,7 @@
</object>
<packing>
<property name="left-attach">1</property>
- <property name="top-attach">2</property>
+ <property name="top-attach">3</property>
</packing>
</child>
<child>
@@ -267,7 +285,7 @@
</object>
<packing>
<property name="left-attach">0</property>
- <property name="top-attach">3</property>
+ <property name="top-attach">4</property>
</packing>
</child>
<child>
@@ -279,7 +297,7 @@
</object>
<packing>
<property name="left-attach">1</property>
- <property name="top-attach">3</property>
+ <property name="top-attach">4</property>
</packing>
</child>
<child>
@@ -297,7 +315,7 @@
</object>
<packing>
<property name="left-attach">0</property>
- <property name="top-attach">4</property>
+ <property name="top-attach">5</property>
</packing>
</child>
<child>
@@ -309,7 +327,7 @@
</object>
<packing>
<property name="left-attach">1</property>
- <property name="top-attach">4</property>
+ <property name="top-attach">5</property>
</packing>
</child>
<child>
@@ -327,7 +345,7 @@
</object>
<packing>
<property name="left-attach">0</property>
- <property name="top-attach">5</property>
+ <property name="top-attach">6</property>
</packing>
</child>
<child>
@@ -339,7 +357,7 @@
</object>
<packing>
<property name="left-attach">1</property>
- <property name="top-attach">5</property>
+ <property name="top-attach">6</property>
</packing>
</child>
<child>
@@ -353,7 +371,7 @@
</object>
<packing>
<property name="left-attach">0</property>
- <property name="top-attach">6</property>
+ <property name="top-attach">7</property>
<property name="width">2</property>
</packing>
</child>
@@ -399,7 +417,7 @@
</object>
<packing>
<property name="left-attach">0</property>
- <property name="top-attach">7</property>
+ <property name="top-attach">8</property>
<property name="width">2</property>
</packing>
</child>
@@ -414,7 +432,7 @@
</object>
<packing>
<property name="left-attach">0</property>
- <property name="top-attach">8</property>
+ <property name="top-attach">9</property>
<property name="width">2</property>
</packing>
</child>
@@ -431,7 +449,7 @@
</object>
<packing>
<property name="left-attach">0</property>
- <property name="top-attach">9</property>
+ <property name="top-attach">10</property>
<property name="width">2</property>
</packing>
</child>
@@ -444,7 +462,7 @@
</object>
<packing>
<property name="left-attach">0</property>
- <property name="top-attach">10</property>
+ <property name="top-attach">11</property>
<property name="width">2</property>
</packing>
</child>
diff --git a/src/gr-edit-page.c b/src/gr-edit-page.c
index 5e2ac8f..c0b3cb5 100644
--- a/src/gr-edit-page.c
+++ b/src/gr-edit-page.c
@@ -73,6 +73,7 @@ struct _GrEditPage
GtkWidget *description_field;
GtkWidget *instructions_field;
GtkWidget *serves_spin;
+ GtkWidget *yield_label;
GtkWidget *gluten_free_check;
GtkWidget *nut_free_check;
GtkWidget *vegan_check;
@@ -1045,6 +1046,17 @@ 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
gr_edit_page_grab_focus (GtkWidget *widget)
{
GrEditPage *self = GR_EDIT_PAGE (widget);
@@ -1099,6 +1111,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, add_step_button);
gtk_widget_class_bind_template_child (widget_class, GrEditPage, link_image_button);
@@ -1141,6 +1154,7 @@ gr_edit_page_class_init (GrEditPageClass *klass)
gtk_widget_class_bind_template_callback (widget_class, prev_step);
gtk_widget_class_bind_template_callback (widget_class, next_step);
gtk_widget_class_bind_template_callback (widget_class, set_unsaved);
+ gtk_widget_class_bind_template_callback (widget_class, serves_value_changed);
gtk_widget_class_bind_template_callback (widget_class, add_list);
gtk_widget_class_bind_template_callback (widget_class, do_add_timer);
@@ -1365,6 +1379,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"));
set_spiciness (page, 0);
populate_ingredients (page, "");
set_text_view_text (GTK_TEXT_VIEW (page->description_field), "");
@@ -1426,6 +1441,7 @@ gr_edit_page_edit (GrEditPage *page,
const char *prep_time;
const char *cook_time;
const char *author;
+ const char *yield;
int serves;
int spiciness;
const char *description;
@@ -1456,6 +1472,7 @@ gr_edit_page_edit (GrEditPage *page,
author = gr_recipe_get_author (recipe);
index = gr_recipe_get_default_image (recipe);
images = gr_recipe_get_images (recipe);
+ yield = gr_recipe_get_yield (recipe);
g_free (page->author);
page->author = g_strdup (author);
@@ -1472,6 +1489,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"));
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");
@@ -1519,6 +1537,7 @@ gr_edit_page_save (GrEditPage *page)
g_autofree char *description = NULL;
g_autofree char *ingredients = NULL;
g_autofree char *instructions = NULL;
+ const char *yield;
GrRecipeStore *store;
g_autoptr(GError) error = NULL;
gboolean ret = TRUE;
diff --git a/src/gr-edit-page.ui b/src/gr-edit-page.ui
index 1857b0e..1982b74 100644
--- a/src/gr-edit-page.ui
+++ b/src/gr-edit-page.ui
@@ -320,7 +320,7 @@
<property name="visible">1</property>
<property name="use-underline">1</property>
<property name="mnemonic-widget">serves_spin</property>
- <property name="label" translatable="yes">Ser_ves</property>
+ <property name="label" translatable="yes">_Yield</property>
<property name="valign">baseline</property>
<property name="xalign">1</property>
<style>
@@ -333,12 +333,29 @@
</packing>
</child>
<child>
- <object class="GtkSpinButton" id="serves_spin">
+ <object class="GtkBox">
<property name="visible">1</property>
- <property name="adjustment">serves_adjustment</property>
+ <property name="orientation">horizontal</property>
<property name="halign">start</property>
<property name="valign">baseline</property>
- <property name="margin-bottom">10</property>
+ <property name="spacing">20</property>
+ <child>
+ <object class="GtkSpinButton" id="serves_spin">
+ <property name="visible">1</property>
+ <property name="adjustment">serves_adjustment</property>
+ <property name="halign">start</property>
+ <property name="valign">baseline</property>
+ <property name="margin-bottom">10</property>
+ <signal name="value-changed" handler="serves_value_changed" swapped="yes"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="yield_label">
+ <property name="visible">1</property>
+ <property name="valign">baseline</property>
+ <property name="margin-bottom">10</property>
+ </object>
+ </child>
</object>
<packing>
<property name="left-attach">1</property>
@@ -585,7 +602,7 @@
<property name="top-attach">8</property>
</packing>
</child>
- <child>
+ _<child>
<object class="GtkLabel">
<property name="visible">1</property>
<property name="label" translatable="yes">Description</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]