Improve handling of the account in the account dialog.

* rename xaccAccountTypesCompatibleWith to
  xaccParentAccountTypesCompatibleWith, typically allow ACCT_TYPE_ROOT
  as parent but not as child
* remove ACCT_TYPE_ROOT from xaccAccountTypesValid
* no need to single-case the root account in gnc_common_ok anymore


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15946 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Andreas Köhler 2007-04-21 12:00:56 +00:00
parent 55c4675868
commit 94364fb33e
4 changed files with 17 additions and 13 deletions

View File

@ -3759,7 +3759,7 @@ xaccAccountGetTypeFromStr (const gchar *str)
\********************************************************************/ \********************************************************************/
guint32 guint32
xaccAccountTypesCompatibleWith (GNCAccountType type) xaccParentAccountTypesCompatibleWith (GNCAccountType type)
{ {
switch (type) { switch (type) {
case ACCT_TYPE_BANK: case ACCT_TYPE_BANK:
@ -3782,15 +3782,18 @@ xaccAccountTypesCompatibleWith (GNCAccountType type)
(1 << ACCT_TYPE_CREDIT) | (1 << ACCT_TYPE_CREDIT) |
(1 << ACCT_TYPE_LIABILITY) | (1 << ACCT_TYPE_LIABILITY) |
(1 << ACCT_TYPE_RECEIVABLE) | (1 << ACCT_TYPE_RECEIVABLE) |
(1 << ACCT_TYPE_PAYABLE); (1 << ACCT_TYPE_PAYABLE) |
(1 << ACCT_TYPE_ROOT);
case ACCT_TYPE_INCOME: case ACCT_TYPE_INCOME:
case ACCT_TYPE_EXPENSE: case ACCT_TYPE_EXPENSE:
return return
(1 << ACCT_TYPE_INCOME) | (1 << ACCT_TYPE_INCOME) |
(1 << ACCT_TYPE_EXPENSE); (1 << ACCT_TYPE_EXPENSE) |
(1 << ACCT_TYPE_ROOT);
case ACCT_TYPE_EQUITY: case ACCT_TYPE_EQUITY:
return return
(1 << ACCT_TYPE_EQUITY); (1 << ACCT_TYPE_EQUITY) |
(1 << ACCT_TYPE_ROOT);
default: default:
PERR("bad account type: %d", type); PERR("bad account type: %d", type);
return 0; return 0;
@ -3801,7 +3804,7 @@ gboolean
xaccAccountTypesCompatible (GNCAccountType parent_type, xaccAccountTypesCompatible (GNCAccountType parent_type,
GNCAccountType child_type) GNCAccountType child_type)
{ {
return ((xaccAccountTypesCompatibleWith (parent_type) & return ((xaccParentAccountTypesCompatibleWith (parent_type) &
(1 << child_type)) (1 << child_type))
!= 0); != 0);
} }
@ -3810,7 +3813,8 @@ guint32
xaccAccountTypesValid(void) xaccAccountTypesValid(void)
{ {
guint32 mask = (1 << NUM_ACCOUNT_TYPES) - 1; guint32 mask = (1 << NUM_ACCOUNT_TYPES) - 1;
mask &= ~(1 << ACCT_TYPE_CURRENCY); /* DEPRECATED */ mask &= ~((1 << ACCT_TYPE_CURRENCY) | /* DEPRECATED */
(1 << ACCT_TYPE_ROOT)); /* ROOT */
return mask; return mask;
} }

View File

@ -946,15 +946,16 @@ const char * xaccAccountGetTypeStr (GNCAccountType type);
* to the local language. */ * to the local language. */
GNCAccountType xaccAccountGetTypeFromStr (const gchar *str); GNCAccountType xaccAccountGetTypeFromStr (const gchar *str);
/** Return the bitmask of account types compatible with a given type. */ /** Return the bitmask of parent account types compatible with a given type. */
guint32 xaccAccountTypesCompatibleWith (GNCAccountType type); guint32 xaccParentAccountTypesCompatibleWith (GNCAccountType type);
/** Return TRUE if accounts of type parent_type can have accounts /** Return TRUE if accounts of type parent_type can have accounts
* of type child_type as children. */ * of type child_type as children. */
gboolean xaccAccountTypesCompatible (GNCAccountType parent_type, gboolean xaccAccountTypesCompatible (GNCAccountType parent_type,
GNCAccountType child_type); GNCAccountType child_type);
/* Returns the bitmask of the account type enums that are valid. */ /** Returns the bitmask of the account type enums that are valid. Deprecated and
* root account types are stripped. */
guint32 xaccAccountTypesValid(void); guint32 xaccAccountTypesValid(void);

View File

@ -750,8 +750,7 @@ gnc_common_ok (AccountWindow *aw)
} }
/* check whether the types of child and parent are compatible */ /* check whether the types of child and parent are compatible */
if (!gnc_account_is_root(parent) && if (!xaccAccountTypesCompatible (aw->type, xaccAccountGetType (parent))) {
!xaccAccountTypesCompatible (aw->type, xaccAccountGetType (parent))) {
const char *message = _("The selected account type is incompatible with " const char *message = _("The selected account type is incompatible with "
"the one of the selected parent."); "the one of the selected parent.");
gnc_error_dialog(aw->dialog, message); gnc_error_dialog(aw->dialog, message);
@ -969,7 +968,7 @@ gnc_account_parent_changed_cb (GtkTreeSelection *selection, gpointer data)
types = aw->valid_types; types = aw->valid_types;
} else { } else {
types = aw->valid_types & types = aw->valid_types &
xaccAccountTypesCompatibleWith (xaccAccountGetType (parent_account)); xaccParentAccountTypesCompatibleWith (xaccAccountGetType (parent_account));
} }
type_model = gtk_tree_view_get_model (GTK_TREE_VIEW (aw->type_view)); type_model = gtk_tree_view_get_model (GTK_TREE_VIEW (aw->type_view));

View File

@ -94,7 +94,7 @@ GType gnc_tree_model_account_types_get_type (void);
/*************** Method 1 functions ***************/ /*************** Method 1 functions ***************/
/* Returns a GtkTreeModelFilter that wraps the model. Deprecated /* Returns a GtkTreeModelFilter that wraps the model. Deprecated and root
account types will be filtered. Caller is responsible for account types will be filtered. Caller is responsible for
ref/unref. */ ref/unref. */
GtkTreeModel * gnc_tree_model_account_types_valid (void); GtkTreeModel * gnc_tree_model_account_types_valid (void);