r20664 - gnucash/trunk/src - Stock Split Assistant - improve validation steps

Geert Janssens gjanssens at code.gnucash.org
Fri May 20 10:04:34 EDT 2011


Author: gjanssens
Date: 2011-05-20 10:04:33 -0400 (Fri, 20 May 2011)
New Revision: 20664
Trac: http://svn.gnucash.org/trac/changeset/20664

Modified:
   gnucash/trunk/src/gnome-utils/gnc-amount-edit.c
   gnucash/trunk/src/gnome-utils/gnc-amount-edit.h
   gnucash/trunk/src/gnome/assistant-stock-split.c
   gnucash/trunk/src/gnome/gtkbuilder/stocks.glade
Log:
Stock Split Assistant - improve validation steps
This is a follow up on bug #650584 (r20662)

Modified: gnucash/trunk/src/gnome/assistant-stock-split.c
===================================================================
--- gnucash/trunk/src/gnome/assistant-stock-split.c	2011-05-19 23:20:23 UTC (rev 20663)
+++ gnucash/trunk/src/gnome/assistant-stock-split.c	2011-05-20 14:04:33 UTC (rev 20664)
@@ -89,9 +89,9 @@
         gpointer user_data);
 void     gnc_stock_split_assistant_cash_prepare      (GtkAssistant *assistant,
         gpointer user_data);
-gboolean gnc_stock_split_assistant_details_test      (GtkAssistant *assistant,
+gboolean gnc_stock_split_assistant_details_complete  (GtkAssistant *assistant,
         gpointer user_data);
-gboolean gnc_stock_split_assistant_cash_test         (GtkAssistant *assistant,
+gboolean gnc_stock_split_assistant_cash_complete     (GtkAssistant *assistant,
         gpointer user_data);
 void     gnc_stock_split_assistant_finish            (GtkAssistant *assistant,
         gpointer user_data);
@@ -249,25 +249,6 @@
 }
 
 
-static void
-gnc_parse_error_dialog (StockSplitInfo *info, const char *error_string)
-{
-    const char * parse_error_string;
-
-    parse_error_string = gnc_exp_parser_error_string ();
-    if (parse_error_string == NULL)
-        parse_error_string = "";
-
-    if (error_string == NULL)
-        error_string = "";
-
-    gnc_error_dialog (info->window,
-                      "%s.\n\n%s: %s.",
-                      error_string, _("Error"),
-                      parse_error_string);
-}
-
-
 void gnc_stock_split_assistant_prepare (GtkAssistant  *assistant, GtkWidget *page,
         gpointer user_data)
 {
@@ -278,12 +259,10 @@
     {
         case 2:
             /* Current page is details page */
-	     gtk_assistant_set_page_complete (assistant, page, FALSE);
              gnc_stock_split_assistant_details_prepare(assistant, user_data);
             break;
         case 3:
             /* Current page is Cash in Lieu page */
-             gtk_assistant_set_page_complete (assistant, page, FALSE);
              gnc_stock_split_assistant_cash_prepare (assistant, user_data);
             break;
     }
@@ -312,14 +291,6 @@
     StockSplitInfo *info = user_data;
     GtkTreeSelection *selection;
 
-    gtk_tree_view_expand_all (GTK_TREE_VIEW(info->income_tree));
-    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(info->income_tree));
-    gtk_tree_selection_unselect_all (selection);
-
-    gtk_tree_view_expand_all (GTK_TREE_VIEW(info->asset_tree));
-    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(info->asset_tree));
-    gtk_tree_selection_unselect_all (selection);
-
     gtk_widget_grab_focus(info->cash_edit);
 
     /** FIXME The focus does not seem to work ? **/
@@ -328,97 +299,58 @@
 
 
 gboolean
-gnc_stock_split_assistant_details_test (GtkAssistant *assistant,
-                                    gpointer user_data)
+gnc_stock_split_assistant_details_complete (GtkAssistant *assistant,
+                                            gpointer user_data)
 {
     StockSplitInfo *info = user_data;
     gnc_numeric amount;
+    gint result;
 
-    if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (info->distribution_edit)))
-    {
-        gnc_parse_error_dialog (info,
-                                _("You must enter a valid distribution amount."));
-        return FALSE;
-    }
+    result = gnc_amount_edit_expr_is_valid (GNC_AMOUNT_EDIT (info->distribution_edit), &amount, TRUE);
+    if ( result != 0)
+        return FALSE; /* Parsing error or field is empty */
 
-    amount = gnc_amount_edit_get_amount
-             (GNC_AMOUNT_EDIT (info->distribution_edit));
-
     if (gnc_numeric_zero_p (amount))
-    {
-        const char *message = _("You must enter a distribution amount.");
-        gnc_error_dialog (info->window, "%s", message);
-        return FALSE;
-    }
+        return FALSE; /* field value is 0 */
 
-    if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (info->price_edit)))
-    {
-        gnc_parse_error_dialog (info,
-                                _("You must either enter a valid price "
-                                  "or leave it blank."));
-        return FALSE;
-    }
-
-    amount = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (info->price_edit));
-
-    if (gnc_numeric_negative_p (amount))
-    {
-        const char *message = _("The price must be positive.");
-        gnc_error_dialog (info->window, "%s", message);
-        return FALSE;
-    }
-
-    return TRUE;
+    result = gnc_amount_edit_expr_is_valid (GNC_AMOUNT_EDIT (info->price_edit), &amount, TRUE);
+    if (result == -1)
+        return TRUE; /* Optional field is empty */
+    else if ( result > 0)
+        return FALSE; /* Parsing error */
+    else if (gnc_numeric_negative_p (amount))
+        return FALSE; /* Negative price is not allowed */
+    else
+        return TRUE; /* Valid positive price */
 }
 
 
 gboolean
-gnc_stock_split_assistant_cash_test (GtkAssistant *assistant,
-                                 gpointer user_data)
+gnc_stock_split_assistant_cash_complete (GtkAssistant *assistant,
+                                         gpointer user_data)
 {
     StockSplitInfo *info = user_data;
     gnc_numeric amount;
+    gint result;
+    Account *account;
 
-    if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (info->cash_edit)))
-    {
-        gnc_parse_error_dialog (info,
-                                _("You must either enter a valid cash amount "
-                                  "or leave it blank."));
+    result = gnc_amount_edit_expr_is_valid (GNC_AMOUNT_EDIT (info->cash_edit), &amount, TRUE);
+    if (result == -1)
+        return TRUE; /* Optional field is empty */
+    else if ( result > 0)
+        return FALSE; /* Parsing error */
+    else if (gnc_numeric_negative_p (amount))
+        return FALSE; /* Negative cash amount is not allowed */
+
+    /* We have a positive cash amount */
+    account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(info->income_tree));
+    if (!account)
         return FALSE;
-    }
 
-    amount = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (info->cash_edit));
-
-    if (gnc_numeric_negative_p (amount))
-    {
-        const char *message = _("The cash distribution must be positive.");
-        gnc_error_dialog (info->window, "%s", message);
+    account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(info->asset_tree));
+    if (!account)
         return FALSE;
-    }
 
-    if (gnc_numeric_positive_p (amount))
-    {
-        Account *account;
-
-        account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(info->income_tree));
-        if (!account)
-        {
-            const char *message = _("You must select an income account "
-                                    "for the cash distribution.");
-            gnc_error_dialog (info->window, "%s", message);
-            return FALSE;
-        }
-
-        account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(info->asset_tree));
-        if (!account)
-        {
-            const char *message = _("You must select an asset account "
-                                    "for the cash distribution.");
-            gnc_error_dialog (info->window, "%s", message);
-            return FALSE;
-        }
-    }
-
     return TRUE;
 }
 
@@ -597,34 +529,28 @@
 
 
 static void
-gnc_stock_split_details_valid_button_cb (GtkButton *button, gpointer user_data)
+gnc_stock_split_details_valid_cb (GtkWidget *widget, gpointer user_data)
 {
    StockSplitInfo *info = user_data;
    GtkAssistant *assistant = GTK_ASSISTANT(info->window);
    gint num = gtk_assistant_get_current_page (assistant);
    GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
 
-   if(gnc_stock_split_assistant_details_test (assistant,user_data) == TRUE)
-   {
-       gtk_assistant_set_page_complete (assistant, page, TRUE);
-       gtk_assistant_set_current_page (assistant, num + 1);
-   }
+   gtk_assistant_set_page_complete (assistant, page,
+       gnc_stock_split_assistant_details_complete (assistant, user_data));
 }
 
 
 static void
-gnc_stock_split_cash_valid_button_cb (GtkButton *button, gpointer user_data)
+gnc_stock_split_cash_valid_cb (GtkWidget *widget, gpointer user_data)
 {
    StockSplitInfo *info = user_data;
    GtkAssistant *assistant = GTK_ASSISTANT(info->window);
    gint num = gtk_assistant_get_current_page (assistant);
    GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
 
-   if(gnc_stock_split_assistant_cash_test (assistant,user_data) == TRUE)
-   {
-       gtk_assistant_set_page_complete (assistant, page, TRUE);
-       gtk_assistant_set_current_page (assistant, num + 1);
-   }
+   gtk_assistant_set_page_complete (assistant, page,
+       gnc_stock_split_assistant_cash_complete (assistant, user_data));
 }
 
 
@@ -642,21 +568,16 @@
     /* Set the assistant colors */
     gnc_assistant_set_colors (GTK_ASSISTANT (info->window));
 
-    /* Enable buttons on first, second and last page. */
+    /* Enable buttons on first, second, fourth and last page. */
     gtk_assistant_set_page_complete (GTK_ASSISTANT (window),
                                      GTK_WIDGET(gtk_builder_get_object(builder, "intro_page_label")),
                                      TRUE);
     gtk_assistant_set_page_complete (GTK_ASSISTANT (window),
                                      GTK_WIDGET(gtk_builder_get_object(builder, "stock_account_page")),
                                      TRUE);
-/**
     gtk_assistant_set_page_complete (GTK_ASSISTANT (window),
-                                     GTK_WIDGET(gtk_builder_get_object(builder, "stock_details_page")),
-                                     TRUE);
-    gtk_assistant_set_page_complete (GTK_ASSISTANT (window),
                                      GTK_WIDGET(gtk_builder_get_object(builder, "stock_cash_page")),
                                      TRUE);
-**/
     gtk_assistant_set_page_complete (GTK_ASSISTANT (window),
                                      GTK_WIDGET(gtk_builder_get_object(builder, "finish_page_label")),
                                      TRUE);
@@ -710,7 +631,7 @@
         GtkWidget *date;
         GtkWidget *ce;
         GtkWidget *label;
-	GtkWidget *button;
+        GtkWidget *button;
 
         info->description_entry = GTK_WIDGET(gtk_builder_get_object(builder, "description_entry"));
 
@@ -723,8 +644,12 @@
 
         box = GTK_WIDGET(gtk_builder_get_object(builder, "distribution_box"));
         amount = gnc_amount_edit_new ();
+        g_signal_connect (amount, "changed",
+                          G_CALLBACK (gnc_stock_split_details_valid_cb), info);
+        gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (amount), TRUE);
         gtk_box_pack_start (GTK_BOX (box), amount, TRUE, TRUE, 0);
         info->distribution_edit = amount;
+
         label = GTK_WIDGET(gtk_builder_get_object(builder, "distribution_label"));
         gtk_label_set_mnemonic_widget(GTK_LABEL(label), amount);
 
@@ -732,22 +657,21 @@
         amount = gnc_amount_edit_new ();
         gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (amount),
                                         gnc_default_price_print_info ());
+        g_signal_connect (amount, "changed",
+                          G_CALLBACK (gnc_stock_split_details_valid_cb), info);
         gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (amount), TRUE);
         gtk_box_pack_start (GTK_BOX (box), amount, TRUE, TRUE, 0);
         info->price_edit = amount;
+
         label = GTK_WIDGET(gtk_builder_get_object(builder, "price_label"));
         gtk_label_set_mnemonic_widget(GTK_LABEL(label), amount);
 
         info->price_currency_edit = gnc_currency_edit_new();
         gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT(info->price_currency_edit), gnc_default_currency());
         gtk_widget_show (info->price_currency_edit);
+
         box = GTK_WIDGET(gtk_builder_get_object (builder, "price_currency_box"));
         gtk_box_pack_start(GTK_BOX(box), info->price_currency_edit, TRUE, TRUE, 0);
-
-        button = GTK_WIDGET(gtk_builder_get_object(builder, "stock_details_valid_button"));
-        g_signal_connect (G_OBJECT (button), "clicked",
-                    G_CALLBACK (gnc_stock_split_details_valid_button_cb), info);
-
     }
 
     /* Cash page Widgets */
@@ -757,12 +681,17 @@
         GtkWidget *amount;
         GtkWidget *label;
         GtkWidget *scroll;
-	GtkWidget *button;
+        GtkWidget *button;
+        GtkTreeSelection *selection;
 
         box = GTK_WIDGET(gtk_builder_get_object(builder, "cash_box"));
         amount = gnc_amount_edit_new ();
+        g_signal_connect (amount, "changed",
+                          G_CALLBACK (gnc_stock_split_cash_valid_cb), info);
+        gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (amount), TRUE);
         gtk_box_pack_start (GTK_BOX (box), amount, TRUE, TRUE, 0);
         info->cash_edit = amount;
+
         label = GTK_WIDGET(gtk_builder_get_object(builder, "cash_label"));
         gtk_label_set_mnemonic_widget(GTK_LABEL(label), amount);
 
@@ -778,6 +707,12 @@
 
         gtk_widget_show (tree);
 
+        gtk_tree_view_expand_all (GTK_TREE_VIEW(tree));
+        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(tree));
+        gtk_tree_selection_unselect_all (selection);
+        g_signal_connect (selection, "changed",
+                          G_CALLBACK (gnc_stock_split_cash_valid_cb), info);
+
         label = GTK_WIDGET(gtk_builder_get_object(builder, "income_label"));
         gtk_label_set_mnemonic_widget (GTK_LABEL(label), tree);
 
@@ -800,10 +735,11 @@
         scroll = GTK_WIDGET(gtk_builder_get_object(builder, "asset_scroll"));
         gtk_container_add (GTK_CONTAINER (scroll), tree);
 
-	button = GTK_WIDGET(gtk_builder_get_object(builder, "stock_cash_valid_button"));
-	g_signal_connect (G_OBJECT (button), "clicked",
-                    G_CALLBACK (gnc_stock_split_cash_valid_button_cb), info);
-
+        gtk_tree_view_expand_all (GTK_TREE_VIEW(tree));
+        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(tree));
+        gtk_tree_selection_unselect_all (selection);
+        g_signal_connect (selection, "changed",
+                          G_CALLBACK (gnc_stock_split_cash_valid_cb), info);
     }
 
     g_signal_connect (G_OBJECT(window), "destroy",

Modified: gnucash/trunk/src/gnome/gtkbuilder/stocks.glade
===================================================================
--- gnucash/trunk/src/gnome/gtkbuilder/stocks.glade	2011-05-19 23:20:23 UTC (rev 20663)
+++ gnucash/trunk/src/gnome/gtkbuilder/stocks.glade	2011-05-20 14:04:33 UTC (rev 20664)
@@ -1,18 +1,16 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0"?>
 <interface>
   <requires lib="gtk+" version="2.16"/>
   <!-- interface-naming-policy project-wide -->
   <object class="GtkAssistant" id="Stock Split Assistant">
     <property name="visible">True</property>
-    <property name="can_focus">False</property>
     <property name="border_width">12</property>
-    <signal name="close" handler="gnc_stock_split_assistant_finish" swapped="no"/>
-    <signal name="cancel" handler="gnc_stock_split_assistant_cancel" swapped="no"/>
-    <signal name="prepare" handler="gnc_stock_split_assistant_prepare" swapped="no"/>
+    <signal name="prepare" handler="gnc_stock_split_assistant_prepare"/>
+    <signal name="cancel" handler="gnc_stock_split_assistant_cancel"/>
+    <signal name="close" handler="gnc_stock_split_assistant_finish"/>
     <child>
       <object class="GtkLabel" id="intro_page_label">
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
         <property name="label" translatable="yes">This assistant will help you record a stock split or stock merger.
 </property>
         <property name="wrap">True</property>
@@ -25,11 +23,10 @@
     <child>
       <object class="GtkVBox" id="stock_account_page">
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
         <child>
           <object class="GtkLabel" id="stock_account_label">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
             <property name="label" translatable="yes">Select the account for which you want to record a stock split or merger.</property>
             <property name="justify">center</property>
           </object>
@@ -53,8 +50,6 @@
             </child>
           </object>
           <packing>
-            <property name="expand">True</property>
-            <property name="fill">True</property>
             <property name="position">1</property>
           </packing>
         </child>
@@ -66,11 +61,10 @@
     <child>
       <object class="GtkVBox" id="stock_details_page">
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
         <child>
           <object class="GtkLabel" id="stock_detail_label">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
             <property name="label" translatable="yes">Enter the date and the number of shares you gained or lost from the stock split or merger. For stock mergers (negative splits) use a negative value for the share distribution. You can also enter a description of the transaction, or accept the default one.</property>
             <property name="justify">center</property>
             <property name="wrap">True</property>
@@ -84,16 +78,14 @@
         <child>
           <object class="GtkTable" id="stock_details_table">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
             <property name="border_width">6</property>
-            <property name="n_rows">8</property>
+            <property name="n_rows">7</property>
             <property name="n_columns">2</property>
             <property name="column_spacing">6</property>
             <property name="row_spacing">12</property>
             <child>
               <object class="GtkLabel" id="date_label">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="xalign">0</property>
                 <property name="label" translatable="yes">_Date:</property>
                 <property name="use_underline">True</property>
@@ -107,7 +99,6 @@
             <child>
               <object class="GtkLabel" id="distribution_label">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="xalign">0</property>
                 <property name="label" translatable="yes">_Shares:</property>
                 <property name="use_underline">True</property>
@@ -123,7 +114,6 @@
             <child>
               <object class="GtkLabel" id="description_label">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="xalign">0</property>
                 <property name="label" translatable="yes">Desc_ription:</property>
                 <property name="use_underline">True</property>
@@ -141,10 +131,8 @@
               <object class="GtkEntry" id="description_entry">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="invisible_char">●</property>
+                <property name="invisible_char">&#x25CF;</property>
                 <property name="text" translatable="yes">Stock Split</property>
-                <property name="primary_icon_activatable">False</property>
-                <property name="secondary_icon_activatable">False</property>
                 <property name="primary_icon_sensitive">True</property>
                 <property name="secondary_icon_sensitive">True</property>
               </object>
@@ -160,7 +148,6 @@
             <child>
               <object class="GtkHSeparator" id="hseparator1">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
               </object>
               <packing>
                 <property name="right_attach">2</property>
@@ -173,7 +160,6 @@
             <child>
               <object class="GtkLabel" id="text_label">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="label" translatable="yes">If you want to record a stock price for the split, enter it below. You may safely leave it blank.</property>
                 <property name="use_underline">True</property>
                 <property name="justify">center</property>
@@ -190,7 +176,6 @@
             <child>
               <object class="GtkLabel" id="price_label">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="xalign">0</property>
                 <property name="label" translatable="yes">New _Price:</property>
                 <property name="use_underline">True</property>
@@ -206,7 +191,6 @@
             <child>
               <object class="GtkLabel" id="currency_label">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="xalign">0</property>
                 <property name="label" translatable="yes">Currenc_y:</property>
                 <property name="use_underline">True</property>
@@ -222,7 +206,6 @@
             <child>
               <object class="GtkHBox" id="date_box">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <child>
                   <placeholder/>
                 </child>
@@ -253,7 +236,6 @@
             <child>
               <object class="GtkHBox" id="price_box">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <child>
                   <placeholder/>
                 </child>
@@ -270,7 +252,6 @@
             <child>
               <object class="GtkHBox" id="price_currency_box">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <child>
                   <placeholder/>
                 </child>
@@ -284,25 +265,8 @@
                 <property name="y_options"></property>
               </packing>
             </child>
-            <child>
-              <object class="GtkButton" id="stock_details_valid_button">
-                <property name="label" translatable="yes"> Click to _Validate and Proceed </property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_action_appearance">False</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="right_attach">2</property>
-                <property name="top_attach">7</property>
-                <property name="bottom_attach">8</property>
-                <property name="x_options"></property>
-              </packing>
-            </child>
           </object>
           <packing>
-            <property name="expand">True</property>
             <property name="fill">False</property>
             <property name="position">1</property>
           </packing>
@@ -315,13 +279,12 @@
     <child>
       <object class="GtkVBox" id="stock_cash_page">
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
         <property name="border_width">6</property>
+        <property name="orientation">vertical</property>
         <property name="spacing">12</property>
         <child>
           <object class="GtkLabel" id="stock_cash_label">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
             <property name="label" translatable="yes">If you received a cash disbursement as a result of the stock split, enter the details of that payment here. Otherwise, just click `Forward'.</property>
             <property name="justify">center</property>
             <property name="wrap">True</property>
@@ -335,7 +298,6 @@
         <child>
           <object class="GtkTable" id="cash_table">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
             <property name="n_rows">2</property>
             <property name="n_columns">2</property>
             <property name="column_spacing">12</property>
@@ -343,7 +305,6 @@
             <child>
               <object class="GtkLabel" id="cash_label">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="label" translatable="yes">_Amount:</property>
                 <property name="use_underline">True</property>
                 <property name="justify">center</property>
@@ -356,7 +317,6 @@
             <child>
               <object class="GtkLabel" id="memo_label">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="label" translatable="yes">_Memo:</property>
                 <property name="use_underline">True</property>
                 <property name="justify">center</property>
@@ -373,10 +333,8 @@
               <object class="GtkEntry" id="memo_entry">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="invisible_char">●</property>
+                <property name="invisible_char">&#x25CF;</property>
                 <property name="text" translatable="yes">Cash In Lieu</property>
-                <property name="primary_icon_activatable">False</property>
-                <property name="secondary_icon_activatable">False</property>
                 <property name="primary_icon_sensitive">True</property>
                 <property name="secondary_icon_sensitive">True</property>
               </object>
@@ -412,14 +370,12 @@
         <child>
           <object class="GtkTable" id="cash_table2">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="n_rows">3</property>
+            <property name="n_rows">2</property>
             <property name="n_columns">2</property>
             <property name="column_spacing">12</property>
             <child>
               <object class="GtkLabel" id="income_label">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="label" translatable="yes">&lt;b&gt;_Income Account&lt;/b&gt;</property>
                 <property name="use_markup">True</property>
                 <property name="use_underline">True</property>
@@ -432,7 +388,6 @@
             <child>
               <object class="GtkLabel" id="asset_label">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="label" translatable="yes">&lt;b&gt;A_sset Account&lt;/b&gt;</property>
                 <property name="use_markup">True</property>
                 <property name="use_underline">True</property>
@@ -447,7 +402,6 @@
             <child>
               <object class="GtkAlignment" id="alignment2">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="left_padding">12</property>
                 <child>
                   <object class="GtkScrolledWindow" id="income_scroll">
@@ -470,7 +424,6 @@
             <child>
               <object class="GtkAlignment" id="alignment3">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <child>
                   <object class="GtkScrolledWindow" id="asset_scroll">
                     <property name="visible">True</property>
@@ -491,27 +444,8 @@
                 <property name="bottom_attach">2</property>
               </packing>
             </child>
-            <child>
-              <object class="GtkButton" id="stock_cash_valid_button">
-                <property name="label" translatable="yes"> Click to _Validate and Proceed </property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_action_appearance">False</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="right_attach">2</property>
-                <property name="top_attach">2</property>
-                <property name="bottom_attach">3</property>
-                <property name="x_options"></property>
-                <property name="y_options"></property>
-              </packing>
-            </child>
           </object>
           <packing>
-            <property name="expand">True</property>
-            <property name="fill">True</property>
             <property name="position">2</property>
           </packing>
         </child>
@@ -523,7 +457,6 @@
     <child>
       <object class="GtkLabel" id="finish_page_label">
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
         <property name="label" translatable="yes">If you are finished creating the stock split or merger, press `Apply'. You may also press `Back' to review your choices, or `Cancel' to quit without making any changes.</property>
         <property name="wrap">True</property>
       </object>

Modified: gnucash/trunk/src/gnome-utils/gnc-amount-edit.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-amount-edit.c	2011-05-19 23:20:23 UTC (rev 20663)
+++ gnucash/trunk/src/gnome-utils/gnc-amount-edit.c	2011-05-20 14:04:33 UTC (rev 20664)
@@ -206,6 +206,57 @@
 }
 
 /**
+ * gnc_amount_edit_expr_is_valid
+ * @gae: The GNCAmountEdit widget
+ * @amount: parameter to hold the value of the parsed expression
+ * @empty_ok: if true, an empty field is skipped, otherwise an empty field
+ *            parses as 0
+ *
+ * If needed, parse the expression in the amount entry. If there's no
+ * parsing error, it returns the amount, otherwise it returns the
+ * position in the expression where the error occurred.
+ *
+ * Return *  0 if the parsing was successful (note that if !empty_ok,
+ *             an empty field will parse to 0)
+ *        * -1 if the field is empty and that's ok (empty_ok)
+ *        * error position if there was a parsing error
+ */
+gint
+gnc_amount_edit_expr_is_valid (GNCAmountEdit *gae, gnc_numeric *amount,
+                               gboolean empty_ok)
+{
+    const char *string;
+    char *error_loc;
+    gboolean ok;
+
+    g_return_val_if_fail(gae != NULL, -1);
+    g_return_val_if_fail(GNC_IS_AMOUNT_EDIT(gae), -1);
+
+    string = gtk_entry_get_text(GTK_ENTRY(gae));
+    if (!string || *string == '\0')
+    {
+        *amount = gnc_numeric_zero();
+        if (empty_ok)
+            return -1; /* indicate an empty field */
+        else
+            return 0; /* indicate successfully parsed as 0 */
+    }
+
+    error_loc = NULL;
+    ok = gnc_exp_parser_parse (string, amount, &error_loc);
+
+    if (ok)
+        return 0;
+
+    /* Not ok */
+    if (error_loc != NULL)
+        return  error_loc - string;
+    else
+        return 1;
+}
+
+
+/**
  * gnc_amount_edit_evaluate
  * @gae: The GNCAmountEdit widget
  *
@@ -219,35 +270,22 @@
 gboolean
 gnc_amount_edit_evaluate (GNCAmountEdit *gae)
 {
-    const char *string;
-    char *error_loc;
+    gint result;
     gnc_numeric amount;
-    gboolean ok;
 
     g_return_val_if_fail(gae != NULL, FALSE);
     g_return_val_if_fail(GNC_IS_AMOUNT_EDIT(gae), FALSE);
 
+
     if (!gae->need_to_parse)
         return TRUE;
 
-    string = gtk_entry_get_text(GTK_ENTRY(gae));
-    if (!string || *string == '\0')
-    {
-        gnc_numeric old_amount = gae->amount;
+    result = gnc_amount_edit_expr_is_valid (gae, &amount, FALSE);
 
-        gnc_amount_edit_set_amount (gae, gnc_numeric_zero ());
-
-        if (!gnc_numeric_equal (gnc_numeric_zero (), old_amount))
-            g_signal_emit (gae, amount_edit_signals [AMOUNT_CHANGED], 0);
-
+    if (result == -1)  /* field was empty and may remain so */
         return TRUE;
-    }
 
-    error_loc = NULL;
-
-    ok = gnc_exp_parser_parse (string, &amount, &error_loc);
-
-    if (ok)
+    if (result == 0)  /* parsing successful */
     {
         gnc_numeric old_amount = gae->amount;
 
@@ -262,10 +300,8 @@
         return TRUE;
     }
 
-    /* Not ok */
-    if (error_loc != NULL)
-        gtk_editable_set_position (GTK_EDITABLE(gae), error_loc - string);
-
+    /* Parse error */
+    gtk_editable_set_position (GTK_EDITABLE(gae), result);
     return FALSE;
 }
 

Modified: gnucash/trunk/src/gnome-utils/gnc-amount-edit.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-amount-edit.h	2011-05-19 23:20:23 UTC (rev 20663)
+++ gnucash/trunk/src/gnome-utils/gnc-amount-edit.h	2011-05-20 14:04:33 UTC (rev 20664)
@@ -75,6 +75,8 @@
 gnc_numeric gnc_amount_edit_get_amount    (GNCAmountEdit *gae);
 double      gnc_amount_edit_get_damount   (GNCAmountEdit *gae);
 
+gint      gnc_amount_edit_expr_is_valid (GNCAmountEdit *gae, gnc_numeric *amount,
+                                         gboolean empty_ok);
 gboolean  gnc_amount_edit_evaluate        (GNCAmountEdit *gae);
 
 void      gnc_amount_edit_set_print_info  (GNCAmountEdit *gae,



More information about the gnucash-changes mailing list