options.scm: upgrade lookup-value to learn section changes

This commit is contained in:
Christopher Lam 2017-12-21 20:19:15 +08:00
parent 2f96b19c77
commit d93d4f68b0

View File

@ -1681,32 +1681,48 @@
(let ((option-hash (hash-ref section-hash name))) (let ((option-hash (hash-ref section-hash name)))
(if option-hash (if option-hash
option-hash option-hash
; Option name was not found. Perhaps it was renamed ? ;; Option name was not found. Perhaps it was renamed ?
; Let's try to map it to a known new name ;; Let's try to map it to a known new name.
;; This list will try match names - if one is found
;; the next item will describe a pair.
;; (cons newsection newname)
;; If newsection is #f then reuse previous section name.
;;
;; Please note the rename list currently supports renaming
;; individual option names, or individual option names moved
;; to another section. It does not currently support renaming
;; whole sections.
(let* ((new-names-list (list (let* ((new-names-list (list
"Accounts to include" "Accounts" "Accounts to include" (cons #f "Accounts")
"Exclude transactions between selected accounts?" "Exclude transactions between selected accounts" "Exclude transactions between selected accounts?" (cons #f "Exclude transactions between selected accounts")
"Filter Accounts" "Filter By..." "Filter Accounts" (cons #f "Filter By...")
"Flatten list to depth limit?" "Flatten list to depth limit" "Flatten list to depth limit?" (cons #f "Flatten list to depth limit")
"From" "Start Date" "From" (cons #f "Start Date")
"Report Accounts" "Accounts" "Report Accounts" (cons #f "Accounts")
"Report Currency" "Report's currency" "Report Currency" (cons #f "Report's currency")
"Show Account Code?" "Show Account Code" "Show Account Code?" (cons #f "Show Account Code")
"Show Full Account Name?" "Show Full Account Name" "Show Full Account Name?" (cons #f "Show Full Account Name")
"Show Multi-currency Totals?" "Show Multi-currency Totals" "Show Multi-currency Totals?" (cons #f "Show Multi-currency Totals")
"Show zero balance items?" "Show zero balance items" "Show zero balance items?" (cons #f "Show zero balance items")
"Sign Reverses?" "Sign Reverses" "Sign Reverses?" (cons #f "Sign Reverses")
"To" "End Date" "To" (cons #f "End Date")
"Use Full Account Name?" "Use Full Account Name" "Use Full Account Name?" (cons #f "Use Full Account Name")
"Use Full Other Account Name?" "Use Full Other Account Name" "Use Full Other Account Name?" (cons #f "Use Full Other Account Name")
"Void Transactions?" "Void Transactions" "Void Transactions?" (cons #f "Void Transactions")
)) ))
(name-match (member name new-names-list))) (name-match (member name new-names-list)))
(if name-match (and name-match
(let ((new-name (cadr name-match))) (let ((new-section (car (cadr name-match)))
(lookup-option section new-name)) (new-name (cdr (cadr name-match))))
#f)))) ;; compare if new-section name exists.
(if new-section
;; if so, if it's different to current section name
;; then try new section name
(and (not (string=? new-section section))
(lookup-option new-section new-name))
;; else reuse section-name with new-name
(lookup-option section new-name)))))))
#f))) #f)))
(define (option-changed section name) (define (option-changed section name)