Bug 720646 - New Book Tabs on Windows

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@23620 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Geert Janssens 2013-12-26 13:47:39 +00:00
parent 1e1c705a14
commit 01b6bcaeb9
4 changed files with 117 additions and 35 deletions

View File

@ -1176,15 +1176,33 @@ gnc_options_dialog_append_page(GNCOptionWin * propertybox,
/********************************************************************\
* 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;
@ -1252,7 +1270,8 @@ gnc_options_dialog_build_contents(GNCOptionWin *propertybox,
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 *

View File

@ -66,6 +66,10 @@ void gnc_options_dialog_set_global_help_cb(GNCOptionWinCallback thunk,
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
*/

View File

@ -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 @@ typedef struct
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 @@ on_choose_account_categories_prepare (hierarchy_data *data)
{
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,12 +997,35 @@ on_cancel (GtkAssistant *gtkassistant,
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);
gnc_resume_gui_refresh ();
}
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)
{
@ -1035,6 +1058,10 @@ on_finish (GtkAssistant *gtkassistant,
}
/* 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 @@ on_finish (GtkAssistant *gtkassistant,
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 @@ on_finish (GtkAssistant *gtkassistant,
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 @@ gnc_create_hierarchy_assistant (gboolean use_defaults, GncHierarchyAssistantFini
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;

View File

@ -92,32 +92,6 @@ Please choose the currency to use for new accounts.</property>
<property name="position">1</property>
</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">&lt;b&gt;Book Options&lt;/b&gt;</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>