r23620 - gnucash/trunk/src - Bug 720646 - New Book Tabs on Windows

Geert Janssens gjanssens at code.gnucash.org
Thu Dec 26 08:47:40 EST 2013


Author: gjanssens
Date: 2013-12-26 08:47:39 -0500 (Thu, 26 Dec 2013)
New Revision: 23620
Trac: http://svn.gnucash.org/trac/changeset/23620

Modified:
   gnucash/trunk/src/gnome-utils/dialog-options.c
   gnucash/trunk/src/gnome-utils/dialog-options.h
   gnucash/trunk/src/gnome/assistant-hierarchy.c
   gnucash/trunk/src/gnome/gtkbuilder/assistant-hierarchy.glade
Log:
Bug 720646 - New Book Tabs on Windows

Modified: gnucash/trunk/src/gnome/assistant-hierarchy.c
===================================================================
--- gnucash/trunk/src/gnome/assistant-hierarchy.c	2013-12-26 13:47:30 UTC (rev 23619)
+++ gnucash/trunk/src/gnome/assistant-hierarchy.c	2013-12-26 13:47:39 UTC (rev 23620)
@@ -33,6 +33,7 @@
 
 #include "gnc-account-merge.h"
 #include "dialog-new-user.h"
+#include "dialog-options.h"
 #include "dialog-utils.h"
 #include "dialog-file-access.h"
 #include "assistant-hierarchy.h"
@@ -41,6 +42,7 @@
 #include "gnc-currency-edit.h"
 #include "gnc-exp-parser.h"
 #include "gnc-general-select.h"
+#include "gnc-gnome-utils.h"
 #include "gnc-prefs.h"
 #include "gnc-hooks.h"
 #include "gnc-component-manager.h"
@@ -99,6 +101,9 @@
     gboolean use_defaults;
     gboolean new_book;  /* presumably only used for new book creation but we check*/
 
+    GNCOptionDB *options;
+    GNCOptionWin *optionwin;
+
     GncHierarchyAssistantFinishedCallback when_completed;
 
 } hierarchy_data;
@@ -457,11 +462,6 @@
 {
     GtkTextBuffer* buffer;
 
-    /* Before creating transactions, if this is a new book, let user specify
-     * book options, since they affect how transactions are created */
-    if (data->new_book)
-        data->new_book = gnc_new_book_option_display (data->dialog);
-
     if (!data->account_list_added)
     {
         /* clear out the description/tree */
@@ -997,6 +997,8 @@
            hierarchy_data  *data)
 {
     gnc_suspend_gui_refresh ();
+    if (data->new_book)
+        gtk_dialog_response(GTK_DIALOG(gnc_options_dialog_widget (data->optionwin)), GTK_RESPONSE_CANCEL);
     delete_hierarchy_dialog (data);
     delete_our_account_tree (data);
     g_free(data);
@@ -1004,6 +1006,27 @@
 }
 
 static void
+finish_book_options_helper(GNCOptionWin * optionwin,
+                          gpointer user_data)
+{
+    GNCOptionDB * options = user_data;
+    kvp_frame *slots = qof_book_get_slots (gnc_get_current_book ());
+    gboolean use_split_action_for_num_before =
+        qof_book_use_split_action_for_num_field (gnc_get_current_book ());
+    gboolean use_split_action_for_num_after;
+
+    if (!options) return;
+
+    gnc_option_db_commit (options);
+    gnc_option_db_save_to_kvp (options, slots, TRUE);
+    qof_book_kvp_changed (gnc_get_current_book());
+    use_split_action_for_num_after =
+        qof_book_use_split_action_for_num_field (gnc_get_current_book ());
+    if (use_split_action_for_num_before != use_split_action_for_num_after)
+        gnc_book_option_num_field_source_change_cb (use_split_action_for_num_after);
+}
+
+static void
 starting_balance_helper (Account *account, hierarchy_data *data)
 {
     gnc_numeric balance;
@@ -1035,6 +1058,10 @@
 
     }
 
+    /* Set book options based on the user's choices */
+    if (data->new_book)
+        finish_book_options_helper(data->optionwin, data->options);
+
     // delete before we suspend GUI events, and then muck with the model,
     // because the model doesn't seem to handle this correctly.
     if (data->initial_category)
@@ -1042,6 +1069,8 @@
     delete_hierarchy_dialog (data);
 
     gnc_suspend_gui_refresh ();
+    if (data->new_book)
+        gtk_dialog_response(GTK_DIALOG(gnc_options_dialog_widget (data->optionwin)), GTK_RESPONSE_CANCEL);
 
     account_trees_merge(gnc_get_current_root_account(), data->our_account_tree);
 
@@ -1063,6 +1092,58 @@
     LEAVE (" ");
 }
 
+/********************************************************
+ * For a new book the assistant will also allow the user
+ * to set default book options, because this impacts how
+ * transactions are created.
+ * Ideally, the book options code can cleanly provide us
+ * with a page to insert in the assistant and be done with
+ * it. Unfortunately this is not possible without a serious
+ * rewrite of the options dialog code.
+ * So instead the following hack is used:
+ * we create the complete dialog, but only use the notebook
+ * part of it to create a new page.
+ * To make sure this dialog is cleaned up properly
+ * when the assistant closes, the close callback is set up anyway
+ * and at the finish we'll send a "close" response signal to the
+ * dialog to make it clean up after itself.
+ */
+static void
+book_options_dialog_close_cb(GNCOptionWin * optionwin,
+                               gpointer user_data)
+{
+    GNCOptionDB * options = user_data;
+
+    gnc_options_dialog_destroy(optionwin);
+    gnc_option_db_destroy(options);
+}
+
+static void
+assistant_instert_book_options_page (hierarchy_data *data)
+{
+    kvp_frame *slots = qof_book_get_slots (gnc_get_current_book ());
+    GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
+
+    data->options = gnc_option_db_new_for_type (QOF_ID_BOOK);
+    gnc_option_db_load_from_kvp (data->options, slots);
+    gnc_option_db_clean (data->options);
+
+    data->optionwin = gnc_options_dialog_new_modal (TRUE, _("New Book Options"));
+    gnc_options_dialog_build_contents_full (data->optionwin, data->options, FALSE);
+
+    gnc_options_dialog_set_close_cb (data->optionwin,
+                                     book_options_dialog_close_cb,
+                                     (gpointer)data->options);
+    gnc_options_dialog_set_new_book_option_values (data->options);
+
+    gtk_widget_reparent (gnc_options_dialog_notebook (data->optionwin), vbox);
+    gtk_widget_show_all (vbox);
+    gtk_assistant_insert_page (GTK_ASSISTANT(data->dialog), vbox, 2);
+    gtk_assistant_set_page_title (GTK_ASSISTANT(data->dialog), vbox, _("New Book Options"));
+    gtk_assistant_set_page_complete (GTK_ASSISTANT(data->dialog), vbox, TRUE);
+
+}
+
 static GtkWidget *
 gnc_create_hierarchy_assistant (gboolean use_defaults, GncHierarchyAssistantFinishedCallback when_completed)
 {
@@ -1126,6 +1207,10 @@
     data->category_description = GTK_TEXT_VIEW(gtk_builder_get_object (builder, "account_types_description"));
     data->account_list_added = FALSE;
 
+    /* Book options page - only on new books */
+    if (data->new_book)
+        assistant_instert_book_options_page (data);
+
     /* Final Accounts Page */
     data->final_account_tree_container = GTK_WIDGET(gtk_builder_get_object (builder, "final_account_tree_box"));
     data->final_account_tree = NULL;

Modified: gnucash/trunk/src/gnome/gtkbuilder/assistant-hierarchy.glade
===================================================================
--- gnucash/trunk/src/gnome/gtkbuilder/assistant-hierarchy.glade	2013-12-26 13:47:30 UTC (rev 23619)
+++ gnucash/trunk/src/gnome/gtkbuilder/assistant-hierarchy.glade	2013-12-26 13:47:39 UTC (rev 23620)
@@ -93,32 +93,6 @@
           </packing>
         </child>
         <child>
-          <object class="GtkLabel" id="book_option_label">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="label" translatable="yes"><b>Book Options</b></property>
-            <property name="use_markup">True</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
-            <property name="position">2</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="book_option_message_label">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="label" translatable="yes">Since you are creating a new file, you will next see a dialog for setting book options. These can affect how GnuCash transactions are handled later, during account setup. If you come back to this page without cancelling and starting over, the dialog for setting book options will not be shown a second time when you go forward. You can access it directly from the menu via File->Properties.</property>
-            <property name="wrap">True</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
-            <property name="position">3</property>
-          </packing>
-        </child>
-        <child>
           <placeholder/>
         </child>
       </object>

Modified: gnucash/trunk/src/gnome-utils/dialog-options.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-options.c	2013-12-26 13:47:30 UTC (rev 23619)
+++ gnucash/trunk/src/gnome-utils/dialog-options.c	2013-12-26 13:47:39 UTC (rev 23620)
@@ -1176,16 +1176,34 @@
 /********************************************************************\
  * gnc_options_dialog_build_contents                                *
  *   builds an options dialog given a property box and an options   *
- *   database                                                       *
+ *   database and make the dialog visible                           *
  *                                                                  *
  * Args: propertybox - gnome property box to use                    *
  *       odb         - option database to use                       *
  * Return: nothing                                                  *
 \********************************************************************/
 void
-gnc_options_dialog_build_contents(GNCOptionWin *propertybox,
-                                  GNCOptionDB  *odb)
+gnc_options_dialog_build_contents (GNCOptionWin *propertybox,
+                                   GNCOptionDB  *odb)
 {
+    gnc_options_dialog_build_contents_full (propertybox, odb, TRUE);
+}
+
+/********************************************************************\
+ * gnc_options_dialog_build_contents                                *
+ *   builds an options dialog given a property box and an options   *
+ *   database and make the dialog visible depending on the          *
+ *   show_dialog flag                                               *
+ *                                                                  *
+ * Args: propertybox - gnome property box to use                    *
+ *       odb         - option database to use                       *
+ *       show_dialog - should dialog be made visible or not         *
+ * Return: nothing                                                  *
+\********************************************************************/
+void
+gnc_options_dialog_build_contents_full (GNCOptionWin *propertybox,
+                                        GNCOptionDB  *odb, gboolean show_dialog)
+{
     GNCOptionSection *section;
     gchar *default_section_name;
     gint default_page = -1;
@@ -1252,7 +1270,8 @@
         gtk_notebook_set_current_page(GTK_NOTEBOOK(propertybox->notebook), default_page);
     }
     gnc_options_dialog_changed_internal(propertybox->dialog, FALSE);
-    gtk_widget_show(propertybox->dialog);
+    if (show_dialog)
+        gtk_widget_show(propertybox->dialog);
 }
 
 GtkWidget *

Modified: gnucash/trunk/src/gnome-utils/dialog-options.h
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-options.h	2013-12-26 13:47:30 UTC (rev 23619)
+++ gnucash/trunk/src/gnome-utils/dialog-options.h	2013-12-26 13:47:39 UTC (rev 23620)
@@ -66,6 +66,10 @@
 void gnc_options_dialog_build_contents(GNCOptionWin *win,
                                        GNCOptionDB  *odb);
 
+void gnc_options_dialog_build_contents_full(GNCOptionWin *win,
+                                            GNCOptionDB  *odb,
+                                            gboolean show_dialog);
+
 /* Both apply_cb and close_cb should be scheme functions with 0 arguments.
  * References to these functions will be held until the close_cb is called
  */



More information about the gnucash-changes mailing list