From 25e3a16191760bc38f5d85500ef1b9d0a5a8cd03 Mon Sep 17 00:00:00 2001 From: Derek Atkins Date: Mon, 8 Jul 2002 00:13:12 +0000 Subject: [PATCH] * hooks.scm: fix documentation * gnc-file.c: change the open/closed book hooks to take a instead of a string. * binary-import.scm: fix the book-opened-hook. * main-window.scm: fix the book-opened/closed-hook calls * main.scm: fix the book-opened/closed-hook calls git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7095 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 7 +++++ src/app-file/gnc-file.c | 29 ++++++++++++------- src/app-utils/hooks.scm | 4 +-- .../binary-import/binary-import.scm | 8 ++++- src/scm/main-window.scm | 16 +++++----- src/scm/main.scm | 5 ++-- 6 files changed, 47 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index e96d92298e..708d8ac0de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,13 @@ * business-options.scm: Implement the kvp->scm and scm->kvp methods for the business options. + * hooks.scm: fix documentation + * gnc-file.c: change the open/closed book hooks to take a + instead of a string. + * binary-import.scm: fix the book-opened-hook. + * main-window.scm: fix the book-opened/closed-hook calls + * main.scm: fix the book-opened/closed-hook calls + 2002-07-06 Derek Atkins * gw-kvp-spec.scm: wrap kvp_slot_set_slot_path_gslist(), diff --git a/src/app-file/gnc-file.c b/src/app-file/gnc-file.c index 2463053e87..4e8c9408b9 100644 --- a/src/app-file/gnc-file.c +++ b/src/app-file/gnc-file.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "Backend.h" #include "global-options.h" @@ -250,10 +251,12 @@ gnc_add_history (GNCSession * session) static void gnc_book_opened (void) { - /* FIXME: when we drop support older guiles, drop the (char *) coercion. */ gh_call2 (gh_eval_str("gnc:hook-run-danglers"), gh_eval_str("gnc:*book-opened-hook*"), - gh_str02scm((char *) gnc_session_get_url(current_session))); + (current_session ? + gw_wcp_assimilate_ptr (current_session, + gh_eval_str("")) : + SCM_BOOL_F)); } void @@ -272,10 +275,11 @@ gnc_file_new (void) * disable events so we don't get spammed by redraws. */ gnc_engine_suspend_events (); - /* FIXME: when we drop support older guiles, drop the (char *) coercion. */ gh_call2(gh_eval_str("gnc:hook-run-danglers"), gh_eval_str("gnc:*book-closed-hook*"), - gh_str02scm((char *) gnc_session_get_url(session))); + (session ? + gw_wcp_assimilate_ptr (session, gh_eval_str("")) : + SCM_BOOL_F)); gnc_session_destroy (session); current_session = NULL; @@ -359,10 +363,12 @@ gnc_post_file_open (const char * filename) /* -------------- BEGIN CORE SESSION CODE ------------- */ /* -- this code is almost identical in FileOpen and FileSaveAs -- */ - /* FIXME: when we drop support older guiles, drop the (char *) coercion. */ gh_call2(gh_eval_str("gnc:hook-run-danglers"), gh_eval_str("gnc:*book-closed-hook*"), - gh_str02scm((char *) gnc_session_get_url(current_session))); + (current_session ? + gw_wcp_assimilate_ptr (current_session, + gh_eval_str("")) : + SCM_BOOL_F)); gnc_session_destroy (current_session); current_session = NULL; @@ -569,9 +575,11 @@ gnc_file_save (void) gnc_book_mark_saved (gnc_session_get_book (session)); /* save the main window state */ - /* FIXME: when we drop support older guiles, drop the (char *) coercion. */ gh_call1 (gh_eval_str("gnc:main-window-save-state"), - gh_str02scm((char *) gnc_session_get_url(current_session))); + (current_session ? + gw_wcp_assimilate_ptr (current_session, + gh_eval_str("")) : + SCM_BOOL_F)); LEAVE (" "); } @@ -700,10 +708,11 @@ gnc_file_quit (void) * transactions during shutdown would cause massive redraws */ gnc_engine_suspend_events (); - /* FIXME: when we drop support older guiles, drop the (char *) coercion. */ gh_call2(gh_eval_str("gnc:hook-run-danglers"), gh_eval_str("gnc:*book-closed-hook*"), - gh_str02scm((char *) gnc_session_get_url(session))); + (session ? + gw_wcp_assimilate_ptr (session, gh_eval_str("")) : + SCM_BOOL_F)); gnc_session_destroy (session); current_session = NULL; diff --git a/src/app-utils/hooks.scm b/src/app-utils/hooks.scm index 2cfd0561f4..c1056d3f32 100644 --- a/src/app-utils/hooks.scm +++ b/src/app-utils/hooks.scm @@ -96,7 +96,7 @@ (define gnc:*book-opened-hook* (gnc:hook-define 'book-opened-hook - "Run after book open. Hook args: book URL.")) + "Run after book open. Hook args: .")) (define gnc:*new-book-hook* (gnc:hook-define @@ -106,7 +106,7 @@ (define gnc:*book-closed-hook* (gnc:hook-define 'book-closed-hook - "Run before file close. Hook args: book URL")) + "Run before file close. Hook args: ")) (define gnc:*report-hook* (gnc:hook-define diff --git a/src/import-export/binary-import/binary-import.scm b/src/import-export/binary-import/binary-import.scm index 093a5182b4..d941fd93c9 100644 --- a/src/import-export/binary-import/binary-import.scm +++ b/src/import-export/binary-import/binary-import.scm @@ -2,5 +2,11 @@ (define-module (gnucash import-export binary-import)) (use-modules (g-wrapped gw-binary-import)) (use-modules (gnucash app-utils)) +(use-modules (gnucash gnc-module)) +(gnc:module-load "gnucash/engine" 0) -(gnc:hook-add-dangler gnc:*book-opened-hook* gnc:import-legacy-commodities) +(define (import-commodities session) + (let ((book-url (gnc:session-get-url session))) + (gnc:import-legacy-commodities book-url))) + +(gnc:hook-add-dangler gnc:*book-opened-hook* import-commodities) diff --git a/src/scm/main-window.scm b/src/scm/main-window.scm index 612f248365..778a015efe 100644 --- a/src/scm/main-window.scm +++ b/src/scm/main-window.scm @@ -118,8 +118,9 @@ the account instead of opening a register.") #f)) ;; book close. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(define (gnc:main-window-save-state book-url) - (let* ((conf-file-name (gnc:html-encode-string book-url)) +(define (gnc:main-window-save-state session) + (let* ((book-url (gnc:session-get-url session)) + (conf-file-name (gnc:html-encode-string book-url)) (dotgnucash-dir (build-path (getenv "HOME") ".gnucash")) (file-dir (build-path dotgnucash-dir "books")) (save-file? #f) @@ -151,8 +152,8 @@ the account instead of opening a register.") #f)) (force-output))) (gnc:mdi-save (gnc:mdi-get-current) book-url))))) -(define (gnc:main-window-book-close-handler book-url) - (gnc:main-window-save-state book-url) +(define (gnc:main-window-book-close-handler session) + (gnc:main-window-save-state session) (let ((dead-reports '())) ;; get a list of the reports we'll be needing to nuke @@ -168,7 +169,7 @@ the account instead of opening a register.") #f)) (hash-remove! *gnc:_reports_* dr)) dead-reports))) -(define (gnc:main-window-book-open-handler book-url) +(define (gnc:main-window-book-open-handler session) (define (try-load file-suffix) (let ((file (build-path (getenv "HOME") ".gnucash" "books" file-suffix))) ;; make sure the books directory is there @@ -178,8 +179,9 @@ the account instead of opening a register.") #f)) (gnc:warn "failure loading " file) #f)) #f))) - (let ((conf-file-name (gnc:html-encode-string book-url)) - (dead-reports '())) + (let* ((book-url (gnc:session-get-url session)) + (conf-file-name (gnc:html-encode-string book-url)) + (dead-reports '())) (if conf-file-name (try-load conf-file-name)) (gnc:mdi-restore (gnc:mdi-get-current) book-url))) diff --git a/src/scm/main.scm b/src/scm/main.scm index ffe40fb8e9..a73a334b1b 100644 --- a/src/scm/main.scm +++ b/src/scm/main.scm @@ -401,12 +401,13 @@ string and 'directories' must be a list of strings." (set-current-module original-module)) (gnc:hook-add-dangler gnc:*book-opened-hook* - (lambda (file) + (lambda (session) (if ((gnc:option-getter (gnc:lookup-global-option "Scheduled Transactions" "Run on GnuCash start" ))) - (gnc:sx-since-last-run-wrapper file)))) + (gnc:sx-since-last-run-wrapper + (gnc:session-get-url session))))) (gnc:hook-add-dangler gnc:*new-book-hook* (lambda ()