[Gnucash-changes] r13429 - gnucash/trunk - Collapse the common
parts of the "new account" and "edit account"
David Hampton
hampton at cvs.gnucash.org
Tue Feb 28 22:54:44 EST 2006
Author: hampton
Date: 2006-02-28 22:54:43 -0500 (Tue, 28 Feb 2006)
New Revision: 13429
Trac: http://svn.gnucash.org/trac/changeset/13429
Modified:
gnucash/trunk/ChangeLog
gnucash/trunk/src/gnome-utils/dialog-account.c
Log:
Collapse the common parts of the "new account" and "edit account"
dialog validation code into a single routine. Fixes 117812.
Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog 2006-03-01 03:28:49 UTC (rev 13428)
+++ gnucash/trunk/ChangeLog 2006-03-01 03:54:43 UTC (rev 13429)
@@ -1,5 +1,9 @@
2006-02-28 David Hampton <hampton at employees.org>
+ * src/gnome-utils/dialog-account.c: Collapse the common parts of
+ the "new account" and "edit account" dialog validation code into a
+ single routine. Fixes 117812.
+
* src/app-utils/options.scm: Andreas Köhler's patch to correctly
build a html color value. Fixes 328933.
Modified: gnucash/trunk/src/gnome-utils/dialog-account.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-account.c 2006-03-01 03:28:49 UTC (rev 13428)
+++ gnucash/trunk/src/gnome-utils/dialog-account.c 2006-03-01 03:54:43 UTC (rev 13429)
@@ -716,72 +716,112 @@
}
-static void
-gnc_edit_account_ok(AccountWindow *aw)
+static gboolean
+gnc_common_ok (AccountWindow *aw)
{
- GHashTable *change_type;
+ Account *account, *parent;
+ AccountGroup *group;
+ gnc_commodity * commodity;
+ gchar separator, sep_string[2];
+ gchar *fullname, *fullname_parent;
+ const gchar *name;
- gboolean change_children;
- gboolean has_children;
- gboolean change_all;
+ ENTER("aw %p", aw);
+ group = gnc_get_current_group ();
- Account *new_parent;
- Account *account;
- AccountGroup *children;
+ separator = gnc_get_account_separator();
- GNCAccountType current_type;
-
- const char *name;
- gnc_commodity * commodity;
-
/* check for valid name */
- ENTER("aw %p", aw);
name = gtk_entry_get_text(GTK_ENTRY(aw->name_entry));
- if (safe_strcmp(name, "") == 0)
- {
+ if (safe_strcmp(name, "") == 0) {
const char *message = _("The account must be given a name.");
gnc_error_dialog(aw->dialog, message);
- LEAVE(" ");
- return;
+ LEAVE("bad name");
+ return FALSE;
}
- /* check for valid type */
- if (aw->type == BAD_TYPE)
- {
- const char *message = _("You must select an account type.");
+ /* check for a duplicate name */
+ parent = gnc_tree_view_account_get_selected_account
+ (GNC_TREE_VIEW_ACCOUNT (aw->parent_tree));
+ if (parent == NULL) {
+ account = xaccGetAccountFromFullName(group, name, separator);
+ } else {
+ sep_string[0] = separator;
+ sep_string[1] = '\0';
+
+ fullname_parent = xaccAccountGetFullName(parent, separator);
+ fullname = g_strconcat(fullname_parent, sep_string, name, NULL);
+
+ account = xaccGetAccountFromFullName(group, fullname, separator);
+
+ g_free(fullname_parent);
+ g_free(fullname);
+ }
+ if (account != NULL) {
+ const char *message = _("There is already an account with that name.");
gnc_error_dialog(aw->dialog, message);
- LEAVE(" ");
- return;
+ LEAVE("duplicate name");
+ return FALSE;
}
- new_parent = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT (aw->parent_tree));
-
/* Parent check, probably not needed, but be safe */
- if (!gnc_filter_parent_accounts(new_parent, aw))
- {
+ if (!gnc_filter_parent_accounts(parent, aw)) {
const char *message = _("You must choose a valid parent account.");
gnc_error_dialog(aw->dialog, message);
- LEAVE(" ");
- return;
+ LEAVE("invalid parent");
+ return FALSE;
}
+ /* check for valid type */
+ if (aw->type == BAD_TYPE) {
+ const char *message = _("You must select an account type.");
+ gnc_error_dialog(aw->dialog, message);
+ LEAVE("invalid type");
+ return FALSE;
+ }
+
+ /* check for commodity */
commodity = (gnc_commodity *)
gnc_general_select_get_selected (GNC_GENERAL_SELECT (aw->commodity_edit));
-
- if (!commodity)
- {
+ if (!commodity) {
const char *message = _("You must choose a commodity.");
gnc_error_dialog(aw->dialog, message);
- LEAVE(" ");
- return;
+ LEAVE("invalid commodity");
+ return FALSE;
}
+ LEAVE("passed");
+ return TRUE;
+}
+
+static void
+gnc_edit_account_ok(AccountWindow *aw)
+{
+ GHashTable *change_type;
+
+ gboolean change_children;
+ gboolean has_children;
+ gboolean change_all;
+
+ Account *new_parent;
+ Account *account;
+ AccountGroup *children;
+
+ GNCAccountType current_type;
+
+ ENTER("aw %p", aw);
+
account = aw_get_account (aw);
if (!account) {
LEAVE(" ");
return;
}
+ if (!gnc_common_ok(aw)) {
+ LEAVE(" ");
+ return;
+ }
+
change_type = g_hash_table_new (NULL, NULL);
children = xaccAccountGetChildren(account);
@@ -801,6 +841,7 @@
/* If the new parent's type is not compatible with the new type,
* the whole sub-tree containing the account must be re-typed. */
+ new_parent = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT (aw->parent_tree));
if (new_parent != aw->top_level_account)
{
int parent_type;
@@ -855,87 +896,15 @@
static void
gnc_new_account_ok (AccountWindow *aw)
{
- const gnc_commodity * commodity;
- Account *parent_account;
gnc_numeric balance;
- const gchar *name;
- /* check for valid name */
ENTER("aw %p", aw);
- name = gtk_entry_get_text(GTK_ENTRY(aw->name_entry));
- if (safe_strcmp(name, "") == 0)
- {
- const char *message = _("The account must be given a name.");
- gnc_error_dialog(aw->dialog, message);
- LEAVE(" ");
- return;
- }
- parent_account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT (aw->parent_tree));
-
- if (parent_account == aw->top_level_account)
- parent_account = NULL;
-
- /* check for a duplicate name */
- {
- Account *account;
- AccountGroup *group;
- char separator;
-
- group = gnc_get_current_group ();
-
- separator = gnc_get_account_separator();
-
- if (parent_account == NULL)
- account = xaccGetAccountFromFullName(group, name, separator);
- else
- {
- char *fullname_parent;
- char *fullname;
- char sep_string[2];
-
- sep_string[0] = separator;
- sep_string[1] = '\0';
-
- fullname_parent = xaccAccountGetFullName(parent_account, separator);
- fullname = g_strconcat(fullname_parent, sep_string, name, NULL);
-
- account = xaccGetAccountFromFullName(group, fullname, separator);
-
- g_free(fullname_parent);
- g_free(fullname);
- }
-
- if (account != NULL)
- {
- const char *message = _("There is already an account with that name.");
- gnc_error_dialog(aw->dialog, message);
- LEAVE(" ");
- return;
- }
- }
-
- /* check for valid type */
- if (aw->type == BAD_TYPE)
- {
- const char *message = _("You must select an account type.");
- gnc_error_dialog(aw->dialog, message);
+ if (!gnc_common_ok(aw)) {
LEAVE(" ");
return;
}
- /* check for commodity */
- commodity = (gnc_commodity *)
- gnc_general_select_get_selected (GNC_GENERAL_SELECT (aw->commodity_edit));
-
- if (!commodity)
- {
- const char *message = _("You must choose a commodity.");
- gnc_error_dialog(aw->dialog, message);
- LEAVE(" ");
- return;
- }
-
if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (aw->opening_balance_edit)))
{
const char *message = _("You must enter a valid opening balance "
More information about the gnucash-changes
mailing list