[gcalctool] Fix bug when entering numeric point and ans is in display
- From: Robin Sonefors <rsonefors src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool] Fix bug when entering numeric point and ans is in display
- Date: Sat, 9 Oct 2010 16:18:21 +0000 (UTC)
commit 382a6df2c1ad86e9a204bfb5c8d574420b34933e
Author: Robin Sonefors <ozamosi flukkost nu>
Date: Sat Oct 9 18:13:36 2010 +0200
Fix bug when entering numeric point and ans is in display
Before, if ans was 2 and you entered .2, you would get an error.
Now, treat the numeric point like a digit and clear the display when it
is entered if display is ans.
src/math-equation.c | 3 ++-
src/mp-serializer.c | 8 ++++++++
src/mp-serializer.h | 3 ++-
3 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/src/math-equation.c b/src/math-equation.c
index 6627635..0f33ab2 100644
--- a/src/math-equation.c
+++ b/src/math-equation.c
@@ -1372,7 +1372,8 @@ pre_insert_text_cb (MathEquation *equation,
/* Clear result on next digit entered if cursor at end of line */
// FIXME Cursor
c = g_utf8_get_char(text);
- if (g_unichar_isdigit(c) && math_equation_is_result(equation)) {
+ if ((g_unichar_isdigit(c) || mp_serializer_is_numeric_point(equation->priv->serializer, text)) &&
+ math_equation_is_result(equation)) {
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(equation), "", -1);
clear_ans(equation, FALSE);
gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(equation), location);
diff --git a/src/mp-serializer.c b/src/mp-serializer.c
index 8d466a0..b397a57 100644
--- a/src/mp-serializer.c
+++ b/src/mp-serializer.c
@@ -337,6 +337,14 @@ mp_serializer_get_thousands_separator_text(MpSerializer *serializer)
return serializer->priv->tsep;
}
+gboolean
+mp_serializer_is_numeric_point(MpSerializer *serializer, const char *text)
+{
+ if (*text == '.' || strncmp(text, serializer->priv->radix, strlen(serializer->priv->radix)) == 0)
+ return true;
+ return false;
+}
+
void
mp_serializer_set_show_thousands_separators(MpSerializer *serializer, gboolean visible)
{
diff --git a/src/mp-serializer.h b/src/mp-serializer.h
index 3490183..f815fa2 100644
--- a/src/mp-serializer.h
+++ b/src/mp-serializer.h
@@ -54,8 +54,9 @@ void mp_serializer_to_standard_string(MpSerializer *serializer, const MPNumber *
void mp_serializer_to_specific_string(const MPNumber *z, int base, int accuracy, bool trim_zeroes, bool localize, char *target, int target_len);
bool mp_serializer_from_string(MpSerializer *serializer, const char *str, MPNumber *z);
-const gchar* mp_serializer_get_numeric_point_text(MpSerializer *serializer);
const gchar* mp_serializer_get_thousands_separator_text(MpSerializer *serializer);
+const gchar* mp_serializer_get_numeric_point_text(MpSerializer *serializer);
+gboolean mp_serializer_is_numeric_point(MpSerializer *serializer, const char* text);
void mp_serializer_set_base(MpSerializer *serializer, int base);
int mp_serializer_get_base(MpSerializer *serializer);
gboolean mp_serializer_get_show_trailing_zeroes(MpSerializer *serializer);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]