* options.scm: Create gnc:make-account-list-limited-option

function that adds a list of valid account-types; this limits the
	account-tree dialog to only "reasonable" accounts.

	* option-util.[ch]: add function to obtain GList* of valid
	account-types.  NULL means "all".

	* dialog-options: Limit account-list by types.

	* Update payables and receivables reports to limit account types.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7076 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins 2002-07-03 00:47:02 +00:00
parent 91a961d792
commit 702d5f3529
8 changed files with 127 additions and 23 deletions

View File

@ -18,6 +18,17 @@
* add a hook in the entry ledger to obtain the current Query (to
set the sort order).
* options.scm: Create gnc:make-account-list-limited-option
function that adds a list of valid account-types; this limits the
account-tree dialog to only "reasonable" accounts.
* option-util.[ch]: add function to obtain GList* of valid
account-types. NULL means "all".
* dialog-options: Limit account-list by types.
* Update payables and receivables reports to limit account types.
2002-07-01 Derek Atkins <derek@ihtfp.com>

View File

@ -59,6 +59,7 @@
(export gnc:date-option-absolute-time)
(export gnc:date-option-relative-time)
(export gnc:make-account-list-option)
(export gnc:make-account-list-limited-option)
(export gnc:multichoice-list-lookup)
(export gnc:make-multichoice-option)
(export gnc:make-multichoice-callback-option)

View File

@ -908,13 +908,62 @@ gnc_option_show_time(GNCOption *option)
gboolean
gnc_option_multiple_selection(GNCOption *option)
{
SCM value;
SCM pair;
initialize_getters();
value = gh_call1(getters.option_data, option->guile_option);
pair = gh_call1(getters.option_data, option->guile_option);
return !gh_scm2bool(gh_not(value));
return !gh_scm2bool(gh_not(gh_car(pair)));
}
/********************************************************************\
* gnc_option_get_account_type_list *
* returns the list of account_types in the option (or NULL if *
* no special list is provided). Only use this for account *
* options. *
* *
* Args: option - the GNCOption *
* Returns: GList of account types (must be freed by caller) *
\********************************************************************/
GList *
gnc_option_get_account_type_list(GNCOption *option)
{
SCM pair;
SCM lst;
SCM conv_func;
GList *type_list = NULL;
initialize_getters();
pair = gh_call1(getters.option_data, option->guile_option);
lst = gh_cdr(pair);
conv_func = gh_eval_str ("gw:enum-<gnc:AccountType>-val->int");
if (!gh_procedure_p (conv_func)) {
PERR ("Cannot obtain conv_func");
return NULL;
}
while (!gh_null_p (lst)) {
GNCAccountType type;
SCM item;
/* Compute this item and the rest of the list */
item = gh_car (lst);
lst = gh_cdr (lst);
item = gh_call1(conv_func, item);
if (SCM_FALSEP (scm_integer_p (item))) {
PERR ("Invalid type");
} else {
type = gh_scm2long (item);
type_list = g_list_prepend (type_list, GINT_TO_POINTER (type));
}
}
return g_list_reverse (type_list);
}

View File

@ -94,6 +94,7 @@ char * gnc_option_permissible_value_description(GNCOption *option, int index);
gboolean gnc_option_show_time(GNCOption *option);
gboolean gnc_option_multiple_selection(GNCOption *option);
GList * gnc_option_get_account_type_list(GNCOption *option);
gboolean gnc_option_get_range_info(GNCOption *option,
double *lower_bound,

View File

@ -466,11 +466,9 @@
#f
(cdr option-value)))
;; account-list options use the option-data as a boolean value. If
;; true, the gui should allow the user to select multiple accounts.
;; Internally, values are always a list of guids. Externally, both
;; guids and account pointers may be used to set the value of the
;; option. The option always returns a list of account pointers.
;; Just like gnc:make-account-list-limited-option except it
;; does not limit the types of accounts that are available
;; to the user.
(define (gnc:make-account-list-option
section
name
@ -480,6 +478,27 @@
value-validator
multiple-selection)
(gnc:make-account-list-limited-option
section name sort-tag documentation-string
default-getter value-validator multiple-selection '()))
;; account-list options use the option-data as a pair; the car is
;; a boolean value, the cdr is a list of account-types. If the boolean is
;; true, the gui should allow the user to select multiple accounts.
;; If the cdr is an empty list, then all account types are shown.
;; Internally, values are always a list of guids. Externally, both
;; guids and account pointers may be used to set the value of the
;; option. The option always returns a list of account pointers.
(define (gnc:make-account-list-limited-option
section
name
sort-tag
documentation-string
default-getter
value-validator
multiple-selection
acct-type-list)
(define (convert-to-guid item)
(if (string? item)
item
@ -524,7 +543,7 @@
(lambda () (map convert-to-account (default-getter)))
(gnc:restore-form-generator value->string)
validator
multiple-selection #f #f #f)))
(cons multiple-selection acct-type-list) #f #f #f)))
(define (gnc:multichoice-list-lookup list item )
(cond

View File

@ -773,8 +773,10 @@ gnc_option_create_account_widget(GNCOption *option, char *name)
GtkWidget *tree;
GtkWidget *vbox;
GtkWidget *bbox;
GList *acct_type_list;
multiple_selection = gnc_option_multiple_selection(option);
acct_type_list = gnc_option_get_account_type_list(option);
frame = gtk_frame_new(name);
@ -790,6 +792,25 @@ gnc_option_create_account_widget(GNCOption *option, char *name)
else
gtk_clist_set_selection_mode(GTK_CLIST(tree), GTK_SELECTION_BROWSE);
if (acct_type_list) {
GList *node;
AccountViewInfo avi;
int i;
gnc_account_tree_get_view_info (GNC_ACCOUNT_TREE (tree), &avi);
for (i = 0; i < NUM_ACCOUNT_TYPES; i++)
avi.include_type[i] = FALSE;
for (node = acct_type_list; node; node = node->next) {
GNCAccountType type = GPOINTER_TO_INT (node->data);
avi.include_type[type] = TRUE;
}
gnc_account_tree_set_view_info (GNC_ACCOUNT_TREE (tree), &avi);
g_list_free (acct_type_list);
}
scroll_win = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_win),
GTK_POLICY_AUTOMATIC,

View File

@ -33,7 +33,7 @@
(use-modules (gnucash report aging))
(use-modules (gnucash report standard-reports))
(define this-acc "this-account")
(define this-acc "Payable Account")
(define (options-generator)
(let* ((options (gnc:new-options))
@ -42,12 +42,13 @@
(gnc:register-option options new-option))))
(add-option
(gnc:make-account-list-option
"__reg" this-acc
(gnc:make-account-list-limited-option
"Account" this-acc
"" ""
(lambda () '())
#f
#f))
#f
'(payable)))
(aging-options-generator options)))
@ -77,7 +78,7 @@
(define (op-value section name)
(gnc:option-value (get-op section name)))
(let* ((payables-account (op-value "__reg" this-acc)))
(let* ((payables-account (op-value "Account" this-acc)))
(gnc:debug "payables-account" payables-account)
(if (null? payables-account)
@ -92,11 +93,11 @@
'name (N_ "Payable Aging")
'options-generator options-generator
'renderer payables-renderer
'in-menu? #f)
'in-menu? #t)
(define (payables-report-create-internal acct)
(let* ((options (gnc:make-report-options "Payable Aging"))
(acct-op (gnc:lookup-option options "__reg" this-acc)))
(acct-op (gnc:lookup-option options "Account" this-acc)))
(gnc:option-set-value acct-op (list acct))
(gnc:make-report "Payable Aging" options)))

View File

@ -33,7 +33,7 @@
(use-modules (gnucash report aging))
(use-modules (gnucash report standard-reports))
(define this-acc "this-account")
(define this-acc "Receivables Account")
(define (options-generator)
(let* ((options (gnc:new-options))
@ -45,12 +45,13 @@
; (gnc:make-internal-option "__reg" this-acc #f))
(add-option
(gnc:make-account-list-option
"__reg" this-acc
(gnc:make-account-list-limited-option
"Account" this-acc
"" ""
(lambda () '())
#f
#f))
#f
'(receivable)))
(aging-options-generator options)))
@ -80,7 +81,7 @@
(define (op-value section name)
(gnc:option-value (get-op section name)))
(let* ((receivables-account (op-value "__reg" this-acc)))
(let* ((receivables-account (op-value "Account" this-acc)))
(gnc:debug "receivables-account" receivables-account)
(if (null? receivables-account)
@ -95,11 +96,11 @@
'name (N_ "Receivable Aging")
'options-generator options-generator
'renderer receivables-renderer
'in-menu? #f)
'in-menu? #t)
(define (receivables-report-create-internal acct)
(let* ((options (gnc:make-report-options "Receivable Aging"))
(acct-op (gnc:lookup-option options "__reg" this-acc)))
(acct-op (gnc:lookup-option options "Account" this-acc)))
(gnc:option-set-value acct-op (list acct))
(gnc:make-report "Receivable Aging" options)))