[Gnucash-changes] r13856 - gnucash/trunk - Bug#119078: promote register parse errors to the user.

Joshua Sled jsled at cvs.gnucash.org
Tue Apr 25 21:31:03 EDT 2006


Author: jsled
Date: 2006-04-25 21:31:02 -0400 (Tue, 25 Apr 2006)
New Revision: 13856
Trac: http://svn.gnucash.org/trac/changeset/13856

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/src/register/ledger-core/split-register-load.c
   gnucash/trunk/src/register/register-core/formulacell.c
   gnucash/trunk/src/register/register-core/pricecell.c
   gnucash/trunk/src/register/register-core/table-allgui.c
Log:
Bug#119078: promote register parse errors to the user.


Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-04-26 01:29:40 UTC (rev 13855)
+++ gnucash/trunk/ChangeLog	2006-04-26 01:31:02 UTC (rev 13856)
@@ -1,3 +1,18 @@
+2006-04-25  Joshua Sled  <jsled at asynchronous.org>
+	Bug#119078: promote register parse errors to the user.
+
+	* src/register/register-core/pricecell.c (gnc_price_cell_parse):
+	Return error if cell text isn't parseable via expression parser.
+
+	* src/register/register-core/pricecell.c (gnc_price_cell_leave):
+	* src/register/register-core/formulacell.c (gnc_formula_cell_leave): 
+	Promote error to UI if cell text isn't parseable.
+
+	* src/register/register-core/table-allgui.c (gnc_table_save_cells): 
+	* src/register/ledger-core/split-register-load.c
+	(gnc_split_register_load): Don't -- seemingly unnecessarily --
+	call [...]leave_update here.
+
 2006-04-25  David Hampton  <hampton at employees.org>
 
 	* src/gnome/gnc-plugin-page-register.c: Don't try to update the

Modified: gnucash/trunk/src/register/ledger-core/split-register-load.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-load.c	2006-04-26 01:29:40 UTC (rev 13855)
+++ gnucash/trunk/src/register/ledger-core/split-register-load.c	2006-04-26 01:31:02 UTC (rev 13856)
@@ -259,7 +259,7 @@
 
   table = reg->table;
 
-  gnc_table_leave_update (table, table->current_cursor_loc);
+  // gnc_table_leave_update (table, table->current_cursor_loc);
 
   multi_line = (reg->style == REG_STYLE_JOURNAL);
   dynamic    = (reg->style == REG_STYLE_AUTO_LEDGER);

Modified: gnucash/trunk/src/register/register-core/formulacell.c
===================================================================
--- gnucash/trunk/src/register/register-core/formulacell.c	2006-04-26 01:29:40 UTC (rev 13855)
+++ gnucash/trunk/src/register/register-core/formulacell.c	2006-04-26 01:31:02 UTC (rev 13856)
@@ -21,8 +21,12 @@
 
 #include "config.h"
 
+#include <glib/gi18n.h>
+
+#include "gnc-exp-parser.h"
 #include "gnc-engine.h"
 #include "gnc-ui-util.h"
+#include "gnc-ui.h"
 
 #include "basiccell.h"
 #include "formulacell.h"
@@ -36,9 +40,7 @@
                                         int *start_selection,
                                         int *end_selection );
 
-#if 0
 static void gnc_formula_cell_leave( BasicCell *_cell );
-#endif
 
 static void gnc_formula_cell_modify_verify( BasicCell *_cell, 
                                             const char *change,
@@ -73,6 +75,7 @@
   fc->cell.enter_cell    = gnc_formula_cell_enter;
   fc->cell.modify_verify = gnc_formula_cell_modify_verify;
   fc->cell.set_value     = gnc_formula_cell_set_value_internal;
+  fc->cell.leave_cell    = gnc_formula_cell_leave;
 }
 
 void
@@ -97,18 +100,26 @@
   return TRUE;
 }
 
-#if 0
-static
-void
-gnc_formula_cell_leave( BasicCell *_cell )
+static void
+gnc_formula_cell_leave(BasicCell *_cell)
 {
   char *str;
   FormulaCell *fc = (FormulaCell*)_cell;
-  DEBUG( "leaving.." );
   str = fc->cell.value;
+  {
+    char *error_location = NULL;
+    gnc_numeric amount;
+    if (str != NULL
+        && strlen(str) != 0
+        && !gnc_exp_parser_parse(str, &amount, &error_location))
+    {
+      gnc_warning_dialog(NULL, _("An error occurred while processing %s."),
+                         str);//, (error_location - str));
+    }
+  }
+
   gnc_basic_cell_set_value_internal( &fc->cell, str );
 }
-#endif
 
 static
 void

Modified: gnucash/trunk/src/register/register-core/pricecell.c
===================================================================
--- gnucash/trunk/src/register/register-core/pricecell.c	2006-04-26 01:29:40 UTC (rev 13855)
+++ gnucash/trunk/src/register/register-core/pricecell.c	2006-04-26 01:31:02 UTC (rev 13856)
@@ -35,12 +35,14 @@
 #include "config.h"
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <locale.h>
 #include <string.h>
 
 #include "gnc-exp-parser.h"
 #include "gnc-engine.h"
 #include "gnc-ui-util.h"
+#include "gnc-ui.h"
 
 #include "basiccell.h"
 #include "pricecell.h"
@@ -119,7 +121,7 @@
   cell->need_to_parse = TRUE;
 }
 
-static void
+static gint
 gnc_price_cell_parse (PriceCell *cell, gboolean update_value)
 {
   const char *newval;
@@ -127,41 +129,58 @@
   gnc_numeric amount;
 
   if (!cell->need_to_parse)
-    return;
+    return -1;
 
   oldval = cell->cell.value;
   if (oldval == NULL)
     oldval = "";
 
-  if (gnc_exp_parser_parse (cell->cell.value, &amount, NULL))
   {
-    if (cell->fraction > 0)
-      amount = gnc_numeric_convert (amount, cell->fraction, GNC_RND_ROUND);
+    char *err_location = NULL;
+    if (strlen(g_strstrip(cell->cell.value)) == 0)
+    {
+      cell->amount = gnc_numeric_zero ();
+    }
+    else if (gnc_exp_parser_parse (cell->cell.value, &amount, &err_location))
+    {
+      if (cell->fraction > 0)
+        amount = gnc_numeric_convert (amount, cell->fraction, GNC_RND_ROUND);
 
-    cell->amount = amount;
+      cell->amount = amount;
+    }
+    else
+    {
+      return (err_location - cell->cell.value);
+    }
   }
-  else
-    cell->amount = gnc_numeric_zero ();
 
   if (!update_value)
-    return;
+    return -1;
 
   newval = gnc_price_cell_print_value (cell);
 
   /* If they are identical do nothing */
   if (strcmp(newval, oldval) == 0)
-    return;
+    return -1;
 
   /* Otherwise, change it */
   gnc_basic_cell_set_value_internal (&cell->cell, newval);
+  return -1;
 }
 
 static void
 gnc_price_cell_leave (BasicCell *_cell) 
 {
+  gint error_position = -1;
   PriceCell *cell = (PriceCell *) _cell;
 
-  gnc_price_cell_parse (cell, TRUE);
+  error_position = gnc_price_cell_parse (cell, TRUE);
+  if (error_position != -1)
+  {
+    gnc_warning_dialog(NULL, _("An error occurred while processing %s."),
+                       cell->cell.value);
+  }
+
 }
 
 BasicCell *

Modified: gnucash/trunk/src/register/register-core/table-allgui.c
===================================================================
--- gnucash/trunk/src/register/register-core/table-allgui.c	2006-04-26 01:29:40 UTC (rev 13855)
+++ gnucash/trunk/src/register/register-core/table-allgui.c	2006-04-26 01:31:02 UTC (rev 13856)
@@ -564,7 +564,7 @@
   if (gnc_table_model_read_only (table->model))
     return;
 
-  gnc_table_leave_update (table, table->current_cursor_loc);
+  // gnc_table_leave_update (table, table->current_cursor_loc);
 
   save_handler = gnc_table_model_get_pre_save_handler (table->model);
   if (save_handler)



More information about the gnucash-changes mailing list