PageRenderTime 149ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/src/app-utils/options.scm

http://github.com/mchochlov/Gnucash
Scheme | 1653 lines | 1306 code | 156 blank | 191 comment | 0 complexity | e455d4de5b21efe7ea06a8419939becf MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. ;; Scheme code for supporting options
  2. ;;
  3. ;; This program is free software; you can redistribute it and/or
  4. ;; modify it under the terms of the GNU General Public License as
  5. ;; published by the Free Software Foundation; either version 2 of
  6. ;; the License, or (at your option) any later version.
  7. ;;
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;;
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program; if not, contact:
  15. ;;
  16. ;; Free Software Foundation Voice: +1-617-542-5942
  17. ;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
  18. ;; Boston, MA 02110-1301, USA gnu@gnu.org
  19. (define (gnc:make-option
  20. ;; The category of this option
  21. section
  22. name
  23. ;; The sort-tag determines the relative ordering of options in
  24. ;; this category. It is used by the gui for display.
  25. sort-tag
  26. type
  27. documentation-string
  28. getter
  29. ;; The setter is responsible for ensuring that the value is valid.
  30. setter
  31. default-getter
  32. ;; Restore form generator should generate an ascii representation
  33. ;; of a function taking one argument. The argument will be an
  34. ;; option. The function should restore the option to the original
  35. ;; value.
  36. generate-restore-form
  37. ;; the scm->kvp and kvp->scm functions should save and load
  38. ;; the option to a kvp. The arguments to these function will be
  39. ;; a kvp-frame and a base key-path list for this option.
  40. scm->kvp
  41. kvp->scm
  42. ;; Validation func should accept a value and return (#t value)
  43. ;; on success, and (#f "failure-message") on failure. If #t,
  44. ;; the supplied value will be used by the gui to set the option.
  45. value-validator
  46. ;;; free-form storage depending on type.
  47. option-data
  48. ;; If this is a "multiple choice" type of option,
  49. ;; this should be a vector of the following five functions:
  50. ;;
  51. ;; Function 1: taking no arguments, giving the number of choices
  52. ;;
  53. ;; Function 2: taking one argument, a non-negative integer, that
  54. ;; returns the scheme value (usually a symbol) matching the
  55. ;; nth choice
  56. ;;
  57. ;; Function 3: taking one argument, a non-negative integer,
  58. ;; that returns the string matching the nth choice
  59. ;;
  60. ;; Function 4: takes one argument and returns the description
  61. ;; containing the nth choice
  62. ;;
  63. ;; Function 5: giving a possible value and returning the index
  64. ;; if an option doesn't use these, this should just be a #f
  65. option-data-fns
  66. ;; This function should return a list of all the strings
  67. ;; in the option other than the section, name, (define
  68. ;; (list-lookup list item) and documentation-string that
  69. ;; might be displayed to the user (and thus should be
  70. ;; translated).
  71. strings-getter
  72. ;; This function will be called when the GUI representation
  73. ;; of the option is changed. This will normally occur before
  74. ;; the setter is called, because setters are only called when
  75. ;; the user selects "OK" or "Apply". Therefore, this
  76. ;; callback shouldn't be used to make changes to the actual
  77. ;; options database.
  78. option-widget-changed-proc)
  79. (let ((changed-callback #f))
  80. (vector section
  81. name
  82. sort-tag
  83. type
  84. documentation-string
  85. getter
  86. (lambda args
  87. (apply setter args)
  88. (if changed-callback (changed-callback)))
  89. default-getter
  90. generate-restore-form
  91. scm->kvp
  92. kvp->scm
  93. value-validator
  94. option-data
  95. option-data-fns
  96. (lambda (callback) (set! changed-callback callback))
  97. strings-getter
  98. option-widget-changed-proc)))
  99. (define (gnc:option-section option)
  100. (vector-ref option 0))
  101. (define (gnc:option-name option)
  102. (vector-ref option 1))
  103. (define (gnc:option-sort-tag option)
  104. (vector-ref option 2))
  105. (define (gnc:option-type option)
  106. (vector-ref option 3))
  107. (define (gnc:option-documentation option)
  108. (vector-ref option 4))
  109. (define (gnc:option-getter option)
  110. (vector-ref option 5))
  111. (define (gnc:option-setter option)
  112. (vector-ref option 6))
  113. (define (gnc:option-default-getter option)
  114. (vector-ref option 7))
  115. (define (gnc:option-generate-restore-form option)
  116. (vector-ref option 8))
  117. (define (gnc:option-scm->kvp option)
  118. (vector-ref option 9))
  119. (define (gnc:set-option-scm->kvp option v)
  120. (vector-set! option 9 v))
  121. (define (gnc:option-kvp->scm option)
  122. (vector-ref option 10))
  123. (define (gnc:set-option-kvp->scm option v)
  124. (vector-set! option 10 v))
  125. (define (gnc:option-value-validator option)
  126. (vector-ref option 11))
  127. (define (gnc:option-data option)
  128. (vector-ref option 12))
  129. (define (gnc:option-data-fns option)
  130. (vector-ref option 13))
  131. (define (gnc:option-set-changed-callback option callback)
  132. (let ((cb-setter (vector-ref option 14)))
  133. (cb-setter callback)))
  134. (define (gnc:option-strings-getter option)
  135. (vector-ref option 15))
  136. (define (gnc:option-widget-changed-proc option)
  137. (vector-ref option 16))
  138. (define (gnc:option-value option)
  139. (let ((getter (gnc:option-getter option)))
  140. (getter)))
  141. (define (gnc:option-set-value option value)
  142. (let ((setter (gnc:option-setter option)))
  143. (setter value)))
  144. (define (gnc:option-index-get-name option index)
  145. (let* ((option-data-fns (gnc:option-data-fns option))
  146. (name-fn (vector-ref option-data-fns 2)))
  147. (name-fn index)))
  148. (define (gnc:option-index-get-description option index)
  149. (let* ((option-data-fns (gnc:option-data-fns option))
  150. (name-fn (vector-ref option-data-fns 3)))
  151. (name-fn index)))
  152. (define (gnc:option-index-get-value option index)
  153. (let* ((option-data-fns (gnc:option-data-fns option))
  154. (name-fn (vector-ref option-data-fns 1)))
  155. (name-fn index)))
  156. (define (gnc:option-value-get-index option value)
  157. (let* ((option-data-fns (gnc:option-data-fns option))
  158. (name-fn (vector-ref option-data-fns 4)))
  159. (name-fn value)))
  160. (define (gnc:option-number-of-indices option)
  161. (let* ((option-data-fns (gnc:option-data-fns option))
  162. (name-fn (vector-ref option-data-fns 0)))
  163. (name-fn)))
  164. (define (gnc:option-default-value option)
  165. (let ((getter (gnc:option-default-getter option)))
  166. (getter)))
  167. (define (gnc:restore-form-generator value->string)
  168. (lambda () (string-append
  169. "(lambda (option) "
  170. "(if option ((gnc:option-setter option) "
  171. (value->string)
  172. ")))")))
  173. (define (gnc:value->string value)
  174. (call-with-output-string
  175. (lambda (port) (write value port))))
  176. (define (gnc:make-string-option
  177. section
  178. name
  179. sort-tag
  180. documentation-string
  181. default-value)
  182. (let* ((value default-value)
  183. (value->string (lambda () (gnc:value->string value))))
  184. (gnc:make-option
  185. section name sort-tag 'string documentation-string
  186. (lambda () value)
  187. (lambda (x) (set! value x))
  188. (lambda () default-value)
  189. (gnc:restore-form-generator value->string)
  190. (lambda (f p) (kvp-frame-set-slot-path-gslist f value p))
  191. (lambda (f p)
  192. (let ((v (kvp-frame-get-slot-path-gslist f p)))
  193. (if (and v (string? v))
  194. (set! value v))))
  195. (lambda (x)
  196. (cond ((string? x)(list #t x))
  197. (else (list #f "string-option: not a string"))))
  198. #f #f #f #f)))
  199. (define (gnc:make-text-option
  200. section
  201. name
  202. sort-tag
  203. documentation-string
  204. default-value)
  205. (let* ((value default-value)
  206. (value->string (lambda () (gnc:value->string value))))
  207. (gnc:make-option
  208. section name sort-tag 'text documentation-string
  209. (lambda () value)
  210. (lambda (x) (set! value x))
  211. (lambda () default-value)
  212. (gnc:restore-form-generator value->string)
  213. (lambda (f p) (kvp-frame-set-slot-path-gslist f value p))
  214. (lambda (f p)
  215. (let ((v (kvp-frame-get-slot-path-gslist f p)))
  216. (if (and v (string? v))
  217. (set! value v))))
  218. (lambda (x)
  219. (cond ((string? x)(list #t x))
  220. (else (list #f "text-option: not a string"))))
  221. #f #f #f #f)))
  222. ;;; font options store fonts as strings a la the X Logical
  223. ;;; Font Description. You should always provide a default
  224. ;;; value, as currently there seems to be no way to go from
  225. ;;; an actual font to a logical font description, and thus
  226. ;;; there is no way for the gui to pick a default value.
  227. (define (gnc:make-font-option
  228. section
  229. name
  230. sort-tag
  231. documentation-string
  232. default-value)
  233. (let* ((value default-value)
  234. (value->string (lambda () (gnc:value->string value))))
  235. (gnc:make-option
  236. section
  237. name
  238. sort-tag
  239. 'font
  240. documentation-string
  241. (lambda () value)
  242. (lambda (x) (set! value x))
  243. (lambda () default-value)
  244. (gnc:restore-form-generator value->string)
  245. (lambda (f p) (kvp-frame-set-slot-path-gslist f value p))
  246. (lambda (f p)
  247. (let ((v (kvp-frame-get-slot-path-gslist f p)))
  248. (if (and v (string? v))
  249. (set! value v))))
  250. (lambda (x)
  251. (cond ((string? x)(list #t x))
  252. (else (list #f "font-option: not a string"))))
  253. #f #f #f #f)))
  254. ;; currency options use a specialized widget for entering currencies
  255. ;; in the GUI implementation.
  256. (define (gnc:make-currency-option
  257. section
  258. name
  259. sort-tag
  260. documentation-string
  261. default-value)
  262. (define (currency->scm currency)
  263. (if (string? currency)
  264. currency
  265. (gnc-commodity-get-mnemonic currency)))
  266. (define (scm->currency currency)
  267. (if (string? currency)
  268. (gnc-commodity-table-lookup
  269. (gnc-commodity-table-get-table (gnc-get-current-book))
  270. GNC_COMMODITY_NS_CURRENCY currency)
  271. currency))
  272. (let* ((value (currency->scm default-value))
  273. (value->string (lambda () (gnc:value->string value))))
  274. (gnc:make-option
  275. section name sort-tag 'currency documentation-string
  276. (lambda () (scm->currency value))
  277. (lambda (x) (set! value (currency->scm x)))
  278. (lambda () (scm->currency default-value))
  279. (gnc:restore-form-generator value->string)
  280. (lambda (f p) (kvp-frame-set-slot-path-gslist f value p))
  281. (lambda (f p)
  282. (let ((v (kvp-frame-get-slot-path-gslist f p)))
  283. (if (and v (string? v))
  284. (set! value v))))
  285. (lambda (x) (list #t x))
  286. #f #f #f #f)))
  287. ;; budget option
  288. ;; TODO: need to double-check this proc (dates back to r11545 or eariler)
  289. ;;
  290. ;; Always takes/returns a budget
  291. ;; Stores the GUID in the KVP
  292. ;;
  293. (define (gnc:make-budget-option
  294. section
  295. name
  296. sort-tag
  297. documentation-string)
  298. (let* ((initial-budget (gnc-budget-get-default (gnc-get-current-book)))
  299. (selection-budget initial-budget)
  300. )
  301. (gnc:make-option
  302. section
  303. name
  304. sort-tag
  305. 'budget
  306. documentation-string
  307. ;; getter -- Return a budget pointer
  308. (lambda ()
  309. selection-budget)
  310. ;; setter -- takes a budget
  311. (lambda (x)
  312. (set! selection-budget x))
  313. ;; default-getter
  314. ;; Default now is #f so saving is independent of book-level default
  315. (lambda ()
  316. #f)
  317. ;; generate-restore-form
  318. ;; "return 'ascii represention of a function'
  319. ;; that will set the option passed as its lone parameter
  320. ;; to the value it was when the picker was first displayed"
  321. ;;
  322. ;; *This* is used to restore reports, not the KVP -- and is stored as text
  323. ;; This does not run in closure with direct access to the option's
  324. ;; internal variables, so the setter generally gets used
  325. (lambda ()
  326. (string-append
  327. "(lambda (option) "
  328. "(if option ((gnc:option-setter option) "
  329. "(gnc-budget-lookup "
  330. (gnc:value->string (gncBudgetGetGUID selection-budget))
  331. " (gnc-get-current-book)))))"))
  332. ;; scm->kvp -- commit the change
  333. ;; f -- kvp-frame; p -- key-path
  334. (lambda (f p)
  335. (kvp-frame-set-slot-path-gslist
  336. f (gncBudgetGetGUID selection-budget) p))
  337. ;; kvp->scm -- get the stored value
  338. (lambda (f p)
  339. (let ((v (kvp-frame-get-slot-path-gslist f p)))
  340. (if (and v (string? v))
  341. (begin
  342. (set! selection-budget (gnc-budget-lookup v (gnc-get-current-book)))))))
  343. ;; value-validator -- returns (#t value) or (#f "failure message")
  344. ;; As no user-generated input, this legacy hard-wire is probably ok
  345. (lambda (x)
  346. (list #t x))
  347. ;; option-data
  348. #f
  349. ;; option-data-fns -- used for multi-pick (this isn't one), or #f
  350. ;; Vector of five functions
  351. ;; 1) () => number of choices
  352. ;; 2) (n) => key for the nth choice
  353. ;; 3) (n) => string for the nth choice
  354. ;; 4) (n) => description for the nth choice
  355. ;; 5) (key) => n (assuming this is the reverse key lookup)
  356. #f
  357. ;; strings-getter -- list of all translatable strings in the option
  358. #f
  359. ;; options-widget-changed-proc -- callback for what it sounds like
  360. #f
  361. ))) ;; completes gnc:make-budget-option
  362. ;; commodity options use a specialized widget for entering commodities
  363. ;; in the GUI implementation.
  364. (define (gnc:make-commodity-option
  365. section
  366. name
  367. sort-tag
  368. documentation-string
  369. default-value)
  370. (define (commodity->scm commodity)
  371. (if (string? commodity)
  372. (list 'commodity-scm
  373. GNC_COMMODITY_NS_CURRENCY
  374. commodity)
  375. (list 'commodity-scm
  376. (gnc-commodity-get-namespace commodity)
  377. (gnc-commodity-get-mnemonic commodity))))
  378. (define (scm->commodity scm)
  379. (gnc-commodity-table-lookup
  380. (gnc-commodity-table-get-table (gnc-get-current-book))
  381. (cadr scm) (caddr scm)))
  382. (let* ((value (commodity->scm default-value))
  383. (value->string (lambda ()
  384. (string-append "'" (gnc:value->string value)))))
  385. (gnc:make-option
  386. section name sort-tag 'commodity documentation-string
  387. (lambda () (scm->commodity value))
  388. (lambda (x) (if (and (pair? x) (eqv? (car x) 'commodity-scm))
  389. (set! value x)
  390. (set! value (commodity->scm x))))
  391. (lambda () default-value)
  392. (gnc:restore-form-generator value->string)
  393. (lambda (f p)
  394. (kvp-frame-set-slot-path-gslist f (cadr value) (append p '("ns")))
  395. (kvp-frame-set-slot-path-gslist f (caddr value) (append p '("monic"))))
  396. (lambda (f p)
  397. (let ((ns (kvp-frame-get-slot-path-gslist f (append p '("ns"))))
  398. (monic (kvp-frame-get-slot-path-gslist f (append p '("monic")))))
  399. (if (and ns monic (string? ns) (string? monic))
  400. (set! value (list 'commodity-scm ns monic)))))
  401. (lambda (x) (list #t x))
  402. #f #f #f #f)))
  403. (define (gnc:make-simple-boolean-option
  404. section
  405. name
  406. sort-tag
  407. documentation-string
  408. default-value)
  409. (gnc:make-complex-boolean-option section
  410. name
  411. sort-tag
  412. documentation-string
  413. default-value
  414. #f
  415. #f))
  416. ;; Complex boolean options are the same as simple boolean options (see
  417. ;; above), with the addition of two function arguments. (If both of
  418. ;; them are #f, you have exactly a simple-boolean-option.) Both
  419. ;; functions should expect one boolean argument. When the option's
  420. ;; value is changed, the function option-widget-changed-cb will be
  421. ;; called with the new option value at the time that the GUI widget
  422. ;; representing the option is changed, and the function
  423. ;; setter-function-called-cb will be called when the option's setter
  424. ;; is called (that is, when the user selects "OK" or "Apply").
  425. ;; The option-widget-changed-cb is tested for procedurehood before
  426. ;; it is called, so it is not validated to be a procedure here.
  427. ;; However, since there could be an option-widget-changed-cb but not
  428. ;; a setter-function-called-cb, the procedurehood of the
  429. ;; setter-function-called-cb is checked here.
  430. (define (gnc:make-complex-boolean-option
  431. section
  432. name
  433. sort-tag
  434. documentation-string
  435. default-value
  436. setter-function-called-cb
  437. option-widget-changed-cb)
  438. (let* ((value default-value)
  439. (value->string (lambda () (gnc:value->string value))))
  440. (gnc:make-option
  441. section name sort-tag 'boolean documentation-string
  442. (lambda () value)
  443. (lambda (x) (set! value x)
  444. (if (procedure? setter-function-called-cb)
  445. (setter-function-called-cb x)))
  446. (lambda () default-value)
  447. (gnc:restore-form-generator value->string)
  448. (lambda (f p) (kvp-frame-set-slot-path-gslist f
  449. ;; As no boolean KvpValue exists, as a workaround
  450. ;; we store the string "t" for TRUE and "f" for
  451. ;; FALSE in a string KvpValue.
  452. (if value "t" "f")
  453. p))
  454. (lambda (f p)
  455. (let ((v (kvp-frame-get-slot-path-gslist f p)))
  456. ;; As no boolean KvpValue exists, as a workaround we store
  457. ;; the string "t" for TRUE and "f" for FALSE.
  458. (cond ((equal? v "t") (set! v #t))
  459. ((equal? v "f") (set! v #f)))
  460. (if (and v (boolean? v) (not (equal? v default-value)))
  461. (set! value v))))
  462. (lambda (x)
  463. (if (boolean? x)
  464. (list #t x)
  465. (list #f "boolean-option: not a boolean")))
  466. #f #f #f (and option-widget-changed-cb
  467. (lambda (x) (option-widget-changed-cb x))))))
  468. (define (gnc:make-pixmap-option
  469. section name sort-tag doc-string
  470. default-value)
  471. (let* ((value default-value))
  472. (gnc:make-option
  473. section name sort-tag 'pixmap doc-string
  474. (lambda () value)
  475. (lambda (x) (set! value x))
  476. (lambda () default-value)
  477. (gnc:restore-form-generator (lambda () (gnc:value->string value)))
  478. #f
  479. #f
  480. (lambda (x)
  481. (if (string? x)
  482. (begin
  483. (list #t x))
  484. (begin
  485. (list #f "pixmap-option: not a string"))))
  486. #f #f #f #f)))
  487. ;; show-time is boolean
  488. ;; subtype should be one of 'relative 'absolute or 'both
  489. ;; if subtype is 'absolute then relative-date-list should be #f
  490. ;; relative-date-list should be the list of relative dates permitted
  491. ;; gnc:all-relative-dates contains a list of all relative dates.
  492. (define (gnc:make-date-option
  493. section
  494. name
  495. sort-tag
  496. documentation-string
  497. default-getter
  498. show-time
  499. subtype
  500. relative-date-list)
  501. (define (date-legal date)
  502. (and (pair? date)
  503. (or
  504. (and (eq? 'relative (car date)) (symbol? (cdr date)))
  505. (and (eq? 'absolute (car date))
  506. (pair? (cdr date))
  507. (exact? (cadr date))
  508. (exact? (cddr date))))))
  509. (define (list-lookup list item)
  510. (cond
  511. ((null? list) #f)
  512. ((eq? item (car list)) 0)
  513. (else (+ 1 (list-lookup (cdr list) item)))))
  514. (let* ((value (default-getter))
  515. (value->string (lambda ()
  516. (string-append "'" (gnc:value->string value)))))
  517. (gnc:make-option
  518. section name sort-tag 'date documentation-string
  519. (lambda () value)
  520. (lambda (date)
  521. (if (date-legal date)
  522. (set! value date)
  523. (gnc:error "Illegal date value set:" date)))
  524. default-getter
  525. (gnc:restore-form-generator value->string)
  526. (lambda (f p)
  527. (kvp-frame-set-slot-path-gslist f (symbol->string (car value))
  528. (append p '("type")))
  529. (kvp-frame-set-slot-path-gslist f
  530. (if (symbol? (cdr value))
  531. (symbol->string (cdr value))
  532. (cdr value))
  533. (append p '("value"))))
  534. (lambda (f p)
  535. (let ((t (kvp-frame-get-slot-path-gslist f (append p '("type"))))
  536. (v (kvp-frame-get-slot-path-gslist f (append p '("value")))))
  537. (if (and t v (string? t))
  538. (set! value (cons (string->symbol t)
  539. (if (string? v) (string->symbol v) v))))))
  540. (lambda (date)
  541. (if (date-legal date)
  542. (list #t date)
  543. (list #f "date-option: illegal date")))
  544. (vector subtype show-time relative-date-list)
  545. (vector (lambda () (length relative-date-list))
  546. (lambda (x) (list-ref relative-date-list x))
  547. (lambda (x) (gnc:get-relative-date-string
  548. (list-ref relative-date-list x)))
  549. (lambda (x) (gnc:get-relative-date-desc
  550. (list-ref relative-date-list x)))
  551. (lambda (x) (list-lookup relative-date-list x)))
  552. #f
  553. #f)))
  554. (define (gnc:get-rd-option-data-subtype option-data)
  555. (vector-ref option-data 0))
  556. (define (gnc:get-rd-option-data-show-time option-data)
  557. (vector-ref option-data 1))
  558. (define (gnc:get-rd-option-data-rd-list option-data)
  559. (vector-ref option-data 2))
  560. (define (gnc:date-option-get-subtype option)
  561. (if (eq? (gnc:option-type option) 'date)
  562. (gnc:get-rd-option-data-subtype (gnc:option-data option))
  563. (gnc:error "Not a date option")))
  564. (define (gnc:date-option-show-time? option)
  565. (if (eq? (gnc:option-type option) 'date)
  566. (gnc:get-rd-option-data-show-time (gnc:option-data option))
  567. (gnc:error "Not a date option")))
  568. (define (gnc:date-option-value-type option-value)
  569. (car option-value))
  570. (define (gnc:date-option-absolute-time option-value)
  571. (if (eq? (car option-value) 'absolute)
  572. (cdr option-value)
  573. (gnc:get-absolute-from-relative-date (cdr option-value))))
  574. (define (gnc:date-option-relative-time option-value)
  575. (if (eq? (car option-value) 'absolute)
  576. #f
  577. (cdr option-value)))
  578. ;; Just like gnc:make-account-list-limited-option except it
  579. ;; does not limit the types of accounts that are available
  580. ;; to the user.
  581. (define (gnc:make-account-list-option
  582. section
  583. name
  584. sort-tag
  585. documentation-string
  586. default-getter
  587. value-validator
  588. multiple-selection)
  589. (gnc:make-account-list-limited-option
  590. section name sort-tag documentation-string
  591. default-getter value-validator multiple-selection '()))
  592. ;; account-list options use the option-data as a pair; the car is
  593. ;; a boolean value, the cdr is a list of account-types. If the boolean is
  594. ;; true, the gui should allow the user to select multiple accounts.
  595. ;; If the cdr is an empty list, then all account types are shown.
  596. ;; Internally, values are always a list of guids. Externally, both
  597. ;; guids and account pointers may be used to set the value of the
  598. ;; option. The option always returns a list of account pointers.
  599. (define (gnc:make-account-list-limited-option
  600. section
  601. name
  602. sort-tag
  603. documentation-string
  604. default-getter
  605. value-validator
  606. multiple-selection
  607. acct-type-list)
  608. (define (convert-to-guid item)
  609. (if (string? item)
  610. item
  611. (gncAccountGetGUID item)))
  612. (define (convert-to-account item)
  613. (if (string? item)
  614. (xaccAccountLookup item (gnc-get-current-book))
  615. item))
  616. (let* ((option (map convert-to-guid (default-getter)))
  617. (option-set #f)
  618. (getter (lambda () (map convert-to-account
  619. (if option-set
  620. option
  621. (default-getter)))))
  622. (value->string (lambda ()
  623. (string-append
  624. "'" (gnc:value->string (if option-set option #f)))))
  625. (validator
  626. (if (not value-validator)
  627. (lambda (account-list) (list #t account-list))
  628. (lambda (account-list)
  629. (value-validator (map convert-to-account account-list))))))
  630. (gnc:make-option
  631. section name sort-tag 'account-list documentation-string getter
  632. (lambda (account-list)
  633. (if (or (not account-list) (null? account-list))
  634. (set! account-list (default-getter)))
  635. (set! account-list
  636. (filter (lambda (x) (if (string? x)
  637. (xaccAccountLookup
  638. x (gnc-get-current-book))
  639. x)) account-list))
  640. (let* ((result (validator account-list))
  641. (valid (car result))
  642. (value (cadr result)))
  643. (if valid
  644. (begin
  645. (set! option (map convert-to-guid value))
  646. (set! option-set #t))
  647. (gnc:error "Illegal account list value set"))))
  648. (lambda () (map convert-to-account (default-getter)))
  649. (gnc:restore-form-generator value->string)
  650. (lambda (f p)
  651. (define (save-acc list count)
  652. (if (not (null? list))
  653. (let ((key (string-append "acc" (gnc:value->string count))))
  654. (kvp-frame-set-slot-path-gslist f (car list) (append p (list key)))
  655. (save-acc (cdr list) (+ 1 count)))))
  656. (if option-set
  657. (begin
  658. (kvp-frame-set-slot-path-gslist f (length option)
  659. (append p '("len")))
  660. (save-acc option 0))))
  661. (lambda (f p)
  662. (let ((len (kvp-frame-get-slot-path-gslist f (append p '("len")))))
  663. (define (load-acc count)
  664. (if (< count len)
  665. (let* ((key (string-append "acc" (gnc:value->string count)))
  666. (guid (kvp-frame-get-slot-path-gslist
  667. f (append p (list key)))))
  668. (cons guid (load-acc (+ count 1))))
  669. '()))
  670. (if (and len (integer? len))
  671. (begin
  672. (set! option (load-acc 0))
  673. (set! option-set #t)))))
  674. validator
  675. (cons multiple-selection acct-type-list) #f #f #f)))
  676. ;; Just like gnc:make-account-sel-limited-option except it
  677. ;; does not limit the types of accounts that are available
  678. ;; to the user.
  679. (define (gnc:make-account-sel-option
  680. section
  681. name
  682. sort-tag
  683. documentation-string
  684. default-getter
  685. value-validator)
  686. (gnc:make-account-sel-limited-option
  687. section name sort-tag documentation-string
  688. default-getter value-validator '()))
  689. ;; account-sel options use the option-data as a pair; the car is
  690. ;; ignored, the cdr is a list of account-types. If the cdr is an empty
  691. ;; list, then all account types are shown. Internally, the value is
  692. ;; always a guid. Externally, both guids and account pointers may be
  693. ;; used to set the value of the option. The option always returns the
  694. ;; "current" account pointer.
  695. (define (gnc:make-account-sel-limited-option
  696. section
  697. name
  698. sort-tag
  699. documentation-string
  700. default-getter
  701. value-validator
  702. acct-type-list)
  703. (define (convert-to-guid item)
  704. (if (string? item)
  705. item
  706. (gncAccountGetGUID item)))
  707. (define (convert-to-account item)
  708. (if (string? item)
  709. (xaccAccountLookup item (gnc-get-current-book))
  710. item))
  711. (define (find-first-account)
  712. (define (find-first account-list)
  713. (if (null? account-list)
  714. '()
  715. (let* ((this-account (car account-list))
  716. (account-type (xaccAccountGetType this-account)))
  717. (if (if (null? acct-type-list)
  718. #t
  719. (member account-type acct-type-list))
  720. this-account
  721. (find-first (cdr account-list))))))
  722. (let* ((current-root (gnc-get-current-root-account))
  723. (account-list (gnc-account-get-descendants-sorted current-root)))
  724. (find-first account-list)))
  725. (define (get-default)
  726. (if default-getter
  727. (default-getter)
  728. (find-first-account)))
  729. (let* ((option (convert-to-guid (get-default)))
  730. (option-set #f)
  731. (getter (lambda () (convert-to-account
  732. (if option-set
  733. option
  734. (get-default)))))
  735. (value->string (lambda ()
  736. (string-append
  737. "'" (gnc:value->string (if option-set option #f)))))
  738. (validator
  739. (if (not value-validator)
  740. (lambda (account) (list #t account))
  741. (lambda (account)
  742. (value-validator (convert-to-account account))))))
  743. (gnc:make-option
  744. section name sort-tag 'account-sel documentation-string getter
  745. (lambda (account)
  746. (if (or (not account) (null? account)) (set! account (get-default)))
  747. (set! account (convert-to-account account))
  748. (let* ((result (validator account))
  749. (valid (car result))
  750. (value (cadr result)))
  751. (if valid
  752. (begin
  753. (set! option (convert-to-guid value))
  754. (set! option-set #t))
  755. (gnc:error "Illegal account value set"))))
  756. (lambda () (convert-to-account (get-default)))
  757. (gnc:restore-form-generator value->string)
  758. (lambda (f p) (kvp-frame-set-slot-path-gslist f value p))
  759. (lambda (f p)
  760. (let ((v (kvp-frame-get-slot-path-gslist f p)))
  761. (if (and v (string? v))
  762. (set! value v))))
  763. validator
  764. (cons #f acct-type-list) #f #f #f)))
  765. (define (gnc:multichoice-list-lookup list item )
  766. (cond
  767. ((null? list) #f)
  768. ((eq? item (vector-ref (car list) 0)) 0)
  769. (else (+ 1 (gnc:multichoice-list-lookup (cdr list) item)))))
  770. ;; multichoice options use the option-data as a list of vectors.
  771. ;; Each vector contains a permissible value (scheme symbol), a
  772. ;; name, and a description string.
  773. (define (gnc:make-multichoice-option
  774. section
  775. name
  776. sort-tag
  777. documentation-string
  778. default-value
  779. ok-values)
  780. (gnc:make-multichoice-callback-option section
  781. name
  782. sort-tag
  783. documentation-string
  784. default-value
  785. ok-values
  786. #f
  787. #f))
  788. ;; The multichoice-option with callback function is the same as the
  789. ;; usual multichoice options (see above), with the addition of two
  790. ;; function arguments. (If both of them are #f, you have exactly a
  791. ;; multichoice-option.) Both functions should expect one argument.
  792. ;; When the option's value is changed, the function
  793. ;; option-widget-changed-cb will be called with the new option value
  794. ;; at the time that the GUI widget representing the option is changed,
  795. ;; and the function setter-function-called-cb will be called when the
  796. ;; option's setter is called (that is, when the user selects "OK" or
  797. ;; "Apply").
  798. (define (gnc:make-multichoice-callback-option
  799. section
  800. name
  801. sort-tag
  802. documentation-string
  803. default-value
  804. ok-values
  805. setter-function-called-cb
  806. option-widget-changed-cb)
  807. (define (multichoice-legal val p-vals)
  808. (cond ((null? p-vals) #f)
  809. ((eq? val (vector-ref (car p-vals) 0)) #t)
  810. (else (multichoice-legal val (cdr p-vals)))))
  811. (define (multichoice-strings p-vals)
  812. (if (null? p-vals)
  813. '()
  814. (cons (vector-ref (car p-vals) 1)
  815. (cons (vector-ref (car p-vals) 2)
  816. (multichoice-strings (cdr p-vals))))))
  817. (let* ((value default-value)
  818. (value->string (lambda ()
  819. (string-append "'" (gnc:value->string value)))))
  820. (gnc:make-option
  821. section name sort-tag 'multichoice documentation-string
  822. (lambda () value)
  823. (lambda (x)
  824. (if (multichoice-legal x ok-values)
  825. (begin
  826. (set! value x)
  827. (if (procedure? setter-function-called-cb)
  828. (setter-function-called-cb x)))
  829. (gnc:error "Illegal Multichoice option set")))
  830. (lambda () default-value)
  831. (gnc:restore-form-generator value->string)
  832. (lambda (f p) (kvp-frame-set-slot-path-gslist f (symbol->string value) p))
  833. (lambda (f p)
  834. (let ((v (kvp-frame-get-slot-path-gslist f p)))
  835. (if (and v (string? v))
  836. (set! value (string->symbol v)))))
  837. (lambda (x)
  838. (if (multichoice-legal x ok-values)
  839. (list #t x)
  840. (list #f "multichoice-option: illegal choice")))
  841. ok-values
  842. (vector (lambda () (length ok-values))
  843. (lambda (x) (vector-ref (list-ref ok-values x) 0))
  844. (lambda (x) (vector-ref (list-ref ok-values x) 1))
  845. (lambda (x) (vector-ref (list-ref ok-values x) 2))
  846. (lambda (x)
  847. (gnc:multichoice-list-lookup ok-values x)))
  848. (lambda () (multichoice-strings ok-values))
  849. (and option-widget-changed-cb
  850. (lambda (x) (option-widget-changed-cb x))))))
  851. ;; radiobutton options use the option-data as a list of vectors.
  852. ;; Each vector contains a permissible value (scheme symbol), a
  853. ;; name, and a description string.
  854. (define (gnc:make-radiobutton-option
  855. section
  856. name
  857. sort-tag
  858. documentation-string
  859. default-value
  860. ok-values)
  861. (gnc:make-radiobutton-callback-option section
  862. name
  863. sort-tag
  864. documentation-string
  865. default-value
  866. ok-values
  867. #f
  868. #f))
  869. ;; The radiobutton-option with callback function is the same as the
  870. ;; usual radiobutton options (see above), with the addition of two
  871. ;; function arguments. (If both of them are #f, you have exactly a
  872. ;; radiobutton-option.) Both functions should expect one argument.
  873. ;; When the option's value is changed, the function
  874. ;; option-widget-changed-cb will be called with the new option value
  875. ;; at the time that the GUI widget representing the option is changed,
  876. ;; and the function setter-function-called-cb will be called when the
  877. ;; option's setter is called (that is, when the user selects "OK" or
  878. ;; "Apply").
  879. (define (gnc:make-radiobutton-callback-option
  880. section
  881. name
  882. sort-tag
  883. documentation-string
  884. default-value
  885. ok-values
  886. setter-function-called-cb
  887. option-widget-changed-cb)
  888. (define (radiobutton-legal val p-vals)
  889. (cond ((null? p-vals) #f)
  890. ((eq? val (vector-ref (car p-vals) 0)) #t)
  891. (else (radiobutton-legal val (cdr p-vals)))))
  892. (define (radiobutton-strings p-vals)
  893. (if (null? p-vals)
  894. '()
  895. (cons (vector-ref (car p-vals) 1)
  896. (cons (vector-ref (car p-vals) 2)
  897. (radiobutton-strings (cdr p-vals))))))
  898. (let* ((value default-value)
  899. (value->string (lambda ()
  900. (string-append "'" (gnc:value->string value)))))
  901. (gnc:make-option
  902. section name sort-tag 'radiobutton documentation-string
  903. (lambda () value)
  904. (lambda (x)
  905. (if (radiobutton-legal x ok-values)
  906. (begin
  907. (set! value x)
  908. (if (procedure? setter-function-called-cb)
  909. (setter-function-called-cb x)))
  910. (gnc:error "Illegal Radiobutton option set")))
  911. (lambda () default-value)
  912. (gnc:restore-form-generator value->string)
  913. (lambda (f p) (kvp-frame-set-slot-path-gslist f (symbol->string value) p))
  914. (lambda (f p)
  915. (let ((v (kvp-frame-get-slot-path-gslist f p)))
  916. (if (and v (string? v))
  917. (set! value (string->symbol v)))))
  918. (lambda (x)
  919. (if (radiobutton-legal x ok-values)
  920. (list #t x)
  921. (list #f "radiobutton-option: illegal choice")))
  922. ok-values
  923. (vector (lambda () (length ok-values))
  924. (lambda (x) (vector-ref (list-ref ok-values x) 0))
  925. (lambda (x) (vector-ref (list-ref ok-values x) 1))
  926. (lambda (x) (vector-ref (list-ref ok-values x) 2))
  927. (lambda (x)
  928. (gnc:multichoice-list-lookup ok-values x)))
  929. (lambda () (radiobutton-strings ok-values))
  930. (and option-widget-changed-cb
  931. (lambda (x) (option-widget-changed-cb x))))))
  932. ;; list options use the option-data in the same way as multichoice
  933. ;; options. List options allow the user to select more than one option.
  934. (define (gnc:make-list-option
  935. section
  936. name
  937. sort-tag
  938. documentation-string
  939. default-value
  940. ok-values)
  941. (define (legal-value? value legal-values)
  942. (cond ((null? legal-values) #f)
  943. ((eq? value (vector-ref (car legal-values) 0)) #t)
  944. (else (legal-value? value (cdr legal-values)))))
  945. (define (list-legal values)
  946. (cond ((null? values) #t)
  947. (else
  948. (and
  949. (legal-value? (car values) ok-values)
  950. (list-legal (cdr values))))))
  951. (define (list-strings p-vals)
  952. (if (null? p-vals)
  953. '()
  954. (cons (vector-ref (car p-vals) 1)
  955. (cons (vector-ref (car p-vals) 2)
  956. (list-strings (cdr p-vals))))))
  957. (let* ((value default-value)
  958. (value->string (lambda ()
  959. (string-append "'" (gnc:value->string value)))))
  960. (gnc:make-option
  961. section name sort-tag 'list documentation-string
  962. (lambda () value)
  963. (lambda (x)
  964. (if (list-legal x)
  965. (set! value x)
  966. (gnc:error "Illegal list option set")))
  967. (lambda () default-value)
  968. (gnc:restore-form-generator value->string)
  969. (lambda (f p)
  970. (define (save-item list count)
  971. (if (not (null? list))
  972. (let ((key (string-append "item" (gnc:value->string count))))
  973. (kvp-frame-set-slot-path-gslist f (car list) (append p (list key)))
  974. (save-item (cdr list) (+ 1 count)))))
  975. (kvp-frame-set-slot-path-gslist f (length value) (append p '("len")))
  976. (save-item value 0))
  977. (lambda (f p)
  978. (let ((len (kvp-frame-get-slot-path-gslist f (append p '("len")))))
  979. (define (load-item count)
  980. (if (< count len)
  981. (let* ((key (string-append "item" (gnc:value->string count)))
  982. (val (kvp-frame-get-slot-path-gslist
  983. f (append p (list key)))))
  984. (cons val (load-item (+ count 1))))
  985. '()))
  986. (if (and len (integer? len))
  987. (set! value (load-item 0)))))
  988. (lambda (x)
  989. (if (list-legal x)
  990. (list #t x)
  991. (list #f "list-option: illegal value")))
  992. ok-values
  993. (vector (lambda () (length ok-values))
  994. (lambda (x) (vector-ref (list-ref ok-values x) 0))
  995. (lambda (x) (vector-ref (list-ref ok-values x) 1))
  996. (lambda (x) (vector-ref (ref ok-values x) 2))
  997. (lambda (x) (gnc:multichoice-list-lookup ok-values x)))
  998. (lambda () (list-strings ok-values)) #f)))
  999. ;; number range options use the option-data as a list whose
  1000. ;; elements are: (lower-bound upper-bound num-decimals step-size)
  1001. (define (gnc:make-number-range-option
  1002. section
  1003. name
  1004. sort-tag
  1005. documentation-string
  1006. default-value
  1007. lower-bound
  1008. upper-bound
  1009. num-decimals
  1010. step-size)
  1011. (let* ((value default-value)
  1012. (value->string (lambda () (number->string value))))
  1013. (gnc:make-option
  1014. section name sort-tag 'number-range documentation-string
  1015. (lambda () value)
  1016. (lambda (x) (set! value x))
  1017. (lambda () default-value)
  1018. (gnc:restore-form-generator value->string)
  1019. (lambda (f p) (kvp-frame-set-slot-path-gslist f (symbol->string value) p))
  1020. (lambda (f p)
  1021. (let ((v (kvp-frame-get-slot-path-gslist f p)))
  1022. (if (and v (number? v))
  1023. (set! value v))))
  1024. (lambda (x)
  1025. (cond ((not (number? x)) (list #f "number-range-option: not a number"))
  1026. ((and (>= value lower-bound)
  1027. (<= value upper-bound))
  1028. (list #t x))
  1029. (else (list #f "number-range-option: out of range"))))
  1030. (list lower-bound upper-bound num-decimals step-size)
  1031. #f #f #f)))
  1032. (define (gnc:make-internal-option
  1033. section
  1034. name
  1035. default-value)
  1036. (let* ((value default-value)
  1037. (value->string (lambda ()
  1038. (string-append "'" (gnc:value->string value)))))
  1039. (gnc:make-option
  1040. section name "" 'internal #f
  1041. (lambda () value)
  1042. (lambda (x) (set! value x))
  1043. (lambda () default-value)
  1044. (gnc:restore-form-generator value->string)
  1045. #f
  1046. #f
  1047. (lambda (x) (list #t x))
  1048. #f #f #f #f)))
  1049. (define (gnc:make-query-option
  1050. section
  1051. name
  1052. default-value)
  1053. (let* ((value (if (list? default-value)
  1054. default-value
  1055. (gnc-query2scm default-value)))
  1056. (value->string (lambda ()
  1057. (string-append "'" (gnc:value->string value)))))
  1058. (gnc:make-option
  1059. section name "" 'query #f
  1060. (lambda () value)
  1061. (lambda (x) (set! value (if (list? x) x (gnc-query2scm x))))
  1062. (lambda () (if (list? default-value)
  1063. default-value
  1064. (gnc-query2scm default-value)))
  1065. (gnc:restore-form-generator value->string)
  1066. #f
  1067. #f
  1068. (lambda (x) (list #t x))
  1069. #f #f #f #f)))
  1070. ;; Color options store rgba values in a list.
  1071. ;; The option-data is a list, whose first element
  1072. ;; is the range of possible rgba values and whose
  1073. ;; second element is a boolean indicating whether
  1074. ;; to use alpha transparency.
  1075. (define (gnc:make-color-option
  1076. section
  1077. name
  1078. sort-tag
  1079. documentation-string
  1080. default-value
  1081. range
  1082. use-alpha)
  1083. (define (canonicalize values)
  1084. (map exact->inexact values))
  1085. (define (values-in-range values)
  1086. (if (null? values)
  1087. #t
  1088. (let ((value (car values)))
  1089. (and (number? value)
  1090. (>= value 0)
  1091. (<= value range)
  1092. (values-in-range (cdr values))))))
  1093. (define (validate-color color)
  1094. (cond ((not (list? color)) (list #f "color-option: not a list"))
  1095. ((not (= 4 (length color))) (list #f "color-option: wrong length"))
  1096. ((not (values-in-range color))
  1097. (list #f "color-option: bad color values"))
  1098. (else (list #t color))))
  1099. (let* ((value (canonicalize default-value))
  1100. (value->string (lambda ()
  1101. (string-append "'" (gnc:value->string value)))))
  1102. (gnc:make-option
  1103. section name sort-tag 'color documentation-string
  1104. (lambda () value)
  1105. (lambda (x) (set! value (canonicalize x)))
  1106. (lambda () (canonicalize default-value))
  1107. (gnc:restore-form-generator value->string)
  1108. #f
  1109. #f
  1110. validate-color
  1111. (list range use-alpha)
  1112. #f #f #f)))
  1113. (define (gnc:color->hex-string color range)
  1114. (define (html-value value)
  1115. (inexact->exact
  1116. (min 255.0
  1117. (truncate (* (/ 255.0 range) value)))))
  1118. (define (number->hex-string number)
  1119. (let ((ret (number->string number 16)))
  1120. (cond ((< (string-length ret) 2) (string-append "0" ret))
  1121. (else ret))))
  1122. (let ((red (car color))
  1123. (green (cadr color))
  1124. (blue (caddr color)))
  1125. (string-append
  1126. (number->hex-string (html-value red))
  1127. (number->hex-string (html-value green))
  1128. (number->hex-string (html-value blue)))))
  1129. (define (gnc:color->html color range)
  1130. (string-append "#"
  1131. (gnc:color->hex-string color range)))
  1132. (define (gnc:color-option->html color-option)
  1133. (let ((color (gnc:option-value color-option))
  1134. (range (car (gnc:option-data color-option))))
  1135. (gnc:color->html color range)))
  1136. (define (gnc:color-option->hex-string color-option)
  1137. (let ((color (gnc:option-value color-option))
  1138. (range (car (gnc:option-data color-option))))
  1139. (gnc:color->hex-string color range)))
  1140. ;;
  1141. ;; dateformat option
  1142. ;;
  1143. (define (gnc:make-dateformat-option
  1144. section
  1145. name
  1146. sort-tag
  1147. documentation-string
  1148. default-value)
  1149. (define (def-value)
  1150. (if (list? default-value)
  1151. default-value
  1152. '(locale number #t "")))
  1153. (let* ((value (def-value))
  1154. (value->string (lambda ()
  1155. (string-append "'" (gnc:value->string value)))))
  1156. (gnc:make-option
  1157. section name sort-tag 'dateformat documentation-string
  1158. (lambda () value)
  1159. (lambda (x) (set! value x))
  1160. (lambda () (def-value))
  1161. (gnc:restore-form-generator value->string)
  1162. (lambda (f p)
  1163. (kvp-frame-set-slot-path-gslist
  1164. f (symbol->string (car value)) (append p '("fmt")))
  1165. (kvp-frame-set-slot-path-gslist
  1166. f (symbol->string (cadr value)) (append p '("month")))
  1167. (kvp-frame-set-slot-path-gslist
  1168. f (if (caddr value) 1 0) (append p '("years")))
  1169. (kvp-frame-set-slot-path-gslist f (cadddr value) (append p '("custom"))))
  1170. (lambda (f p)
  1171. (let ((fmt (kvp-frame-get-slot-path-gslist f (append p '("fmt"))))
  1172. (month (kvp-frame-get-slot-path-gslist f (append p '("month"))))
  1173. (years (kvp-frame-get-slot-path-gslist f (append p '("years"))))
  1174. (custom (kvp-frame-get-slot-path-gslist f (append p '("custom")))))
  1175. (if (and
  1176. fmt (string? fmt)
  1177. month (string? month)
  1178. years (number? years)
  1179. custom (string? custom))
  1180. (set! value (list (string->symbol fmt) (string->symbol month)
  1181. (if (= years 0) #f #t) custom)))))
  1182. (lambda (x)
  1183. (cond ((not (list? x)) (list #f "dateformat-option: not a list"))
  1184. ((not (= (length x) 4))
  1185. (list #f "dateformat-option: wrong list length" (length x)))
  1186. ((not (symbol? (car x)))
  1187. (list #f "dateformat-option: no format symbol"))
  1188. ((not (symbol? (cadr x)))
  1189. (list #f "dateformat-option: no months symbol"))
  1190. ((not (string? (cadddr x)))
  1191. (list #f "dateformat-option: no custom string"))
  1192. (else (list #t x))))
  1193. #f #f #f #f)))
  1194. (define (gnc:dateformat-get-format v)
  1195. (cadddr v))
  1196. ;; Create a new options database
  1197. (define (gnc:new-options)
  1198. (define option-hash (make-hash-table 23))
  1199. (define options-changed #f)
  1200. (define changed-hash (make-hash-table 23))
  1201. (define callback-hash (make-hash-table 23))
  1202. (define last-callback-id 0)
  1203. (define (lookup-option section name)
  1204. (let ((section-hash (hash-ref option-hash section)))
  1205. (if section-hash
  1206. (let ((option-hash (hash-ref section-hash name)))
  1207. (if option-hash
  1208. option-hash
  1209. ; Option name was not found. Perhaps it was renamed ?
  1210. ; Let's try to map it to a known new name
  1211. (let* ((new-names-list (list
  1212. "Accounts to include" "Accounts"
  1213. "Exclude transactions between selected accounts?" "Exclude transactions between selected accounts"
  1214. "Filter Accounts" "Filter By..."
  1215. "Flatten list to depth limit?" "Flatten list to depth limit"
  1216. "From" "Start Date"
  1217. "Report Accounts" "Accounts"
  1218. "Report Currency" "Report's currency"
  1219. "Show Account Code?" "Show Account Code"
  1220. "Show Full Account Name?" "Show Full Account Name"
  1221. "Show Multi-currency Totals?" "Show Multi-currency Totals"
  1222. "Show zero balance items?" "Show zero balance items"
  1223. "Sign Reverses?" "Sign Reverses"
  1224. "To" "End Date"
  1225. "Use Full Account Name?" "Use Full Account Name"
  1226. "Use Full Other Account Name?" "Use Full Other Account Name"
  1227. "Void Transactions?" "Void Transactions"
  1228. ))
  1229. (name-match (member name new-names-list)))
  1230. (if name-match
  1231. (let ((new-name (cadr name-match)))
  1232. (lookup-option section new-name))
  1233. #f))))
  1234. #f)))
  1235. (define (option-changed section name)
  1236. (set! options-changed #t)
  1237. (let ((section-changed-hash (hash-ref changed-hash section)))
  1238. (if (not section-changed-hash)
  1239. (begin
  1240. (set! section-changed-hash (make-hash-table 23))
  1241. (hash-set! changed-hash section section-changed-hash)))
  1242. (hash-set! section-changed-hash name #t)))
  1243. (define (clear-changes)
  1244. (set! options-changed #f)
  1245. (set! changed-hash (make-hash-table 23)))
  1246. (define (register-option new-option)
  1247. (let* ((name (gnc:option-name new-option))
  1248. (section (gnc:option-sectio

Large files files are truncated, but you can click here to view the full file