[recipes/temperature: 3/3] Add an 'add temperature' button
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/temperature: 3/3] Add an 'add temperature' button
- Date: Wed, 15 Feb 2017 16:40:47 +0000 (UTC)
commit 86c538359525162836d35b4fbf77344f76a7c9db
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Feb 15 10:14:53 2017 -0500
Add an 'add temperature' button
This is similar to the other add buttons we have on the edit
page, to support the new markup for temperatures.
src/gr-edit-page.c | 47 +++++++++++++++++++++++++++++
src/gr-edit-page.ui | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 129 insertions(+), 0 deletions(-)
---
diff --git a/src/gr-edit-page.c b/src/gr-edit-page.c
index 76bae6b..6cf4853 100644
--- a/src/gr-edit-page.c
+++ b/src/gr-edit-page.c
@@ -111,6 +111,9 @@ struct _GrEditPage
GtkWidget *image_popover;
GtkWidget *image_flowbox;
GtkWidget *timer_popover;
+ GtkWidget *temperature_popover;
+ GtkWidget *temperature_spin;
+ GtkWidget *celsius_button;
GtkWidget *timer_spin;
GtkWidget *preview_stack;
@@ -947,6 +950,18 @@ add_tag_to_step (GrEditPage *self,
}
static void
+add_tag_at_insert (GrEditPage *self,
+ const char *tag)
+{
+ GtkTextBuffer *buffer;
+ GtkTextIter start;
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->instructions_field));
+ gtk_text_buffer_get_iter_at_mark (buffer, &start, gtk_text_buffer_get_insert (buffer));
+ gtk_text_buffer_insert (buffer, &start, tag, -1);
+}
+
+static void
image_activated (GtkFlowBox *flowbox,
GtkFlowBoxChild *child,
GrEditPage *self)
@@ -1103,6 +1118,33 @@ add_timer (GtkButton *button, GrEditPage *page)
}
static void
+temperature_spin_activate (GtkEntry *entry, GrEditPage *self)
+{
+ int value;
+ g_autofree char *text = NULL;
+ const char *unit;
+
+ gtk_spin_button_update (GTK_SPIN_BUTTON (entry));
+
+ value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (entry));
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->celsius_button)))
+ unit = "C";
+ else
+ unit = "F";
+
+ text = g_strdup_printf ("[temperature:%d%s]", value, unit);
+ add_tag_at_insert (self, text);
+
+ gtk_popover_popdown (GTK_POPOVER (self->temperature_popover));
+ gtk_widget_grab_focus (self->instructions_field);
+}
+static void
+add_temperature (GtkButton *button, GrEditPage *page)
+{
+ gtk_popover_popup (GTK_POPOVER (page->temperature_popover));
+}
+
+static void
add_step (GtkButton *button, GrEditPage *self)
{
GtkTextBuffer *buffer;
@@ -1349,6 +1391,9 @@ gr_edit_page_class_init (GrEditPageClass *klass)
gtk_widget_class_bind_template_child (widget_class, GrEditPage, image_popover);
gtk_widget_class_bind_template_child (widget_class, GrEditPage, image_flowbox);
gtk_widget_class_bind_template_child (widget_class, GrEditPage, timer_popover);
+ gtk_widget_class_bind_template_child (widget_class, GrEditPage, temperature_popover);
+ gtk_widget_class_bind_template_child (widget_class, GrEditPage, temperature_spin);
+ gtk_widget_class_bind_template_child (widget_class, GrEditPage, celsius_button);
gtk_widget_class_bind_template_child (widget_class, GrEditPage, timer_spin);
gtk_widget_class_bind_template_child (widget_class, GrEditPage, preview_stack);
gtk_widget_class_bind_template_child (widget_class, GrEditPage, cooking_view);
@@ -1377,6 +1422,7 @@ gr_edit_page_class_init (GrEditPageClass *klass)
gtk_widget_class_bind_template_callback (widget_class, add_image_link);
gtk_widget_class_bind_template_callback (widget_class, add_timer);
gtk_widget_class_bind_template_callback (widget_class, add_step);
+ gtk_widget_class_bind_template_callback (widget_class, add_temperature);
gtk_widget_class_bind_template_callback (widget_class, image_activated);
gtk_widget_class_bind_template_callback (widget_class, set_default_image);
@@ -1385,6 +1431,7 @@ gr_edit_page_class_init (GrEditPageClass *klass)
gtk_widget_class_bind_template_callback (widget_class, time_spin_input);
gtk_widget_class_bind_template_callback (widget_class, time_spin_output);
gtk_widget_class_bind_template_callback (widget_class, time_spin_activate);
+ gtk_widget_class_bind_template_callback (widget_class, temperature_spin_activate);
gtk_widget_class_bind_template_callback (widget_class, preview_visible_changed);
gtk_widget_class_bind_template_callback (widget_class, prev_step);
gtk_widget_class_bind_template_callback (widget_class, next_step);
diff --git a/src/gr-edit-page.ui b/src/gr-edit-page.ui
index 95090a1..7384008 100644
--- a/src/gr-edit-page.ui
+++ b/src/gr-edit-page.ui
@@ -750,6 +750,14 @@
</object>
</child>
<child>
+ <object class="GtkButton" id="temperature_button">
+ <property name="visible">1</property>
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">Add Temperature</property>
+ <signal name="clicked" handler="add_temperature"/>
+ </object>
+ </child>
+ <child>
<object class="GtkButton" id="prev_step_button">
<property name="halign">start</property>
<signal name="clicked" handler="prev_step" swapped="yes"/>
@@ -1023,6 +1031,58 @@
</object>
</child>
</object>
+ <object class="GtkAdjustment" id="temperature_adjustment">
+ <property name="upper">500</property>
+ <property name="step-increment">1</property>
+ <property name="page-increment">10</property>
+ </object>
+ <object class="GtkPopover" id="temperature_popover">
+ <property name="relative-to">temperature_button</property>
+ <property name="constrain-to">none</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">1</property>
+ <style>
+ <class name="linked"/>
+ </style>
+ <child>
+ <object class="GtkSpinButton" id="temperature_spin">
+ <property name="visible">1</property>
+ <property name="width-chars">4</property>
+ <property name="adjustment">temperature_adjustment</property>
+ <signal name="activate" handler="temperature_spin_activate"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="celsius_button">
+ <property name="visible">1</property>
+ <property name="draw-indicator">0</property>
+ <property name="valign">center</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">1</property>
+ <property name="label">C</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="fahrenheit_button">
+ <property name="visible">1</property>
+ <property name="draw-indicator">0</property>
+ <property name="group">celsius_button</property>
+ <property name="valign">center</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">1</property>
+ <property name="label">F</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
<object class="GtkPopover" id="directions_help_popover">
<property name="relative-to">directions_help_button</property>
<property name="constrain-to">none</property>
@@ -1116,6 +1176,28 @@
<property name="top-attach">4</property>
</packing>
</child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">1</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Temperature</property>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">5</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">1</property>
+ <property name="xalign">0</property>
+ <property name="label">[temperature:200C]</property>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="top-attach">5</property>
+ </packing>
+ </child>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]