summaryrefslogtreecommitdiff
path: root/src/math-history-entry.c
diff options
context:
space:
mode:
authormbkma <[email protected]>2021-02-20 09:45:59 +0100
committerraveit65 <[email protected]>2021-03-22 23:31:26 +0100
commite3ea3965890dcbccc9a7d2958472f0ed46b872fc (patch)
tree5870952f65e051b8b6e1846c16ed73ea608babf7 /src/math-history-entry.c
parent2dd5cac39d37c8f15ddc3d702e79bba11d8ad8ad (diff)
downloadmate-calc-e3ea3965890dcbccc9a7d2958472f0ed46b872fc.tar.bz2
mate-calc-e3ea3965890dcbccc9a7d2958472f0ed46b872fc.tar.xz
history view follows preferences
Diffstat (limited to 'src/math-history-entry.c')
-rw-r--r--src/math-history-entry.c47
1 files changed, 34 insertions, 13 deletions
diff --git a/src/math-history-entry.c b/src/math-history-entry.c
index 8277f88..f3f0f5b 100644
--- a/src/math-history-entry.c
+++ b/src/math-history-entry.c
@@ -20,6 +20,7 @@ struct MathHistoryEntryPrivate
{
MathEquation *equation;
+ MPNumber *number;
GtkWidget *equation_label;
GtkWidget *answer_label;
};
@@ -59,33 +60,39 @@ equation_clicked_cb (GtkWidget *widget, GdkEventButton *eventbutton, MathHistory
}
void
-math_history_entry_insert_entry(MathHistoryEntry *history_entry, const gchar *equation, const gchar *answer_four_digits, const gchar *answer_nine_digits)
+math_history_entry_insert_entry(MathHistoryEntry *history_entry, const gchar *equation, MPNumber *answer, MpSerializer *serializer)
{
#define get_widget(x) GTK_WIDGET(gtk_builder_get_object(builder, x))
- GtkBuilder *builder = NULL;
+ GtkBuilder *builder;
GtkWidget *grid;
- GError *error = NULL;
-
- builder = gtk_builder_new();
- if(gtk_builder_add_from_resource (builder, UI_HISTORY_ENTRY_RESOURCE_PATH, &error) == 0)
- {
- g_warning("Error loading history-entry UI: %s", error->message);
- g_clear_error(&error);
- return;
- }
+
+ mp_set_from_mp(answer, history_entry->priv->number);
+
+ builder = gtk_builder_new_from_resource(UI_HISTORY_ENTRY_RESOURCE_PATH);
grid = get_widget("grid");
gtk_container_add(GTK_CONTAINER(history_entry), grid);
history_entry->priv->equation_label = get_widget("equation_label");
history_entry->priv->answer_label = get_widget("answer_label");
gtk_widget_set_tooltip_text(history_entry->priv->equation_label, equation);
- gtk_widget_set_tooltip_text(history_entry->priv->answer_label, answer_nine_digits);
gtk_label_set_text(GTK_LABEL(history_entry->priv->equation_label), equation);
- gtk_label_set_text(GTK_LABEL(history_entry->priv->answer_label), answer_four_digits);
gtk_builder_connect_signals(builder, history_entry);
g_object_unref(builder);
#undef get_widget
+
+ math_history_entry_redisplay(history_entry, serializer);
+}
+
+void
+math_history_entry_redisplay(MathHistoryEntry *history_entry, MpSerializer *serializer)
+{
+ gchar *answer = mp_serializer_to_string(serializer, history_entry->priv->number);
+
+ gtk_widget_set_tooltip_text(history_entry->priv->answer_label, answer);
+ gtk_label_set_text(GTK_LABEL(history_entry->priv->answer_label), answer);
+
+ g_free(answer);
}
gchar *
@@ -95,12 +102,26 @@ math_history_entry_get_equation(MathHistoryEntry *history_entry)
}
static void
+math_history_entry_finalize(GObject *object)
+{
+ MathHistoryEntry *self = MATH_HISTORY_ENTRY (object);
+
+ mp_free(self->priv->number);
+
+ G_OBJECT_CLASS (math_history_entry_parent_class)->finalize (object);
+}
+
+static void
math_history_entry_class_init(MathHistoryEntryClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ object_class->finalize = math_history_entry_finalize;
}
static void
math_history_entry_init(MathHistoryEntry *history_entry)
{
history_entry->priv = math_history_entry_get_instance_private(history_entry);
+ history_entry->priv->number = mp_new_ptr();
}