[options.scm] gnc:make-budget-option stores guid instead of object

because object may become stale if UI is used to delete it, leading to
stale pointer and segfault. storing guid is safer, and will return
null if budget is deleted.
This commit is contained in:
Christopher Lam 2021-12-04 01:36:08 +08:00
parent 53d93e0c44
commit 5a812ca1eb

View File

@ -470,6 +470,13 @@ the option '~a'."))
(selection-budget initial-budget) (selection-budget initial-budget)
) )
(define (convert-to-guid item)
(if (string? item) item (gncBudgetGetGUID item)))
(define (convert-to-budget item)
(if (string? item) (gnc-budget-lookup item (gnc-get-current-book)) item))
(gnc:make-option (gnc:make-option
section section
name name
@ -478,12 +485,12 @@ the option '~a'."))
documentation-string documentation-string
;; getter -- Return a budget pointer ;; getter -- Return a budget pointer
(lambda () (lambda ()
selection-budget) (convert-to-budget selection-budget))
;; setter -- takes a budget ;; setter -- takes a budget
(lambda (x) (lambda (x)
(set! selection-budget x)) (set! selection-budget (convert-to-guid x)))
;; default-getter ;; default-getter
;; Default now is #f so saving is independent of book-level default ;; Default now is #f so saving is independent of book-level default