From e3ea3965890dcbccc9a7d2958472f0ed46b872fc Mon Sep 17 00:00:00 2001 From: mbkma Date: Sat, 20 Feb 2021 09:45:59 +0100 Subject: history view follows preferences --- src/math-history-entry.c | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'src/math-history-entry.c') 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 * @@ -94,13 +101,27 @@ math_history_entry_get_equation(MathHistoryEntry *history_entry) return gtk_widget_get_tooltip_text(history_entry->priv->equation_label); } +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(); } -- cgit v1.2.1