diff --git a/src/app-file/gnc-file.c b/src/app-file/gnc-file.c index ea7c952791..f2356c2db1 100644 --- a/src/app-file/gnc-file.c +++ b/src/app-file/gnc-file.c @@ -237,6 +237,14 @@ gnc_add_history (GNCBook *book) g_free (url); } +static void +gnc_book_opened (void) +{ + gh_call2 (gh_eval_str("gnc:hook-run-danglers"), + gh_eval_str("gnc:*book-opened-hook*"), + gh_str02scm(gnc_book_get_url(current_book))); +} + void gnc_file_new (void) { @@ -255,7 +263,7 @@ gnc_file_new (void) gh_call2(gh_eval_str("gnc:hook-run-danglers"), gh_eval_str("gnc:*book-closed-hook*"), - gh_str02scm(gnc_book_get_url(book))); + gh_str02scm(gnc_book_get_url(book))); gnc_book_destroy (book); current_book = NULL; @@ -265,18 +273,10 @@ gnc_file_new (void) /* start a new book */ gnc_get_current_book_internal (); - if(gnc_lookup_boolean_option("General", - "No account list setup on new file", - TRUE)) - { - gh_call2(gh_eval_str("gnc:hook-run-danglers"), - gh_eval_str("gnc:*book-opened-hook*"), - gh_str02scm(gnc_book_get_url(current_book))); - } - else - { - gnc_ui_hierarchy_druid (); - } + gh_call1(gh_eval_str("gnc:hook-run-danglers"), + gh_eval_str("gnc:*new-book-hook*")); + + gnc_book_opened (); gnc_engine_resume_events (); gnc_gui_refresh_all (); @@ -451,9 +451,7 @@ gnc_post_file_open (const char * filename) gnc_engine_resume_events (); gnc_gui_refresh_all (); - gh_call2(gh_eval_str("gnc:hook-run-danglers"), - gh_eval_str("gnc:*book-opened-hook*"), - gh_str02scm(gnc_book_get_url(current_book))); + gnc_book_opened (); return FALSE; } @@ -462,9 +460,7 @@ gnc_post_file_open (const char * filename) /* close up the old file session (if any) */ current_book = new_book; - gh_call2(gh_eval_str("gnc:hook-run-danglers"), - gh_eval_str("gnc:*book-opened-hook*"), - gh_str02scm(gnc_book_get_url(current_book))); + gnc_book_opened (); /* --------------- END CORE SESSION CODE -------------- */ diff --git a/src/app-utils/app-utils.scm b/src/app-utils/app-utils.scm index 08a4e90bdb..2b034d06b9 100644 --- a/src/app-utils/app-utils.scm +++ b/src/app-utils/app-utils.scm @@ -225,6 +225,7 @@ (export gnc:*ui-startup-hook*) (export gnc:*ui-shutdown-hook*) (export gnc:*book-opened-hook*) +(export gnc:*new-book-hook*) (export gnc:*book-closed-hook*) ;; utilities diff --git a/src/app-utils/hooks.scm b/src/app-utils/hooks.scm index 7e9b820e86..c2b8d42a82 100644 --- a/src/app-utils/hooks.scm +++ b/src/app-utils/hooks.scm @@ -98,6 +98,11 @@ 'book-opened-hook "Run after book open. Hook args: book URL.")) +(define gnc:*new-book-hook* + (gnc:hook-define + 'new-book-hook + "Run after a new (empty) book is opened, before the book-opened-hook. Hook args: ()")) + (define gnc:*book-closed-hook* (gnc:hook-define 'book-closed-hook diff --git a/src/gnc-ui.h b/src/gnc-ui.h index 1a34183a5d..6a37f9b381 100644 --- a/src/gnc-ui.h +++ b/src/gnc-ui.h @@ -102,9 +102,6 @@ gboolean gnc_get_username_password (gncUIWidget parent, char **username, char **password); -void gnc_ui_new_user_dialog (void); -void gnc_ui_hierarchy_druid (void); - /* Managing the GUI Windows *****************************************/ void gnc_ui_shutdown (void); diff --git a/src/gnome/dialog-new-user.c b/src/gnome/dialog-new-user.c index 0c11653313..093def16f4 100644 --- a/src/gnome/dialog-new-user.c +++ b/src/gnome/dialog-new-user.c @@ -124,6 +124,5 @@ gnc_ui_new_user_cancel_dialog (void) void gncp_new_user_finish (void) { - gh_eval_str("(gnc:show-main-window)"); gh_eval_str("(gnc:hook-run-danglers gnc:*book-opened-hook* #f)"); } diff --git a/src/gnome/top-level.c b/src/gnome/top-level.c index 3f6ba43f54..e63a7d99f7 100644 --- a/src/gnome/top-level.c +++ b/src/gnome/top-level.c @@ -605,19 +605,6 @@ gnc_ui_destroy (void) /* ============================================================== */ -int -gnc_ui_show_main_window (void) -{ - /* Initialize gnome */ - gnucash_ui_init(); - - /* Get the main window on screen. */ - while (gtk_events_pending()) - gtk_main_iteration(); - - return 0; -} - static gboolean gnc_ui_check_events (gpointer not_used) { diff --git a/src/gnome/top-level.h b/src/gnome/top-level.h index 8c3946ad09..7d9a65440a 100644 --- a/src/gnome/top-level.h +++ b/src/gnome/top-level.h @@ -35,7 +35,6 @@ gboolean gnucash_ui_open_file(const char * name); GNCMainInfo * gnc_ui_get_data(void); void gnc_ui_shutdown(void); void gnc_ui_destroy(void); -int gnc_ui_show_main_window(void); int gnc_ui_start_event_loop(void); gboolean gnc_reverse_balance_type(GNCAccountType type); gboolean gnc_reverse_balance(Account *account); diff --git a/src/scm/main-window.scm b/src/scm/main-window.scm index c802f41468..91e0484c19 100644 --- a/src/scm/main-window.scm +++ b/src/scm/main-window.scm @@ -188,11 +188,3 @@ the account instead of opening a register.") #f)) gnc:main-window-book-open-handler) (gnc:hook-add-dangler gnc:*book-closed-hook* gnc:main-window-book-close-handler) - -(gnc:hook-add-dangler gnc:*book-opened-hook* - (lambda (file) - (if ((gnc:option-getter - (gnc:lookup-global-option - (N_ "Scheduled Transactions") - (N_ "Run on GnuCash start" )))) - (gnc:sx-since-last-run-wrapper file))) ) diff --git a/src/scm/main.scm b/src/scm/main.scm index 9a855b7f44..f16d096173 100644 --- a/src/scm/main.scm +++ b/src/scm/main.scm @@ -168,6 +168,22 @@ (gnc:depend "price-quotes.scm") (gnc:depend "tip-of-the-day.scm") + (gnc:hook-add-dangler gnc:*book-opened-hook* + (lambda (file) + (if ((gnc:option-getter + (gnc:lookup-global-option + "Scheduled Transactions" + "Run on GnuCash start" ))) + (gnc:sx-since-last-run-wrapper file)))) + + (gnc:hook-add-dangler gnc:*new-book-hook* + (lambda () + (let ((option (gnc:lookup-global-option + "General" + "No account list setup on new file"))) + (if (and option (not (gnc:option-value option))) + (gnc:ui-hierarchy-druid))))) + (if (not (gnc:handle-command-line-args)) (gnc:shutdown 1)) @@ -259,7 +275,6 @@ (if (null? gnc:*batch-mode-things-to-do*) ;; We're not in batch mode; we can go ahead and do the normal thing. (begin - ;; (gnc:load-account-file) (gnc:hook-add-dangler gnc:*ui-shutdown-hook* gnc:ui-finish) (gnc:ui-init) (if (and @@ -267,13 +282,9 @@ (not (string? (gnc:history-get-last))) (gnc:option-value (gnc:lookup-global-option "__new_user" "first_startup"))) - (begin - (gnc:new-user-dialog) - (gnc:start-ui-event-loop)) - (begin - (gnc:load-account-file) - (gnc:show-main-window) - (gnc:start-ui-event-loop))) + (gnc:new-user-dialog) + (gnc:load-account-file)) + (gnc:start-ui-event-loop) (gnc:hook-remove-dangler gnc:*ui-shutdown-hook* gnc:ui-finish)) ;; else: we're in batch mode. Just do what the user said on the