diff --git a/ChangeLog b/ChangeLog index 7adfab36af..cd290a2936 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2004-06-18 Christian Stimming + + * src/scm/main-window.scm, src/scm/main.scm: Added example Menu + item "File -> Save all reports" that will call the new report + saving function for all reports. Reports are appended to + ~/.gnucash/saved-reports-1.8 . This would need more work so that + not all reports are saved but only the currently selected one -- + any volunteer may feel free to add that. + + * src/report/report-system/report.scm, report-system.scm: Added + gnc:report-generate-saved-forms that will generate the scheme code + necessary to create a new report from the saved options of an old + report (merged from 1-8-branch). + 2004-06-18 Derek Atkins * src/scm/paths.scm: create gnc:current-saved-reports, as diff --git a/src/report/report-system/report-system.scm b/src/report/report-system/report-system.scm index 0dfe3f4e86..dae7afe23c 100644 --- a/src/report/report-system/report-system.scm +++ b/src/report/report-system/report-system.scm @@ -105,6 +105,7 @@ (export *gnc:_reports_*) (export gnc:report-template-new-options/name) (export gnc:report-template-menu-name/name) +(export gnc:report-template-renderer/name) (export gnc:report-template-new-options) (export gnc:report-template-version) (export gnc:report-template-name) @@ -146,6 +147,7 @@ (export gnc:find-report) (export gnc:find-report-template) (export gnc:report-generate-restore-forms) +(export gnc:report-generate-saved-forms) (export gnc:report-render-html) (export gnc:report-run) (export gnc:report-templates-for-each) diff --git a/src/report/report-system/report.scm b/src/report/report-system/report.scm index 95a130ec5c..a539b1f173 100644 --- a/src/report/report-system/report.scm +++ b/src/report/report-system/report.scm @@ -135,6 +135,12 @@ (gnc:report-template-name templ)) #f))) +(define (gnc:report-template-renderer/name template-name) + (let ((templ (hash-ref *gnc:_report-templates_* template-name))) + (if templ + (gnc:report-template-renderer templ) + #f))) + (define (gnc:report-template-new-options report-template) (let ((generator (gnc:report-template-options-generator report-template)) (namer @@ -353,6 +359,31 @@ #f " (gnc:restore-report ~S ~S options))\n" (gnc:report-id report) (gnc:report-type report)))) +(define (gnc:report-generate-saved-forms report) + ;; clean up the options if necessary. this is only needed + ;; in special cases. + (let* ((template + (hash-ref *gnc:_report-templates_* + (gnc:report-type report))) + (thunk (gnc:report-template-options-cleanup-cb template))) + (if thunk + (thunk report))) + + ;; save them + (string-append + ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n" + (simple-format #f ";; Options for saved report ~S, based on template ~S\n" + (gnc:report-name report) (gnc:report-type report)) + (simple-format + #f "(let ()\n (define (options-gen)\n (let ((options (gnc:report-template-new-options/name ~S)))\n" + (gnc:report-type report)) + (gnc:generate-restore-forms (gnc:report-options report) "options") + " options))\n" + (simple-format + #f " (gnc:define-report \n 'version 1\n 'name ~S\n 'options-generator options-gen\n 'renderer (gnc:report-template-renderer/name ~S)))\n\n" + (gnc:report-name report) + (gnc:report-type report)))) + (define (gnc:report-render-html report headers?) (if (and (not (gnc:report-dirty? report)) (gnc:report-ctext report)) diff --git a/src/scm/main-window.scm b/src/scm/main-window.scm index 7d3183e081..a61d5a3853 100644 --- a/src/scm/main-window.scm +++ b/src/scm/main-window.scm @@ -162,6 +162,18 @@ the account instead of opening a register.") #f)) (force-output))) (gnc:mdi-save (gnc:mdi-get-current) book-url))))) +(define (gnc:main-window-save-report) + (let ((conf-file-name gnc:current-saved-reports)) + ;;(display conf-file-name) + (with-output-to-port (open-file conf-file-name "a") + (lambda () + (hash-fold + (lambda (k v p) + (display + (gnc:report-generate-saved-forms v))) + #t *gnc:_reports_*) + (force-output))))) + (define (gnc:main-window-book-close-handler session) (gnc:main-window-save-state session) diff --git a/src/scm/main.scm b/src/scm/main.scm index 939176eccb..7f544495ba 100644 --- a/src/scm/main.scm +++ b/src/scm/main.scm @@ -78,6 +78,7 @@ (export gnc:make-new-acct-tree-window) (export gnc:free-acct-tree-window) (export gnc:main-window-save-state) +(export gnc:main-window-save-report) ;; from printing/print-check.scm (export make-print-check-format) @@ -508,6 +509,15 @@ string and 'directories' must be a list of strings." (lambda () (gnc:main-window-open-report (gnc:make-welcome-report) #f)))) + ;; The "save current report" entry + (gnc:add-extension + (gnc:make-menu-item + (N_ "_Save all current reports") + (N_ "Save all the current report in ~/.gnucash/saved-reports-1.8 so that they are accessible as menu entries in the report menu. Effects are only visible at next startup of gnucash.") + (list gnc:window-name-main "_File" "_Export") + (lambda () + (gnc:main-window-save-report)))) + (gnc:hook-run-danglers gnc:*startup-hook*) (if (gnc:config-var-value-get gnc:*loglevel*)