Add filter for currency symbol for GNCAmountEdit widget

When pasting an amount that includes the currency symbol the validation
will silently fail which may lead to unusual behaviour.
This commit is contained in:
Robert Fewell
2021-05-31 10:55:42 +01:00
parent db6f233705
commit 7ee9dac2e9
3 changed files with 96 additions and 3 deletions

View File

@@ -2784,3 +2784,28 @@ gnc_filter_text_for_currency_symbol (const gchar *incoming_text,
g_strfreev (split);
return ret_text;
}
gchar *
gnc_filter_text_for_currency_commodity (const gnc_commodity *comm,
const gchar *incoming_text,
const gchar **symbol)
{
if (!incoming_text)
{
*symbol = NULL;
return NULL;
}
if (!gnc_commodity_is_currency (comm))
{
*symbol = NULL;
return g_strdup (incoming_text);
}
if (comm)
*symbol = gnc_commodity_get_nice_symbol (comm);
else
*symbol = gnc_commodity_get_nice_symbol (gnc_default_currency ());
return gnc_filter_text_for_currency_symbol (incoming_text, *symbol);
}

View File

@@ -433,6 +433,20 @@ void gnc_filter_text_set_cursor_position (const gchar *incoming_text,
gchar * gnc_filter_text_for_currency_symbol (const gchar *incoming_text,
const gchar *symbol);
/** Returns the incoming text removed of currency symbol
*
* @param comm commodity of entry if known
*
* @param incoming_text The text to filter
*
* @param symbol return the symbol used
*
* @return The incoming text with symbol removed to be freed by the caller
*/
gchar * gnc_filter_text_for_currency_commodity (const gnc_commodity *comm,
const gchar *incoming_text,
const gchar **symbol);
#endif
/** @} */
/** @} */