From abae418947fd078d2b17fcb88fbabfd1ef4ad9b4 Mon Sep 17 00:00:00 2001 From: Joshua Sled Date: Sun, 19 Feb 2006 16:36:08 +0000 Subject: [PATCH] Implement new-hierarchy-druid placeholder-value merge policy as discussed on -devel. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13297 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 10 ++++ src/app-utils/gnc-account-merge.c | 41 -------------- src/app-utils/gnc-account-merge.h | 4 -- src/gnome/druid-hierarchy.c | 89 ++++++++++++++++++++++++------- 4 files changed, 81 insertions(+), 63 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3f170b2254..d51d1c2bd3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-02-19 Joshua Sled + + * src/app-utils/gnc-account-merge.[ch]: Remove placeholder-difference + "ERROR" merge state. + + * src/gnome/druid-hierarchy.c (placeholder_cell_data_func) + (on_final_account_prepare): Remove use of default + account-tree-model placeholder column, and substitute a column + that reflects the post-merge value. + 2006-02-19 Derek Atkins * src/engine/TransLog.c: use TABS not SPACES for column separators diff --git a/src/app-utils/gnc-account-merge.c b/src/app-utils/gnc-account-merge.c index 91cf2ee9eb..4b16b381c7 100644 --- a/src/app-utils/gnc-account-merge.c +++ b/src/app-utils/gnc-account-merge.c @@ -12,10 +12,6 @@ determine_account_merge_disposition(Account *existing_acct, Account *new_acct) if (existing_acct == NULL) return GNC_ACCOUNT_MERGE_DISPOSITION_CREATE_NEW; - if (xaccAccountGetPlaceholder(existing_acct) != xaccAccountGetPlaceholder(new_acct)) -/* return GNC_ACCOUNT_MERGE_DISPOSITION_ERROR;*/ - return GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING; - return GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING; } @@ -33,40 +29,6 @@ determine_merge_disposition(AccountGroup *existing_root, Account *new_acct) return determine_account_merge_disposition(existing_acct, new_acct); } -static void -_account_merge_error_detection(AccountGroup *existing_grp, AccountGroup *new_grp, GList **error_accum) -{ - AccountList *accts; - for (accts = xaccGroupGetAccountList(new_grp); accts; accts = accts->next) - { - Account *new_acct, *existing_acct; - GncAccountMergeDisposition disp; - - new_acct = (Account*)accts->data; - existing_acct = xaccGetAccountFromName(existing_grp, xaccAccountGetName(new_acct)); - disp = determine_account_merge_disposition(existing_acct, new_acct); - if (disp == GNC_ACCOUNT_MERGE_DISPOSITION_ERROR) - { - GncAccountMergeError *err = g_new0(GncAccountMergeError, 1); - err->existing_acct = existing_acct; - err->new_acct = new_acct; - err->disposition = disp; - *error_accum = g_list_append(*error_accum, err); - } - _account_merge_error_detection(xaccAccountGetChildren(existing_acct), - xaccAccountGetChildren(new_acct), - error_accum); - } -} - -GList* -account_merge_error_detection(AccountGroup *existing_grp, AccountGroup *new_grp) -{ - GList *errors = NULL; - _account_merge_error_detection(existing_grp, new_grp, &errors); - return errors; -} - void account_group_merge(AccountGroup *existing_grp, AccountGroup *new_grp) { @@ -89,9 +51,6 @@ account_group_merge(AccountGroup *existing_grp, AccountGroup *new_grp) existing_named = xaccGetAccountFromName(existing_grp, name); switch (determine_account_merge_disposition(existing_named, new_acct)) { - case GNC_ACCOUNT_MERGE_DISPOSITION_ERROR: - g_assert_not_reached(); - return; case GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING: /* recurse */ account_group_merge(xaccAccountGetChildren(existing_named), diff --git a/src/app-utils/gnc-account-merge.h b/src/app-utils/gnc-account-merge.h index dba441f859..f91d1f9244 100644 --- a/src/app-utils/gnc-account-merge.h +++ b/src/app-utils/gnc-account-merge.h @@ -7,7 +7,6 @@ #include "Group.h" typedef enum { - GNC_ACCOUNT_MERGE_DISPOSITION_ERROR, GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING, GNC_ACCOUNT_MERGE_DISPOSITION_CREATE_NEW } GncAccountMergeDisposition; @@ -21,9 +20,6 @@ typedef struct _merge_error { GncAccountMergeDisposition determine_account_merge_disposition(Account *existing_acct, Account *new_acct); GncAccountMergeDisposition determine_merge_disposition(AccountGroup *existing_root, Account *new_acct); -/** @return GList **/ -GList* account_merge_error_detection(AccountGroup *existing_grp, AccountGroup *new_grp); - void account_group_merge(AccountGroup *existing_grp, AccountGroup *new_grp); #endif /* GNC_ACCOUNT_MERGE_H */ diff --git a/src/gnome/druid-hierarchy.c b/src/gnome/druid-hierarchy.c index f916bfb36b..6bf322223b 100644 --- a/src/gnome/druid-hierarchy.c +++ b/src/gnome/druid-hierarchy.c @@ -650,6 +650,42 @@ balance_cell_edited (GtkCellRendererText *cell, gnc_engine_gen_event ((QofEntity*)account, GNC_EVENT_MODIFY); } +static void +placeholder_cell_data_func (GtkTreeViewColumn *tree_column, + GtkCellRenderer *cell, + GtkTreeModel *model, + GtkTreeIter *iter, + gpointer user_data) +{ + Account *account; + gboolean willbe_placeholder = FALSE; + GncAccountMergeDisposition disp; + + g_return_if_fail (GTK_TREE_MODEL (model)); + account = gnc_tree_view_account_get_account_from_iter (model, iter); + disp = determine_merge_disposition(gnc_book_get_group(gnc_get_current_book()), account); + switch (disp) + { + case GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING: { + /* find the existing account, do whatever it is. */ + const char sep_char = '.'; + gchar *full_name; + Account *existing_acct; + AccountGroup *root_group = gnc_book_get_group(gnc_get_current_book()); + full_name = xaccAccountGetFullName(account, sep_char); + existing_acct = xaccGetAccountFromFullName(root_group, full_name, sep_char); + willbe_placeholder = xaccAccountGetPlaceholder(existing_acct); + g_free(full_name); + } break; + case GNC_ACCOUNT_MERGE_DISPOSITION_CREATE_NEW: + willbe_placeholder = xaccAccountGetPlaceholder(account); + break; + } + + gtk_cell_renderer_toggle_set_active(GTK_CELL_RENDERER_TOGGLE(cell), willbe_placeholder); +} + + static void use_existing_account_data_func(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, @@ -674,9 +710,6 @@ use_existing_account_data_func(GtkTreeViewColumn *tree_column, disposition = determine_merge_disposition(real_root, new_acct); switch (disposition) { - case GNC_ACCOUNT_MERGE_DISPOSITION_ERROR: - to_user = "error: placeholders different"; - break; case GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING: to_user = "yes"; break; @@ -736,27 +769,47 @@ on_final_account_prepare (GnomeDruidPage *gnomedruidpage, gtk_tree_view_set_headers_visible (tree_view, TRUE); gnc_tree_view_configure_columns (GNC_TREE_VIEW(data->final_account_tree), - "type", "placeholder", NULL); + "type", /*"placeholder", */ NULL); gnc_tree_view_set_show_column_menu (GNC_TREE_VIEW(data->final_account_tree), FALSE); selection = gtk_tree_view_get_selection (tree_view); gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), - "xalign", 1.0, - (char *)NULL); - g_signal_connect (G_OBJECT (renderer), "edited", - G_CALLBACK (balance_cell_edited), - data); - column = gtk_tree_view_column_new_with_attributes (_("Opening Balance"), - renderer, - NULL); - gtk_tree_view_column_set_cell_data_func (column, renderer, - balance_cell_data_func, - (gpointer)data, NULL); - gnc_tree_view_append_column (GNC_TREE_VIEW(tree_view), column); + // This is a re-definition of the placeholder that the account-tree model + // provides, reflecting the to-be-created state of the account tree + // post-merge. + { + renderer = gtk_cell_renderer_toggle_new(); + g_object_set(G_OBJECT (renderer), + "activatable", FALSE, + "sensitive", FALSE, + NULL); + column = gtk_tree_view_column_new_with_attributes(_("Placeholder"), + renderer, NULL); + gtk_tree_view_column_set_cell_data_func (column, renderer, + placeholder_cell_data_func, + (gpointer)data, NULL); + gnc_tree_view_append_column (GNC_TREE_VIEW(tree_view), column); + } + + + { + renderer = gtk_cell_renderer_text_new (); + g_object_set (G_OBJECT (renderer), + "xalign", 1.0, + (char *)NULL); + g_signal_connect (G_OBJECT (renderer), "edited", + G_CALLBACK (balance_cell_edited), + data); + column = gtk_tree_view_column_new_with_attributes (_("Opening Balance"), + renderer, + NULL); + gtk_tree_view_column_set_cell_data_func (column, renderer, + balance_cell_data_func, + (gpointer)data, NULL); + gnc_tree_view_append_column (GNC_TREE_VIEW(tree_view), column); + } // only in the case where there *are* existing accounts... if (xaccGroupGetNumSubAccounts(gnc_book_get_group(gnc_get_current_book())) > 0)