From 4df714037b77d98ca5322448acd53b037a95cc61 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Sat, 15 Jul 2017 11:06:26 +0100 Subject: [PATCH] Add function to clear the display of the currency edit widget When first created, the display is blank and in this position will return the default currency. If a currency is selected, there is no way to go back to this state. The only way to do this is destroy the widget and create a new one so added a function to do this without destroying the widget. This is used in the next commit. --- src/gnome-utils/gnc-currency-edit.c | 36 +++++++++++++++++++++++++++++ src/gnome-utils/gnc-currency-edit.h | 10 ++++++++ 2 files changed, 46 insertions(+) diff --git a/src/gnome-utils/gnc-currency-edit.c b/src/gnome-utils/gnc-currency-edit.c index bf62342cfd..2abf9d6ddf 100644 --- a/src/gnome-utils/gnc-currency-edit.c +++ b/src/gnome-utils/gnc-currency-edit.c @@ -467,6 +467,42 @@ gnc_currency_edit_get_currency (GNCCurrencyEdit *gce) return commodity; } +/** Clear the displayed currency of the widget. + * + * This will clear the currency being displayed just like when first created + * but it still returns the default currency as usual + * + * @param gce The currency editor widget whose values should be retrieved. + */ +void +gnc_currency_edit_clear_display (GNCCurrencyEdit *gce) +{ + GtkTreeModel *model; + GtkWidget *entry; + + g_return_if_fail(gce != NULL); + g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce)); + + model = gtk_combo_box_get_model (GTK_COMBO_BOX(gce)); + + entry = gtk_bin_get_child (GTK_BIN(gce)); + + g_object_ref (model); + + g_signal_handlers_block_by_func (G_OBJECT(gce), + G_CALLBACK(gnc_currency_edit_active_changed), gce); + + gtk_combo_box_set_model (GTK_COMBO_BOX(gce), NULL); + gtk_entry_set_text (GTK_ENTRY(entry),""); + gtk_combo_box_set_active (GTK_COMBO_BOX(gce), -1); + gtk_combo_box_set_model (GTK_COMBO_BOX(gce), model); + + g_signal_handlers_block_by_func (G_OBJECT(gce), + G_CALLBACK(gnc_currency_edit_active_changed), gce); + + g_object_unref (model); +} + /** @} */ /** @} */ /** @} */ diff --git a/src/gnome-utils/gnc-currency-edit.h b/src/gnome-utils/gnc-currency-edit.h index a8c1e1cd8f..652050e811 100644 --- a/src/gnome-utils/gnc-currency-edit.h +++ b/src/gnome-utils/gnc-currency-edit.h @@ -114,6 +114,16 @@ void gnc_currency_edit_set_currency (GNCCurrencyEdit *gce, */ gnc_commodity *gnc_currency_edit_get_currency (GNCCurrencyEdit *gce); + +/** Clear the displayed currency of the widget. + * + * This will clear the currency being displayed just like when first created + * but it still returns the default currency as usual + * + * @param gce The currency editor widget whose values should be retrieved. + */ +void gnc_currency_edit_clear_display (GNCCurrencyEdit *gce); + /** @} */ #endif