From 0c32774210ba6543ba2beeb05121d014751973b0 Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Mon, 10 Jan 2011 21:39:40 +0000 Subject: [PATCH] Bug #638543: Add a GUI for the counter format and current value. Patch by Matthijs Kooijman: This allows the user to change the format used for the various counters, as well as see and change the current value of the counter. This is a bit of hack right now, since the format and current counter values are stored in the counter_formats and counters kvp slots respectively, instead of options/
like the other options in the File->properties window. This is implemented by adding the make-counter-option and make-counter-format-option, which both replace the scm->kvp and kvp->scm functions defined by make-number-range-option and make-string-option respectively. The replaced function simply ignores the "path" parameter and instead saves to the "counter" or "counter_formats" slot hardcoded. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20057 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/app-utils/app-utils.scm | 2 + src/app-utils/options.scm | 4 + .../business-utils/business-options.scm | 44 +++++++++++ .../business-utils/business-prefs.scm | 74 ++++++++++++++++++- 4 files changed, 123 insertions(+), 1 deletion(-) diff --git a/src/app-utils/app-utils.scm b/src/app-utils/app-utils.scm index 20dda86a7d..2c64b12e33 100644 --- a/src/app-utils/app-utils.scm +++ b/src/app-utils/app-utils.scm @@ -43,7 +43,9 @@ (export gnc:option-default-getter) (export gnc:option-generate-restore-form) (export gnc:option-scm->kvp) +(export gnc:set-option-scm->kvp) (export gnc:option-kvp->scm) +(export gnc:set-option-kvp->scm) (export gnc:option-value-validator) (export gnc:option-data) (export gnc:option-data-fns) diff --git a/src/app-utils/options.scm b/src/app-utils/options.scm index c17c8c546d..52b04863b1 100644 --- a/src/app-utils/options.scm +++ b/src/app-utils/options.scm @@ -118,8 +118,12 @@ (vector-ref option 8)) (define (gnc:option-scm->kvp option) (vector-ref option 9)) +(define (gnc:set-option-scm->kvp option v) + (vector-set! option 9 v)) (define (gnc:option-kvp->scm option) (vector-ref option 10)) +(define (gnc:set-option-kvp->scm option v) + (vector-set! option 10 v)) (define (gnc:option-value-validator option) (vector-ref option 11)) (define (gnc:option-data option) diff --git a/src/business/business-utils/business-options.scm b/src/business/business-utils/business-options.scm index c9717db988..e8a6560a77 100644 --- a/src/business/business-utils/business-options.scm +++ b/src/business/business-utils/business-options.scm @@ -432,9 +432,53 @@ validator #f #f #f #f))) +;; This defines an option to set a counter value. This is a slightly +;; different kind of option: Unlike all other options, the values edited +;; by this option are not saved in the "options"/
kvm slot, but +;; in the "counters" slot. This is mostly due to backwards compatibility +;; and partly because counters are a bit different from other options +;; anyway. +;; +;; This is implemented by overriding the scm->kvp and kvp->scm methods +;; to ignore the kvp path passed and replace it with a hardcoded +;; "counters". +(define (gnc:make-counter-option + section + name + key + sort-tag + documentation-string + default-value) + (let ((option (gnc:make-number-range-option section name sort-tag documentation-string default-value 0 999999999 0 1))) + (gnc:set-option-scm->kvp option (lambda (f p) (kvp-frame-set-slot-path-gslist f (inexact->exact ((gnc:option-getter option))) (list "counters" key)))) + (gnc:set-option-kvp->scm option (lambda (f p) + (let ((v (kvp-frame-get-slot-path-gslist f (list "counters" key)))) + (if (and v (integer? v)) + ((gnc:option-setter option) v))))) + option)) + +;; This defines an option to set a counter format, which has the same +;; exception as gnc:make-counter-option above. +(define (gnc:make-counter-format-option + section + name + key + sort-tag + documentation-string + default-value) + (let ((option (gnc:make-string-option section name sort-tag documentation-string default-value))) + (gnc:set-option-scm->kvp option (lambda (f p) (kvp-frame-set-slot-path-gslist f ((gnc:option-getter option)) (list "counter_formats" key)))) + (gnc:set-option-kvp->scm option (lambda (f p) + (let ((v (kvp-frame-get-slot-path-gslist f (list "counter_formats" key)))) + (if (and v (string? v)) + ((gnc:option-setter option) v))))) + option)) + (export gnc:make-invoice-option) (export gnc:make-customer-option) (export gnc:make-vendor-option) (export gnc:make-employee-option) (export gnc:make-owner-option) (export gnc:make-taxtable-option) +(export gnc:make-counter-option) +(export gnc:make-counter-format-option) diff --git a/src/business/business-utils/business-prefs.scm b/src/business/business-utils/business-prefs.scm index 2819800dc8..d93beaad52 100644 --- a/src/business/business-utils/business-prefs.scm +++ b/src/business/business-utils/business-prefs.scm @@ -19,6 +19,47 @@ ;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 ;; Boston, MA 02110-1301, USA gnu@gnu.org +(define gnc:*option-section-counters* (N_ "Counters")) + +;; This defines all available counter types to show options for. This a +;; list that contains a sublist for each counter type, containing: The +;; (untranslated) counter name, the format label, the previous number +;; label, the format help text and the previous number help text. +(define counter-types + (list (list "gncCustomer" (N_ "Customer number format") + (N_ "Customer number") + (N_ "The format string to use for generating customer numbers. This is a printf-style format string.") + (N_ "The previous customer number generated. This number will be incremented to generate the next customer number.")) + (list "gncEmployee" (N_ "Employee number format") + (N_ "Employee number") + (N_ "The format string to use for generating employee numbers. This is a printf-style format string.") + (N_ "The previous employee number generated. This number will be incremented to generate the next employee number.")) + (list "gncInvoice" (N_ "Invoice number format") + (N_ "Invoice number") + (N_ "The format string to use for generating invoice numbers. This is a printf-style format string.") + (N_ "The previous invoice number generated. This number will be incremented to generate the next invoice number.")) + (list "gncBill" (N_ "Bill number format") + (N_ "Bill number") + (N_ "The format string to use for generating bill numbers. This is a printf-style format string.") + (N_ "The previous bill number generated. This number will be incremented to generate the next bill number.")) + (list "gncExpVoucher" (N_ "Expense voucher number format") + (N_ "Expense voucher number") + (N_ "The format string to use for generating expense voucher numbers. This is a printf-style format string.") + (N_ "The previous expense voucher number generated. This number will be incremented to generate the next voucher number.")) + (list "gncJob" (N_ "Job number format") + (N_ "Job number") + (N_ "The format string to use for generating job numbers. This is a printf-style format string.") + (N_ "The previous job number generated. This number will be incremented to generate the next job number.")) + (list "gncOrder" (N_ "Order number format") + (N_ "Order number") + (N_ "The format string to use for generating order numbers. This is a printf-style format string.") + (N_ "The previous order number generated. This number will be incremented to generate the next order number.")) + (list "gncVendor" (N_ "Vendor number format") + (N_ "Vendor number") + (N_ "The format string to use for generating vendor numbers. This is a printf-style format string.") + (N_ "The previous vendor number generated. This number will be incremented to generate the next vendor number.")) +)) + (define (book-options-generator options) (define (reg-option new-option) (gnc:register-option options new-option)) @@ -81,7 +122,9 @@ gnc:*business-label* (N_ "Fancy Date Format") "g" (N_ "The default date format used for fancy printed dates") #f)) - + + ;; Accounts tab + (reg-option (gnc:make-simple-boolean-option gnc:*option-section-accounts* gnc:*option-name-trading-accounts* @@ -95,6 +138,35 @@ gnc:*option-section-budgeting* gnc:*option-name-default-budget* "a" (N_ "Budget to be used when none has been otherwise specified"))) + ;; Counters Tab + (map (lambda (vals) + (let* ( + ; Unpack the list of strings for this counter type + (key (car vals)) + (sort-string key) + (format-label (cadr vals)) + (number-label (caddr vals)) + (format-description (cadddr vals)) + (number-description (cadddr (cdr vals))) + ) + (begin + ; For each counter-type we create an option for + ; the last used number and the format string to + ; use. + (reg-option + (gnc:make-counter-option + gnc:*option-section-counters* number-label key + (string-append sort-string "a") number-description 0)) + (reg-option + (gnc:make-counter-format-option + gnc:*option-section-counters* format-label key + (string-append sort-string "b") format-description "")) + ) + ) + ) + ;; Make counter and format option for each defined counter + counter-types + ) )